SupaLidlGame/UI/Inventory/Hotbar.cs

26 lines
647 B
C#
Raw Normal View History

2023-12-31 05:59:33 -08:00
using Godot;
2024-05-29 14:55:23 -07:00
namespace SupaLidlGame.UI.Inventory;
2023-12-31 05:59:33 -08:00
public partial class Hotbar : GridContainer
{
[Export]
2024-05-29 14:55:23 -07:00
private Godot.Collections.Array<HotbarSlot> _slots;
2023-12-31 05:59:33 -08:00
public override void _Ready()
{
Events.EventBus.Instance.PlayerInventoryUpdate += OnInventoryUpdate;
}
2024-05-29 14:55:23 -07:00
public void OnInventoryUpdate(Items.Inventory inventory)
2023-12-31 05:59:33 -08:00
{
2024-01-01 22:55:53 -08:00
GD.Print($"UPDATE: {inventory.SelectedIndex} is selected index.");
2023-12-31 05:59:33 -08:00
for (int i = 0; i < 3; i++)
{
var slot = _slots[i];
2024-01-01 22:55:53 -08:00
slot.Item = inventory.Hotbar[i]?.Metadata;
slot.IsSelected = inventory.SelectedIndex == i;
2023-12-31 05:59:33 -08:00
}
}
}