Skip to content

Commit 1cd19e5

Browse files
committed
fix(Gamepad Settings): add mouse handling for gamepad settings button
1 parent 545a0f9 commit 1cd19e5

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed
Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
extends Control
22

3+
var input_plumber := load("res://core/systems/input/input_plumber.tres") as InputPlumberInstance
4+
var state_machine := load("res://assets/state/state_machines/menu_state_machine.tres") as StateMachine
5+
var state := load("res://assets/state/states/gamepad_settings.tres") as State
6+
7+
@onready var gamepad_button := $%GamepadSettingsButton as CardButton
8+
39
# Called when the node enters the scene tree for the first time.
410
func _ready():
5-
pass
11+
gamepad_button.gui_input.connect(_on_button_input)
12+
13+
14+
# If the user presses the gamepad settings button with a non-gamepad input method,
15+
# open the settings for the first detected controller.
16+
# TODO: Add a controller select pop-up to select a gamepad to configure
17+
func _on_button_input(event: InputEvent) -> void:
18+
if event is InputEventMouseButton:
19+
if (event as InputEventMouseButton).button_index != MOUSE_BUTTON_LEFT:
20+
return
21+
if (event as InputEventMouseButton).pressed:
22+
return
23+
_open_menu_default_gamepad()
24+
return
25+
26+
if event is InputEventKey:
27+
if !event.is_action("ui_accept"):
28+
return
29+
if event.pressed:
30+
return
31+
_open_menu_default_gamepad()
32+
33+
34+
# Push the gamepad config menu for the first detected controller.
35+
func _open_menu_default_gamepad() -> void:
36+
state.set_meta("dbus_path", "")
37+
var devices := input_plumber.get_composite_devices()
38+
if !devices.is_empty():
39+
var device := devices[0]
40+
state.set_meta("dbus_path", device.dbus_path)
41+
42+
state_machine.push_state(state)

core/ui/card_ui/settings/general_controller_settings_menu.tscn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ layout_mode = 2
5555

5656
[node name="FocusGroup" parent="MarginContainer/VBoxContainer" instance=ExtResource("2_fdccl")]
5757

58-
[node name="CardButton" parent="MarginContainer/VBoxContainer" instance=ExtResource("7_ynn8u")]
58+
[node name="GamepadSettingsButton" parent="MarginContainer/VBoxContainer" instance=ExtResource("7_ynn8u")]
59+
unique_name_in_owner = true
5960
layout_mode = 2
6061
text = "Gamepad Settings"
6162

62-
[node name="StateUpdater" parent="MarginContainer/VBoxContainer/CardButton" instance=ExtResource("8_1egj0")]
63+
[node name="StateUpdater" parent="MarginContainer/VBoxContainer/GamepadSettingsButton" instance=ExtResource("8_1egj0")]
6364
state_machine = ExtResource("10_ij44t")
6465
state = ExtResource("10_uoc6p")
6566
on_signal = "player_button_up"

0 commit comments

Comments
 (0)