Skip to content

Commit 96c5f3d

Browse files
committed
Hide joypad controls if joypad 0 is not connected
1 parent b7971c8 commit 96c5f3d

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

scenes/control_legend.gd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extends Control
2+
3+
@onready var _grid: GridContainer = $PanelContainer/Grid
4+
5+
func _ready() -> void:
6+
_toggle_joypad_controls(false)
7+
Input.joy_connection_changed.connect(_on_joy_connection_changed_cb)
8+
9+
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
14+
15+
func _on_joy_connection_changed_cb(_device: int, _connected: bool):
16+
_toggle_joypad_controls(not Input.get_connected_joypads().is_empty())

scenes/control_legend.tscn

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
[gd_scene load_steps=10 format=3 uid="uid://b4upvm74gte5"]
1+
[gd_scene load_steps=11 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"]
45
[ext_resource type="Texture2D" uid="uid://ffs8ne7b7ijc" path="res://assets/kenney_input-prompts/Keyboard & Mouse/Default/keyboard_arrows_horizontal.png" id="2_w3q02"]
56
[ext_resource type="Texture2D" uid="uid://blprvur1vdmtb" path="res://assets/kenney_input-prompts/Steam Deck/Default/steamdeck_stick_l_vertical.png" id="3_kfgte"]
67
[ext_resource type="Texture2D" uid="uid://ibjkhn23vq8e" path="res://assets/kenney_input-prompts/Keyboard & Mouse/Default/keyboard_arrows_vertical.png" id="4_r850h"]
@@ -25,6 +26,7 @@ grow_horizontal = 2
2526
grow_vertical = 2
2627
size_flags_horizontal = 8
2728
size_flags_vertical = 8
29+
script = ExtResource("1_hbahy")
2830

2931
[node name="PanelContainer" type="PanelContainer" parent="."]
3032
layout_mode = 1
@@ -52,7 +54,7 @@ horizontal_alignment = 2
5254
layout_mode = 2
5355
texture = ExtResource("1_6u7qc")
5456

55-
[node name="KeyboardLeftRight" type="TextureRect" parent="PanelContainer/Grid" groups=["joypad"]]
57+
[node name="KeyboardLeftRight" type="TextureRect" parent="PanelContainer/Grid"]
5658
layout_mode = 2
5759
texture = ExtResource("2_w3q02")
5860

@@ -65,7 +67,7 @@ horizontal_alignment = 2
6567
layout_mode = 2
6668
texture = ExtResource("3_kfgte")
6769

68-
[node name="KeyboardUpDown" type="TextureRect" parent="PanelContainer/Grid" groups=["joypad"]]
70+
[node name="KeyboardUpDown" type="TextureRect" parent="PanelContainer/Grid"]
6971
layout_mode = 2
7072
texture = ExtResource("4_r850h")
7173

@@ -78,7 +80,7 @@ horizontal_alignment = 2
7880
layout_mode = 2
7981
texture = ExtResource("5_hnd0v")
8082

81-
[node name="KeyboardEnter" type="TextureRect" parent="PanelContainer/Grid" groups=["joypad"]]
83+
[node name="KeyboardEnter" type="TextureRect" parent="PanelContainer/Grid"]
8284
layout_mode = 2
8385
texture = ExtResource("10_kj4r4")
8486

@@ -87,7 +89,7 @@ layout_mode = 2
8789
text = "Start visitor timer"
8890
horizontal_alignment = 2
8991

90-
[node name="JoypadB" type="TextureRect" parent="PanelContainer/Grid"]
92+
[node name="JoypadB" type="TextureRect" parent="PanelContainer/Grid" groups=["joypad"]]
9193
layout_mode = 2
9294
texture = ExtResource("6_ycckv")
9395

0 commit comments

Comments
 (0)