feat: gamepad/keyboard UI navigation on all menus
This commit is contained in:
@@ -19,6 +19,10 @@ public partial class SettingsMenu : Control
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
InputSettingsButton.FocusMode = Control.FocusModeEnum.All;
|
||||
AudioSettingsButton.FocusMode = Control.FocusModeEnum.All;
|
||||
DisplaySettingsButton.FocusMode = Control.FocusModeEnum.All;
|
||||
GameplaySettingsButton.FocusMode = Control.FocusModeEnum.All;
|
||||
|
||||
InputSettingsButton.Pressed += OnInputSettingsPressed;
|
||||
AudioSettingsButton.Pressed += OnAudioSettingsPressed;
|
||||
@@ -29,8 +33,33 @@ public partial class SettingsMenu : Control
|
||||
AudioSettingsControl?.Hide();
|
||||
DisplaySettingsControl?.Hide();
|
||||
GameplaySettingsControl?.Hide();
|
||||
|
||||
if (InputDeviceManager.Instance != null)
|
||||
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
|
||||
VisibilityChanged += OnVisibilityChanged;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (InputDeviceManager.Instance != null)
|
||||
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
|
||||
}
|
||||
|
||||
private void OnVisibilityChanged()
|
||||
{
|
||||
if (IsVisibleInTree() && InputDeviceManager.Instance?.IsPointerless == true)
|
||||
GrabFirstFocus();
|
||||
}
|
||||
|
||||
private void OnDeviceChanged(int device)
|
||||
{
|
||||
var d = (InputDeviceManager.InputDevice)device;
|
||||
if (d != InputDeviceManager.InputDevice.Mouse && IsVisibleInTree())
|
||||
GrabFirstFocus();
|
||||
}
|
||||
|
||||
private void GrabFirstFocus() => InputSettingsButton.GrabFocus();
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (!@event.IsActionPressed("ui_cancel")) return;
|
||||
|
||||
Reference in New Issue
Block a user