diff --git a/Cirno.sln.DotSettings.user b/Cirno.sln.DotSettings.user index ced46b99..fb3467a3 100644 --- a/Cirno.sln.DotSettings.user +++ b/Cirno.sln.DotSettings.user @@ -12,6 +12,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -19,6 +20,8 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded diff --git a/Scenes/HUD/HUD.tscn b/Scenes/HUD/HUD.tscn index 79f269c2..5dd69e6e 100644 --- a/Scenes/HUD/HUD.tscn +++ b/Scenes/HUD/HUD.tscn @@ -327,7 +327,7 @@ offset_right = 354.0 offset_bottom = 198.0 theme_override_styles/panel = ExtResource("20_0ncp3") -[node name="InventoryMenu" type="TabContainer" parent="Control"] +[node name="InventoryMenu" type="TabContainer" parent="Control" node_paths=PackedStringArray("ParentContainer")] layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 @@ -345,6 +345,7 @@ theme = ExtResource("9_sx5r0") theme_override_fonts/font = ExtResource("6_sk1eq") current_tab = 4 script = ExtResource("11_7pulb") +ParentContainer = NodePath("..") metadata/_edit_group_ = true [node name="Weapons" type="ItemList" parent="Control/InventoryMenu"] diff --git a/Scripts/Components/FSM/3DPlayer/Active.cs b/Scripts/Components/FSM/3DPlayer/Active.cs index 9ff47936..174bbe49 100644 --- a/Scripts/Components/FSM/3DPlayer/Active.cs +++ b/Scripts/Components/FSM/3DPlayer/Active.cs @@ -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 //_activationProvider.Enabled = true; //_interactionController.Enabled = true; - + _canOpenInventory = true; + _inventoryCooldown = 0; } public override void ExitState() @@ -74,11 +76,11 @@ public partial class Active : BaseState // _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 // 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(); diff --git a/Scripts/UI/InventoryMenu.cs b/Scripts/UI/InventoryMenu.cs index 5ed1cb65..7b0676dc 100644 --- a/Scripts/UI/InventoryMenu.cs +++ b/Scripts/UI/InventoryMenu.cs @@ -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) {