2 extends DialogicLayoutLayer
4 ## Example scene for viewing the History
5 ## Implements most of the visual options from 1.x History mode
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 = ""
16 @export_subgroup('Buttons')
17 @export var show_open_button: bool = true
18 @export var show_close_button: bool = true
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
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 = ": "
30 var scroll_to_bottom_flag: bool = false
32 @export_group('Private')
33 @export var HistoryItem: PackedScene = null
35 var history_item_theme: Theme = null
37 func get_show_history_button() -> Button:
41 func get_hide_history_button() -> Button:
45 func get_history_box() -> ScrollContainer:
49 func get_history_log() -> VBoxContainer:
53 func _ready() -> void:
54 if Engine.is_editor_hint():
56 DialogicUtil.autoload().History.open_requested.connect(_on_show_history_pressed)
57 DialogicUtil.autoload().History.close_requested.connect(_on_hide_history_pressed)
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')
65 set(&'visible', false)
67 history_item_theme = Theme.new()
69 if font_use_global_size:
70 history_item_theme.default_font_size = get_global_setting(&'font_size', font_custom_size)
72 history_item_theme.default_font_size = font_custom_size
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)
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)
86 func _process(_delta : float) -> void:
87 if Engine.is_editor_hint():
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
95 func _on_show_history_pressed() -> void:
96 DialogicUtil.autoload().paused = true
100 func show_history() -> void:
101 for child: Node in get_history_log().get_children():
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:
110 if info.has('character') and info['character']:
112 history_item.call(&'load_info', info['text'], info['character']+name_delimeter, info['character_color'])
114 history_item.call(&'load_info', info['text'], info['character']+name_delimeter)
116 history_item.call(&'load_info', info['text'])
118 if !show_join_and_leave:
119 history_item.queue_free()
121 history_item.call(&'load_info', '[i]'+info['text'])
123 var choices_text: String = ""
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"
131 choices_text += "-> "+i+"\n"
133 choices_text += "- [b]"+info['text']+"[/b]\n"
134 history_item.call(&'load_info', choices_text)
136 get_history_log().add_child(history_item)
139 scroll_to_bottom_flag = true
141 get_show_history_button().hide()
142 get_hide_history_button().visible = show_close_button
143 get_history_box().show()
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')