Skip to content

Commit

Permalink
fix(Gamepad Settings): add mouse handling for gamepad settings button
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Jan 26, 2025
1 parent 049c03c commit 1b006c5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
39 changes: 38 additions & 1 deletion core/ui/card_ui/settings/general_controller_settings_menu.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
extends Control

var input_plumber := load("res://core/systems/input/input_plumber.tres") as InputPlumberInstance
var state_machine := load("res://assets/state/state_machines/menu_state_machine.tres") as StateMachine
var state := load("res://assets/state/states/gamepad_settings.tres") as State

@onready var gamepad_button := $%GamepadSettingsButton as CardButton

# Called when the node enters the scene tree for the first time.
func _ready():
pass
gamepad_button.gui_input.connect(_on_button_input)


# If the user presses the gamepad settings button with a non-gamepad input method,
# open the settings for the first detected controller.
# TODO: Add a controller select pop-up to select a gamepad to configure
func _on_button_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
if (event as InputEventMouseButton).button_index != MOUSE_BUTTON_LEFT:
return
if (event as InputEventMouseButton).pressed:
return
_open_menu_default_gamepad()
return

if event is InputEventKey:
if !event.is_action("ui_accept"):
return
if event.pressed:
return
_open_menu_default_gamepad()


# Push the gamepad config menu for the first detected controller.
func _open_menu_default_gamepad() -> void:
state.set_meta("dbus_path", "")
var devices := input_plumber.get_composite_devices()
if !devices.is_empty():
var device := devices[0]
state.set_meta("dbus_path", device.dbus_path)

state_machine.push_state(state)
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ layout_mode = 2

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

[node name="CardButton" parent="MarginContainer/VBoxContainer" instance=ExtResource("7_ynn8u")]
[node name="GamepadSettingsButton" parent="MarginContainer/VBoxContainer" instance=ExtResource("7_ynn8u")]
unique_name_in_owner = true
layout_mode = 2
text = "Gamepad Settings"

[node name="StateUpdater" parent="MarginContainer/VBoxContainer/CardButton" instance=ExtResource("8_1egj0")]
[node name="StateUpdater" parent="MarginContainer/VBoxContainer/GamepadSettingsButton" instance=ExtResource("8_1egj0")]
state_machine = ExtResource("10_ij44t")
state = ExtResource("10_uoc6p")
on_signal = "player_button_up"

0 comments on commit 1b006c5

Please sign in to comment.