mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:35:34 +00:00
Fix for immediately closing inventory
This commit is contained in:
parent
f1b5251045
commit
c11acda1df
4 changed files with 93 additions and 26 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using Cirno.Scripts.Components.Actors;
|
||||
using System.Threading.Tasks;
|
||||
using Cirno.Scripts.Components.Actors;
|
||||
using Cirno.Scripts.Components.Actors._3D;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
|
|
@ -62,7 +63,8 @@ public partial class Active : BaseState<PlayerState, CharacterBody3D>
|
|||
//_activationProvider.Enabled = true;
|
||||
//_interactionController.Enabled = true;
|
||||
|
||||
|
||||
_canOpenInventory = true;
|
||||
_inventoryCooldown = 0;
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
|
|
@ -74,11 +76,11 @@ public partial class Active : BaseState<PlayerState, CharacterBody3D>
|
|||
// _hitboxSpriteProvider.Hide();
|
||||
//
|
||||
DamageReceiver.Enabled = false;
|
||||
|
||||
_canOpenInventory = true;
|
||||
// _activationProvider.Enabled = false;
|
||||
// _interactionController.Enabled = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
|
|
@ -87,36 +89,54 @@ public partial class Active : BaseState<PlayerState, CharacterBody3D>
|
|||
|
||||
// Process modules
|
||||
base.PhysicsProcessState(delta);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
base.ProcessState(delta);
|
||||
|
||||
HandleInputHotkeys();
|
||||
HandleInputHotkeys(delta);
|
||||
|
||||
AnimationProvider.SetAnimationSpeed(new Vector2(MainObject.Velocity.X, MainObject.Velocity.Z));
|
||||
AnimationProvider.SetAnimation(Storage.FacingDirection);
|
||||
}
|
||||
|
||||
private bool _canOpenInventory = true;
|
||||
private double _inventoryCooldown = 0;
|
||||
|
||||
private void HandleInputHotkeys()
|
||||
private void HandleInputHotkeys(double delta)
|
||||
{
|
||||
if (_inputProvider.GetInventoryJustPressed())
|
||||
if (_canOpenInventory && _inputProvider.GetInventoryJustPressed())
|
||||
{
|
||||
_canOpenInventory = false;
|
||||
|
||||
GameStateManager.SetState(GameState.Inventory);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_canOpenInventory)
|
||||
{
|
||||
_inventoryCooldown += delta;
|
||||
if (_inventoryCooldown >= 0.2)
|
||||
{
|
||||
_canOpenInventory = true;
|
||||
_inventoryCooldown = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (_inputProvider.GetPauseJustPressed())
|
||||
{
|
||||
GameStateManager.Instance.Pause();
|
||||
//PauseDeferred();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void InventoryDeferred()
|
||||
{
|
||||
GameStateManager.SetState(GameState.Inventory);
|
||||
}
|
||||
|
||||
private void PauseDeferred()
|
||||
{
|
||||
GameStateManager.Instance.Pause();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue