2025-02-25 18:11:57 +01:00
|
|
|
using Godot;
|
|
|
|
|
using System;
|
|
|
|
|
using Cirno.Scripts;
|
|
|
|
|
using Godot.Collections;
|
|
|
|
|
|
|
|
|
|
public partial class ItemsMenu : ItemList
|
|
|
|
|
{
|
|
|
|
|
private InventoryManager _inventoryManager;
|
|
|
|
|
private Dictionary<long, string> _itemsDic = new();
|
|
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
|
{
|
|
|
|
|
CallDeferred(MethodName.DeferredInitialize);
|
|
|
|
|
this.Hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void _Process(double delta)
|
|
|
|
|
{
|
|
|
|
|
if (Input.IsActionJustPressed("inventory"))
|
|
|
|
|
{
|
|
|
|
|
if (!Visible)
|
|
|
|
|
{
|
|
|
|
|
ShowInventory();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
HideInventory();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DeferredInitialize()
|
|
|
|
|
{
|
|
|
|
|
_inventoryManager = GameManager.Instance.GetInventoryManager();
|
|
|
|
|
|
|
|
|
|
ItemSelected += OnItemSelected;
|
|
|
|
|
Clear();
|
|
|
|
|
|
|
|
|
|
ItemActivated += OnItemSelected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnItemSelected(long index)
|
|
|
|
|
{
|
|
|
|
|
var item = _itemsDic[index];
|
|
|
|
|
GD.Print("Item: " + item);
|
2025-02-25 18:42:11 +01:00
|
|
|
|
|
|
|
|
_inventoryManager.UseItem(item);
|
2025-02-25 18:11:57 +01:00
|
|
|
|
|
|
|
|
HideInventory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HideInventory()
|
|
|
|
|
{
|
|
|
|
|
this.Hide();
|
|
|
|
|
Clear();
|
|
|
|
|
_itemsDic.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowInventory()
|
|
|
|
|
{
|
|
|
|
|
this.Show();
|
2025-02-25 18:42:11 +01:00
|
|
|
foreach (var item in _inventoryManager.Items)
|
2025-02-25 18:11:57 +01:00
|
|
|
{
|
2025-02-25 18:42:11 +01:00
|
|
|
if (item.Count <= 0) continue;
|
|
|
|
|
|
2025-02-25 18:11:57 +01:00
|
|
|
var index = this.AddItem($"{item.Item.ItemName} x{item.Count}", item.Item.InventorySprite,
|
|
|
|
|
item.Item.Selectable);
|
|
|
|
|
|
|
|
|
|
this.SetItemTooltip(index, item.Item.ItemDescription);
|
|
|
|
|
|
|
|
|
|
_itemsDic.Add(index, item.Item.ItemKey);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|