mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Tabbed inventory
This commit is contained in:
parent
c81a92679b
commit
6d7282f5cb
214 changed files with 9329 additions and 186 deletions
98
Scripts/UI/InventoryMenu.cs
Normal file
98
Scripts/UI/InventoryMenu.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.UI;
|
||||
|
||||
public partial class InventoryMenu : TabContainer
|
||||
{
|
||||
private List<ItemsMenu> _itemMenus = [];
|
||||
|
||||
[Export]
|
||||
public StringName InventoryActionName { get; private set; } = "inventory";
|
||||
|
||||
[Export]
|
||||
public StringName PauseActionName { get; private set; } = "pause";
|
||||
|
||||
[Export]
|
||||
public StringName CancelActionName { get; private set; } = "ui_cancel";
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CallDeferred(MethodName.DeferredInitialize);
|
||||
this.Hide();
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed(InventoryActionName) || Input.IsActionJustPressed(PauseActionName))
|
||||
{
|
||||
if (Visible)
|
||||
{
|
||||
CallDeferred(MethodName.HideInventory);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// ShowInventory();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
private void DeferredInitialize()
|
||||
{
|
||||
var children = this.GetChildren();
|
||||
foreach (var child in children)
|
||||
{
|
||||
if (child is ItemsMenu menu)
|
||||
{
|
||||
_itemMenus.Add(menu);
|
||||
menu.Init(this);
|
||||
}
|
||||
}
|
||||
//Clear();
|
||||
|
||||
//ItemActivated += OnItemSelected;
|
||||
|
||||
GameManager.Instance.GameStateChange += state =>
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case GameState.Inventory:
|
||||
CallDeferred(MethodName.ShowInventory);
|
||||
break;
|
||||
default:
|
||||
CallDeferred(MethodName.HideInventory);
|
||||
//HideInventory();
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void HideInventory()
|
||||
{
|
||||
if (!Visible) return;
|
||||
GD.Print("Hiding inventory");
|
||||
this.Hide();
|
||||
foreach (var menu in _itemMenus)
|
||||
{
|
||||
menu.Empty();
|
||||
}
|
||||
|
||||
//_itemsDic.Clear();
|
||||
|
||||
//GameManager.Instance.ChangeState(GameState.Playing);
|
||||
}
|
||||
|
||||
private void ShowInventory()
|
||||
{
|
||||
if (Visible) return;
|
||||
this.Show();
|
||||
|
||||
foreach (var menu in _itemMenus)
|
||||
{
|
||||
menu.Fill();
|
||||
}
|
||||
|
||||
_itemMenus.FirstOrDefault()?.GrabFocus();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue