Skip to content

Commit a5f781d

Browse files
committed
Improve keyboard/joypad switch in control legend
1 parent 96c5f3d commit a5f781d

File tree

4 files changed

+56
-19
lines changed

4 files changed

+56
-19
lines changed

main.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[ext_resource type="Texture2D" uid="uid://cjrg281l8dowd" path="res://assets/faces/manuel.png" id="7_2g80n"]
1212
[ext_resource type="Texture2D" uid="uid://qoxaittblcj" path="res://assets/faces/matt.png" id="8_bp373"]
1313
[ext_resource type="Script" path="res://snow.gd" id="11_3ircf"]
14-
[ext_resource type="PackedScene" uid="uid://b4upvm74gte5" path="res://scenes/control_legend.tscn" id="12_55xyr"]
14+
[ext_resource type="PackedScene" uid="uid://b4upvm74gte5" path="res://scenes/control_legend/control_legend.tscn" id="12_55xyr"]
1515

1616
[sub_resource type="Curve2D" id="Curve2D_nm8ru"]
1717
_data = {
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ extends Control
33
@onready var _grid: GridContainer = $PanelContainer/Grid
44

55
func _ready() -> void:
6-
_toggle_joypad_controls(false)
76
Input.joy_connection_changed.connect(_on_joy_connection_changed_cb)
87

98
func _toggle_joypad_controls(connected: bool):
10-
_grid.columns = (3 if connected else 2)
11-
for child in $PanelContainer/Grid.get_children():
12-
if child.is_in_group("joypad"):
13-
child.visible = connected
9+
for child in get_tree().get_nodes_in_group("joypad"):
10+
child.visible = connected
1411

1512
func _on_joy_connection_changed_cb(_device: int, _connected: bool):
1613
_toggle_joypad_controls(not Input.get_connected_joypads().is_empty())
Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
[gd_scene load_steps=11 format=3 uid="uid://b4upvm74gte5"]
1+
[gd_scene load_steps=12 format=3 uid="uid://b4upvm74gte5"]
22

33
[ext_resource type="Texture2D" uid="uid://csuaoaclr7fyb" path="res://assets/kenney_input-prompts/Steam Deck/Default/steamdeck_stick_l_horizontal.png" id="1_6u7qc"]
4-
[ext_resource type="Script" path="res://scenes/control_legend.gd" id="1_hbahy"]
4+
[ext_resource type="Script" path="res://scenes/control_legend/control_legend.gd" id="1_hbahy"]
5+
[ext_resource type="StyleBox" uid="uid://db4ob2gq7j8vs" path="res://scenes/control_legend/mode_switch_tab_panel.tres" id="2_j4jmc"]
56
[ext_resource type="Texture2D" uid="uid://ffs8ne7b7ijc" path="res://assets/kenney_input-prompts/Keyboard & Mouse/Default/keyboard_arrows_horizontal.png" id="2_w3q02"]
67
[ext_resource type="Texture2D" uid="uid://blprvur1vdmtb" path="res://assets/kenney_input-prompts/Steam Deck/Default/steamdeck_stick_l_vertical.png" id="3_kfgte"]
78
[ext_resource type="Texture2D" uid="uid://ibjkhn23vq8e" path="res://assets/kenney_input-prompts/Keyboard & Mouse/Default/keyboard_arrows_vertical.png" id="4_r850h"]
@@ -35,64 +36,100 @@ anchor_left = 1.0
3536
anchor_top = 1.0
3637
anchor_right = 1.0
3738
anchor_bottom = 1.0
38-
offset_left = -273.0
39-
offset_top = -268.0
39+
offset_left = -233.0
40+
offset_top = -278.0
4041
grow_horizontal = 0
4142
grow_vertical = 0
4243
theme_override_styles/panel = SubResource("StyleBoxFlat_b1qas")
4344

4445
[node name="Grid" type="GridContainer" parent="PanelContainer"]
4546
layout_mode = 2
46-
columns = 3
47+
columns = 2
4748

4849
[node name="Label" type="Label" parent="PanelContainer/Grid"]
4950
layout_mode = 2
5051
text = "Adjust wind speed"
5152
horizontal_alignment = 2
5253

53-
[node name="JoystickLeftRight" type="TextureRect" parent="PanelContainer/Grid" groups=["joypad"]]
54+
[node name="LeftRight" type="TabContainer" parent="PanelContainer/Grid"]
55+
layout_mode = 2
56+
theme_override_styles/panel = ExtResource("2_j4jmc")
57+
current_tab = 1
58+
tabs_visible = false
59+
60+
[node name="JoystickLeftRight" type="TextureRect" parent="PanelContainer/Grid/LeftRight" groups=["joypad"]]
61+
visible = false
5462
layout_mode = 2
5563
texture = ExtResource("1_6u7qc")
64+
metadata/_tab_index = 0
5665

57-
[node name="KeyboardLeftRight" type="TextureRect" parent="PanelContainer/Grid"]
66+
[node name="KeyboardLeftRight" type="TextureRect" parent="PanelContainer/Grid/LeftRight"]
5867
layout_mode = 2
5968
texture = ExtResource("2_w3q02")
69+
metadata/_tab_index = 1
6070

6171
[node name="Label2" type="Label" parent="PanelContainer/Grid"]
6272
layout_mode = 2
6373
text = "Adjust snow speed"
6474
horizontal_alignment = 2
6575

66-
[node name="JoystickUpDown" type="TextureRect" parent="PanelContainer/Grid" groups=["joypad"]]
76+
[node name="UpDown" type="TabContainer" parent="PanelContainer/Grid"]
77+
layout_mode = 2
78+
theme_override_styles/panel = ExtResource("2_j4jmc")
79+
current_tab = 1
80+
tabs_visible = false
81+
82+
[node name="JoystickUpDown" type="TextureRect" parent="PanelContainer/Grid/UpDown" groups=["joypad"]]
83+
visible = false
6784
layout_mode = 2
6885
texture = ExtResource("3_kfgte")
86+
metadata/_tab_index = 0
6987

70-
[node name="KeyboardUpDown" type="TextureRect" parent="PanelContainer/Grid"]
88+
[node name="KeyboardUpDown" type="TextureRect" parent="PanelContainer/Grid/UpDown"]
7189
layout_mode = 2
7290
texture = ExtResource("4_r850h")
91+
metadata/_tab_index = 1
7392

7493
[node name="Label3" type="Label" parent="PanelContainer/Grid"]
7594
layout_mode = 2
7695
text = "Spawn a visitor"
7796
horizontal_alignment = 2
7897

79-
[node name="JoypadA" type="TextureRect" parent="PanelContainer/Grid" groups=["joypad"]]
98+
[node name="Spawn" type="TabContainer" parent="PanelContainer/Grid"]
99+
layout_mode = 2
100+
theme_override_styles/panel = ExtResource("2_j4jmc")
101+
current_tab = 1
102+
tabs_visible = false
103+
104+
[node name="JoypadA" type="TextureRect" parent="PanelContainer/Grid/Spawn" groups=["joypad"]]
105+
visible = false
80106
layout_mode = 2
81107
texture = ExtResource("5_hnd0v")
108+
metadata/_tab_index = 0
82109

83-
[node name="KeyboardEnter" type="TextureRect" parent="PanelContainer/Grid"]
110+
[node name="KeyboardEnter" type="TextureRect" parent="PanelContainer/Grid/Spawn"]
84111
layout_mode = 2
85112
texture = ExtResource("10_kj4r4")
113+
metadata/_tab_index = 1
86114

87115
[node name="Label4" type="Label" parent="PanelContainer/Grid"]
88116
layout_mode = 2
89117
text = "Start visitor timer"
90118
horizontal_alignment = 2
91119

92-
[node name="JoypadB" type="TextureRect" parent="PanelContainer/Grid" groups=["joypad"]]
120+
[node name="RestartTimer" type="TabContainer" parent="PanelContainer/Grid"]
121+
layout_mode = 2
122+
theme_override_styles/panel = ExtResource("2_j4jmc")
123+
current_tab = 1
124+
tabs_visible = false
125+
126+
[node name="JoypadB" type="TextureRect" parent="PanelContainer/Grid/RestartTimer" groups=["joypad"]]
127+
visible = false
93128
layout_mode = 2
94129
texture = ExtResource("6_ycckv")
130+
metadata/_tab_index = 0
95131

96-
[node name="KeyboardBackspace" type="TextureRect" parent="PanelContainer/Grid"]
132+
[node name="KeyboardBackspace" type="TextureRect" parent="PanelContainer/Grid/RestartTimer"]
97133
layout_mode = 2
98134
texture = ExtResource("12_vm4m3")
135+
metadata/_tab_index = 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[gd_resource type="StyleBoxEmpty" format=3 uid="uid://db4ob2gq7j8vs"]
2+
3+
[resource]

0 commit comments

Comments
 (0)