Fix for immediately closing inventory

This commit is contained in:
MaddoScientisto 2025-12-30 15:27:37 +01:00
commit c11acda1df
4 changed files with 93 additions and 26 deletions

View file

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Cirno.Scripts.Utils;
using Godot;
@ -18,17 +19,48 @@ public partial class InventoryMenu : TabContainer
[Export]
public StringName CancelActionName { get; private set; } = "ui_cancel";
[Export]
public Control ParentContainer { get; private set; }
public override void _Ready()
{
CallDeferred(MethodName.DeferredInitialize);
this.Hide();
HideCommand();
}
private void ShowCommand()
{
ParentContainer?.Show();
this.Show();
}
private void HideCommand()
{
if (ParentContainer is not null)
{
ParentContainer.Hide();
this.Show();
}
else
{
this.Hide();
}
}
private new bool IsVisible()
{
return ParentContainer?.Visible ?? Visible;
}
public override void _Process(double delta)
{
if (Input.IsActionJustPressed(InventoryActionName) || Input.IsActionJustPressed(PauseActionName) || Input.IsActionJustPressed(CancelActionName))
if (Input.IsActionJustPressed(InventoryActionName) ||
Input.IsActionJustPressed(PauseActionName) ||
Input.IsActionJustPressed(CancelActionName))
{
if (Visible)
if (IsVisible())
{
GameStateManager.Instance.ChangeState(GameState.Playing);
//CallDeferred(MethodName.HideInventory);
@ -63,37 +95,48 @@ public partial class InventoryMenu : TabContainer
switch (state)
{
case GameState.Inventory:
CallDeferred(MethodName.ShowInventory);
//CallDeferred(MethodName.ShowInventory);
ShowInventory();
break;
default:
CallDeferred(MethodName.HideInventory);
HideInventory();
//_ = UnpauseAsync();
// _ = new Task(async () =>
// {
// await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
// HideInventory();
// });
//CallDeferred(MethodName.HideInventory);
//HideInventory();
break;
}
};
}
}
private async Task UnpauseAsync()
{
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
HideInventory();
}
private void HideInventory()
{
if (!Visible) return;
GD.Print("Hiding inventory");
this.Hide();
if (!IsVisible()) return;
HideCommand();
foreach (var menu in _itemMenus)
{
menu.Empty();
}
//_itemsDic.Clear();
//GameManager.Instance.ChangeState(GameState.Playing);
}
private void ShowInventory()
{
if (Visible) return;
this.Show();
if (IsVisible()) return;
ShowCommand();
foreach (var menu in _itemMenus)
{