feat: marketplace keyboard/gamepad navigation

This commit is contained in:
2026-03-19 03:44:35 +01:00
parent 9043cfa63c
commit e647cd7b29
3 changed files with 45 additions and 0 deletions

View File

@@ -38,6 +38,9 @@ public partial class Marketplace : Control
SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocked;
EventBus.Instance.SkillCollected += OnGlobalSkillCollected;
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
}
public override void _ExitTree()
@@ -47,10 +50,21 @@ public partial class Marketplace : Control
{
EventBus.Instance.SkillCollected -= OnGlobalSkillCollected;
}
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
}
public override void _Input(InputEvent @event)
{
if (@event.IsActionPressed("ui_cancel") && IsVisible())
{
Hide();
foreach (var c in ComponentsToDisable) c.ProcessMode = ProcessModeEnum.Inherit;
GetViewport().SetInputAsHandled();
return;
}
if (!@event.IsActionPressed("show_marketplace")) return;
if (IsVisible())
@@ -62,6 +76,35 @@ public partial class Marketplace : Control
{
Show();
foreach (var c in ComponentsToDisable) c.ProcessMode = ProcessModeEnum.Disabled;
if (InputDeviceManager.Instance?.IsPointerless == true)
GrabFirstFocus();
}
}
private void OnDeviceChanged(int device)
{
var d = (InputDeviceManager.InputDevice)device;
if (d != InputDeviceManager.InputDevice.Mouse && IsVisible())
GrabFirstFocus();
}
private void GrabFirstFocus()
{
foreach (var btn in _unlockButtons)
{
if (btn.Visible && !btn.Disabled)
{
btn.GrabFocus();
return;
}
}
foreach (var btn in _skillButtons)
{
if (btn.Visible)
{
btn.GrabFocus();
return;
}
}
}