diff options
Diffstat (limited to 'client/menu/settings/input')
-rw-r--r-- | client/menu/settings/input/input_manager.gd | 42 | ||||
-rw-r--r-- | client/menu/settings/input/input_setting.gd | 19 | ||||
-rw-r--r-- | client/menu/settings/input/input_value_node.gd | 5 |
3 files changed, 16 insertions, 50 deletions
diff --git a/client/menu/settings/input/input_manager.gd b/client/menu/settings/input/input_manager.gd index 96cdca09..d216884b 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,19 +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 - -func settings_dictionary_to_input_map(settings: Dictionary) -> Dictionary: - var map := {} - for k in settings.keys(): - var setting: InputSetting = settings[k] - map[k] = setting.get_value() - return map + entries.append(InputSetting.new(k, events)) + return entries func change_input_map_action(action_name: String, events: Array, save: bool = true): if !InputMap.has_action(action_name): diff --git a/client/menu/settings/input/input_setting.gd b/client/menu/settings/input/input_setting.gd index eec68bdc..7388af78 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 @@ -18,17 +19,9 @@ extends GameSetting const INPUT_VALUE_NODE_SCENE = preload("res://menu/settings/input/input_value_node.tscn") -func _update_row(): - super() +func create_row(): + var row = super() row.value_node = INPUT_VALUE_NODE_SCENE.instantiate() - row.value_node.value = _value - -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() + Settings.hook_changed_init(key, true, func(value): row.value_node.value = value) + row.value_node.changed.connect(func(): Global.set_setting(key, row.value_node.value)) + return row 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: |