aboutsummaryrefslogtreecommitdiff
path: root/game/src/OptionMenu/SettingNodes
diff options
context:
space:
mode:
Diffstat (limited to 'game/src/OptionMenu/SettingNodes')
-rw-r--r--game/src/OptionMenu/SettingNodes/SettingHSlider.gd7
-rw-r--r--game/src/OptionMenu/SettingNodes/SettingOptionButton.gd51
2 files changed, 51 insertions, 7 deletions
diff --git a/game/src/OptionMenu/SettingNodes/SettingHSlider.gd b/game/src/OptionMenu/SettingNodes/SettingHSlider.gd
index da9348f..cf2adf4 100644
--- a/game/src/OptionMenu/SettingNodes/SettingHSlider.gd
+++ b/game/src/OptionMenu/SettingNodes/SettingHSlider.gd
@@ -10,10 +10,17 @@ var setting_name : String = "SettingHSlider"
@export
var default_value : float = 0
+func _ready():
+ Events.Options.load_settings.connect(load_setting)
+ Events.Options.save_settings.connect(save_setting)
+ Events.Options.reset_settings.connect(reset_setting)
+
func load_setting(file : ConfigFile):
+ if file == null: return
value = file.get_value(section_name, setting_name, default_value)
func save_setting(file : ConfigFile):
+ if file == null: return
file.set_value(section_name, setting_name, value)
func reset_setting():
diff --git a/game/src/OptionMenu/SettingNodes/SettingOptionButton.gd b/game/src/OptionMenu/SettingNodes/SettingOptionButton.gd
index 46fc825..3a5c979 100644
--- a/game/src/OptionMenu/SettingNodes/SettingOptionButton.gd
+++ b/game/src/OptionMenu/SettingNodes/SettingOptionButton.gd
@@ -8,15 +8,52 @@ var section_name : String = "Setting"
var setting_name : String = "SettingOptionMenu"
@export
-var default_value : int = 0
+var default_selected : int = -1:
+ get: return default_selected
+ set(v):
+ if v == -1:
+ default_selected = -1
+ return
+ default_selected = v % item_count
-func load_setting(file : ConfigFile):
- selected = file.get_value(section_name, setting_name, default_value)
+@export
+var add_nonstandard_value := false
+
+func _get_value_for_file(select_value : int):
+ if select_value > -1:
+ return get_item_text(select_value)
+ else:
+ return null
+
+func _set_value_from_file(load_value) -> void:
+ selected = -1
+ for item_index in range(item_count):
+ if load_value == get_item_text(item_index):
+ selected = item_index
+ if selected == -1:
+ if add_nonstandard_value:
+ add_item(load_value)
+ selected = item_count - 1
+ else: push_error("Setting value '%s' invalid for setting [%s] \"%s\"" % [load_value, section_name, setting_name])
+
+func _setup_button() -> void:
+ pass
+
+func _ready():
+ Events.Options.load_settings.connect(load_setting)
+ Events.Options.save_settings.connect(save_setting)
+ Events.Options.reset_settings.connect(reset_setting)
+ _setup_button()
+
+func load_setting(file : ConfigFile) -> void:
+ if file == null: return
+ _set_value_from_file(file.get_value(section_name, setting_name, _get_value_for_file(default_selected)))
item_selected.emit(selected)
-func save_setting(file : ConfigFile):
- file.set_value(section_name, setting_name, selected)
+func save_setting(file : ConfigFile) -> void:
+ if file == null: return
+ file.set_value(section_name, setting_name, _get_value_for_file(selected))
-func reset_setting():
- selected = default_value
+func reset_setting() -> void:
+ selected = default_selected
item_selected.emit(selected)