From 1227ad6ee06f220891cf5efb81aac8f64085b26d Mon Sep 17 00:00:00 2001 From: Matteo Piccina Date: Sun, 7 Jan 2024 18:25:35 +0100 Subject: [PATCH] Add L1 and R1 tabs navigation --- tools/configurator/TabContainer.gd | 34 ++++++++++++++++++++++++++++++ tools/configurator/main.gd | 0 tools/configurator/main.tscn | 7 ++++-- tools/configurator/project.godot | 10 +++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 tools/configurator/TabContainer.gd mode change 100755 => 100644 tools/configurator/main.gd mode change 100755 => 100644 tools/configurator/project.godot diff --git a/tools/configurator/TabContainer.gd b/tools/configurator/TabContainer.gd new file mode 100644 index 00000000..25a9e4b1 --- /dev/null +++ b/tools/configurator/TabContainer.gd @@ -0,0 +1,34 @@ +extends TabContainer + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + +func _input(event): + if (event.is_action_pressed("next_tab")): + self.select_next_available() + focusFirstFocusableChild() + + if (event.is_action_pressed("previous_tab")): + self.select_previous_available() + focusFirstFocusableChild() + +func focusFirstFocusableChild(): + var children = findElements(get_current_tab_control(), "Control") + for n: Control in children: + if (n.focus_mode == FOCUS_ALL): + n.grab_focus.call_deferred() + break + +func findElements(node: Node, className: String, result: Array = []) -> Array: + if node.is_class(className): + result.push_back(node) + for child in node.get_children(): + result = findElements(child, className, result) + return result diff --git a/tools/configurator/main.gd b/tools/configurator/main.gd old mode 100755 new mode 100644 diff --git a/tools/configurator/main.tscn b/tools/configurator/main.tscn index 2d60d754..1c83395d 100644 --- a/tools/configurator/main.tscn +++ b/tools/configurator/main.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=17 format=3 uid="uid://61f6m4r1mpan"] +[gd_scene load_steps=18 format=3 uid="uid://61f6m4r1mpan"] [ext_resource type="Texture2D" uid="uid://bv6vh33cnfaw4" path="res://icon.svg" id="1_axfei"] [ext_resource type="Script" path="res://main.gd" id="1_obpq7"] +[ext_resource type="Script" path="res://TabContainer.gd" id="3_id6l4"] [ext_resource type="AudioStream" uid="uid://dig4pco500pyt" path="res://res/configurator.mp3" id="3_xivj6"] [ext_resource type="Texture2D" uid="uid://dx0u5hiwxfgu5" path="res://res/pixel_ui_theme/8x8_ui_elements.png" id="4_2tuu4"] [ext_resource type="Script" path="res://Rekku.gd" id="4_nqqx3"] @@ -105,8 +106,11 @@ grow_vertical = 2 [node name="TabContainer" type="TabContainer" parent="MarginContainer"] layout_mode = 2 tab_alignment = 1 +current_tab = 4 +script = ExtResource("3_id6l4") [node name="System" type="Control" parent="MarginContainer/TabContainer"] +visible = false layout_mode = 2 [node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/TabContainer/System"] @@ -447,7 +451,6 @@ text = "Move User Files" layout_mode = 2 [node name="Network" type="Control" parent="MarginContainer/TabContainer"] -visible = false layout_mode = 2 [node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/TabContainer/Network"] diff --git a/tools/configurator/project.godot b/tools/configurator/project.godot old mode 100755 new mode 100644 index f8ccd8a6..38060bd3 --- a/tools/configurator/project.godot +++ b/tools/configurator/project.godot @@ -66,6 +66,16 @@ quit={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":81,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) ] } +next_tab={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":10,"pressure":0.0,"pressed":false,"script":null) +] +} +previous_tab={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":9,"pressure":0.0,"pressed":false,"script":null) +] +} [rendering]