diff options
author | Hop311 <Hop3114@gmail.com> | 2023-06-24 00:55:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-24 00:55:45 +0200 |
commit | 432000a3ab73980fc6421b3587de4b97af30d3ad (patch) | |
tree | 4b80d98261252f25011e34b22a8d49767525559f /game/src/Game/Menu/OptionMenu/SettingNodes | |
parent | 40cf0fa95e325f3bf875e42c11254da23192f506 (diff) | |
parent | 206cafc8bba310e4d4f35f4898ef3ac289abe81a (diff) |
Merge pull request #131 from OpenVicProject/ui-cleanup
Localisation and UI focus cleanup
Diffstat (limited to 'game/src/Game/Menu/OptionMenu/SettingNodes')
-rw-r--r-- | game/src/Game/Menu/OptionMenu/SettingNodes/SettingCheckBox.gd | 53 | ||||
-rw-r--r-- | game/src/Game/Menu/OptionMenu/SettingNodes/SettingRevertButton.gd | 2 |
2 files changed, 54 insertions, 1 deletions
diff --git a/game/src/Game/Menu/OptionMenu/SettingNodes/SettingCheckBox.gd b/game/src/Game/Menu/OptionMenu/SettingNodes/SettingCheckBox.gd new file mode 100644 index 0000000..fcc411e --- /dev/null +++ b/game/src/Game/Menu/OptionMenu/SettingNodes/SettingCheckBox.gd @@ -0,0 +1,53 @@ +extends CheckBox +class_name SettingCheckBox + +signal option_selected(pressed : bool, by_user : bool) + +@export +var section_name : String = "setting" + +@export +var setting_name : String = "setting_checkbox" + +@export +var default_pressed : bool = true + +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) + toggled.connect(func(pressed : bool): option_selected.emit(pressed, true)) + _setup_button() + +func _set_value_from_file(load_value) -> void: + match typeof(load_value): + TYPE_BOOL, TYPE_INT: + set_pressed_no_signal(load_value as bool) + return + TYPE_STRING, TYPE_STRING_NAME: + var load_str := (load_value as String).to_lower() + if load_str.is_empty() or load_str.begins_with("f") or load_str.begins_with("n"): + set_pressed_no_signal(false) + return + if load_str.begins_with("t") or load_str.begins_with("y"): + set_pressed_no_signal(true) + return + push_error("Setting value '%s' invalid for setting [%s] \"%s\"" % [load_value, section_name, setting_name]) + set_pressed_no_signal(default_pressed) + +func load_setting(file : ConfigFile) -> void: + if file == null: return + _set_value_from_file(file.get_value(section_name, setting_name, default_pressed)) + option_selected.emit(button_pressed, false) + +func save_setting(file : ConfigFile) -> void: + if file == null: return + file.set_value(section_name, setting_name, button_pressed) + +func reset_setting(no_emit : bool = false) -> void: + set_pressed_no_signal(default_pressed) + if not no_emit: + option_selected.emit(button_pressed, false) diff --git a/game/src/Game/Menu/OptionMenu/SettingNodes/SettingRevertButton.gd b/game/src/Game/Menu/OptionMenu/SettingNodes/SettingRevertButton.gd index 945d35b..431e3e5 100644 --- a/game/src/Game/Menu/OptionMenu/SettingNodes/SettingRevertButton.gd +++ b/game/src/Game/Menu/OptionMenu/SettingNodes/SettingRevertButton.gd @@ -2,7 +2,7 @@ extends SettingOptionButton class_name SettingRevertButton @export_group("Nodes") -@export var revert_dialog : ResolutionRevertDialog +@export var revert_dialog : SettingRevertDialog var previous_index : int = -1 |