aboutsummaryrefslogtreecommitdiff
path: root/client/menu/settings_row.gd
diff options
context:
space:
mode:
Diffstat (limited to 'client/menu/settings_row.gd')
-rw-r--r--client/menu/settings_row.gd42
1 files changed, 34 insertions, 8 deletions
diff --git a/client/menu/settings_row.gd b/client/menu/settings_row.gd
index ee4b8cb9..4f1d326f 100644
--- a/client/menu/settings_row.gd
+++ b/client/menu/settings_row.gd
@@ -1,20 +1,40 @@
class_name SettingsRow
extends PanelContainer
+signal apply_preset
+
@onready var value_parent = $HBoxContainer/BoxContainer
@onready var label = $HBoxContainer/Label
var value_node
var description = tr("no value was given to the row")
-func setup(description_: String, value):
- description = description_
- if value is bool:
- value_node = CheckButton.new()
- value_node.button_pressed = value
- elif value is String:
- value_node = LineEdit.new()
- value_node.text = value
+func setup(key: String, dict: Dictionary, defaults: Dictionary):
+ var setting = dict[key]
+ description = setting["description"]
+ var value = setting["value"]
+ var default = defaults[key]["value"]
+ match setting["type"]:
+ "toggle":
+ value_node = CheckButton.new()
+ value_node.button_pressed = value
+ "line":
+ value_node = LineEdit.new()
+ value_node.text = value
+ value_node.placeholder_text = default
+ "dropdown":
+ value_node = OptionButton.new()
+ for i in setting["options"]:
+ value_node.add_item(i)
+ value_node.select(value)
+ "dropdown_preset":
+ value_node = OptionButton.new()
+ for i in setting["options"]:
+ value_node.add_item(i)
+ value_node.select(value)
+ value_node.connect("item_selected", apply.bind(setting["apply"]))
+ _:
+ push_error("Could not set up SettingsRow: Unknown setting type \"%s\"" % setting["type"])
func _ready():
if value_node != null:
@@ -24,13 +44,19 @@ func _ready():
label.text = description
value_parent.add_child(c)
+func apply(idx: int, apply: Array):
+ emit_signal("apply_preset", apply[idx])
+
func get_value():
if value_node != null:
if value_node is CheckButton:
return value_node.button_pressed
elif value_node is LineEdit:
return value_node.text
+ elif value_node is OptionButton:
+ return value_node.selected
else:
+ push_error("get_value() failed for unknown node type: %s" % value_node)
return null
else:
return null