From 206cafc8bba310e4d4f35f4898ef3ac289abe81a Mon Sep 17 00:00:00 2001 From: Hop311 Date: Sat, 10 Jun 2023 20:48:17 +0100 Subject: Localisation and UI focus cleanup Updated Russian localisation Resolution, window_mode, monitor refactor Locale based number formatting --- .../OptionMenu/SettingNodes/SettingCheckBox.gd | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 game/src/Game/Menu/OptionMenu/SettingNodes/SettingCheckBox.gd (limited to 'game/src/Game/Menu/OptionMenu/SettingNodes/SettingCheckBox.gd') 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) -- cgit v1.2.3-56-ga3b1