feat: marketplace keyboard/gamepad navigation
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
[ext_resource type="Script" uid="uid://vokgv56bjpf1" path="res://scripts/UI/MarketplaceButton.cs" id="2_vb2qn"]
|
[ext_resource type="Script" uid="uid://vokgv56bjpf1" path="res://scripts/UI/MarketplaceButton.cs" id="2_vb2qn"]
|
||||||
|
|
||||||
[node name="MarketplaceButton" type="Button" node_paths=PackedStringArray("SkillLevelContainer")]
|
[node name="MarketplaceButton" type="Button" node_paths=PackedStringArray("SkillLevelContainer")]
|
||||||
|
focus_mode = 2
|
||||||
offset_right = 8.0
|
offset_right = 8.0
|
||||||
offset_bottom = 8.0
|
offset_bottom = 8.0
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
[ext_resource type="Script" uid="uid://bw8dlgq86jrtt" path="res://scripts/UI/SkillButton.cs" id="2_m2732"]
|
[ext_resource type="Script" uid="uid://bw8dlgq86jrtt" path="res://scripts/UI/SkillButton.cs" id="2_m2732"]
|
||||||
|
|
||||||
[node name="SkillButton" type="Button"]
|
[node name="SkillButton" type="Button"]
|
||||||
|
focus_mode = 2
|
||||||
offset_right = 8.0
|
offset_right = 8.0
|
||||||
offset_bottom = 8.0
|
offset_bottom = 8.0
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ public partial class Marketplace : Control
|
|||||||
|
|
||||||
SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocked;
|
SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocked;
|
||||||
EventBus.Instance.SkillCollected += OnGlobalSkillCollected;
|
EventBus.Instance.SkillCollected += OnGlobalSkillCollected;
|
||||||
|
|
||||||
|
if (InputDeviceManager.Instance != null)
|
||||||
|
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _ExitTree()
|
public override void _ExitTree()
|
||||||
@@ -47,10 +50,21 @@ public partial class Marketplace : Control
|
|||||||
{
|
{
|
||||||
EventBus.Instance.SkillCollected -= OnGlobalSkillCollected;
|
EventBus.Instance.SkillCollected -= OnGlobalSkillCollected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (InputDeviceManager.Instance != null)
|
||||||
|
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Input(InputEvent @event)
|
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 (!@event.IsActionPressed("show_marketplace")) return;
|
||||||
|
|
||||||
if (IsVisible())
|
if (IsVisible())
|
||||||
@@ -62,6 +76,35 @@ public partial class Marketplace : Control
|
|||||||
{
|
{
|
||||||
Show();
|
Show();
|
||||||
foreach (var c in ComponentsToDisable) c.ProcessMode = ProcessModeEnum.Disabled;
|
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