feat: marketplace keyboard/gamepad navigation
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user