SupaLidlGame/UI/Inventory/Hotbar.cs

26 lines
650 B
C#
Raw Normal View History

2023-12-31 05:59:33 -08:00
using Godot;
namespace SupaLidlGame.UI.Inventory;
2023-12-31 05:59:33 -08:00
public partial class Hotbar : GridContainer
{
[Export]
private Godot.Collections.Array<InventorySlot> _slots;
public override void _Ready()
{
Events.EventBus.Instance.PlayerInventoryUpdate += OnInventoryUpdate;
}
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
}
}
}