feat: gamepad/keyboard UI navigation on all menus

This commit is contained in:
2026-03-19 03:26:50 +01:00
parent 2bc0b76050
commit 3b18e328b2
5 changed files with 137 additions and 0 deletions

View File

@@ -21,6 +21,11 @@ public partial class MainMenu : Control
public override void _Ready()
{
NewGameButton.FocusMode = Control.FocusModeEnum.All;
ContinueButton.FocusMode = Control.FocusModeEnum.All;
SettingsButton.FocusMode = Control.FocusModeEnum.All;
CreditsButton.FocusMode = Control.FocusModeEnum.All;
ExitButton.FocusMode = Control.FocusModeEnum.All;
NewGameButton.Pressed += OnNewGamePressed;
ContinueButton.Pressed += OnContinuePressed;
@@ -31,6 +36,34 @@ public partial class MainMenu : Control
VersionLabel.Text = $"v. {ProjectSettings.GetSetting("application/config/version")}";
ContinueButton.Disabled = !SaveSystem.CheckSaveExists();
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
VisibilityChanged += OnVisibilityChanged;
GrabFirstFocus();
}
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()
{
if (SaveSystem.CheckSaveExists())
ContinueButton.GrabFocus();
else