Inventory close and open by button

This commit is contained in:
Marco 2025-03-01 20:50:47 +01:00
commit 80a13d047d
11 changed files with 165 additions and 53 deletions

View file

@ -7,6 +7,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AContainer_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003F8146f3e3f6341957cdf79e3ab90302acaa98c2e4c60a2f098a6fcc8a2c86c7_003FContainer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADisposablesTracker_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FDecompilerCache_003Fdecompiler_003F4fd22cd129a84c16b5d8004b467c426f518800_003Fb8_003Fee061233_003FDisposablesTracker_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnemy_005FScriptProperties_002Egenerated_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Fd6739058209280d46591ab296d6b49dfcf7ecd2_003FEnemy_005FScriptProperties_002Egenerated_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGameManager_005FScriptMethods_002Egenerated_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003F642294f86639b2f8d4cb4d14e791d697e55369_003FGameManager_005FScriptMethods_002Egenerated_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Fbb1b701f3c7411227a9d2e09f965d857ff3e771557650c4f513e427d77c_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlayerMovement_005FScriptMethods_002Egenerated_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003F4af4702ac4bbb9ab7299554c41beea2bf703b4a_003FPlayerMovement_005FScriptMethods_002Egenerated_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AScriptManagerBridge_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FDecompilerCache_003Fdecompiler_003F4fd22cd129a84c16b5d8004b467c426f518800_003F3a_003Fc456f450_003FScriptManagerBridge_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>

View file

@ -200,6 +200,7 @@ MaxResource = 32.0
shape = SubResource("CircleShape2D_igu66")
[node name="InteractionProvider" type="Area2D" parent="." node_paths=PackedStringArray("_inputProvider", "_errorSound")]
visible = false
collision_layer = 2
collision_mask = 4
script = ExtResource("22_12cwd")

View file

@ -9,11 +9,13 @@ public abstract partial class InputProvider : Node2D
public abstract bool GetActionJustPressed(string action);
public abstract bool GetActionPressed(string action);
public abstract bool GetInventoryJustPressed();
public abstract bool GetShootPressed();
public abstract bool GetShootJustPressed();
public abstract bool GetUseJustPressed();
public abstract bool GetScanJustPressed();
public abstract bool GetStrafePressed();
public abstract bool GetWeaponNextJustPressed();
public abstract bool GetWeaponPreviousJustPressed();
public abstract bool GetPauseJustPressed();
}

View file

@ -31,6 +31,8 @@ public partial class KeyboardInputProvider : InputProvider
[Export] private string _strafeActionName = "strafe";
[Export] private string _nextWeaponActionName = "next_weapon";
[Export] private string _previousWeaponActionName = "previous_weapon";
[Export] private string _inventoryActionName = "inventory";
[Export] private string _pauseActionName = "pause";
public override Vector2 GetMovementInput()
{
@ -60,10 +62,20 @@ public partial class KeyboardInputProvider : InputProvider
return Input.IsActionPressed(action);
}
public override bool GetInventoryJustPressed()
{
return GetActionJustPressed(_inventoryActionName);
}
public override bool GetShootPressed()
{
return GetActionPressed(_shootActionName);
}
public override bool GetShootJustPressed()
{
return GetActionJustPressed(_shootActionName);
}
public override bool GetUseJustPressed()
{
@ -89,4 +101,9 @@ public partial class KeyboardInputProvider : InputProvider
return GetActionJustPressed(_previousWeaponActionName);
}
public override bool GetPauseJustPressed()
{
return GetActionJustPressed(_pauseActionName);
}
}

View file

@ -35,11 +35,15 @@ public partial class Active : PlayerFSMState
public int MovementSpeed => _isStrafing ? StrafeSpeed : Speed;
private PlayerStateMachine _player;
private Hud _hud;
public override void Init(ActorStateMachine stateMachine)
{
base.Init(stateMachine);
_hud = Hud.Instance;
_player = (PlayerStateMachine)stateMachine;
_damageReceiver.Death += () =>
@ -50,11 +54,13 @@ public partial class Active : PlayerFSMState
_damageReceiver.HealthChanged += (value, maxValue) =>
{
_animationProvider.Blink();
_hud.UpdateHealth(value, maxValue);
};
_damageReceiver.ShieldChanged += (value, maxValue) =>
{
_animationProvider.PlayShieldAnimation();
_hud.UpdateShield(value, maxValue);
};
_damageReceiver.Init();
@ -128,6 +134,21 @@ public partial class Active : PlayerFSMState
// _crosshair.Position = CalculateCrosshairPosition();
if (_inputProvider.GetInventoryJustPressed())
{
GameManager.Instance.ChangeState(GameState.Inventory);
}
if (_inputProvider.GetPauseJustPressed())
{
//CallDeferred(MethodName.PauseDeferred);
PauseDeferred();
}
}
private void PauseDeferred()
{
GameManager.Instance.Pause();
}
private void HandleShoot()

View file

@ -1,4 +1,5 @@
using Godot;
using Cirno.Scripts.Components.Actors;
using Godot;
namespace Cirno.Scripts.Components.FSM.Player;
@ -6,33 +7,58 @@ public partial class Dead : PlayerFSMState
{
[Export]
private PlayerAnimationProvider _animationProvider;
[Export]
private InputProvider _inputProvider;
[Export]
private ActorResourceProvider _healthProvider;
private GameManager _gameManager;
private Hud _hud;
public override void Init(ActorStateMachine stateMachine)
{
base.Init(stateMachine);
// get hud?
_gameManager = GameManager.Instance;
_hud = Hud.Instance;
}
public override void EnterState()
{
_animationProvider.PlayDeathAnimation();
// show game over
_hud.ShowGameOver();
}
public override void ExitState()
{
// Hide game over
_hud.HideGameOver();
}
public override void ProcessState(double delta)
{
// wait for button
if (_inputProvider.GetShootJustPressed())
{
Respawn();
}
}
public override void PhysicsProcessState(double delta)
{
}
public void Respawn()
{
_stateMachine.GlobalPosition = _gameManager.LastCheckpointPosition;
_healthProvider.FillResource();
_gameManager.ClearBullets();
_stateMachine.SetState((int)PlayerState.Active);
}
}

View file

@ -41,6 +41,9 @@ public partial class GameManager : Node2D
//public AlarmManager AlarmManager => _alarmManager;
[Export]
public string PauseActionName { get; private set; } = "pause";
private Node2D _bulletsContainer;
public Node2D BulletsContainer => _bulletsContainer;
@ -49,6 +52,8 @@ public partial class GameManager : Node2D
[Signal]
public delegate void PlayerRespawnedEventHandler();
public Vector2 LastCheckpointPosition { get; set; }
// Called when the node enters the scene tree for the first time.
public override void _Ready()
@ -104,20 +109,17 @@ public partial class GameManager : Node2D
{
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if (GameState is GameState.Playing && Input.IsActionJustPressed("pause"))
if (GameState is GameState.Paused && Input.IsActionJustPressed(PauseActionName))
{
TogglePause();
Unpause();
}
}
private void DelayPlayerSpawn()
{
//await Task.Delay(500);
if (SpawnMarkers.Any())
{
SpawnPlayer();
@ -244,17 +246,17 @@ public partial class GameManager : Node2D
AddChild(_bulletsContainer);
}
public void TogglePause()
{
if (GameState == GameState.Paused)
{
Unpause();
}
else if (GameState == GameState.Playing)
{
Pause();
}
}
// public void TogglePause()
// {
// if (GameState == GameState.Paused)
// {
// Unpause();
// }
// else if (GameState == GameState.Playing)
// {
// Pause();
// }
// }
public void Pause()
{
@ -268,7 +270,8 @@ public partial class GameManager : Node2D
{
if (GameState == GameState.Paused)
{
ChangeState(GameState.Playing);
CallDeferred(MethodName.ChangeState, (int)GameState.Playing);
//ChangeState(GameState.Playing);
}
}
@ -290,22 +293,19 @@ public partial class GameManager : Node2D
{
if (state == GameState) return;
GameState = state;
EmitSignal(nameof(GameStateChange), (int)GameState);
EmitSignal(SignalName.GameStateChange, (int)state);
GD.Print($"Game state changed to {state}");
switch (state)
{
case GameState.Menu:
GetTree().SetPause(false);
break;
case GameState.Paused:
case GameState.Dialogue:
case GameState.Inventory:
GetTree().SetPause(true);
break;
case GameState.Playing:
GetTree().SetPause(false);
break;
case GameState.Controlling:
case GameState.Menu:
GetTree().SetPause(false);
break;
}
@ -327,5 +327,6 @@ public enum GameState
Paused,
Playing,
Dialogue,
Controlling
Controlling,
Inventory
}

View file

@ -8,6 +8,7 @@ using Cirno.Scripts.UI;
public partial class Hud : CanvasLayer
{
public static Hud Instance { get; private set; }
[Signal]
public delegate void StartGameEventHandler();
@ -48,10 +49,11 @@ public partial class Hud : CanvasLayer
private PauseMenu _pauseMenu;
private bool _playerDead = false;
private bool _playerDead = false; // useless
public override void _Ready()
{
Instance = this;
// Assuming the HUD has a Label node named "HealthLabel"
//_healthLabel = GetNode<Label>("HealthLabel");
_gameOverPanel.Hide();
@ -83,6 +85,11 @@ public partial class Hud : CanvasLayer
// await ToSignal(GetTree().CreateTimer(1.0), SceneTreeTimer.SignalName.Timeout);
// GetNode<Button>("StartButton").Show();
}
public void HideGameOver()
{
}
public void UpdateHealth(float newHealth, float maxHealth)
{
@ -190,20 +197,16 @@ public partial class Hud : CanvasLayer
public void OnGameStateChanged(GameState state)
{
// Clear on every change
ClearPauseMenu();
switch (state)
{
case GameState.Menu:
break;
case GameState.Paused:
SpawnPauseMenu();
break;
case GameState.Controlling:
case GameState.Menu:
case GameState.Playing:
ClearPauseMenu();
break;
case GameState.Dialogue:
default:
ClearPauseMenu();
break;
}

View file

@ -17,6 +17,7 @@ public partial class UpdateCheckPointEvent : EventResource
public override void Start(Node2D parent)
{
_gameManager.LastCheckpointPosition = parent.GetNode<Node2D>(Target).GlobalPosition;
_gameManager.Player.LastCheckPointPosition = parent.GetNode<Node2D>(Target).GlobalPosition;
}

View file

@ -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)
{

View file

@ -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);