Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Gamepad Settings): add mouse handling for gamepad settings button #430

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should prioritize this soon, along with gamepad ordering. This shouldn't be exclusive to mouse/touch input though, I think it would be reasonable to configure multiple gamepads with player 1 for example .

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"
Loading