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