Skip to content

Commit

Permalink
Improve keyboard/joypad switch in control legend
Browse files Browse the repository at this point in the history
  • Loading branch information
wjt committed Dec 16, 2024
1 parent 96c5f3d commit a5f781d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
2 changes: 1 addition & 1 deletion main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[ext_resource type="Texture2D" uid="uid://cjrg281l8dowd" path="res://assets/faces/manuel.png" id="7_2g80n"]
[ext_resource type="Texture2D" uid="uid://qoxaittblcj" path="res://assets/faces/matt.png" id="8_bp373"]
[ext_resource type="Script" path="res://snow.gd" id="11_3ircf"]
[ext_resource type="PackedScene" uid="uid://b4upvm74gte5" path="res://scenes/control_legend.tscn" id="12_55xyr"]
[ext_resource type="PackedScene" uid="uid://b4upvm74gte5" path="res://scenes/control_legend/control_legend.tscn" id="12_55xyr"]

[sub_resource type="Curve2D" id="Curve2D_nm8ru"]
_data = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ extends Control
@onready var _grid: GridContainer = $PanelContainer/Grid

func _ready() -> void:
_toggle_joypad_controls(false)
Input.joy_connection_changed.connect(_on_joy_connection_changed_cb)

func _toggle_joypad_controls(connected: bool):
_grid.columns = (3 if connected else 2)
for child in $PanelContainer/Grid.get_children():
if child.is_in_group("joypad"):
child.visible = connected
for child in get_tree().get_nodes_in_group("joypad"):
child.visible = connected

func _on_joy_connection_changed_cb(_device: int, _connected: bool):
_toggle_joypad_controls(not Input.get_connected_joypads().is_empty())
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=11 format=3 uid="uid://b4upvm74gte5"]
[gd_scene load_steps=12 format=3 uid="uid://b4upvm74gte5"]

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

[node name="Grid" type="GridContainer" parent="PanelContainer"]
layout_mode = 2
columns = 3
columns = 2

[node name="Label" type="Label" parent="PanelContainer/Grid"]
layout_mode = 2
text = "Adjust wind speed"
horizontal_alignment = 2

[node name="JoystickLeftRight" type="TextureRect" parent="PanelContainer/Grid" groups=["joypad"]]
[node name="LeftRight" type="TabContainer" parent="PanelContainer/Grid"]
layout_mode = 2
theme_override_styles/panel = ExtResource("2_j4jmc")
current_tab = 1
tabs_visible = false

[node name="JoystickLeftRight" type="TextureRect" parent="PanelContainer/Grid/LeftRight" groups=["joypad"]]
visible = false
layout_mode = 2
texture = ExtResource("1_6u7qc")
metadata/_tab_index = 0

[node name="KeyboardLeftRight" type="TextureRect" parent="PanelContainer/Grid"]
[node name="KeyboardLeftRight" type="TextureRect" parent="PanelContainer/Grid/LeftRight"]
layout_mode = 2
texture = ExtResource("2_w3q02")
metadata/_tab_index = 1

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

[node name="JoystickUpDown" type="TextureRect" parent="PanelContainer/Grid" groups=["joypad"]]
[node name="UpDown" type="TabContainer" parent="PanelContainer/Grid"]
layout_mode = 2
theme_override_styles/panel = ExtResource("2_j4jmc")
current_tab = 1
tabs_visible = false

[node name="JoystickUpDown" type="TextureRect" parent="PanelContainer/Grid/UpDown" groups=["joypad"]]
visible = false
layout_mode = 2
texture = ExtResource("3_kfgte")
metadata/_tab_index = 0

[node name="KeyboardUpDown" type="TextureRect" parent="PanelContainer/Grid"]
[node name="KeyboardUpDown" type="TextureRect" parent="PanelContainer/Grid/UpDown"]
layout_mode = 2
texture = ExtResource("4_r850h")
metadata/_tab_index = 1

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

[node name="JoypadA" type="TextureRect" parent="PanelContainer/Grid" groups=["joypad"]]
[node name="Spawn" type="TabContainer" parent="PanelContainer/Grid"]
layout_mode = 2
theme_override_styles/panel = ExtResource("2_j4jmc")
current_tab = 1
tabs_visible = false

[node name="JoypadA" type="TextureRect" parent="PanelContainer/Grid/Spawn" groups=["joypad"]]
visible = false
layout_mode = 2
texture = ExtResource("5_hnd0v")
metadata/_tab_index = 0

[node name="KeyboardEnter" type="TextureRect" parent="PanelContainer/Grid"]
[node name="KeyboardEnter" type="TextureRect" parent="PanelContainer/Grid/Spawn"]
layout_mode = 2
texture = ExtResource("10_kj4r4")
metadata/_tab_index = 1

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

[node name="JoypadB" type="TextureRect" parent="PanelContainer/Grid" groups=["joypad"]]
[node name="RestartTimer" type="TabContainer" parent="PanelContainer/Grid"]
layout_mode = 2
theme_override_styles/panel = ExtResource("2_j4jmc")
current_tab = 1
tabs_visible = false

[node name="JoypadB" type="TextureRect" parent="PanelContainer/Grid/RestartTimer" groups=["joypad"]]
visible = false
layout_mode = 2
texture = ExtResource("6_ycckv")
metadata/_tab_index = 0

[node name="KeyboardBackspace" type="TextureRect" parent="PanelContainer/Grid"]
[node name="KeyboardBackspace" type="TextureRect" parent="PanelContainer/Grid/RestartTimer"]
layout_mode = 2
texture = ExtResource("12_vm4m3")
metadata/_tab_index = 1
3 changes: 3 additions & 0 deletions scenes/control_legend/mode_switch_tab_panel.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gd_resource type="StyleBoxEmpty" format=3 uid="uid://db4ob2gq7j8vs"]

[resource]

0 comments on commit a5f781d

Please sign in to comment.