]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Text/settings_text.gd
Adding import files
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Text / settings_text.gd
1 @tool
2 extends DialogicSettingsPage
3
4 var autopause_sets := {}
5
6 const _SETTING_LETTER_SPEED := 'dialogic/text/letter_speed'
7
8 const _SETTING_INPUT_ACTION := 'dialogic/text/input_action'
9
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'
13
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'
17
18 const _SETTING_AUTOSKIP_TIME_PER_EVENT          := 'dialogic/text/autoskip_time_per_event'
19
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'
26
27 const _SETTING_ABSOLUTE_AUTOPAUSES      := 'dialogic/text/absolute_autopauses'
28 const _SETTING_AUTOPAUSES       := 'dialogic/text/autopauses'
29
30
31 func _get_priority() -> int:
32         return 98
33
34
35 func _get_title() -> String:
36         return "Text"
37
38
39 func _ready() -> void:
40         %DefaultSpeed.value_changed.connect(_on_float_set.bind(_SETTING_LETTER_SPEED))
41
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))
45
46         %AutocolorNames.toggled.connect(_on_bool_set.bind(_SETTING_AUTOCOLOR_NAMES))
47
48         %NewEvents.toggled.connect(_on_bool_set.bind(_SETTING_SPLIT_AT_NEW_LINES))
49
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))
53
54         %AutoskipTimePerEvent.value_changed.connect(_on_float_set.bind(_SETTING_AUTOSKIP_TIME_PER_EVENT))
55
56         %AutoPausesAbsolute.toggled.connect(_on_bool_set.bind(_SETTING_ABSOLUTE_AUTOPAUSES))
57
58
59 func _refresh() -> void:
60         ## BEHAVIOUR
61         %DefaultSpeed.value = ProjectSettings.get_setting(_SETTING_LETTER_SPEED, 0.01)
62
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
66
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)
70
71         %AutocolorNames.button_pressed = ProjectSettings.get_setting(_SETTING_AUTOCOLOR_NAMES, false)
72
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))
75
76         ## AUTO-ADVANCE
77         %AutoAdvance.button_pressed = ProjectSettings.get_setting(_SETTING_AUTOADVANCE_ENABLED, false)
78         %FixedDelay.value = ProjectSettings.get_setting(_SETTING_AUTOADVANCE_FIXED_DELAY, 1)
79
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)
86         else:
87                 _on_additional_delay_mode_item_selected(1, per_word_delay)
88
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
95
96         ## AUTO-SKIP
97         %AutoskipTimePerEvent.value = ProjectSettings.get_setting(_SETTING_AUTOSKIP_TIME_PER_EVENT, 0.1)
98
99         ## AUTO-PAUSES
100         %AutoPausesAbsolute.button_pressed = ProjectSettings.get_setting(_SETTING_ABSOLUTE_AUTOPAUSES, false)
101         load_autopauses(ProjectSettings.get_setting(_SETTING_AUTOPAUSES, {}))
102
103
104 func _about_to_close() -> void:
105         save_autopauses()
106
107
108 func _on_bool_set(button_pressed:bool, setting:String) -> void:
109         ProjectSettings.set_setting(setting, button_pressed)
110         ProjectSettings.save()
111
112
113 func _on_float_set(value:float, setting:String) -> void:
114         ProjectSettings.set_setting(setting, value)
115         ProjectSettings.save()
116
117
118 #region BEHAVIOUR
119 ################################################################################
120
121 func _on_InputAction_value_changed(property_name:String, value:String) -> void:
122         ProjectSettings.set_setting(_SETTING_INPUT_ACTION, value)
123         ProjectSettings.save()
124
125 func suggest_actions(search:String) -> Dictionary:
126         var suggs := {}
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/')}
130         return suggs
131
132
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()
136
137 #endregion
138
139 #region AUTO-ADVANCE
140 ################################################################################
141
142 func _on_additional_delay_mode_item_selected(index:int, delay:float=-1) -> void:
143         %AdditionalDelayMode.selected = index
144         match index:
145                 0: # NONE
146                         %AdditionalDelay.hide()
147                         %AutoadvanceIgnoreCharacters.hide()
148                         ProjectSettings.set_setting(_SETTING_AUTOADVANCE_WORD_DELAY, 0)
149                         ProjectSettings.set_setting(_SETTING_AUTOADVANCE_CHARACTER_DELAY, 0)
150                 1: # PER WORD
151                         %AdditionalDelay.show()
152                         %AutoadvanceIgnoreCharacters.hide()
153                         if delay != -1:
154                                 %AdditionalDelay.value = delay
155                         else:
156                                 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_WORD_DELAY, %AdditionalDelay.value)
157                                 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_CHARACTER_DELAY, 0)
158                 2: # PER CHARACTER
159                         %AdditionalDelay.show()
160                         %AutoadvanceIgnoreCharacters.show()
161                         if delay != -1:
162                                 %AdditionalDelay.value = delay
163                         else:
164                                 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_CHARACTER_DELAY, %AdditionalDelay.value)
165                                 ProjectSettings.set_setting(_SETTING_AUTOADVANCE_WORD_DELAY, 0)
166         ProjectSettings.save()
167
168
169 func _on_additional_delay_value_changed(value:float) -> void:
170         match %AdditionalDelayMode.selected:
171                 0: # NONE
172                         ProjectSettings.set_setting(_SETTING_AUTOADVANCE_CHARACTER_DELAY, 0)
173                         ProjectSettings.set_setting(_SETTING_AUTOADVANCE_WORD_DELAY, 0)
174                 1: # PER WORD
175                         ProjectSettings.set_setting(_SETTING_AUTOADVANCE_WORD_DELAY, value)
176                 2: # PER CHARACTER
177                         ProjectSettings.set_setting(_SETTING_AUTOADVANCE_CHARACTER_DELAY, value)
178         ProjectSettings.save()
179
180
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()
184
185 #endregion
186
187
188 ## AUTO-PAUSES
189 ################################################################################
190
191 func load_autopauses(dictionary:Dictionary) -> void:
192         for i in %AutoPauseSets.get_children():
193                 i.queue_free()
194
195
196         for i in dictionary.keys():
197                 add_autopause_set(i, dictionary[i])
198
199
200 func save_autopauses() -> void:
201         var dictionary := {}
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()
207
208
209 func _on_add_autopauses_set_pressed() -> void:
210         add_autopause_set('', 0.1)
211
212
213 func add_autopause_set(text: String, time: float) -> void:
214         var info := {}
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
223         spin_box.step = 0.01
224         spin_box.value = time
225         info['time'] = spin_box
226         %AutoPauseSets.add_child(spin_box)
227
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
234
235
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)
240