mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 12:35:53 +00:00
Inventory close and open by button
This commit is contained in:
parent
0687b6de99
commit
80a13d047d
11 changed files with 165 additions and 53 deletions
|
|
@ -7,6 +7,14 @@ public partial class ItemsMenu : ItemList
|
|||
{
|
||||
private InventoryManager _inventoryManager;
|
||||
private Dictionary<long, string> _itemsDic = new();
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
[Export]
|
||||
public string InventoryActionName { get; private set; } = "inventory";
|
||||
|
||||
[Export]
|
||||
public string PauseActionName { get; private set; } = "pause";
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -16,48 +24,68 @@ public partial class ItemsMenu : ItemList
|
|||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("inventory"))
|
||||
if (Input.IsActionJustPressed(InventoryActionName) || Input.IsActionJustPressed(PauseActionName))
|
||||
{
|
||||
if (!Visible)
|
||||
if (Visible)
|
||||
{
|
||||
ShowInventory();
|
||||
}
|
||||
else
|
||||
{
|
||||
HideInventory();
|
||||
CallDeferred(MethodName.HideInventory);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// ShowInventory();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
private void DeferredInitialize()
|
||||
{
|
||||
_inventoryManager = GameManager.Instance.GetInventoryManager();
|
||||
_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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void OnItemSelected(long index)
|
||||
{
|
||||
var item = _itemsDic[index];
|
||||
GD.Print("Item: " + item);
|
||||
|
||||
_inventoryManager.UseItem(item);
|
||||
|
||||
HideInventory();
|
||||
|
||||
_inventoryManager.UseItem(item);
|
||||
}
|
||||
|
||||
public void HideInventory()
|
||||
private void HideInventory()
|
||||
{
|
||||
if (!Visible) return;
|
||||
GD.Print("Hiding inventory");
|
||||
this.Hide();
|
||||
Clear();
|
||||
_itemsDic.Clear();
|
||||
|
||||
GameManager.Instance.ChangeState(GameState.Playing);
|
||||
}
|
||||
|
||||
public void ShowInventory()
|
||||
private void ShowInventory()
|
||||
{
|
||||
if (Visible) return;
|
||||
GD.Print("Showing inventory");
|
||||
this.Show();
|
||||
foreach (var item in _inventoryManager.Items)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ namespace Cirno.Scripts.UI;
|
|||
|
||||
public partial class PauseMenu : Control
|
||||
{
|
||||
[Export]
|
||||
public string PauseActionName = "pause";
|
||||
|
||||
[ExportGroup("Scenes")]
|
||||
[Export]
|
||||
public string MainMenuScene { get; private set; }
|
||||
|
|
@ -11,13 +14,13 @@ public partial class PauseMenu : Control
|
|||
[ExportGroup("Buttons")]
|
||||
[Export]
|
||||
public Button ResumeButton { get; private set; }
|
||||
[ExportGroup("Buttons")]
|
||||
|
||||
[Export]
|
||||
public Button QuitButton { get; private set; }
|
||||
[ExportGroup("Buttons")]
|
||||
|
||||
[Export]
|
||||
public Button OptionsButton { get; private set; }
|
||||
[ExportGroup("Buttons")]
|
||||
|
||||
[Export]
|
||||
public Button DebugButton { get; private set; }
|
||||
|
||||
|
|
@ -36,6 +39,14 @@ public partial class PauseMenu : Control
|
|||
DebugButton.Pressed += DebugButtonOnPressed;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_gameManager.GameState == GameState.Paused && Input.IsActionJustPressed(PauseActionName))
|
||||
{
|
||||
_gameManager.Unpause();
|
||||
}
|
||||
}
|
||||
|
||||
private void DebugButtonOnPressed()
|
||||
{
|
||||
EmitSignal(SignalName.SpawnDebugMenu);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue