From cf7c9fcc14471f4f0ced5f21e60fa8d9e0e9af1e Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Mon, 10 Apr 2023 22:46:15 +0200 Subject: [PATCH] Full Controller Menu Support --- Prefabs/Settings Menu.tscn | 10 +++++++++- Scripts/UI/MainMenuManager.gd | 1 + Scripts/UI/SettingsMenu.gd | 35 +++++++++++++++++++++++++++++++++++ project.godot | 25 ++++++++++++++++++++++++- 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/Prefabs/Settings Menu.tscn b/Prefabs/Settings Menu.tscn index 2a5ae6f..e827acc 100644 --- a/Prefabs/Settings Menu.tscn +++ b/Prefabs/Settings Menu.tscn @@ -4,8 +4,13 @@ [ext_resource type="Script" path="res://Scripts/UI/Remaping/RemapController.gd" id="2_2f8ap"] [ext_resource type="Script" path="res://Scripts/UI/Remaping/RemapButton.gd" id="2_4asaa"] -[node name="SettingsMenu" type="Node" node_paths=PackedStringArray("display_options_button", "vsync_toggle", "resolutions_options_button", "master_volume_slider", "music_volume_slider", "sfx_volume_slider")] +[node name="SettingsMenu" type="Node" node_paths=PackedStringArray("back_button", "tab_container", "bottom_item_video", "bottom_item_audio", "bottom_item_controls", "display_options_button", "vsync_toggle", "resolutions_options_button", "master_volume_slider", "music_volume_slider", "sfx_volume_slider")] script = ExtResource("1_2rgd2") +back_button = NodePath("Back Button") +tab_container = NodePath("CenterContainer/SettingsTabs") +bottom_item_video = NodePath("CenterContainer/SettingsTabs/Video/MarginContainer/VideoSettings/ResolutionsOptions") +bottom_item_audio = NodePath("CenterContainer/SettingsTabs/Audio/MarginContainer/AudioSettings/SFXVolSlider") +bottom_item_controls = NodePath("CenterContainer/SettingsTabs/Controls/MarginContainer/ControlSettings/MoveRightRemapButton") display_options_button = NodePath("CenterContainer/SettingsTabs/Video/MarginContainer/VideoSettings/DisplayModeOptions") vsync_toggle = NodePath("CenterContainer/SettingsTabs/Video/MarginContainer/VideoSettings/VsyncButton") resolutions_options_button = NodePath("CenterContainer/SettingsTabs/Video/MarginContainer/VideoSettings/ResolutionsOptions") @@ -113,6 +118,7 @@ vertical_alignment = 1 custom_minimum_size = Vector2(500, 40) layout_mode = 2 size_flags_horizontal = 10 +focus_neighbor_bottom = NodePath("../../../../../../Back Button") fit_to_longest_item = false [node name="Audio" type="VBoxContainer" parent="CenterContainer/SettingsTabs"] @@ -175,6 +181,7 @@ vertical_alignment = 1 custom_minimum_size = Vector2(500, 40) layout_mode = 2 size_flags_horizontal = 10 +focus_neighbor_bottom = NodePath("../../../../../../Back Button") min_value = -72.0 max_value = 0.0 @@ -261,6 +268,7 @@ vertical_alignment = 1 custom_minimum_size = Vector2(500, 40) layout_mode = 2 size_flags_horizontal = 10 +focus_neighbor_bottom = NodePath("../../../../../../Back Button") toggle_mode = true script = ExtResource("2_4asaa") input_action_name = "move_right" diff --git a/Scripts/UI/MainMenuManager.gd b/Scripts/UI/MainMenuManager.gd index 06e599a..cd71434 100644 --- a/Scripts/UI/MainMenuManager.gd +++ b/Scripts/UI/MainMenuManager.gd @@ -22,6 +22,7 @@ func _on_play_button_pressed(): func _on_settings_button_pressed(): var settings_scene_instance = load(settings_scene.resource_path).instantiate() + settings_scene_instance.on_back = Callable(func(): default_focus.grab_focus()) get_tree().current_scene.add_child(settings_scene_instance) pass diff --git a/Scripts/UI/SettingsMenu.gd b/Scripts/UI/SettingsMenu.gd index 8b8485e..4368726 100644 --- a/Scripts/UI/SettingsMenu.gd +++ b/Scripts/UI/SettingsMenu.gd @@ -1,10 +1,18 @@ extends Node # Video Settings UI References +@export var back_button : Control +@export var tab_container : TabContainer +@export var bottom_item_video : Control +@export var bottom_item_audio : Control +@export var bottom_item_controls : Control + @export var display_options_button : OptionButton @export var vsync_toggle : CheckButton @export var resolutions_options_button : OptionButton +var on_back : Callable + # Audio Settings UI References @export var master_volume_slider : Slider @export var music_volume_slider : Slider @@ -12,6 +20,9 @@ extends Node # Engine Callbacks func _ready(): + back_button.grab_focus() + back_button.focus_neighbor_top = bottom_item_video.get_path() + add_resolution_items() display_options_button.select(Save.game_data.display_mode) GlobalSettings.set_display_mode(Save.game_data.display_mode) @@ -26,6 +37,29 @@ func _ready(): sfx_volume_slider.value = Save.game_data.sfx_volume GlobalSettings.update_sfx_volume(Save.game_data.sfx_volume) pass + +func _process(delta): + update_change_tab() + pass + +func update_change_tab(): + var do_left = Input.is_action_just_pressed("ui_tab_left") + var do_right = Input.is_action_just_pressed("ui_tab_right") + + if do_left: + var new_rab = tab_container.current_tab - 1 + tab_container.current_tab = new_rab if new_rab >= 0 else tab_container.get_tab_count() - 1 + if do_right: + var new_rab = tab_container.current_tab + 1 + tab_container.current_tab = new_rab if new_rab < tab_container.get_tab_count() else 0 + + if do_left or do_right: + match tab_container.current_tab: + 0: back_button.focus_neighbor_top = bottom_item_video.get_path() + 1: back_button.focus_neighbor_top = bottom_item_audio.get_path() + 2: back_button.focus_neighbor_top = bottom_item_controls.get_path() + back_button.grab_focus() + pass func add_resolution_items(): for key in GlobalSettings.resolutions_dictionary.keys(): @@ -33,6 +67,7 @@ func add_resolution_items(): # Other Buttons func _on_back_pressed(): + on_back.call() queue_free() pass diff --git a/project.godot b/project.godot index 94e6dba..954430a 100644 --- a/project.godot +++ b/project.godot @@ -52,7 +52,12 @@ ui_accept={ ui_select={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"echo":false,"script":null) -, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":true,"script":null) +] +} +ui_cancel={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194305,"physical_keycode":0,"key_label":0,"unicode":4194305,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null) ] } ui_left={ @@ -60,6 +65,7 @@ ui_left={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":4194319,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null) ] } ui_right={ @@ -67,6 +73,7 @@ ui_right={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":4194321,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null) ] } ui_up={ @@ -74,6 +81,7 @@ ui_up={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":4194320,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null) ] } ui_down={ @@ -81,6 +89,7 @@ ui_down={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":4194322,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null) ] } move_left={ @@ -157,6 +166,20 @@ aim_down_controller={ "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null) ] } +ui_tab_left={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":9,"pressure":0.0,"pressed":true,"script":null) +] +} +ui_tab_right={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":10,"pressure":0.0,"pressed":true,"script":null) +] +} [layer_names]