mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
72 lines
1.6 KiB
C#
72 lines
1.6 KiB
C#
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);
|
|
|
|
HideInventory();
|
|
}
|
|
|
|
public void HideInventory()
|
|
{
|
|
this.Hide();
|
|
Clear();
|
|
_itemsDic.Clear();
|
|
}
|
|
|
|
public void ShowInventory()
|
|
{
|
|
this.Show();
|
|
foreach (var itm in _inventoryManager.Items)
|
|
{
|
|
var item = itm.Value;
|
|
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);
|
|
|
|
}
|
|
}
|
|
}
|