|
1 | 1 | extends Control |
2 | 2 |
|
| 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 | + |
3 | 9 | # Called when the node enters the scene tree for the first time. |
4 | 10 | 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) |
0 commit comments