-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Gamepad Settings): add mouse handling for gamepad settings button
- Loading branch information
1 parent
049c03c
commit 1b006c5
Showing
2 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
39 changes: 38 additions & 1 deletion
39
core/ui/card_ui/settings/general_controller_settings_menu.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters