mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:55:35 +00:00
Tabbed inventory
This commit is contained in:
parent
c81a92679b
commit
6d7282f5cb
214 changed files with 9329 additions and 186 deletions
|
|
@ -1,103 +1,88 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using Cirno.Scripts;
|
||||
using Cirno.Scripts.UI;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class ItemsMenu : ItemList
|
||||
{
|
||||
private InventoryManager _inventoryManager;
|
||||
private Dictionary<long, string> _itemsDic = new();
|
||||
|
||||
[Export] public Array<ItemTypes> ItemsFilter { get; private set; } = [];
|
||||
|
||||
private InventoryMenu _parent;
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
[Export]
|
||||
public string InventoryActionName { get; private set; } = "inventory";
|
||||
|
||||
[Export]
|
||||
public string PauseActionName { get; private set; } = "pause";
|
||||
|
||||
public override void _Ready()
|
||||
public void Init(InventoryMenu parent)
|
||||
{
|
||||
CallDeferred(MethodName.DeferredInitialize);
|
||||
this.Hide();
|
||||
_parent = parent;
|
||||
Empty();
|
||||
ItemActivated += OnItemSelected;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
public void Fill()
|
||||
{
|
||||
if (Input.IsActionJustPressed(InventoryActionName) || Input.IsActionJustPressed(PauseActionName))
|
||||
foreach (var item in InventoryManager.Instance.Items)
|
||||
{
|
||||
if (Visible)
|
||||
{
|
||||
CallDeferred(MethodName.HideInventory);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// ShowInventory();
|
||||
// }
|
||||
if (item.Count <= 0) continue;
|
||||
if (!ItemsFilter.Contains(item.Item.Item)) continue;
|
||||
|
||||
var index = this.AddItem($"{item.Item.ItemName} x{item.Count}", item.Item.InventorySprite,
|
||||
true);
|
||||
|
||||
//this.SetItemTooltip(index, item.Item.ItemDescription);
|
||||
|
||||
_itemsDic.Add(index, item.Item.ItemKey);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void DeferredInitialize()
|
||||
public void Empty()
|
||||
{
|
||||
_gameManager = GameManager.Instance;
|
||||
_inventoryManager = _gameManager.GetInventoryManager();
|
||||
|
||||
ItemSelected += OnItemSelected;
|
||||
Clear();
|
||||
|
||||
ItemActivated += OnItemSelected;
|
||||
|
||||
_gameManager.GameStateChange += state =>
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case GameState.Inventory:
|
||||
CallDeferred(MethodName.ShowInventory);
|
||||
break;
|
||||
default:
|
||||
CallDeferred(MethodName.HideInventory);
|
||||
//HideInventory();
|
||||
break;
|
||||
}
|
||||
};
|
||||
_itemsDic.Clear();
|
||||
}
|
||||
|
||||
private void OnItemSelected(long index)
|
||||
{
|
||||
var item = _itemsDic[index];
|
||||
GD.Print("Item: " + item);
|
||||
HideInventory();
|
||||
|
||||
_inventoryManager.UseItem(item);
|
||||
}
|
||||
InventoryManager.Instance.TryGetItem(item, out var lootItem);
|
||||
if (!lootItem.Item.Selectable) return;
|
||||
|
||||
private void HideInventory()
|
||||
{
|
||||
if (!Visible) return;
|
||||
GD.Print("Hiding inventory");
|
||||
this.Hide();
|
||||
Clear();
|
||||
_itemsDic.Clear();
|
||||
|
||||
GameManager.Instance.ChangeState(GameState.Playing);
|
||||
|
||||
InventoryManager.Instance.UseItem(item);
|
||||
}
|
||||
|
||||
private void ShowInventory()
|
||||
{
|
||||
if (Visible) return;
|
||||
GD.Print("Showing inventory");
|
||||
this.Show();
|
||||
foreach (var item in _inventoryManager.Items)
|
||||
{
|
||||
if (item.Count <= 0) continue;
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
// private void HideInventory()
|
||||
// {
|
||||
// if (!Visible) return;
|
||||
// GD.Print("Hiding inventory");
|
||||
// this.Hide();
|
||||
// Clear();
|
||||
// _itemsDic.Clear();
|
||||
//
|
||||
// GameManager.Instance.ChangeState(GameState.Playing);
|
||||
// }
|
||||
|
||||
// private void ShowInventory()
|
||||
// {
|
||||
// if (Visible) return;
|
||||
// this.Show();
|
||||
// GrabFocus();
|
||||
// foreach (var item in _inventoryManager.Items)
|
||||
// {
|
||||
// if (item.Count <= 0) continue;
|
||||
// if (!ItemsFilter.Contains(item.Item.Item)) continue;
|
||||
//
|
||||
// var index = this.AddItem($"{item.Item.ItemName} x{item.Count}", item.Item.InventorySprite,
|
||||
// true);
|
||||
//
|
||||
// this.SetItemTooltip(index, item.Item.ItemDescription);
|
||||
//
|
||||
// _itemsDic.Add(index, item.Item.ItemKey);
|
||||
//
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue