diff options
Diffstat (limited to 'client/menu/settings')
-rw-r--r-- | client/menu/settings/dropdown_setting.gd | 21 | ||||
-rw-r--r-- | client/menu/settings/game_setting.gd | 50 | ||||
-rw-r--r-- | client/menu/settings/input/input_manager.gd | 35 | ||||
-rw-r--r-- | client/menu/settings/input/input_setting.gd | 16 | ||||
-rw-r--r-- | client/menu/settings/input/input_value_node.gd | 5 | ||||
-rw-r--r-- | client/menu/settings/preset_row.gd (renamed from client/menu/settings/preset.gd) | 13 | ||||
-rw-r--r-- | client/menu/settings/range_setting.gd | 18 | ||||
-rw-r--r-- | client/menu/settings/settings_category.gd | 51 | ||||
-rw-r--r-- | client/menu/settings/settings_root.gd | 36 | ||||
-rw-r--r-- | client/menu/settings/settings_row.gd | 1 | ||||
-rw-r--r-- | client/menu/settings/text_setting.gd | 19 | ||||
-rw-r--r-- | client/menu/settings/toggle_setting.gd | 19 |
12 files changed, 153 insertions, 131 deletions
diff --git a/client/menu/settings/dropdown_setting.gd b/client/menu/settings/dropdown_setting.gd index e57fc40f..62162320 100644 --- a/client/menu/settings/dropdown_setting.gd +++ b/client/menu/settings/dropdown_setting.gd @@ -18,23 +18,18 @@ extends GameSetting var options: Array -func _init(new_description: String, new_preset: int, new_options: Array): - assert(new_preset < new_options.size()) - super(new_description, new_preset) +func _init(new_id: String, new_default, new_options: Array): + super(new_id, new_default) options = new_options func _update_row(): super() row.value_node = OptionButton.new() for i in options: - row.value_node.add_item(i) - row.value_node.select(_value) + row.value_node.add_item(tr(nskey + "." + i)) + row.value_node.select(options.find(Global.get_setting(key))) + if not row.value_node.item_selected.is_connected(from_ui): + row.value_node.item_selected.connect(from_ui) -func fetch_setting(): - if row != null: - _value = row.value_node.selected - -func set_value(v): - super(v) - if row != null: - row.value_node.selected = _value +func from_ui(index): + Global.set_setting(key, options[index]) diff --git a/client/menu/settings/game_setting.gd b/client/menu/settings/game_setting.gd index afe1fe65..2846cbe3 100644 --- a/client/menu/settings/game_setting.gd +++ b/client/menu/settings/game_setting.gd @@ -16,39 +16,31 @@ class_name GameSetting extends Object -var preset -var _value -var description: String +var default +var key: String +var nskey: String -var row: SettingsRow +var row: Node -func _init(new_description: String, new_preset): - preset = new_preset - set_value(new_preset) - description = new_description +func _init(new_id: String, new_default = null): + default = new_default + key = new_id -func reset(): - set_value(preset) - -func get_row() -> SettingsRow: - _update_row() - return row +func set_parent(parent: GameSetting): + if parent != null: key = parent.key + "." + key + nskey = "c.settings." + key func _update_row(): - if row != null: - row.queue_free() - row = preload("res://menu/settings/settings_row.tscn").instantiate() - row.description = description - row.reset.connect(reset) + if row == null: row = preload("res://menu/settings/settings_row.tscn").instantiate() + row.description = tr(nskey) + if not row.reset.is_connected(reset): row.reset.connect(reset) -func fetch_setting(): - pass - -func get_value(): - return _value +func reset(): + Global.set_setting(key, default) -func set_value(v): - if v is Array: - _value = v.duplicate(true) - else: - _value = v +func check(): + if default != null: + if not key in Global.settings: + Global.set_setting_unchecked(key, default) + if typeof(default) != typeof(Global.settings[key]): + Global.set_setting_unchecked(key, default) diff --git a/client/menu/settings/input/input_manager.gd b/client/menu/settings/input/input_manager.gd index 96cdca09..784b4974 100644 --- a/client/menu/settings/input/input_manager.gd +++ b/client/menu/settings/input/input_manager.gd @@ -1,5 +1,6 @@ # Hurry Curry! - a game about cooking # Copyright 2024 tpart +# Copyright 2024 metamuffin # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -15,32 +16,6 @@ # extends Node -var action_descriptions = { - "forwards": tr("Move forwards"), - "backwards": tr("Move backwards"), - "left": tr("Move left"), - "right": tr("Move right"), - "rotate_left": tr("Rotate camera to the left"), - "rotate_right": tr("Rotate camera to the right"), - "rotate_up": tr("Rotate camera upwards"), - "rotate_down": tr("Rotate camera downwards"), - "interact": tr("Interact", "Interacting with items, etc."), - "boost": tr("Boost movement"), - "zoom_in": tr("Zoom in"), - "zoom_out": tr("Zoom out"), - "chat": tr("Toggle chat", "Toggle chat on or off"), - "reset": tr("Reset camera view"), - "fullscreen": tr("Toggle fullscreen"), - "previous": tr("Previous"), - "next": tr("Next"), - "start_game": tr("Start game"), - "join_spectate": tr("Join / Spectate"), - "zoom_in_discrete": tr("Zoom in (discrete)"), - "zoom_out_discrete": tr("Zoom out (discrete)"), - "scroll_down": tr("Scroll down"), - "scroll_up": tr("Scroll up"), -} - var default_input_map = {} var input_map @@ -56,12 +31,12 @@ func get_input_map() -> Dictionary: kb[a] = input_events return kb -func input_map_to_settings_dictionary(map: Dictionary) -> Dictionary: - var settings_dict := {} +func input_map_to_settings(map: Dictionary) -> Array: + var entries := [] for k in map.keys(): var events = map[k] - settings_dict[k] = InputSetting.new(action_descriptions[k] if action_descriptions.has(k) else k, events) - return settings_dict + entries.append(InputSetting.new(k, events)) + return entries func settings_dictionary_to_input_map(settings: Dictionary) -> Dictionary: var map := {} diff --git a/client/menu/settings/input/input_setting.gd b/client/menu/settings/input/input_setting.gd index eec68bdc..e32e800c 100644 --- a/client/menu/settings/input/input_setting.gd +++ b/client/menu/settings/input/input_setting.gd @@ -1,5 +1,6 @@ # Hurry Curry! - a game about cooking # Copyright 2024 tpart +# Copyright 2024 metamuffin # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -21,14 +22,9 @@ const INPUT_VALUE_NODE_SCENE = preload("res://menu/settings/input/input_value_no func _update_row(): super() row.value_node = INPUT_VALUE_NODE_SCENE.instantiate() - row.value_node.value = _value + row.value_node.value = Global.get_setting(key) + if not row.value_node.changed.is_connected(from_ui): + row.value_node.changed.connect(from_ui) -func fetch_setting(): - if row != null: - _value = row.value_node.value - -func set_value(v): - super(v) - if row != null: - row.value_node.value = _value - row.value_node.update() +func from_ui(): + Global.set_setting(key, row.value_node.value) diff --git a/client/menu/settings/input/input_value_node.gd b/client/menu/settings/input/input_value_node.gd index 125a946b..9f89416b 100644 --- a/client/menu/settings/input/input_value_node.gd +++ b/client/menu/settings/input/input_value_node.gd @@ -1,5 +1,6 @@ # Hurry Curry! - a game about cooking # Copyright 2024 tpart +# Copyright 2024 metamuffin # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -19,6 +20,8 @@ class_name InputValueNode var value: Array[InputEvent] = [] var listening := false +signal changed() + @onready var actions_container: VBoxContainer = $ActionsContainer @onready var add_button: Button = $Add @onready var add_text = add_button.text @@ -55,6 +58,7 @@ func update(fix_focus: bool = false): func erase_event(e: InputEvent): value.erase(e) update(true) + changed.emit() func _input(e: InputEvent): if listening: @@ -66,6 +70,7 @@ func _input(e: InputEvent): value.append(e) _on_add_pressed() update() + changed.emit() func events_equal(e1: InputEvent, e2: InputEvent) -> bool: if e1 is InputEventKey and e2 is InputEventKey: diff --git a/client/menu/settings/preset.gd b/client/menu/settings/preset_row.gd index bb13b570..808f6381 100644 --- a/client/menu/settings/preset.gd +++ b/client/menu/settings/preset_row.gd @@ -1,5 +1,6 @@ # Hurry Curry! - a game about cooking # Copyright 2024 nokoe +# Copyright 2024 metamuffin # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -14,13 +15,13 @@ # along with this program. If not, see <https://www.gnu.org/licenses/>. # class_name Preset -extends Object +extends GameSetting -var label: String var options: Dictionary +var arr: Array[Button] -func _init(name_: String, options_: Dictionary): - label = name_ +func _init(id: String, options_: Dictionary): + super(id) options = options_ func apply(preset_name: String): @@ -29,11 +30,9 @@ func apply(preset_name: String): var setting_name: String = i Global.set_setting(setting_name, preset[setting_name]) -func buttons() -> Array[Button]: - var arr: Array[Button] = [] +func _update_row(): for i in options.keys(): var button := Button.new() button.pressed.connect(apply.bind(i)) button.text = i arr.push_back(button) - return arr diff --git a/client/menu/settings/range_setting.gd b/client/menu/settings/range_setting.gd index d13e2262..d8616d54 100644 --- a/client/menu/settings/range_setting.gd +++ b/client/menu/settings/range_setting.gd @@ -1,5 +1,6 @@ # Hurry Curry! - a game about cooking # Copyright 2024 nokoe +# Copyright 2024 metamuffin # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -21,8 +22,8 @@ var max_value: float var tick_count var smooth: bool -func _init(new_description: String, new_preset: float, new_min_value: float, new_max_value: float, new_smooth: bool = true, new_tick_count = null): - super(new_description, new_preset) +func _init(new_id: String, new_default: float, new_min_value: float, new_max_value: float, new_smooth: bool = true, new_tick_count = null): + super(new_id, new_default) min_value = new_min_value max_value = new_max_value tick_count = new_tick_count @@ -35,13 +36,8 @@ func _update_row(): row.value_node.max_value = max_value row.value_node.tick_count = abs(max_value - min_value) if tick_count == null else tick_count row.value_node.step = 0 if smooth else (1 if tick_count == null else abs(max_value - min_value) / (tick_count - 1)) - row.value_node.value = _value + row.value_node.value = Global.get_setting(key) + if not row.value_node.value_changed.is_connected(from_ui): row.value_node.value_changed.connect(from_ui) -func fetch_setting(): - if row != null: - _value = row.value_node.value - -func set_value(v): - super(v) - if row != null: - row.value_node.value = _value +func from_ui(): + Global.set_setting(key, row.value_node.value) diff --git a/client/menu/settings/settings_category.gd b/client/menu/settings/settings_category.gd index c4601429..7425ea19 100644 --- a/client/menu/settings/settings_category.gd +++ b/client/menu/settings/settings_category.gd @@ -14,15 +14,48 @@ # along with this program. If not, see <https://www.gnu.org/licenses/>. # class_name SettingsCategory -extends Object +extends GameSetting -var name: String -var id: String -var settings: Dictionary # Dictionary[String, GameSetting] -var presets # Array[Preset] | null +var settings: Array # Dictionary[String, GameSetting] +var presets # Array[Preset] -func _init(new_name: String, new_id: String, new_settings: Dictionary, new_presets = null): - name = new_name - id = new_id +var options: VBoxContainer + +func _init(new_id: String, new_settings: Array, new_presets = []): + super(new_id) settings = new_settings - presets = new_presets + presets = new_presets + +func set_parent(parent: GameSetting): + super(parent) + for c in settings: + c.set_parent(self) + +func _update_row(): + if row == null: row = ScrollContainerCustom.new() + if options == null: options = VBoxContainer.new() + row.name = tr(nskey) + row.size_flags_horizontal = Control.SIZE_EXPAND_FILL + options.size_flags_horizontal = Control.SIZE_EXPAND_FILL + + if options.get_parent() != row: + row.add_child(options) + + if presets != null: + for i in presets: + var prow: SettingsRow = preload("res://menu/settings/settings_row.tscn").instantiate() + options.add_child(prow) + prow.label.text = i.label + prow.reset_button.visible = false + for b in i.buttons(): + prow.value_parent.add_child(b) + + for r in settings: + r._update_row() + if r.row.get_parent() != options: + print(r.row) + options.add_child(r.row) + +func check(): + for c in settings: + c.check() diff --git a/client/menu/settings/settings_root.gd b/client/menu/settings/settings_root.gd new file mode 100644 index 00000000..5acf7f11 --- /dev/null +++ b/client/menu/settings/settings_root.gd @@ -0,0 +1,36 @@ +# Hurry Curry! - a game about cooking +# Copyright 2024 metamuffin +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License only. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +extends GameSetting +class_name SettingsRoot + +var children: Array +func _init(new_children: Array): + super("root") + children = new_children + for c in children: + c.set_parent(null) + +func _update_row(): + if row == null: row = TabContainer.new() + row.size_flags_vertical = Control.SIZE_EXPAND_FILL + for r in children: + r._update_row() + if r.row.get_parent() != row: + row.add_child(r.row) + +func check(): + for c in children: + c.check() diff --git a/client/menu/settings/settings_row.gd b/client/menu/settings/settings_row.gd index f5621d78..68340918 100644 --- a/client/menu/settings/settings_row.gd +++ b/client/menu/settings/settings_row.gd @@ -1,5 +1,6 @@ # Hurry Curry! - a game about cooking # Copyright 2024 nokoe +# Copyright 2024 metamuffin # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by diff --git a/client/menu/settings/text_setting.gd b/client/menu/settings/text_setting.gd index faafa610..6fa6b1ef 100644 --- a/client/menu/settings/text_setting.gd +++ b/client/menu/settings/text_setting.gd @@ -1,5 +1,6 @@ # Hurry Curry! - a game about cooking # Copyright 2024 nokoe +# Copyright 2024 metamuffin # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -18,21 +19,17 @@ extends GameSetting var placeholder: String -func _init(new_description: String, new_preset: String, new_placeholder: String = ""): - super(new_description, new_preset) +func _init(new_id: String, new_default: String, new_placeholder: String = ""): + super(new_id, new_default) placeholder = new_placeholder func _update_row(): super() row.value_node = LineEdit.new() - row.value_node.text = _value + row.value_node.text = Global.get_setting(key) row.value_node.placeholder_text = placeholder + if not row.value_node.text_changed.is_connected(from_ui): + row.value_node.text_changed.connect(from_ui) -func fetch_setting(): - if row != null: - _value = row.value_node.text - -func set_value(v): - super(v) - if row != null: - row.value_node.text = _value +func from_ui(text): + Global.set_setting(key, text) diff --git a/client/menu/settings/toggle_setting.gd b/client/menu/settings/toggle_setting.gd index 6d4150d4..45f08d9f 100644 --- a/client/menu/settings/toggle_setting.gd +++ b/client/menu/settings/toggle_setting.gd @@ -1,5 +1,6 @@ # Hurry Curry! - a game about cooking # Copyright 2024 nokoe +# Copyright 2024 metamuffin # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -16,19 +17,15 @@ class_name ToggleSetting extends GameSetting -func _init(new_description: String, new_preset: bool): - super(new_description, new_preset) - -func fetch_setting(): - if row != null: - _value = row.value_node.button_pressed +func _init(new_id: String, new_default: bool): + super(new_id, new_default) func _update_row(): super() row.value_node = CheckButton.new() - row.value_node.button_pressed = _value + row.value_node.button_pressed = Global.get_setting(key) + if not row.value_node.pressed.is_connected(from_ui): + row.value_node.pressed.connect(from_ui) -func set_value(v): - super(v) - if row != null: - row.value_node.button_pressed = _value +func from_ui(): + Global.set_setting(key, row.value_node.button_pressed) |