diff options
Diffstat (limited to 'client/menu')
| -rw-r--r-- | client/menu/settings/input/input_manager.gd (renamed from client/menu/input/input_manager.gd) | 12 | ||||
| -rw-r--r-- | client/menu/settings/input/input_setting.gd | 34 | ||||
| -rw-r--r-- | client/menu/settings/input/input_value_node.gd | 69 | ||||
| -rw-r--r-- | client/menu/settings/input/input_value_node.tscn | 24 | 
4 files changed, 137 insertions, 2 deletions
| diff --git a/client/menu/input/input_manager.gd b/client/menu/settings/input/input_manager.gd index 77affb38..14e1b99c 100644 --- a/client/menu/input/input_manager.gd +++ b/client/menu/settings/input/input_manager.gd @@ -26,8 +26,16 @@ func get_input_map() -> Dictionary:  	var actions = InputMap.get_actions().filter(func isBuiltIn(k: String): return !k.begins_with("ui_"))  	var kb = {}  	for a in actions: -		kb[a] = InputMap.action_get_events(a).duplicate(true) -	return kb.duplicate(true) +		var input_events: Array[InputEvent] = InputMap.action_get_events(a).duplicate(true) +		kb[a] = input_events +	return kb + +func input_map_to_settings_dictionary(map: Dictionary) -> Dictionary: +	var settings_dict := {} +	for k in map.keys(): +		var events = map[k] +		settings_dict[k] = InputSetting.new(k, events) +	return settings_dict  func change_input_map_action(action_name: String, event: InputEvent, 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 new file mode 100644 index 00000000..eec68bdc --- /dev/null +++ b/client/menu/settings/input/input_setting.gd @@ -0,0 +1,34 @@ +# Hurry Curry! - a game about cooking +# Copyright 2024 tpart +# +# 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/>. +# +class_name InputSetting +extends GameSetting + +const INPUT_VALUE_NODE_SCENE = preload("res://menu/settings/input/input_value_node.tscn") + +func _update_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() diff --git a/client/menu/settings/input/input_value_node.gd b/client/menu/settings/input/input_value_node.gd new file mode 100644 index 00000000..4436d97f --- /dev/null +++ b/client/menu/settings/input/input_value_node.gd @@ -0,0 +1,69 @@ +# Hurry Curry! - a game about cooking +# Copyright 2024 tpart +# +# 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 VBoxContainer +class_name InputValueNode + +var value: Array[InputEvent] = [] +var listening := false + +@onready var actions_container: VBoxContainer = $ActionsContainer +@onready var add_button: Button = $Add +@onready var add_text = add_button.text + +func _ready(): +	update() + +func update(fix_focus: bool = false): +	for c in actions_container.get_children(): +		c.queue_free() +	 +	for e: InputEvent in value: +		var description: String +		 +		if e is InputEventKey: +			description = tr("%s (Keyboard)") % OS.get_keycode_string(e.physical_keycode) +		elif e is InputEventMouseButton: +			description = tr("Mouse button %s") % e.button_index +		elif e is InputEventJoypadButton: +			description = tr("%s (Joypad)") % e.button_index +		elif e is InputEventJoypadMotion: +			description = tr("Joypad axis %s") % [e.axis] +		else: +			description = tr("Other event") +		 +		var button := Button.new() +		button.text = description +		button.pressed.connect(erase_event.bind(e)) +		actions_container.add_child(button) +	 +	if fix_focus: +		add_button.grab_focus() + +func erase_event(e: InputEvent): +	value.erase(e) +	update(true) + +func _input(e: InputEvent): +	if listening: +		if e is InputEventKey or e is InputEventMouseButton or e is InputEventJoypadButton or e is InputEventJoypadMotion: +			value.append(e) +			_on_add_pressed() +			update() + +func _on_add_pressed() -> void: +	listening = not listening +	 +	add_button.text = tr("Press any key...") if listening else add_text diff --git a/client/menu/settings/input/input_value_node.tscn b/client/menu/settings/input/input_value_node.tscn new file mode 100644 index 00000000..496bfaa0 --- /dev/null +++ b/client/menu/settings/input/input_value_node.tscn @@ -0,0 +1,24 @@ +[gd_scene load_steps=3 format=3 uid="uid://c6r0nv5daq7wc"] + +[ext_resource type="Script" path="res://menu/settings/input/input_value_node.gd" id="1_snxax"] +[ext_resource type="Texture2D" uid="uid://cnfjbowd2i02r" path="res://menu/plus.svg" id="2_3vlvc"] + +[node name="InputValueNode" type="VBoxContainer"] +offset_right = 128.0 +offset_bottom = 31.0 +theme_override_constants/separation = 0 +script = ExtResource("1_snxax") + +[node name="ActionsContainer" type="VBoxContainer" parent="."] +layout_mode = 2 +theme_override_constants/separation = 0 + +[node name="Add" type="Button" parent="."] +custom_minimum_size = Vector2(128, 0) +layout_mode = 2 +size_flags_vertical = 3 +text = "Add new" +icon = ExtResource("2_3vlvc") +expand_icon = true + +[connection signal="pressed" from="Add" to="." method="_on_add_pressed"] | 
