]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/DefaultLayoutParts/Layer_History/history_layer.gd
Squashed commit of the following:
[wolf-seeking-sheep.git] / addons / dialogic / Modules / DefaultLayoutParts / Layer_History / history_layer.gd
1 @tool
2 extends DialogicLayoutLayer
3
4 ## Example scene for viewing the History
5 ## Implements most of the visual options from 1.x History mode
6
7 @export_group('Look')
8 @export_subgroup('Font')
9 @export var font_use_global_size: bool = true
10 @export var font_custom_size: int = 15
11 @export var font_use_global_fonts: bool = true
12 @export_file('*.ttf', '*.tres') var font_custom_normal: String = ""
13 @export_file('*.ttf', '*.tres') var font_custom_bold: String = ""
14 @export_file('*.ttf', '*.tres') var font_custom_italics: String = ""
15
16 @export_subgroup('Buttons')
17 @export var show_open_button: bool = true
18 @export var show_close_button: bool = true
19
20 @export_group('Settings')
21 @export_subgroup('Events')
22 @export var show_all_choices: bool = true
23 @export var show_join_and_leave: bool = true
24
25 @export_subgroup('Behaviour')
26 @export var scroll_to_bottom: bool = true
27 @export var show_name_colors: bool = true
28 @export var name_delimeter: String = ": "
29
30 var scroll_to_bottom_flag: bool = false
31
32 @export_group('Private')
33 @export var HistoryItem: PackedScene = null
34
35 var history_item_theme: Theme = null
36
37 func get_show_history_button() -> Button:
38         return $ShowHistory
39
40
41 func get_hide_history_button() -> Button:
42         return $HideHistory
43
44
45 func get_history_box() -> ScrollContainer:
46         return %HistoryBox
47
48
49 func get_history_log() -> VBoxContainer:
50         return %HistoryLog
51
52
53 func _ready() -> void:
54         if Engine.is_editor_hint():
55                 return
56         DialogicUtil.autoload().History.open_requested.connect(_on_show_history_pressed)
57         DialogicUtil.autoload().History.close_requested.connect(_on_hide_history_pressed)
58
59
60 func _apply_export_overrides() -> void:
61         var history_subsystem: Node = DialogicUtil.autoload().get(&'History')
62         if history_subsystem != null:
63                 get_show_history_button().visible = show_open_button and history_subsystem.get(&'simple_history_enabled')
64         else:
65                 set(&'visible', false)
66
67         history_item_theme = Theme.new()
68
69         if font_use_global_size:
70                 history_item_theme.default_font_size = get_global_setting(&'font_size', font_custom_size)
71         else:
72                 history_item_theme.default_font_size = font_custom_size
73
74         if font_use_global_fonts and ResourceLoader.exists(get_global_setting(&'font', '') as String):
75                 history_item_theme.default_font = load(get_global_setting(&'font', '') as String) as Font
76         elif ResourceLoader.exists(font_custom_normal):
77                 history_item_theme.default_font = load(font_custom_normal)
78
79         if ResourceLoader.exists(font_custom_bold):
80                 history_item_theme.set_font(&'RichtTextLabel', &'bold_font', load(font_custom_bold) as Font)
81         if ResourceLoader.exists(font_custom_italics):
82                 history_item_theme.set_font(&'RichtTextLabel', &'italics_font', load(font_custom_italics) as Font)
83
84
85
86 func _process(_delta : float) -> void:
87         if Engine.is_editor_hint():
88                 return
89         if scroll_to_bottom_flag and get_history_box().visible and get_history_log().get_child_count():
90                 await get_tree().process_frame
91                 get_history_box().ensure_control_visible(get_history_log().get_children()[-1] as Control)
92                 scroll_to_bottom_flag = false
93
94
95 func _on_show_history_pressed() -> void:
96         DialogicUtil.autoload().paused = true
97         show_history()
98
99
100 func show_history() -> void:
101         for child: Node in get_history_log().get_children():
102                 child.queue_free()
103
104         var history_subsystem: Node = DialogicUtil.autoload().get(&'History')
105         for info: Dictionary in history_subsystem.call(&'get_simple_history'):
106                 var history_item : Node = HistoryItem.instantiate()
107                 history_item.set(&'theme', history_item_theme)
108                 match info.event_type:
109                         "Text":
110                                 if info.has('character') and info['character']:
111                                         if show_name_colors:
112                                                 history_item.call(&'load_info', info['text'], info['character']+name_delimeter, info['character_color'])
113                                         else:
114                                                 history_item.call(&'load_info', info['text'], info['character']+name_delimeter)
115                                 else:
116                                         history_item.call(&'load_info', info['text'])
117                         "Character":
118                                 if !show_join_and_leave:
119                                         history_item.queue_free()
120                                         continue
121                                 history_item.call(&'load_info', '[i]'+info['text'])
122                         "Choice":
123                                 var choices_text: String = ""
124                                 if show_all_choices:
125                                         for i : String in info['all_choices']:
126                                                 if i.ends_with('#disabled'):
127                                                         choices_text += "-  [i]("+i.trim_suffix('#disabled')+")[/i]\n"
128                                                 elif i == info['text']:
129                                                         choices_text += "-> [b]"+i+"[/b]\n"
130                                                 else:
131                                                         choices_text += "-> "+i+"\n"
132                                 else:
133                                         choices_text += "- [b]"+info['text']+"[/b]\n"
134                                 history_item.call(&'load_info', choices_text)
135
136                 get_history_log().add_child(history_item)
137
138         if scroll_to_bottom:
139                 scroll_to_bottom_flag = true
140
141         get_show_history_button().hide()
142         get_hide_history_button().visible = show_close_button
143         get_history_box().show()
144
145
146 func _on_hide_history_pressed() -> void:
147         DialogicUtil.autoload().paused = false
148         get_history_box().hide()
149         get_hide_history_button().hide()
150         var history_subsystem: Node = DialogicUtil.autoload().get(&'History')
151         get_show_history_button().visible = show_open_button and history_subsystem.get(&'simple_history_enabled')