diff options
| author | tpart <tpart120@proton.me> | 2024-09-02 00:34:06 +0200 | 
|---|---|---|
| committer | tpart <tpart120@proton.me> | 2024-09-02 00:34:13 +0200 | 
| commit | e864abcf6469c877087e53525de632b89546659d (patch) | |
| tree | 87039b2e5556c64e0b2da95f23152dcc49dbd790 /client | |
| parent | eb7fa5392997ac5c165d1ae011e57a1b7fcac084 (diff) | |
| download | hurrycurry-e864abcf6469c877087e53525de632b89546659d.tar hurrycurry-e864abcf6469c877087e53525de632b89546659d.tar.bz2 hurrycurry-e864abcf6469c877087e53525de632b89546659d.tar.zst | |
Add input settings UI
Diffstat (limited to 'client')
| -rw-r--r-- | client/global.gd | 26 | ||||
| -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 | ||||
| -rw-r--r-- | client/project.godot | 4 | 
6 files changed, 154 insertions, 15 deletions
| diff --git a/client/global.gd b/client/global.gd index 942ff3cf..e9bd1954 100644 --- a/client/global.gd +++ b/client/global.gd @@ -43,7 +43,7 @@ var languages := language_array()  var using_joypad := false  var using_touch := false -var default_settings := [ +@onready var default_settings := [  		SettingsCategory.new(tr("Gameplay"), "gameplay", {  			"touch_controls": DropdownSetting.new(tr("Enable touch screen controls"), 0, [tr("Automatic"), tr("Enabled"), tr("Disabled")]),  			"interpolate_camera_rotation": ToggleSetting.new(tr("Smooth camera rotation"), true), @@ -53,11 +53,6 @@ var default_settings := [  			"tutorial_started": ToggleSetting.new(tr("Tutorial started"), false),  			"latch_boost": ToggleSetting.new(tr("Always extend boost to maximum duration"), true),  		}), -		SettingsCategory.new(tr("User interface"), "ui", { -			"language": DropdownSetting.new(tr("Language"), 0, languages.map(func(e): return e[1])), -			"ui_scale_mode": DropdownSetting.new(tr("UI scale mode"), 0, [tr("Resize"), tr("Disabled")]), -			"ui_scale_factor": RangeSetting.new(tr("UI scale factor"), 1. if not on_mobile() else 1.5, 0.5, 1.5, 3), -		}),  		SettingsCategory.new(tr("Graphics"), "graphics", {  			"fullscreen": DropdownSetting.new(tr("Fullscreen"), 0, [tr("Keep"), tr("Always"), tr("Never")]),  			"aa": DropdownSetting.new(tr("Anti-aliasing"), 2 if on_high_end() else 0, [tr("Disabled"), "FXAA", "MSAA 2x", "MSAA 4x"]), @@ -108,6 +103,14 @@ var default_settings := [  			"music_volume": RangeSetting.new(tr("Music Volume"), 0, -30, 0),  			"sfx_volume": RangeSetting.new(tr("SFX Volume"), 0, -30, 0),  		}), +		SettingsCategory.new(tr("User interface"), "ui", { +			"language": DropdownSetting.new(tr("Language"), 0, languages.map(func(e): return e[1])), +			"ui_scale_mode": DropdownSetting.new(tr("UI scale mode"), 0, [tr("Resize"), tr("Disabled")]), +			"ui_scale_factor": RangeSetting.new(tr("UI scale factor"), 1. if not on_mobile() else 1.5, 0.5, 1.5, 3), +		}), +		SettingsCategory.new(tr("Controls"), "input", +			InputManager.input_map_to_settings_dictionary(InputManager.default_input_map) +		),  		SettingsCategory.new(tr("Other"), "other", {  			"server_binary": TextSetting.new(tr("Server binary (leave empty to search PATH)"), "", tr("Enter path")),  			"server_data": TextSetting.new(tr("Server data directory (leave empty to auto-detect)"), "", tr("Enter path")), @@ -255,7 +258,8 @@ func save_settings():  func save_dict(path: String, dict: Dictionary):  	var f = FileAccess.open(path, FileAccess.WRITE) -	f.store_var(dict.duplicate(true)) +	var to_save = dict.duplicate(true) +	f.store_var(to_save, true)  func load_dict(path: String, default: Dictionary) -> Dictionary:  	# TOCTOU here. Godot docs says its fine. @@ -263,7 +267,7 @@ func load_dict(path: String, default: Dictionary) -> Dictionary:  		print("Skip profile load")  		return default  	var f = FileAccess.open(path, FileAccess.READ) -	var saved_dict = f.get_var() +	var saved_dict = f.get_var(true)  	if saved_dict != null and saved_dict is Dictionary:  		add_missing_keys(saved_dict, default) @@ -271,7 +275,7 @@ func load_dict(path: String, default: Dictionary) -> Dictionary:  	return saved_dict  func load_settings(path: String): -	for category: SettingsCategory in default_settings: +	for category: SettingsCategory in default_settings.duplicate(true):  		for k: String in category.settings.keys():  			settings[k] = category.settings[k] @@ -279,8 +283,8 @@ func load_settings(path: String):  		print("Skip settings load")  		return  	var f = FileAccess.open(path, FileAccess.READ) -	var saved_dict = f.get_var() - +	var saved_dict = f.get_var(true) +	  	if saved_dict != null and saved_dict is Dictionary:  		for k in settings.keys():  			if saved_dict.has(k) and typeof(settings[k].get_value()) == typeof(saved_dict[k]): 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"] diff --git a/client/project.godot b/client/project.godot index d0f35b17..b705eed8 100644 --- a/client/project.godot +++ b/client/project.godot @@ -23,7 +23,7 @@ Global="*res://global.gd"  Server="*res://server.gd"  Sound="*res://audio/sound.tscn"  DisableWrongJoypads="*res://disable_wrong_joypads.gd" -InputManager="*res://menu/input/input_manager.gd" +InputManager="*res://menu/settings/input/input_manager.gd"  [display] @@ -196,7 +196,7 @@ scroll_up={  [internationalization]  locale/translations=PackedStringArray("res://po/de.po", "res://po/fr.po", "res://po/es.po", "res://po/ja.po", "res://po/fi.po", "res://po/he.po", "res://po/tr.po", "res://po/ar.po", "res://po/zh_Hant.po", "res://po/zh_Hans.po", "res://po/pl.po", "res://po/pt.po") -locale/translations_pot_files=PackedStringArray("res://global.gd", "res://menu/overlay.tscn", "res://menu/setup.tscn", "res://menu/character.tscn", "res://menu/error.tscn", "res://menu/ingame.tscn", "res://menu/lobby.tscn", "res://menu/main.tscn", "res://menu/settings.tscn", "res://menu/ingame.gd", "res://menu/lobby.gd", "res://menu/popup_message.gd", "res://multiplayer.gd", "res://menu/hairstyle_preview.gd", "res://menu/credits.tscn", "res://menu/credits.gd", "res://menu/rating/rating.gd", "res://menu/warning_popup.tscn", "res://menu/play.tscn") +locale/translations_pot_files=PackedStringArray("res://global.gd", "res://menu/overlay.tscn", "res://menu/setup.tscn", "res://menu/character.tscn", "res://menu/error.tscn", "res://menu/ingame.tscn", "res://menu/lobby.tscn", "res://menu/main.tscn", "res://menu/settings.tscn", "res://menu/ingame.gd", "res://menu/lobby.gd", "res://menu/popup_message.gd", "res://multiplayer.gd", "res://menu/hairstyle_preview.gd", "res://menu/credits.tscn", "res://menu/credits.gd", "res://menu/rating/rating.gd", "res://menu/warning_popup.tscn", "res://menu/play.tscn", "res://menu/settings/input/input_value_node.gd", "res://menu/settings/input/input_value_node.tscn")  [rendering] | 
