2 extends DialogicSettingsPage
4 var autopause_sets := {}
6 const _SETTING_LETTER_SPEED := 'dialogic/text/letter_speed'
8 const _SETTING_INPUT_ACTION := 'dialogic/text/input_action'
10 const _SETTING_TEXT_REVEAL_SKIPPABLE := 'dialogic/text/initial_text_reveal_skippable'
11 const _SETTING_TEXT_REVEAL_SKIPPABLE_DELAY := 'dialogic/text/text_reveal_skip_delay'
12 const _SETTING_TEXT_ADVANCE_DELAY := 'dialogic/text/advance_delay'
14 const _SETTING_AUTOCOLOR_NAMES := 'dialogic/text/autocolor_names'
15 const _SETTING_SPLIT_AT_NEW_LINES := 'dialogic/text/split_at_new_lines'
16 const _SETTING_SPLIT_AT_NEW_LINES_AS := 'dialogic/text/split_at_new_lines_as'
18 const _SETTING_AUTOSKIP_TIME_PER_EVENT := 'dialogic/text/autoskip_time_per_event'
20 const _SETTING_AUTOADVANCE_ENABLED := 'dialogic/text/autoadvance_enabled'
21 const _SETTING_AUTOADVANCE_FIXED_DELAY := 'dialogic/text/autoadvance_fixed_delay'
22 const _SETTING_AUTOADVANCE_WORD_DELAY := 'dialogic/text/autoadvance_per_word_delay'
23 const _SETTING_AUTOADVANCE_CHARACTER_DELAY := 'dialogic/text/autoadvance_per_character_delay'
24 const _SETTING_AUTOADVANCE_IGNORED_CHARACTERS_ENABLED := 'dialogic/text/autoadvance_ignored_characters_enabled'
25 const _SETTING_AUTOADVANCE_IGNORED_CHARACTERS := 'dialogic/text/autoadvance_ignored_characters'
27 const _SETTING_ABSOLUTE_AUTOPAUSES := 'dialogic/text/absolute_autopauses'
28 const _SETTING_AUTOPAUSES := 'dialogic/text/autopauses'
31 func _get_priority() -> int:
35 func _get_title() -> String:
39 func _ready() -> void:
40 %DefaultSpeed.value_changed.connect(_on_float_set.bind(_SETTING_LETTER_SPEED))
42 %Skippable.toggled.connect(_on_bool_set.bind(_SETTING_TEXT_REVEAL_SKIPPABLE))
43 %SkippableDelay.value_changed.connect(_on_float_set.bind(_SETTING_TEXT_REVEAL_SKIPPABLE_DELAY))
44 %AdvanceDelay.value_changed.connect(_on_float_set.bind(_SETTING_TEXT_ADVANCE_DELAY))
46 %AutocolorNames.toggled.connect(_on_bool_set.bind(_SETTING_AUTOCOLOR_NAMES))
48 %NewEvents.toggled.connect(_on_bool_set.bind(_SETTING_SPLIT_AT_NEW_LINES))
50 %AutoAdvance.toggled.connect(_on_bool_set.bind(_SETTING_AUTOADVANCE_ENABLED))
51 %FixedDelay.value_changed.connect(_on_float_set.bind(_SETTING_AUTOADVANCE_FIXED_DELAY))
52 %IgnoredCharactersEnabled.toggled.connect(_on_bool_set.bind(_SETTING_AUTOADVANCE_IGNORED_CHARACTERS_ENABLED))
54 %AutoskipTimePerEvent.value_changed.connect(_on_float_set.bind(_SETTING_AUTOSKIP_TIME_PER_EVENT))
56 %AutoPausesAbsolute.toggled.connect(_on_bool_set.bind(_SETTING_ABSOLUTE_AUTOPAUSES))
59 func _refresh() -> void:
61 %DefaultSpeed.value = ProjectSettings.get_setting(_SETTING_LETTER_SPEED, 0.01)
63 %InputAction.resource_icon = get_theme_icon(&"Mouse", &"EditorIcons")
64 %InputAction.set_value(ProjectSettings.get_setting(_SETTING_INPUT_ACTION, &'dialogic_default_action'))
65 %InputAction.get_suggestions_func = suggest_actions
67 %Skippable.button_pressed = ProjectSettings.get_setting(_SETTING_TEXT_REVEAL_SKIPPABLE, true)
68 %SkippableDelay.value = ProjectSettings.get_setting(_SETTING_TEXT_REVEAL_SKIPPABLE_DELAY, 0.1)
69 %AdvanceDelay.value = ProjectSettings.get_setting(_SETTING_TEXT_ADVANCE_DELAY, 0.1)
71 %AutocolorNames.button_pressed = ProjectSettings.get_setting(_SETTING_AUTOCOLOR_NAMES, false)
73 %NewEvents.button_pressed = ProjectSettings.get_setting(_SETTING_SPLIT_AT_NEW_LINES, false)
74 %NewEventOption.select(ProjectSettings.get_setting(_SETTING_SPLIT_AT_NEW_LINES_AS, 0))
77 %AutoAdvance.button_pressed = ProjectSettings.get_setting(_SETTING_AUTOADVANCE_ENABLED, false)
78 %FixedDelay.value = ProjectSettings.get_setting(_SETTING_AUTOADVANCE_FIXED_DELAY, 1)
80 var per_character_delay: float = ProjectSettings.get_setting(_SETTING_AUTOADVANCE_CHARACTER_DELAY, 0.1)
81 var per_word_delay: float = ProjectSettings.get_setting(_SETTING_AUTOADVANCE_WORD_DELAY, 0)
82 if per_character_delay == 0 and per_word_delay == 0:
83 _on_additional_delay_mode_item_selected(0)
84 elif per_word_delay == 0:
85 _on_additional_delay_mode_item_selected(2, per_character_delay)
87 _on_additional_delay_mode_item_selected(1, per_word_delay)
89 %IgnoredCharactersEnabled.button_pressed = ProjectSettings.get_setting(_SETTING_AUTOADVANCE_IGNORED_CHARACTERS_ENABLED, true)
90 var ignored_characters: String = ''
91 var ignored_characters_dict: Dictionary = ProjectSettings.get_setting(_SETTING_AUTOADVANCE_IGNORED_CHARACTERS, {})
92 for ignored_character in ignored_characters_dict.keys():
93 ignored_characters += ignored_character
94 %IgnoredCharacters.text = ignored_characters
97 %AutoskipTimePerEvent.value = ProjectSettings.get_setting(_SETTING_AUTOSKIP_TIME_PER_EVENT, 0.1)
100 %AutoPausesAbsolute.button_pressed = ProjectSettings.get_setting(_SETTING_ABSOLUTE_AUTOPAUSES, false)
101 load_autopauses(ProjectSettings.get_setting(_SETTING_AUTOPAUSES, {}))
104 func _about_to_close() -> void:
108 func _on_bool_set(button_pressed:bool, setting:String) -> void:
109 ProjectSettings.set_setting(setting, button_pressed)
110 ProjectSettings.save()
113 func _on_float_set(value:float, setting:String) -> void:
114 ProjectSettings.set_setting(setting, value)
115 ProjectSettings.save()
119 ################################################################################
121 func _on_InputAction_value_changed(property_name:String, value:String) -> void:
122 ProjectSettings.set_setting(_SETTING_INPUT_ACTION, value)
123 ProjectSettings.save()
125 func suggest_actions(search:String) -> Dictionary:
127 for prop in ProjectSettings.get_property_list():
128 if prop.name.begins_with('input/') and not prop.name.begins_with('input/ui_') :
129 suggs[prop.name.trim_prefix('input/')] = {'value':prop.name.trim_prefix('input/')}
133 func _on_new_event_option_item_selected(index:int) -> void:
134 ProjectSettings.set_setting(_SETTING_SPLIT_AT_NEW_LINES_AS, index)
135 ProjectSettings.save()
140 ################################################################################
142 func _on_additional_delay_mode_item_selected(index:int, delay:float=-1) -> void:
143 %AdditionalDelayMode.selected = index
146 %AdditionalDelay.hide()
147 %AutoadvanceIgnoreCharacters.hide()
148 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_WORD_DELAY, 0)
149 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_CHARACTER_DELAY, 0)
151 %AdditionalDelay.show()
152 %AutoadvanceIgnoreCharacters.hide()
154 %AdditionalDelay.value = delay
156 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_WORD_DELAY, %AdditionalDelay.value)
157 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_CHARACTER_DELAY, 0)
159 %AdditionalDelay.show()
160 %AutoadvanceIgnoreCharacters.show()
162 %AdditionalDelay.value = delay
164 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_CHARACTER_DELAY, %AdditionalDelay.value)
165 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_WORD_DELAY, 0)
166 ProjectSettings.save()
169 func _on_additional_delay_value_changed(value:float) -> void:
170 match %AdditionalDelayMode.selected:
172 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_CHARACTER_DELAY, 0)
173 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_WORD_DELAY, 0)
175 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_WORD_DELAY, value)
177 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_CHARACTER_DELAY, value)
178 ProjectSettings.save()
181 func _on_IgnoredCharacters_text_changed(text_input):
182 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_IGNORED_CHARACTERS, DialogicUtil.str_to_hash_set(text_input))
183 ProjectSettings.save()
189 ################################################################################
191 func load_autopauses(dictionary:Dictionary) -> void:
192 for i in %AutoPauseSets.get_children():
196 for i in dictionary.keys():
197 add_autopause_set(i, dictionary[i])
200 func save_autopauses() -> void:
202 for i in autopause_sets:
203 if is_instance_valid(autopause_sets[i].time):
204 dictionary[autopause_sets[i].text.text] = autopause_sets[i].time.value
205 ProjectSettings.set_setting(_SETTING_AUTOPAUSES, dictionary)
206 ProjectSettings.save()
209 func _on_add_autopauses_set_pressed() -> void:
210 add_autopause_set('', 0.1)
213 func add_autopause_set(text: String, time: float) -> void:
215 var line_edit := LineEdit.new()
216 line_edit.size_flags_horizontal = Control.SIZE_EXPAND_FILL
217 line_edit.placeholder_text = 'e.g. "?!.,;:"'
218 line_edit.text = text
219 info['text'] = line_edit
220 %AutoPauseSets.add_child(line_edit)
221 var spin_box := SpinBox.new()
222 spin_box.min_value = 0.1
224 spin_box.value = time
225 info['time'] = spin_box
226 %AutoPauseSets.add_child(spin_box)
228 var remove_btn := Button.new()
229 remove_btn.icon = get_theme_icon(&'Remove', &'EditorIcons')
230 remove_btn.pressed.connect(_on_remove_autopauses_set_pressed.bind(len(autopause_sets)))
231 info['delete'] = remove_btn
232 %AutoPauseSets.add_child(remove_btn)
233 autopause_sets[len(autopause_sets)] = info
236 func _on_remove_autopauses_set_pressed(index: int) -> void:
237 for key in autopause_sets[index]:
238 autopause_sets[index][key].queue_free()
239 autopause_sets.erase(index)