From b3c7c142c54f8d1bb3a64f84db0ea1e6f389a766 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 31 Jul 2021 15:46:59 +0200 Subject: [PATCH] Now tab containers are also navigable with keys in the menu. --- game/menu/Menu.gd | 1 - game/project.godot | 20 +++++++++++ game/scenes/Main.tscn | 6 ++-- game/ui/KeyboardTabContainer.gd | 60 +++++++++++++++++++++++++++++++++ game/ui/about/About.tscn | 9 ++++- game/ui/options/Options.tscn | 5 ++- 6 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 game/ui/KeyboardTabContainer.gd diff --git a/game/menu/Menu.gd b/game/menu/Menu.gd index f2a3531c..a2b9724c 100644 --- a/game/menu/Menu.gd +++ b/game/menu/Menu.gd @@ -1,4 +1,3 @@ - extends Control class_name Menu diff --git a/game/project.godot b/game/project.godot index 98b5e257..1d61442b 100644 --- a/game/project.godot +++ b/game/project.godot @@ -713,6 +713,26 @@ jump={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } +ui_prev_page={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777244,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +ui_next_page={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777245,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +ui_prev_page_2={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777254,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +ui_next_page_2={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777255,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} [layer_names] diff --git a/game/scenes/Main.tscn b/game/scenes/Main.tscn index b8ab5bdf..0f9e9409 100644 --- a/game/scenes/Main.tscn +++ b/game/scenes/Main.tscn @@ -63,7 +63,7 @@ Broken Seals [wave]LOADING[/wave] [/center]" -text = "[center] +text = " @@ -90,7 +90,7 @@ Broken Seals -[wave]LOADING[/wave] -[/center]" +LOADING +" [node name="DebugInfo" parent="." instance=ExtResource( 5 )] diff --git a/game/ui/KeyboardTabContainer.gd b/game/ui/KeyboardTabContainer.gd new file mode 100644 index 00000000..964dddb1 --- /dev/null +++ b/game/ui/KeyboardTabContainer.gd @@ -0,0 +1,60 @@ +extends TabContainer + +# Copyright (c) 2019-2021 Péter Magyar +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +export(NodePath) var focus_control_on_tab_change_path : NodePath + +export(String) var prev_tab_action : String = "ui_prev_page" +export(String) var next_tab_action : String = "ui_next_page" + +var _focus_control_on_tab_change : Control = null + +func _ready(): + _focus_control_on_tab_change = get_node(focus_control_on_tab_change_path) as Control + + connect("visibility_changed", self, "on_visibility_changed") + on_visibility_changed() + +func _input(event : InputEvent) -> void: + if event.is_action_pressed(next_tab_action, false): + var oct : int = current_tab + + current_tab += 1 + + if current_tab != oct: + _focus_control_on_tab_change.grab_focus() + + get_tree().set_input_as_handled() + elif event.is_action_pressed(prev_tab_action, false): + var oct : int = current_tab + + current_tab -= 1 + + if current_tab != oct: + _focus_control_on_tab_change.grab_focus() + + get_tree().set_input_as_handled() + +func on_visibility_changed() -> void: + if is_visible_in_tree(): + set_process_input(true) + else: + set_process_input(false) diff --git a/game/ui/about/About.tscn b/game/ui/about/About.tscn index aafc82c3..d9af93e6 100644 --- a/game/ui/about/About.tscn +++ b/game/ui/about/About.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://ui/about/GodotAuthors.gd" type="Script" id=1] [ext_resource path="res://ui/about/GodotDonors.gd" type="Script" id=2] @@ -8,6 +8,7 @@ [ext_resource path="res://ui/about/Authors.gd" type="Script" id=6] [ext_resource path="res://ui/about/Third-Party Licenses.gd" type="Script" id=7] [ext_resource path="res://ui/Window.gd" type="Script" id=8] +[ext_resource path="res://ui/KeyboardTabContainer.gd" type="Script" id=9] [node name="About" type="Control"] anchor_right = 1.0 @@ -45,6 +46,8 @@ margin_bottom = 431.0 size_flags_horizontal = 3 size_flags_vertical = 3 tab_align = 0 +script = ExtResource( 9 ) +focus_control_on_tab_change_path = NodePath("../Close") [node name="Authors" type="ScrollContainer" parent="PanelContainer/VBoxContainer/TabContainer"] anchor_right = 1.0 @@ -155,6 +158,10 @@ margin_right = -4.0 margin_bottom = -4.0 size_flags_horizontal = 3 size_flags_vertical = 3 +script = ExtResource( 9 ) +focus_control_on_tab_change_path = NodePath("../../Close") +prev_tab_action = "ui_prev_page_2" +next_tab_action = "ui_next_page_2" [node name="Authors" type="ScrollContainer" parent="PanelContainer/VBoxContainer/TabContainer/Godot"] anchor_right = 1.0 diff --git a/game/ui/options/Options.tscn b/game/ui/options/Options.tscn index 8127bef1..d206917c 100644 --- a/game/ui/options/Options.tscn +++ b/game/ui/options/Options.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://ui/theme/ui_theme.tres" type="Theme" id=1] [ext_resource path="res://ui/player_ui/RemoveProfile.gd" type="Script" id=2] @@ -8,6 +8,7 @@ [ext_resource path="res://ui/options/OptionEnumRow.tscn" type="PackedScene" id=6] [ext_resource path="res://ui/Window.gd" type="Script" id=7] [ext_resource path="res://ui/options/OptionsSpinboxRow.tscn" type="PackedScene" id=8] +[ext_resource path="res://ui/KeyboardTabContainer.gd" type="Script" id=9] [node name="Options" type="Control"] anchor_right = 1.0 @@ -45,6 +46,8 @@ margin_bottom = 431.0 size_flags_horizontal = 3 size_flags_vertical = 3 tab_align = 0 +script = ExtResource( 9 ) +focus_control_on_tab_change_path = NodePath("../Close") [node name="Video" type="VBoxContainer" parent="PanelContainer/VBoxContainer/TabContainer"] anchor_right = 1.0