diff --git a/addons/dialogic/Events/Text/index.gd b/addons/dialogic/Events/Text/index.gd index d7312118b..5c27c999b 100644 --- a/addons/dialogic/Events/Text/index.gd +++ b/addons/dialogic/Events/Text/index.gd @@ -31,7 +31,7 @@ func _get_text_effects() -> Array[Dictionary]: func _get_text_modifiers() -> Array[Dictionary]: return [ + {'subsystem':'Text', 'method':'modifier_autopauses'}, {'subsystem':'Text', 'method':'modifier_random_selection'}, {'subsystem':'Text', 'method':"modifier_break", 'command':'br'}, - ] diff --git a/addons/dialogic/Events/Text/settings_text.gd b/addons/dialogic/Events/Text/settings_text.gd index 8541fe4bb..1dd34a6ee 100644 --- a/addons/dialogic/Events/Text/settings_text.gd +++ b/addons/dialogic/Events/Text/settings_text.gd @@ -12,8 +12,12 @@ func refresh(): %InputAction.resource_icon = get_theme_icon("Mouse", "EditorIcons") %InputAction.set_value(DialogicUtil.get_project_setting('dialogic/text/input_action', 'dialogic_default_action')) %InputAction.get_suggestions_func = suggest_actions + load_autopauses(DialogicUtil.get_project_setting('dialogic/text/autopauses', {})) +func _about_to_close(): + save_autopauses() + func _on_AutocontinueDelay_value_changed(value): ProjectSettings.set_setting('dialogic/text/autocontinue_delay', value) ProjectSettings.save() @@ -38,8 +42,8 @@ func _on_InputAction_value_changed(property_name, value): ProjectSettings.set_setting('dialogic/text/input_action', value) ProjectSettings.save() -func suggest_actions(search): - var suggs = {} +func suggest_actions(search:String) -> Dictionary: + var suggs := {} for prop in ProjectSettings.get_property_list(): if prop.name.begins_with('input/'): suggs[prop.name.trim_prefix('input/')] = {'value':prop.name.trim_prefix('input/')} @@ -49,3 +53,41 @@ func suggest_actions(search): func _on_AutocolorNames_toggled(button_pressed): ProjectSettings.set_setting('dialogic/text/autocolor_names', button_pressed) ProjectSettings.save() + + +func load_autopauses(dictionary:Dictionary) -> void: + for i in %AutoPauseSets.get_children(): + if i.get_index() != 0: + i.queue_free() + + for i in dictionary.keys(): + add_autopause_set(i, dictionary[i]) + + +func save_autopauses() -> void: + var dictionary := {} + for i in %AutoPauseSets.get_children(): + if i.get_index() != 0: + if i.get_child(0).text: + dictionary[i.get_child(0).text] = i.get_child(1).value + ProjectSettings.set_setting('dialogic/text/autopauses', dictionary) + ProjectSettings.save() + + +func _on_add_autopauses_set_pressed(): + add_autopause_set('', 0.1) + + +func add_autopause_set(text:String, time:float) -> void: + var hbox := HBoxContainer.new() + %AutoPauseSets.add_child(hbox) + var line_edit := LineEdit.new() + line_edit.size_flags_horizontal = Control.SIZE_EXPAND_FILL + line_edit.placeholder_text = 'e.g. "?!.,;:"' + line_edit.text = text + hbox.add_child(line_edit) + var spin_box := SpinBox.new() + spin_box.min_value = 0.1 + spin_box.step = 0.01 + spin_box.value = time + hbox.add_child(spin_box) diff --git a/addons/dialogic/Events/Text/settings_text.tscn b/addons/dialogic/Events/Text/settings_text.tscn index e9a8bb39f..73fb068f6 100644 --- a/addons/dialogic/Events/Text/settings_text.tscn +++ b/addons/dialogic/Events/Text/settings_text.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=6 format=3] +[gd_scene load_steps=7 format=3 uid="uid://t5w26hs6gisl"] [ext_resource type="Script" path="res://addons/dialogic/Events/Text/settings_text.gd" id="2"] [ext_resource type="PackedScene" uid="uid://dpwhshre1n4t6" path="res://addons/dialogic/Editor/Events/Fields/ComplexPicker.tscn" id="3"] +[ext_resource type="Script" path="res://addons/dialogic/Editor/Settings/HintLabelStylingScript.gd" id="3_wiy0g"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_oy8x6"] content_margin_left = 5.0 @@ -15,148 +16,146 @@ bg_color = Color(0.545098, 0.545098, 0.545098, 0.211765) [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_mamwx"] [node name="DialogText" type="HBoxContainer"] +anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 script = ExtResource("2") [node name="VBoxContainer" type="VBoxContainer" parent="."] -offset_right = 506.0 -offset_bottom = 600.0 +layout_mode = 2 size_flags_horizontal = 3 [node name="Title" type="Label" parent="VBoxContainer"] -offset_right = 506.0 -offset_bottom = 36.0 +layout_mode = 2 theme_override_styles/normal = SubResource("StyleBoxFlat_oy8x6") text = "Dialog Text Settings" [node name="DefaultSpeed" type="HBoxContainer" parent="VBoxContainer"] -offset_top = 40.0 -offset_right = 506.0 -offset_bottom = 71.0 +layout_mode = 2 [node name="Label" type="Label" parent="VBoxContainer/DefaultSpeed"] -offset_top = 2.0 -offset_right = 419.0 -offset_bottom = 28.0 +layout_mode = 2 size_flags_horizontal = 3 text = "Default speed" [node name="DefaultSpeed" type="SpinBox" parent="VBoxContainer/DefaultSpeed"] unique_name_in_owner = true -offset_left = 423.0 -offset_right = 506.0 -offset_bottom = 31.0 +layout_mode = 2 step = 0.001 [node name="InputAction" type="HBoxContainer" parent="VBoxContainer"] -offset_top = 75.0 -offset_right = 506.0 -offset_bottom = 108.0 +layout_mode = 2 [node name="Label2" type="Label" parent="VBoxContainer/InputAction"] -offset_top = 3.0 -offset_right = 302.0 -offset_bottom = 29.0 +layout_mode = 2 size_flags_horizontal = 3 text = "Input action" [node name="InputAction" parent="VBoxContainer/InputAction" instance=ExtResource("3")] unique_name_in_owner = true -anchor_right = 0.0 -anchor_bottom = 0.0 -offset_left = 306.0 -offset_right = 506.0 -offset_bottom = 33.0 +layout_mode = 2 [node name="Skippable" type="HBoxContainer" parent="VBoxContainer"] -offset_top = 112.0 -offset_right = 506.0 -offset_bottom = 138.0 +layout_mode = 2 [node name="Label3" type="Label" parent="VBoxContainer/Skippable"] -offset_right = 478.0 -offset_bottom = 26.0 +layout_mode = 2 size_flags_horizontal = 3 text = "Skippable" [node name="Skippable" type="CheckBox" parent="VBoxContainer/Skippable"] unique_name_in_owner = true -offset_left = 482.0 -offset_right = 506.0 -offset_bottom = 26.0 +layout_mode = 2 [node name="ColorNames" type="HBoxContainer" parent="VBoxContainer"] -offset_top = 142.0 -offset_right = 506.0 -offset_bottom = 168.0 +layout_mode = 2 [node name="Label4" type="Label" parent="VBoxContainer/ColorNames"] -offset_right = 478.0 -offset_bottom = 26.0 +layout_mode = 2 size_flags_horizontal = 3 text = "Autocolor names" [node name="AutocolorNames" type="CheckBox" parent="VBoxContainer/ColorNames"] unique_name_in_owner = true -offset_left = 482.0 -offset_right = 506.0 -offset_bottom = 26.0 +layout_mode = 2 [node name="AutoContinue" type="HBoxContainer" parent="VBoxContainer"] -offset_top = 172.0 -offset_right = 506.0 -offset_bottom = 203.0 +layout_mode = 2 [node name="Label5" type="Label" parent="VBoxContainer/AutoContinue"] -offset_top = 2.0 -offset_right = 391.0 -offset_bottom = 28.0 +layout_mode = 2 size_flags_horizontal = 3 text = "Autocontinue" [node name="Autocontinue" type="CheckBox" parent="VBoxContainer/AutoContinue"] unique_name_in_owner = true -offset_left = 395.0 -offset_right = 419.0 -offset_bottom = 31.0 +layout_mode = 2 [node name="AutocontinueDelay" type="SpinBox" parent="VBoxContainer/AutoContinue"] unique_name_in_owner = true -offset_left = 423.0 -offset_right = 506.0 -offset_bottom = 31.0 +layout_mode = 2 step = 0.01 suffix = "s" +[node name="Title2" type="Label" parent="VBoxContainer"] +layout_mode = 2 +theme_override_styles/normal = SubResource("StyleBoxFlat_oy8x6") +text = "Auto-Pauses" + +[node name="AutoPauseSets" type="VBoxContainer" parent="VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/AutoPauseSets"] +layout_mode = 2 + +[node name="Label6" type="Label" parent="VBoxContainer/AutoPauseSets/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Adds pauses after certain letters." +script = ExtResource("3_wiy0g") + +[node name="Add" type="Button" parent="VBoxContainer/AutoPauseSets/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 8 +text = "Add set" + +[node name="AutoPauses1" type="HBoxContainer" parent="VBoxContainer/AutoPauseSets"] +layout_mode = 2 + +[node name="Letters" type="LineEdit" parent="VBoxContainer/AutoPauseSets/AutoPauses1"] +layout_mode = 2 +size_flags_horizontal = 3 +placeholder_text = "e.g. \"?!,.:;\"" + +[node name="PauseTime" type="SpinBox" parent="VBoxContainer/AutoPauseSets/AutoPauses1"] +unique_name_in_owner = true +layout_mode = 2 +min_value = 0.1 +step = 0.01 +value = 0.1 +suffix = "s" + [node name="VSeparator" type="VSeparator" parent="."] -offset_left = 510.0 -offset_right = 514.0 -offset_bottom = 600.0 +layout_mode = 2 [node name="VBoxContainer2" type="VBoxContainer" parent="."] -offset_left = 518.0 -offset_right = 1024.0 -offset_bottom = 600.0 +layout_mode = 2 size_flags_horizontal = 3 [node name="Title" type="Label" parent="VBoxContainer2"] -offset_right = 506.0 -offset_bottom = 36.0 +layout_mode = 2 theme_override_styles/normal = SubResource("StyleBoxFlat_oy8x6") text = "Tipps and tricks:" [node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer2"] -offset_top = 40.0 -offset_right = 506.0 -offset_bottom = 600.0 +layout_mode = 2 size_flags_vertical = 3 horizontal_scroll_mode = 0 [node name="Info" type="RichTextLabel" parent="VBoxContainer2/ScrollContainer"] unique_name_in_owner = true -offset_right = 506.0 -offset_bottom = 560.0 +layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_colors/default_color = Color(1, 1, 1, 0.611765) @@ -181,3 +180,4 @@ Learn more about bbcode in the official godot docs." [connection signal="toggled" from="VBoxContainer/ColorNames/AutocolorNames" to="." method="_on_AutocolorNames_toggled"] [connection signal="toggled" from="VBoxContainer/AutoContinue/Autocontinue" to="." method="_on_Autocontinue_toggled"] [connection signal="value_changed" from="VBoxContainer/AutoContinue/AutocontinueDelay" to="." method="_on_AutocontinueDelay_value_changed"] +[connection signal="pressed" from="VBoxContainer/AutoPauseSets/HBoxContainer/Add" to="." method="_on_add_autopauses_set_pressed"] diff --git a/addons/dialogic/Events/Text/subsystem_text.gd b/addons/dialogic/Events/Text/subsystem_text.gd index 194053e14..14f225954 100644 --- a/addons/dialogic/Events/Text/subsystem_text.gd +++ b/addons/dialogic/Events/Text/subsystem_text.gd @@ -19,6 +19,7 @@ var text_modifiers := [] var input_handler_node :Node = null +var autopauses := {} #################################################################################################### ## STATE @@ -275,6 +276,11 @@ func _ready(): collect_text_modifiers() Dialogic.event_handled.connect(hide_next_indicators) input_handler_node = Node.new() + autopauses = {} + var autopause_data :Dictionary= ProjectSettings.get_setting('dialogic/text/autopauses', {}) + for i in autopause_data.keys(): + autopauses[RegEx.create_from_string('(? String: func modifier_break(text:String) -> String: return text.replace('[br]', '\n') + + +func modifier_autopauses(text:String) -> String: + for i in autopauses.keys(): + var offset := 0 + for result in i.search_all(text): + text = text.insert(result.get_end()+offset, '[pause='+str(autopauses[i])+']') + offset += len('[pause='+str(autopauses[i])+']') + return text