Skip to content

Commit 451872d

Browse files
Add autopausing-capability (#1518)
* Add autopausing-capability Adds autopausing for certain letters. The sets of letters can be changed in the DialogText settings page. The autopausing is done as a modifier that adds [pause] effects after these letters. A regex is used so letters inside of [brackets] or {brackets} are not altered. This is mainly important for the dot (.). * Remove label settings
1 parent 68fd097 commit 451872d

File tree

4 files changed

+126
-69
lines changed

4 files changed

+126
-69
lines changed

addons/dialogic/Events/Text/index.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func _get_text_effects() -> Array[Dictionary]:
3131

3232
func _get_text_modifiers() -> Array[Dictionary]:
3333
return [
34+
{'subsystem':'Text', 'method':'modifier_autopauses'},
3435
{'subsystem':'Text', 'method':'modifier_random_selection'},
3536
{'subsystem':'Text', 'method':"modifier_break", 'command':'br'},
36-
3737
]

addons/dialogic/Events/Text/settings_text.gd

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ func refresh():
1212
%InputAction.resource_icon = get_theme_icon("Mouse", "EditorIcons")
1313
%InputAction.set_value(DialogicUtil.get_project_setting('dialogic/text/input_action', 'dialogic_default_action'))
1414
%InputAction.get_suggestions_func = suggest_actions
15+
load_autopauses(DialogicUtil.get_project_setting('dialogic/text/autopauses', {}))
1516

1617

18+
func _about_to_close():
19+
save_autopauses()
20+
1721
func _on_AutocontinueDelay_value_changed(value):
1822
ProjectSettings.set_setting('dialogic/text/autocontinue_delay', value)
1923
ProjectSettings.save()
@@ -38,8 +42,8 @@ func _on_InputAction_value_changed(property_name, value):
3842
ProjectSettings.set_setting('dialogic/text/input_action', value)
3943
ProjectSettings.save()
4044

41-
func suggest_actions(search):
42-
var suggs = {}
45+
func suggest_actions(search:String) -> Dictionary:
46+
var suggs := {}
4347
for prop in ProjectSettings.get_property_list():
4448
if prop.name.begins_with('input/'):
4549
suggs[prop.name.trim_prefix('input/')] = {'value':prop.name.trim_prefix('input/')}
@@ -49,3 +53,41 @@ func suggest_actions(search):
4953
func _on_AutocolorNames_toggled(button_pressed):
5054
ProjectSettings.set_setting('dialogic/text/autocolor_names', button_pressed)
5155
ProjectSettings.save()
56+
57+
58+
func load_autopauses(dictionary:Dictionary) -> void:
59+
for i in %AutoPauseSets.get_children():
60+
if i.get_index() != 0:
61+
i.queue_free()
62+
63+
for i in dictionary.keys():
64+
add_autopause_set(i, dictionary[i])
65+
66+
67+
func save_autopauses() -> void:
68+
var dictionary := {}
69+
for i in %AutoPauseSets.get_children():
70+
if i.get_index() != 0:
71+
if i.get_child(0).text:
72+
dictionary[i.get_child(0).text] = i.get_child(1).value
73+
ProjectSettings.set_setting('dialogic/text/autopauses', dictionary)
74+
ProjectSettings.save()
75+
76+
77+
func _on_add_autopauses_set_pressed():
78+
add_autopause_set('', 0.1)
79+
80+
81+
func add_autopause_set(text:String, time:float) -> void:
82+
var hbox := HBoxContainer.new()
83+
%AutoPauseSets.add_child(hbox)
84+
var line_edit := LineEdit.new()
85+
line_edit.size_flags_horizontal = Control.SIZE_EXPAND_FILL
86+
line_edit.placeholder_text = 'e.g. "?!.,;:"'
87+
line_edit.text = text
88+
hbox.add_child(line_edit)
89+
var spin_box := SpinBox.new()
90+
spin_box.min_value = 0.1
91+
spin_box.step = 0.01
92+
spin_box.value = time
93+
hbox.add_child(spin_box)
Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
[gd_scene load_steps=6 format=3]
1+
[gd_scene load_steps=7 format=3 uid="uid://t5w26hs6gisl"]
22

33
[ext_resource type="Script" path="res://addons/dialogic/Events/Text/settings_text.gd" id="2"]
44
[ext_resource type="PackedScene" uid="uid://dpwhshre1n4t6" path="res://addons/dialogic/Editor/Events/Fields/ComplexPicker.tscn" id="3"]
5+
[ext_resource type="Script" path="res://addons/dialogic/Editor/Settings/HintLabelStylingScript.gd" id="3_wiy0g"]
56

67
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_oy8x6"]
78
content_margin_left = 5.0
@@ -15,148 +16,146 @@ bg_color = Color(0.545098, 0.545098, 0.545098, 0.211765)
1516
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_mamwx"]
1617

1718
[node name="DialogText" type="HBoxContainer"]
19+
anchors_preset = 15
1820
anchor_right = 1.0
1921
anchor_bottom = 1.0
2022
script = ExtResource("2")
2123

2224
[node name="VBoxContainer" type="VBoxContainer" parent="."]
23-
offset_right = 506.0
24-
offset_bottom = 600.0
25+
layout_mode = 2
2526
size_flags_horizontal = 3
2627

2728
[node name="Title" type="Label" parent="VBoxContainer"]
28-
offset_right = 506.0
29-
offset_bottom = 36.0
29+
layout_mode = 2
3030
theme_override_styles/normal = SubResource("StyleBoxFlat_oy8x6")
3131
text = "Dialog Text Settings"
3232

3333
[node name="DefaultSpeed" type="HBoxContainer" parent="VBoxContainer"]
34-
offset_top = 40.0
35-
offset_right = 506.0
36-
offset_bottom = 71.0
34+
layout_mode = 2
3735

3836
[node name="Label" type="Label" parent="VBoxContainer/DefaultSpeed"]
39-
offset_top = 2.0
40-
offset_right = 419.0
41-
offset_bottom = 28.0
37+
layout_mode = 2
4238
size_flags_horizontal = 3
4339
text = "Default speed"
4440

4541
[node name="DefaultSpeed" type="SpinBox" parent="VBoxContainer/DefaultSpeed"]
4642
unique_name_in_owner = true
47-
offset_left = 423.0
48-
offset_right = 506.0
49-
offset_bottom = 31.0
43+
layout_mode = 2
5044
step = 0.001
5145

5246
[node name="InputAction" type="HBoxContainer" parent="VBoxContainer"]
53-
offset_top = 75.0
54-
offset_right = 506.0
55-
offset_bottom = 108.0
47+
layout_mode = 2
5648

5749
[node name="Label2" type="Label" parent="VBoxContainer/InputAction"]
58-
offset_top = 3.0
59-
offset_right = 302.0
60-
offset_bottom = 29.0
50+
layout_mode = 2
6151
size_flags_horizontal = 3
6252
text = "Input action"
6353

6454
[node name="InputAction" parent="VBoxContainer/InputAction" instance=ExtResource("3")]
6555
unique_name_in_owner = true
66-
anchor_right = 0.0
67-
anchor_bottom = 0.0
68-
offset_left = 306.0
69-
offset_right = 506.0
70-
offset_bottom = 33.0
56+
layout_mode = 2
7157

7258
[node name="Skippable" type="HBoxContainer" parent="VBoxContainer"]
73-
offset_top = 112.0
74-
offset_right = 506.0
75-
offset_bottom = 138.0
59+
layout_mode = 2
7660

7761
[node name="Label3" type="Label" parent="VBoxContainer/Skippable"]
78-
offset_right = 478.0
79-
offset_bottom = 26.0
62+
layout_mode = 2
8063
size_flags_horizontal = 3
8164
text = "Skippable"
8265

8366
[node name="Skippable" type="CheckBox" parent="VBoxContainer/Skippable"]
8467
unique_name_in_owner = true
85-
offset_left = 482.0
86-
offset_right = 506.0
87-
offset_bottom = 26.0
68+
layout_mode = 2
8869

8970
[node name="ColorNames" type="HBoxContainer" parent="VBoxContainer"]
90-
offset_top = 142.0
91-
offset_right = 506.0
92-
offset_bottom = 168.0
71+
layout_mode = 2
9372

9473
[node name="Label4" type="Label" parent="VBoxContainer/ColorNames"]
95-
offset_right = 478.0
96-
offset_bottom = 26.0
74+
layout_mode = 2
9775
size_flags_horizontal = 3
9876
text = "Autocolor names"
9977

10078
[node name="AutocolorNames" type="CheckBox" parent="VBoxContainer/ColorNames"]
10179
unique_name_in_owner = true
102-
offset_left = 482.0
103-
offset_right = 506.0
104-
offset_bottom = 26.0
80+
layout_mode = 2
10581

10682
[node name="AutoContinue" type="HBoxContainer" parent="VBoxContainer"]
107-
offset_top = 172.0
108-
offset_right = 506.0
109-
offset_bottom = 203.0
83+
layout_mode = 2
11084

11185
[node name="Label5" type="Label" parent="VBoxContainer/AutoContinue"]
112-
offset_top = 2.0
113-
offset_right = 391.0
114-
offset_bottom = 28.0
86+
layout_mode = 2
11587
size_flags_horizontal = 3
11688
text = "Autocontinue"
11789

11890
[node name="Autocontinue" type="CheckBox" parent="VBoxContainer/AutoContinue"]
11991
unique_name_in_owner = true
120-
offset_left = 395.0
121-
offset_right = 419.0
122-
offset_bottom = 31.0
92+
layout_mode = 2
12393

12494
[node name="AutocontinueDelay" type="SpinBox" parent="VBoxContainer/AutoContinue"]
12595
unique_name_in_owner = true
126-
offset_left = 423.0
127-
offset_right = 506.0
128-
offset_bottom = 31.0
96+
layout_mode = 2
12997
step = 0.01
13098
suffix = "s"
13199

100+
[node name="Title2" type="Label" parent="VBoxContainer"]
101+
layout_mode = 2
102+
theme_override_styles/normal = SubResource("StyleBoxFlat_oy8x6")
103+
text = "Auto-Pauses"
104+
105+
[node name="AutoPauseSets" type="VBoxContainer" parent="VBoxContainer"]
106+
unique_name_in_owner = true
107+
layout_mode = 2
108+
109+
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/AutoPauseSets"]
110+
layout_mode = 2
111+
112+
[node name="Label6" type="Label" parent="VBoxContainer/AutoPauseSets/HBoxContainer"]
113+
layout_mode = 2
114+
size_flags_horizontal = 3
115+
text = "Adds pauses after certain letters."
116+
script = ExtResource("3_wiy0g")
117+
118+
[node name="Add" type="Button" parent="VBoxContainer/AutoPauseSets/HBoxContainer"]
119+
layout_mode = 2
120+
size_flags_horizontal = 8
121+
text = "Add set"
122+
123+
[node name="AutoPauses1" type="HBoxContainer" parent="VBoxContainer/AutoPauseSets"]
124+
layout_mode = 2
125+
126+
[node name="Letters" type="LineEdit" parent="VBoxContainer/AutoPauseSets/AutoPauses1"]
127+
layout_mode = 2
128+
size_flags_horizontal = 3
129+
placeholder_text = "e.g. \"?!,.:;\""
130+
131+
[node name="PauseTime" type="SpinBox" parent="VBoxContainer/AutoPauseSets/AutoPauses1"]
132+
unique_name_in_owner = true
133+
layout_mode = 2
134+
min_value = 0.1
135+
step = 0.01
136+
value = 0.1
137+
suffix = "s"
138+
132139
[node name="VSeparator" type="VSeparator" parent="."]
133-
offset_left = 510.0
134-
offset_right = 514.0
135-
offset_bottom = 600.0
140+
layout_mode = 2
136141

137142
[node name="VBoxContainer2" type="VBoxContainer" parent="."]
138-
offset_left = 518.0
139-
offset_right = 1024.0
140-
offset_bottom = 600.0
143+
layout_mode = 2
141144
size_flags_horizontal = 3
142145

143146
[node name="Title" type="Label" parent="VBoxContainer2"]
144-
offset_right = 506.0
145-
offset_bottom = 36.0
147+
layout_mode = 2
146148
theme_override_styles/normal = SubResource("StyleBoxFlat_oy8x6")
147149
text = "Tipps and tricks:"
148150

149151
[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer2"]
150-
offset_top = 40.0
151-
offset_right = 506.0
152-
offset_bottom = 600.0
152+
layout_mode = 2
153153
size_flags_vertical = 3
154154
horizontal_scroll_mode = 0
155155

156156
[node name="Info" type="RichTextLabel" parent="VBoxContainer2/ScrollContainer"]
157157
unique_name_in_owner = true
158-
offset_right = 506.0
159-
offset_bottom = 560.0
158+
layout_mode = 2
160159
size_flags_horizontal = 3
161160
size_flags_vertical = 3
162161
theme_override_colors/default_color = Color(1, 1, 1, 0.611765)
@@ -181,3 +180,4 @@ Learn more about bbcode in the official godot docs."
181180
[connection signal="toggled" from="VBoxContainer/ColorNames/AutocolorNames" to="." method="_on_AutocolorNames_toggled"]
182181
[connection signal="toggled" from="VBoxContainer/AutoContinue/Autocontinue" to="." method="_on_Autocontinue_toggled"]
183182
[connection signal="value_changed" from="VBoxContainer/AutoContinue/AutocontinueDelay" to="." method="_on_AutocontinueDelay_value_changed"]
183+
[connection signal="pressed" from="VBoxContainer/AutoPauseSets/HBoxContainer/Add" to="." method="_on_add_autopauses_set_pressed"]

addons/dialogic/Events/Text/subsystem_text.gd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var text_modifiers := []
1919

2020
var input_handler_node :Node = null
2121

22+
var autopauses := {}
2223

2324
####################################################################################################
2425
## STATE
@@ -275,6 +276,11 @@ func _ready():
275276
collect_text_modifiers()
276277
Dialogic.event_handled.connect(hide_next_indicators)
277278
input_handler_node = Node.new()
279+
autopauses = {}
280+
var autopause_data :Dictionary= ProjectSettings.get_setting('dialogic/text/autopauses', {})
281+
for i in autopause_data.keys():
282+
autopauses[RegEx.create_from_string('(?<!(\\[|\\{))['+i+'](?![\\w\\s]*[\\]\\}])')] = autopause_data[i]
283+
278284
input_handler_node.set_script(load(get_script().resource_path.get_base_dir().path_join('default_input_handler.gd')))
279285
add_child(input_handler_node)
280286

@@ -371,3 +377,12 @@ func modifier_random_selection(text:String) -> String:
371377

372378
func modifier_break(text:String) -> String:
373379
return text.replace('[br]', '\n')
380+
381+
382+
func modifier_autopauses(text:String) -> String:
383+
for i in autopauses.keys():
384+
var offset := 0
385+
for result in i.search_all(text):
386+
text = text.insert(result.get_end()+offset, '[pause='+str(autopauses[i])+']')
387+
offset += len('[pause='+str(autopauses[i])+']')
388+
return text

0 commit comments

Comments
 (0)