Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autopausing-capability #1518

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/dialogic/Events/Text/index.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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'},

]
46 changes: 44 additions & 2 deletions addons/dialogic/Events/Text/settings_text.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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/')}
Expand All @@ -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)
132 changes: 66 additions & 66 deletions addons/dialogic/Events/Text/settings_text.tscn
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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"]
15 changes: 15 additions & 0 deletions addons/dialogic/Events/Text/subsystem_text.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var text_modifiers := []

var input_handler_node :Node = null

var autopauses := {}

####################################################################################################
## STATE
Expand Down Expand Up @@ -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('(?<!(\\[|\\{))['+i+'](?![\\w\\s]*[\\]\\}])')] = autopause_data[i]

input_handler_node.set_script(load(get_script().resource_path.get_base_dir().path_join('default_input_handler.gd')))
add_child(input_handler_node)

Expand Down Expand Up @@ -371,3 +377,12 @@ func modifier_random_selection(text: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