Skip to content

Commit 21608b0

Browse files
add support for custom choice buttons (#248)
* add support for custom choice buttons * Hide custom buttons behind advanced settings
1 parent 351ede3 commit 21608b0

File tree

5 files changed

+221
-40
lines changed

5 files changed

+221
-40
lines changed

addons/dialogic/Editor/SettingsEditor/SettingsEditor.gd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ onready var nodes = {
88
'auto_color_names': $VBoxContainer/HBoxContainer3/VBoxContainer/VBoxContainer2/HBoxContainer3/AutoColorNames,
99
'propagate_input': $VBoxContainer/HBoxContainer3/VBoxContainer/VBoxContainer2/HBoxContainer4/PropagateInput,
1010
'dim_characters': $VBoxContainer/HBoxContainer3/VBoxContainer/VBoxContainer2/HBoxContainer5/DimCharacters,
11+
'advanced_themes': $VBoxContainer/HBoxContainer3/VBoxContainer/VBoxContainer2/HBoxContainer6/AdvancedThemes,
1112
}
1213

1314

@@ -20,6 +21,7 @@ func _ready():
2021
nodes['auto_color_names'].connect('toggled', self, '_on_auto_color_names_toggled')
2122
nodes['propagate_input'].connect('toggled', self, '_on_propagate_input_toggled')
2223
nodes['dim_characters'].connect('toggled', self, '_on_dim_characters_toggled')
24+
nodes['advanced_themes'].connect('toggled', self, '_on_advanced_themes_toggled')
2325

2426

2527
func update_data():
@@ -39,6 +41,8 @@ func dialog_options(settings):
3941
nodes['propagate_input'].pressed = settings.get_value('dialog', 'propagate_input')
4042
if settings.has_section_key('dialog', 'dim_characters'):
4143
nodes['dim_characters'].pressed = settings.get_value('dialog', 'dim_characters')
44+
if settings.has_section_key('dialog', 'advanced_themes'):
45+
nodes['advanced_themes'].pressed = settings.get_value('dialog', 'advanced_themes')
4246

4347

4448
func refresh_themes(settings):
@@ -88,6 +92,11 @@ func _on_propagate_input_toggled(value):
8892
func _on_dim_characters_toggled(value):
8993
set_value('dialog', 'dim_characters', value)
9094

95+
96+
func _on_advanced_themes_toggled(value):
97+
set_value('dialog', 'advanced_themes', value)
98+
99+
91100
# Reading and saving data to the settings file
92101
func set_value(section, key, value):
93102
DialogicResources.set_settings_value(section, key, value)

addons/dialogic/Editor/SettingsEditor/SettingsEditor.tscn

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ size_flags_vertical = 3
1818

1919
[node name="HBoxContainer3" type="HBoxContainer" parent="VBoxContainer"]
2020
margin_right = 1024.0
21-
margin_bottom = 240.0
21+
margin_bottom = 268.0
2222

2323
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer3"]
2424
margin_right = 304.0
25-
margin_bottom = 240.0
25+
margin_bottom = 268.0
2626
custom_constants/separation = 16
2727

2828
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer3/VBoxContainer"]
@@ -59,20 +59,18 @@ margin_left = 50.0
5959
margin_right = 190.0
6060
margin_bottom = 20.0
6161
rect_min_size = Vector2( 140, 0 )
62-
text = "Basic"
63-
items = [ "Alternative", null, false, 0, {
64-
"file": "theme-1617143167.cfg"
65-
}, "Basic", null, false, 1, {
66-
"file": "theme-1616778229.cfg"
67-
}, "New Theme", null, false, 2, {
68-
"file": "theme-1617143282.cfg"
62+
text = "normal"
63+
items = [ "no_gloss", null, false, 0, {
64+
"file": "theme-1618722854.cfg"
65+
}, "normal", null, false, 1, {
66+
"file": "theme-1616687382.cfg"
6967
} ]
7068
selected = 1
7169

7270
[node name="VBoxContainer2" type="VBoxContainer" parent="VBoxContainer/HBoxContainer3/VBoxContainer"]
7371
margin_top = 70.0
7472
margin_right = 304.0
75-
margin_bottom = 240.0
73+
margin_bottom = 268.0
7674

7775
[node name="Panel2" type="Panel" parent="VBoxContainer/HBoxContainer3/VBoxContainer/VBoxContainer2"]
7876
margin_right = 304.0
@@ -175,3 +173,20 @@ margin_left = 280.0
175173
margin_right = 304.0
176174
margin_bottom = 24.0
177175
pressed = true
176+
177+
[node name="HBoxContainer6" type="HBoxContainer" parent="VBoxContainer/HBoxContainer3/VBoxContainer/VBoxContainer2"]
178+
margin_top = 174.0
179+
margin_right = 304.0
180+
margin_bottom = 198.0
181+
hint_tooltip = "These options can lead to unexpected behaviors. Make sure to read the documentation before using these."
182+
183+
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer3/VBoxContainer/VBoxContainer2/HBoxContainer6"]
184+
margin_top = 5.0
185+
margin_right = 160.0
186+
margin_bottom = 19.0
187+
text = "Advanced theme options"
188+
189+
[node name="AdvancedThemes" type="CheckBox" parent="VBoxContainer/HBoxContainer3/VBoxContainer/VBoxContainer2/HBoxContainer6"]
190+
margin_left = 164.0
191+
margin_right = 188.0
192+
margin_bottom = 24.0

addons/dialogic/Editor/ThemeEditor/ThemeEditor.gd

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ onready var master_tree = get_node('../MasterTreeContainer/MasterTree')
66
onready var settings_editor = get_node('../SettingsEditor')
77
var current_theme : String = ''
88

9+
var use_advanced_themes := false
10+
911
# When loading the variables to the input fields in the
1012
# load_theme function, every element thinks the value was updated
1113
# so it has to perform a "saving" of that property.
@@ -17,6 +19,14 @@ var loading : bool = true
1719
# complain because "that is not how you are supposed to work". If there was only
1820
# a way to set an id and then access that node via id...
1921
# Here you have paths in all its glory. Praise the paths (っ´ω`c)♡
22+
23+
onready var advanced_containers := {
24+
'buttons' : {
25+
'container': $"VBoxContainer/TabContainer/Choice Buttons/Column3/GridContainer",
26+
'disabled_text': $"VBoxContainer/TabContainer/Choice Buttons/Column3/Label"
27+
}
28+
}
29+
2030
onready var n : Dictionary = {
2131
# Dialog Text
2232
'theme_text_shadow': $"VBoxContainer/TabContainer/Dialog Text/Column/GridContainer/HBoxContainer2/CheckBoxShadow",
@@ -71,6 +81,8 @@ onready var n : Dictionary = {
7181
'button_modulation': $"VBoxContainer/TabContainer/Choice Buttons/Column/GridContainer/HBoxContainer6/CheckBox",
7282
'button_modulation_color': $"VBoxContainer/TabContainer/Choice Buttons/Column/GridContainer/HBoxContainer6/ColorPickerButton",
7383
'button_use_native': $"VBoxContainer/TabContainer/Choice Buttons/Column/GridContainer/CheckBox",
84+
'button_use_custom': $"VBoxContainer/TabContainer/Choice Buttons/Column3/GridContainer/HBoxContainer5/CustomButtonsCheckBox",
85+
'button_custom_path': $"VBoxContainer/TabContainer/Choice Buttons/Column3/GridContainer/HBoxContainer5/CustomButtonsButton",
7486
'button_offset_x': $"VBoxContainer/TabContainer/Choice Buttons/Column2/GridContainer/HBoxContainer/TextOffsetH",
7587
'button_offset_y': $"VBoxContainer/TabContainer/Choice Buttons/Column2/GridContainer/HBoxContainer/TextOffsetV",
7688
'button_separation': $"VBoxContainer/TabContainer/Choice Buttons/Column2/GridContainer/VerticalSeparation",
@@ -106,10 +118,24 @@ func _ready() -> void:
106118
_on_visibility_changed()
107119

108120

121+
func setup_advanced_containers():
122+
use_advanced_themes = DialogicResources.get_settings_config().get_value('dialog', 'advanced_themes', false)
123+
124+
for key in advanced_containers:
125+
var c = advanced_containers[key]
126+
if use_advanced_themes:
127+
c["container"].show()
128+
c["disabled_text"].hide()
129+
else:
130+
c["container"].hide()
131+
c["disabled_text"].show()
132+
133+
109134
func load_theme(filename):
110135
loading = true
111136
current_theme = filename
112137
var theme = DialogicResources.get_theme_config(filename)
138+
setup_advanced_containers()
113139
# Settings
114140
n['theme_action_key'].text = theme.get_value('settings', 'action_key', 'ui_accept')
115141

@@ -142,6 +168,8 @@ func load_theme(filename):
142168
n['button_image'].text = DialogicResources.get_filename_from_path(theme.get_value('buttons', 'image', 'res://addons/dialogic/Example Assets/backgrounds/background-2.png'))
143169
n['button_image_visible'].pressed = theme.get_value('buttons', 'use_image', true)
144170
n['button_use_native'].pressed = theme.get_value('buttons', 'use_native', false)
171+
n['button_use_custom'].pressed = theme.get_value('buttons', 'use_custom', false)
172+
n['button_custom_path'].text = DialogicResources.get_filename_from_path(theme.get_value('buttons', 'custom_path', ""))
145173
n['button_offset_x'].value = theme.get_value('buttons', 'padding', Vector2(5,5)).x
146174
n['button_offset_y'].value = theme.get_value('buttons', 'padding', Vector2(5,5)).y
147175
n['button_separation'].value = theme.get_value('buttons', 'gap', 5)
@@ -151,7 +179,7 @@ func load_theme(filename):
151179
n['button_fixed_x'].value = theme.get_value('buttons', 'fixed_size', Vector2(130,40)).x
152180
n['button_fixed_y'].value = theme.get_value('buttons', 'fixed_size', Vector2(130,40)).y
153181

154-
toggle_button_customization_fields(not theme.get_value('buttons', 'use_native', false))
182+
toggle_button_customization_fields(theme.get_value('buttons', 'use_native', false), theme.get_value('buttons', 'use_custom', false))
155183

156184
# Definitions
157185
n['glossary_color'].color = Color(theme.get_value('definitions', 'color', "#ffffffff"))
@@ -461,20 +489,42 @@ func _on_native_button_toggled(button_pressed) -> void:
461489
if loading:
462490
return
463491
DialogicResources.set_theme_value(current_theme, 'buttons', 'use_native', button_pressed)
464-
toggle_button_customization_fields(not button_pressed)
465-
466-
func toggle_button_customization_fields(enabled) -> void:
467-
var disabled = not enabled
468-
n['button_text_color_enabled'].disabled = disabled
469-
n['button_text_color'].disabled = disabled
470-
n['button_background'].disabled = disabled
471-
n['button_background_visible'].disabled = disabled
472-
n['button_image'].disabled = disabled
473-
n['button_image_visible'].disabled = disabled
474-
n['button_modulation'].disabled = disabled
475-
n['button_modulation_color'].disabled = disabled
476-
n['button_offset_x'].editable = enabled
477-
n['button_offset_y'].editable = enabled
492+
toggle_button_customization_fields(button_pressed, false)
493+
494+
495+
func toggle_button_customization_fields(native_enabled: bool, custom_enabled: bool) -> void:
496+
var customization_disabled = native_enabled or custom_enabled
497+
n['button_text_color_enabled'].disabled = customization_disabled
498+
n['button_text_color'].disabled = customization_disabled
499+
n['button_background'].disabled = customization_disabled
500+
n['button_background_visible'].disabled = customization_disabled
501+
n['button_image'].disabled = customization_disabled
502+
n['button_image_visible'].disabled = customization_disabled
503+
n['button_modulation'].disabled = customization_disabled
504+
n['button_modulation_color'].disabled = customization_disabled
505+
n['button_use_native'].disabled = custom_enabled
506+
n['button_use_custom'].disabled = native_enabled
507+
n['button_custom_path'].disabled = native_enabled
508+
n['button_offset_x'].editable = not customization_disabled
509+
n['button_offset_y'].editable = not customization_disabled
510+
511+
512+
func _on_CustomButtonsCheckBox_toggled(button_pressed):
513+
if loading:
514+
return
515+
DialogicResources.set_theme_value(current_theme, 'buttons', 'use_custom', button_pressed)
516+
toggle_button_customization_fields(false, button_pressed)
517+
518+
519+
func _on_CustomButtonsButton_pressed():
520+
editor_reference.godot_dialog("*.tscn")
521+
editor_reference.godot_dialog_connect(self, "_on_custom_button_selected")
522+
523+
func _on_custom_button_selected(path, target) -> void:
524+
if loading:
525+
return
526+
DialogicResources.set_theme_value(current_theme, 'buttons', 'custom_path', path)
527+
n['button_custom_path'].text = DialogicResources.get_filename_from_path(path)
478528

479529

480530
func _on_GlossaryColorPicker_color_changed(color) -> void:

addons/dialogic/Editor/ThemeEditor/ThemeEditor.tscn

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,6 @@ allow_greater = true
824824
allow_lesser = true
825825

826826
[node name="Choice Buttons" type="HBoxContainer" parent="VBoxContainer/TabContainer"]
827-
visible = false
828827
anchor_right = 1.0
829828
anchor_bottom = 1.0
830829
margin_left = 4.0
@@ -851,7 +850,7 @@ text = "Visuals"
851850
[node name="GridContainer" type="GridContainer" parent="VBoxContainer/TabContainer/Choice Buttons/Column"]
852851
margin_top = 26.0
853852
margin_right = 270.0
854-
margin_bottom = 162.0
853+
margin_bottom = 170.0
855854
size_flags_horizontal = 3
856855
custom_constants/hseparation = 10
857856
columns = 2
@@ -951,17 +950,34 @@ margin_right = 126.0
951950
margin_bottom = 24.0
952951
size_flags_horizontal = 3
953952

953+
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/TabContainer/Choice Buttons/Column/GridContainer"]
954+
margin_top = 112.0
955+
margin_right = 134.0
956+
margin_bottom = 116.0
957+
__meta__ = {
958+
"_edit_use_anchors_": false
959+
}
960+
961+
[node name="HSeparator2" type="HSeparator" parent="VBoxContainer/TabContainer/Choice Buttons/Column/GridContainer"]
962+
margin_left = 144.0
963+
margin_top = 112.0
964+
margin_right = 270.0
965+
margin_bottom = 116.0
966+
__meta__ = {
967+
"_edit_use_anchors_": false
968+
}
969+
954970
[node name="Label2" type="Label" parent="VBoxContainer/TabContainer/Choice Buttons/Column/GridContainer"]
955-
margin_top = 117.0
971+
margin_top = 125.0
956972
margin_right = 134.0
957-
margin_bottom = 131.0
973+
margin_bottom = 139.0
958974
text = "Use Native Buttons"
959975

960976
[node name="CheckBox" type="CheckBox" parent="VBoxContainer/TabContainer/Choice Buttons/Column/GridContainer"]
961977
margin_left = 144.0
962-
margin_top = 112.0
978+
margin_top = 120.0
963979
margin_right = 270.0
964-
margin_bottom = 136.0
980+
margin_bottom = 144.0
965981

966982
[node name="VSeparator" type="VSeparator" parent="VBoxContainer/TabContainer/Choice Buttons"]
967983
margin_left = 280.0
@@ -1068,7 +1084,71 @@ rounded = true
10681084
allow_greater = true
10691085
allow_lesser = true
10701086

1087+
[node name="VSeparator2" type="VSeparator" parent="VBoxContainer/TabContainer/Choice Buttons"]
1088+
margin_left = 613.0
1089+
margin_right = 617.0
1090+
margin_bottom = 488.0
1091+
1092+
[node name="Column3" type="VBoxContainer" parent="VBoxContainer/TabContainer/Choice Buttons"]
1093+
margin_left = 627.0
1094+
margin_right = 897.0
1095+
margin_bottom = 488.0
1096+
rect_min_size = Vector2( 270, 0 )
1097+
size_flags_vertical = 3
1098+
__meta__ = {
1099+
"_edit_use_anchors_": false
1100+
}
1101+
1102+
[node name="SectionTitle" type="Label" parent="VBoxContainer/TabContainer/Choice Buttons/Column3"]
1103+
margin_right = 270.0
1104+
margin_bottom = 22.0
1105+
custom_styles/normal = SubResource( 1 )
1106+
text = "Advanced"
1107+
1108+
[node name="Label" type="Label" parent="VBoxContainer/TabContainer/Choice Buttons/Column3"]
1109+
margin_top = 26.0
1110+
margin_right = 270.0
1111+
margin_bottom = 40.0
1112+
text = "Go to settings to enable those options"
1113+
1114+
[node name="GridContainer" type="GridContainer" parent="VBoxContainer/TabContainer/Choice Buttons/Column3"]
1115+
margin_top = 44.0
1116+
margin_right = 270.0
1117+
margin_bottom = 68.0
1118+
size_flags_horizontal = 3
1119+
custom_constants/hseparation = 10
1120+
columns = 2
1121+
1122+
[node name="CustomButtonsLabel" type="Label" parent="VBoxContainer/TabContainer/Choice Buttons/Column3/GridContainer"]
1123+
margin_top = 5.0
1124+
margin_right = 132.0
1125+
margin_bottom = 19.0
1126+
hint_tooltip = "The selected scene must have the 'pressed' signal and the 'text' property'"
1127+
mouse_filter = 1
1128+
text = "Use Custom Buttons"
1129+
__meta__ = {
1130+
"_editor_description_": ""
1131+
}
1132+
1133+
[node name="HBoxContainer5" type="HBoxContainer" parent="VBoxContainer/TabContainer/Choice Buttons/Column3/GridContainer"]
1134+
margin_left = 142.0
1135+
margin_right = 230.0
1136+
margin_bottom = 24.0
1137+
1138+
[node name="CustomButtonsCheckBox" type="CheckBox" parent="VBoxContainer/TabContainer/Choice Buttons/Column3/GridContainer/HBoxContainer5"]
1139+
margin_right = 24.0
1140+
margin_bottom = 24.0
1141+
1142+
[node name="CustomButtonsButton" type="Button" parent="VBoxContainer/TabContainer/Choice Buttons/Column3/GridContainer/HBoxContainer5"]
1143+
margin_left = 28.0
1144+
margin_right = 88.0
1145+
margin_bottom = 24.0
1146+
hint_tooltip = "The selected scene must have the 'pressed' signal and the 'text' property'"
1147+
size_flags_horizontal = 3
1148+
text = "custom"
1149+
10711150
[node name="Glossary" type="HBoxContainer" parent="VBoxContainer/TabContainer"]
1151+
visible = false
10721152
anchor_right = 1.0
10731153
anchor_bottom = 1.0
10741154
margin_left = 4.0
@@ -1256,6 +1336,8 @@ one_shot = true
12561336
[connection signal="toggled" from="VBoxContainer/TabContainer/Choice Buttons/Column2/GridContainer/HBoxContainer2/FixedSize" to="." method="_on_FixedSize_toggled"]
12571337
[connection signal="value_changed" from="VBoxContainer/TabContainer/Choice Buttons/Column2/GridContainer/HBoxContainer2/ButtonSizeX" to="." method="_on_ButtonSize_value_changed"]
12581338
[connection signal="value_changed" from="VBoxContainer/TabContainer/Choice Buttons/Column2/GridContainer/HBoxContainer2/ButtonSizeY" to="." method="_on_ButtonSize_value_changed"]
1339+
[connection signal="toggled" from="VBoxContainer/TabContainer/Choice Buttons/Column3/GridContainer/HBoxContainer5/CustomButtonsCheckBox" to="." method="_on_CustomButtonsCheckBox_toggled"]
1340+
[connection signal="pressed" from="VBoxContainer/TabContainer/Choice Buttons/Column3/GridContainer/HBoxContainer5/CustomButtonsButton" to="." method="_on_CustomButtonsButton_pressed"]
12591341
[connection signal="pressed" from="VBoxContainer/TabContainer/Glossary/Column/GridContainer/FontButton" to="." method="_on_GlossaryFontButton_pressed"]
12601342
[connection signal="color_changed" from="VBoxContainer/TabContainer/Glossary/Column/GridContainer/ColorPickerButton" to="." method="_on_GlossaryColorPicker_color_changed"]
12611343
[connection signal="toggled" from="VBoxContainer/TabContainer/Glossary/Column/GridContainer/ShowGlossaryCheckBox" to="." method="_on_ShowGlossaryCheckBox_toggled"]

0 commit comments

Comments
 (0)