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

@@ -16,19 +16,44 @@ public partial class AudioSettings : Control
public override void _Ready()
{
MasterVolumeSlider.FocusMode = Control.FocusModeEnum.All;
MusicVolumeSlider.FocusMode = Control.FocusModeEnum.All;
SfxVolumeSlider.FocusMode = Control.FocusModeEnum.All;
Initialize();
MasterVolumeSlider.ValueChanged += OnMasterVolumeChanged;
MusicVolumeSlider.ValueChanged += OnMusicVolumeChanged;
SfxVolumeSlider.ValueChanged += OnSfxVolumeChanged;
LoadSettings();
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
AudioSettingsControl.VisibilityChanged += OnVisibilityChanged;
}
public override void _ExitTree()
{
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
SaveSettings();
}
private void OnVisibilityChanged()
{
if (AudioSettingsControl.IsVisibleInTree() && InputDeviceManager.Instance?.IsPointerless == true)
GrabFirstFocus();
}
private void OnDeviceChanged(int device)
{
var d = (InputDeviceManager.InputDevice)device;
if (d != InputDeviceManager.InputDevice.Mouse && AudioSettingsControl.IsVisibleInTree())
GrabFirstFocus();
}
private void GrabFirstFocus() => MasterVolumeSlider.GrabFocus();
public override void _UnhandledInput(InputEvent @event)
{
if (!@event.IsActionReleased("ui_cancel")) return;