feat: gamepad/keyboard UI navigation on all menus
This commit is contained in:
@@ -18,6 +18,10 @@ public partial class PauseMenu : Control
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
ResumeButton.FocusMode = Control.FocusModeEnum.All;
|
||||
MainMenuButton.FocusMode = Control.FocusModeEnum.All;
|
||||
QuitButton.FocusMode = Control.FocusModeEnum.All;
|
||||
SettingsButton.FocusMode = Control.FocusModeEnum.All;
|
||||
|
||||
ResumeButton.Pressed += OnResumePressed;
|
||||
MainMenuButton.Pressed += OnMainMenuPressed;
|
||||
@@ -25,8 +29,33 @@ public partial class PauseMenu : Control
|
||||
SettingsButton.Pressed += OnSettingsPressed;
|
||||
|
||||
PauseMenuControl.Hide();
|
||||
|
||||
if (InputDeviceManager.Instance != null)
|
||||
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
|
||||
PauseMenuControl.VisibilityChanged += OnVisibilityChanged;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (InputDeviceManager.Instance != null)
|
||||
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
|
||||
}
|
||||
|
||||
private void OnVisibilityChanged()
|
||||
{
|
||||
if (PauseMenuControl.IsVisibleInTree() && InputDeviceManager.Instance?.IsPointerless == true)
|
||||
GrabFirstFocus();
|
||||
}
|
||||
|
||||
private void OnDeviceChanged(int device)
|
||||
{
|
||||
var d = (InputDeviceManager.InputDevice)device;
|
||||
if (d != InputDeviceManager.InputDevice.Mouse && PauseMenuControl.IsVisibleInTree())
|
||||
GrabFirstFocus();
|
||||
}
|
||||
|
||||
private void GrabFirstFocus() => ResumeButton.GrabFocus();
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (!@event.IsActionPressed("pause")) return;
|
||||
|
||||
Reference in New Issue
Block a user