feat: gamepad/keyboard UI navigation on all menus
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user