mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-21 08:53:47 +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,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_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_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_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_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_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>
|
<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>
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,7 @@ MaxResource = 32.0
|
||||||
shape = SubResource("CircleShape2D_igu66")
|
shape = SubResource("CircleShape2D_igu66")
|
||||||
|
|
||||||
[node name="InteractionProvider" type="Area2D" parent="." node_paths=PackedStringArray("_inputProvider", "_errorSound")]
|
[node name="InteractionProvider" type="Area2D" parent="." node_paths=PackedStringArray("_inputProvider", "_errorSound")]
|
||||||
|
visible = false
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
collision_mask = 4
|
collision_mask = 4
|
||||||
script = ExtResource("22_12cwd")
|
script = ExtResource("22_12cwd")
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,13 @@ public abstract partial class InputProvider : Node2D
|
||||||
|
|
||||||
public abstract bool GetActionJustPressed(string action);
|
public abstract bool GetActionJustPressed(string action);
|
||||||
public abstract bool GetActionPressed(string action);
|
public abstract bool GetActionPressed(string action);
|
||||||
|
public abstract bool GetInventoryJustPressed();
|
||||||
public abstract bool GetShootPressed();
|
public abstract bool GetShootPressed();
|
||||||
|
public abstract bool GetShootJustPressed();
|
||||||
public abstract bool GetUseJustPressed();
|
public abstract bool GetUseJustPressed();
|
||||||
public abstract bool GetScanJustPressed();
|
public abstract bool GetScanJustPressed();
|
||||||
public abstract bool GetStrafePressed();
|
public abstract bool GetStrafePressed();
|
||||||
public abstract bool GetWeaponNextJustPressed();
|
public abstract bool GetWeaponNextJustPressed();
|
||||||
public abstract bool GetWeaponPreviousJustPressed();
|
public abstract bool GetWeaponPreviousJustPressed();
|
||||||
|
public abstract bool GetPauseJustPressed();
|
||||||
}
|
}
|
||||||
|
|
@ -31,6 +31,8 @@ public partial class KeyboardInputProvider : InputProvider
|
||||||
[Export] private string _strafeActionName = "strafe";
|
[Export] private string _strafeActionName = "strafe";
|
||||||
[Export] private string _nextWeaponActionName = "next_weapon";
|
[Export] private string _nextWeaponActionName = "next_weapon";
|
||||||
[Export] private string _previousWeaponActionName = "previous_weapon";
|
[Export] private string _previousWeaponActionName = "previous_weapon";
|
||||||
|
[Export] private string _inventoryActionName = "inventory";
|
||||||
|
[Export] private string _pauseActionName = "pause";
|
||||||
|
|
||||||
public override Vector2 GetMovementInput()
|
public override Vector2 GetMovementInput()
|
||||||
{
|
{
|
||||||
|
|
@ -60,11 +62,21 @@ public partial class KeyboardInputProvider : InputProvider
|
||||||
return Input.IsActionPressed(action);
|
return Input.IsActionPressed(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool GetInventoryJustPressed()
|
||||||
|
{
|
||||||
|
return GetActionJustPressed(_inventoryActionName);
|
||||||
|
}
|
||||||
|
|
||||||
public override bool GetShootPressed()
|
public override bool GetShootPressed()
|
||||||
{
|
{
|
||||||
return GetActionPressed(_shootActionName);
|
return GetActionPressed(_shootActionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool GetShootJustPressed()
|
||||||
|
{
|
||||||
|
return GetActionJustPressed(_shootActionName);
|
||||||
|
}
|
||||||
|
|
||||||
public override bool GetUseJustPressed()
|
public override bool GetUseJustPressed()
|
||||||
{
|
{
|
||||||
return GetActionJustPressed(_useActionName);
|
return GetActionJustPressed(_useActionName);
|
||||||
|
|
@ -89,4 +101,9 @@ public partial class KeyboardInputProvider : InputProvider
|
||||||
return GetActionJustPressed(_previousWeaponActionName);
|
return GetActionJustPressed(_previousWeaponActionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool GetPauseJustPressed()
|
||||||
|
{
|
||||||
|
return GetActionJustPressed(_pauseActionName);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -36,10 +36,14 @@ public partial class Active : PlayerFSMState
|
||||||
|
|
||||||
private PlayerStateMachine _player;
|
private PlayerStateMachine _player;
|
||||||
|
|
||||||
|
private Hud _hud;
|
||||||
|
|
||||||
public override void Init(ActorStateMachine stateMachine)
|
public override void Init(ActorStateMachine stateMachine)
|
||||||
{
|
{
|
||||||
base.Init(stateMachine);
|
base.Init(stateMachine);
|
||||||
|
|
||||||
|
_hud = Hud.Instance;
|
||||||
|
|
||||||
_player = (PlayerStateMachine)stateMachine;
|
_player = (PlayerStateMachine)stateMachine;
|
||||||
|
|
||||||
_damageReceiver.Death += () =>
|
_damageReceiver.Death += () =>
|
||||||
|
|
@ -50,11 +54,13 @@ public partial class Active : PlayerFSMState
|
||||||
_damageReceiver.HealthChanged += (value, maxValue) =>
|
_damageReceiver.HealthChanged += (value, maxValue) =>
|
||||||
{
|
{
|
||||||
_animationProvider.Blink();
|
_animationProvider.Blink();
|
||||||
|
_hud.UpdateHealth(value, maxValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
_damageReceiver.ShieldChanged += (value, maxValue) =>
|
_damageReceiver.ShieldChanged += (value, maxValue) =>
|
||||||
{
|
{
|
||||||
_animationProvider.PlayShieldAnimation();
|
_animationProvider.PlayShieldAnimation();
|
||||||
|
_hud.UpdateShield(value, maxValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
_damageReceiver.Init();
|
_damageReceiver.Init();
|
||||||
|
|
@ -128,6 +134,21 @@ public partial class Active : PlayerFSMState
|
||||||
|
|
||||||
// _crosshair.Position = CalculateCrosshairPosition();
|
// _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()
|
private void HandleShoot()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Godot;
|
using Cirno.Scripts.Components.Actors;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
namespace Cirno.Scripts.Components.FSM.Player;
|
namespace Cirno.Scripts.Components.FSM.Player;
|
||||||
|
|
||||||
|
|
@ -7,32 +8,57 @@ public partial class Dead : PlayerFSMState
|
||||||
[Export]
|
[Export]
|
||||||
private PlayerAnimationProvider _animationProvider;
|
private PlayerAnimationProvider _animationProvider;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
private InputProvider _inputProvider;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
private ActorResourceProvider _healthProvider;
|
||||||
|
|
||||||
|
private GameManager _gameManager;
|
||||||
|
private Hud _hud;
|
||||||
|
|
||||||
public override void Init(ActorStateMachine stateMachine)
|
public override void Init(ActorStateMachine stateMachine)
|
||||||
{
|
{
|
||||||
base.Init(stateMachine);
|
base.Init(stateMachine);
|
||||||
// get hud?
|
|
||||||
|
|
||||||
|
_gameManager = GameManager.Instance;
|
||||||
|
_hud = Hud.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void EnterState()
|
public override void EnterState()
|
||||||
{
|
{
|
||||||
_animationProvider.PlayDeathAnimation();
|
_animationProvider.PlayDeathAnimation();
|
||||||
// show game over
|
// show game over
|
||||||
|
|
||||||
|
_hud.ShowGameOver();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ExitState()
|
public override void ExitState()
|
||||||
{
|
{
|
||||||
// Hide game over
|
// Hide game over
|
||||||
|
_hud.HideGameOver();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ProcessState(double delta)
|
public override void ProcessState(double delta)
|
||||||
{
|
{
|
||||||
// wait for button
|
// wait for button
|
||||||
|
if (_inputProvider.GetShootJustPressed())
|
||||||
|
{
|
||||||
|
Respawn();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void PhysicsProcessState(double delta)
|
public override void PhysicsProcessState(double delta)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Respawn()
|
||||||
|
{
|
||||||
|
_stateMachine.GlobalPosition = _gameManager.LastCheckpointPosition;
|
||||||
|
_healthProvider.FillResource();
|
||||||
|
_gameManager.ClearBullets();
|
||||||
|
|
||||||
|
_stateMachine.SetState((int)PlayerState.Active);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -41,6 +41,9 @@ public partial class GameManager : Node2D
|
||||||
|
|
||||||
//public AlarmManager AlarmManager => _alarmManager;
|
//public AlarmManager AlarmManager => _alarmManager;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public string PauseActionName { get; private set; } = "pause";
|
||||||
|
|
||||||
private Node2D _bulletsContainer;
|
private Node2D _bulletsContainer;
|
||||||
public Node2D BulletsContainer => _bulletsContainer;
|
public Node2D BulletsContainer => _bulletsContainer;
|
||||||
|
|
||||||
|
|
@ -50,6 +53,8 @@ public partial class GameManager : Node2D
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void PlayerRespawnedEventHandler();
|
public delegate void PlayerRespawnedEventHandler();
|
||||||
|
|
||||||
|
public Vector2 LastCheckpointPosition { get; set; }
|
||||||
|
|
||||||
// Called when the node enters the scene tree for the first time.
|
// Called when the node enters the scene tree for the first time.
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
|
|
@ -105,19 +110,16 @@ public partial class GameManager : Node2D
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
public override void _Process(double delta)
|
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()
|
private void DelayPlayerSpawn()
|
||||||
{
|
{
|
||||||
//await Task.Delay(500);
|
|
||||||
|
|
||||||
if (SpawnMarkers.Any())
|
if (SpawnMarkers.Any())
|
||||||
{
|
{
|
||||||
SpawnPlayer();
|
SpawnPlayer();
|
||||||
|
|
@ -244,17 +246,17 @@ public partial class GameManager : Node2D
|
||||||
AddChild(_bulletsContainer);
|
AddChild(_bulletsContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TogglePause()
|
// public void TogglePause()
|
||||||
{
|
// {
|
||||||
if (GameState == GameState.Paused)
|
// if (GameState == GameState.Paused)
|
||||||
{
|
// {
|
||||||
Unpause();
|
// Unpause();
|
||||||
}
|
// }
|
||||||
else if (GameState == GameState.Playing)
|
// else if (GameState == GameState.Playing)
|
||||||
{
|
// {
|
||||||
Pause();
|
// Pause();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void Pause()
|
public void Pause()
|
||||||
{
|
{
|
||||||
|
|
@ -268,7 +270,8 @@ public partial class GameManager : Node2D
|
||||||
{
|
{
|
||||||
if (GameState == GameState.Paused)
|
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;
|
if (state == GameState) return;
|
||||||
GameState = state;
|
GameState = state;
|
||||||
EmitSignal(nameof(GameStateChange), (int)GameState);
|
EmitSignal(SignalName.GameStateChange, (int)state);
|
||||||
GD.Print($"Game state changed to {state}");
|
GD.Print($"Game state changed to {state}");
|
||||||
|
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case GameState.Menu:
|
|
||||||
GetTree().SetPause(false);
|
|
||||||
break;
|
|
||||||
case GameState.Paused:
|
case GameState.Paused:
|
||||||
case GameState.Dialogue:
|
case GameState.Dialogue:
|
||||||
|
case GameState.Inventory:
|
||||||
GetTree().SetPause(true);
|
GetTree().SetPause(true);
|
||||||
break;
|
break;
|
||||||
case GameState.Playing:
|
case GameState.Playing:
|
||||||
GetTree().SetPause(false);
|
|
||||||
break;
|
|
||||||
case GameState.Controlling:
|
case GameState.Controlling:
|
||||||
|
case GameState.Menu:
|
||||||
GetTree().SetPause(false);
|
GetTree().SetPause(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -327,5 +327,6 @@ public enum GameState
|
||||||
Paused,
|
Paused,
|
||||||
Playing,
|
Playing,
|
||||||
Dialogue,
|
Dialogue,
|
||||||
Controlling
|
Controlling,
|
||||||
|
Inventory
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ using Cirno.Scripts.UI;
|
||||||
|
|
||||||
public partial class Hud : CanvasLayer
|
public partial class Hud : CanvasLayer
|
||||||
{
|
{
|
||||||
|
public static Hud Instance { get; private set; }
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void StartGameEventHandler();
|
public delegate void StartGameEventHandler();
|
||||||
|
|
||||||
|
|
@ -48,10 +49,11 @@ public partial class Hud : CanvasLayer
|
||||||
|
|
||||||
private PauseMenu _pauseMenu;
|
private PauseMenu _pauseMenu;
|
||||||
|
|
||||||
private bool _playerDead = false;
|
private bool _playerDead = false; // useless
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
|
Instance = this;
|
||||||
// Assuming the HUD has a Label node named "HealthLabel"
|
// Assuming the HUD has a Label node named "HealthLabel"
|
||||||
//_healthLabel = GetNode<Label>("HealthLabel");
|
//_healthLabel = GetNode<Label>("HealthLabel");
|
||||||
_gameOverPanel.Hide();
|
_gameOverPanel.Hide();
|
||||||
|
|
@ -84,6 +86,11 @@ public partial class Hud : CanvasLayer
|
||||||
// GetNode<Button>("StartButton").Show();
|
// GetNode<Button>("StartButton").Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void HideGameOver()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateHealth(float newHealth, float maxHealth)
|
public void UpdateHealth(float newHealth, float maxHealth)
|
||||||
{
|
{
|
||||||
// Hide game over if player is no longer dead
|
// Hide game over if player is no longer dead
|
||||||
|
|
@ -190,20 +197,16 @@ public partial class Hud : CanvasLayer
|
||||||
|
|
||||||
public void OnGameStateChanged(GameState state)
|
public void OnGameStateChanged(GameState state)
|
||||||
{
|
{
|
||||||
// Clear on every change
|
|
||||||
ClearPauseMenu();
|
|
||||||
|
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case GameState.Menu:
|
|
||||||
break;
|
|
||||||
case GameState.Paused:
|
case GameState.Paused:
|
||||||
SpawnPauseMenu();
|
SpawnPauseMenu();
|
||||||
break;
|
break;
|
||||||
|
case GameState.Controlling:
|
||||||
|
case GameState.Menu:
|
||||||
case GameState.Playing:
|
case GameState.Playing:
|
||||||
ClearPauseMenu();
|
|
||||||
break;
|
|
||||||
case GameState.Dialogue:
|
case GameState.Dialogue:
|
||||||
|
default:
|
||||||
ClearPauseMenu();
|
ClearPauseMenu();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ public partial class UpdateCheckPointEvent : EventResource
|
||||||
|
|
||||||
public override void Start(Node2D parent)
|
public override void Start(Node2D parent)
|
||||||
{
|
{
|
||||||
|
_gameManager.LastCheckpointPosition = parent.GetNode<Node2D>(Target).GlobalPosition;
|
||||||
_gameManager.Player.LastCheckPointPosition = parent.GetNode<Node2D>(Target).GlobalPosition;
|
_gameManager.Player.LastCheckPointPosition = parent.GetNode<Node2D>(Target).GlobalPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,14 @@ public partial class ItemsMenu : ItemList
|
||||||
private InventoryManager _inventoryManager;
|
private InventoryManager _inventoryManager;
|
||||||
private Dictionary<long, string> _itemsDic = new();
|
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()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
CallDeferred(MethodName.DeferredInitialize);
|
CallDeferred(MethodName.DeferredInitialize);
|
||||||
|
|
@ -16,48 +24,68 @@ public partial class ItemsMenu : ItemList
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
if (Input.IsActionJustPressed("inventory"))
|
if (Input.IsActionJustPressed(InventoryActionName) || Input.IsActionJustPressed(PauseActionName))
|
||||||
{
|
{
|
||||||
if (!Visible)
|
if (Visible)
|
||||||
{
|
{
|
||||||
ShowInventory();
|
CallDeferred(MethodName.HideInventory);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
HideInventory();
|
|
||||||
}
|
}
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// ShowInventory();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeferredInitialize()
|
private void DeferredInitialize()
|
||||||
{
|
{
|
||||||
_inventoryManager = GameManager.Instance.GetInventoryManager();
|
_gameManager = GameManager.Instance;
|
||||||
|
_inventoryManager = _gameManager.GetInventoryManager();
|
||||||
|
|
||||||
ItemSelected += OnItemSelected;
|
ItemSelected += OnItemSelected;
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
ItemActivated += OnItemSelected;
|
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)
|
private void OnItemSelected(long index)
|
||||||
{
|
{
|
||||||
var item = _itemsDic[index];
|
var item = _itemsDic[index];
|
||||||
GD.Print("Item: " + item);
|
GD.Print("Item: " + item);
|
||||||
|
HideInventory();
|
||||||
|
|
||||||
_inventoryManager.UseItem(item);
|
_inventoryManager.UseItem(item);
|
||||||
|
|
||||||
HideInventory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HideInventory()
|
private void HideInventory()
|
||||||
{
|
{
|
||||||
|
if (!Visible) return;
|
||||||
|
GD.Print("Hiding inventory");
|
||||||
this.Hide();
|
this.Hide();
|
||||||
Clear();
|
Clear();
|
||||||
_itemsDic.Clear();
|
_itemsDic.Clear();
|
||||||
|
|
||||||
|
GameManager.Instance.ChangeState(GameState.Playing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowInventory()
|
private void ShowInventory()
|
||||||
{
|
{
|
||||||
|
if (Visible) return;
|
||||||
|
GD.Print("Showing inventory");
|
||||||
this.Show();
|
this.Show();
|
||||||
foreach (var item in _inventoryManager.Items)
|
foreach (var item in _inventoryManager.Items)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@ namespace Cirno.Scripts.UI;
|
||||||
|
|
||||||
public partial class PauseMenu : Control
|
public partial class PauseMenu : Control
|
||||||
{
|
{
|
||||||
|
[Export]
|
||||||
|
public string PauseActionName = "pause";
|
||||||
|
|
||||||
[ExportGroup("Scenes")]
|
[ExportGroup("Scenes")]
|
||||||
[Export]
|
[Export]
|
||||||
public string MainMenuScene { get; private set; }
|
public string MainMenuScene { get; private set; }
|
||||||
|
|
@ -11,13 +14,13 @@ public partial class PauseMenu : Control
|
||||||
[ExportGroup("Buttons")]
|
[ExportGroup("Buttons")]
|
||||||
[Export]
|
[Export]
|
||||||
public Button ResumeButton { get; private set; }
|
public Button ResumeButton { get; private set; }
|
||||||
[ExportGroup("Buttons")]
|
|
||||||
[Export]
|
[Export]
|
||||||
public Button QuitButton { get; private set; }
|
public Button QuitButton { get; private set; }
|
||||||
[ExportGroup("Buttons")]
|
|
||||||
[Export]
|
[Export]
|
||||||
public Button OptionsButton { get; private set; }
|
public Button OptionsButton { get; private set; }
|
||||||
[ExportGroup("Buttons")]
|
|
||||||
[Export]
|
[Export]
|
||||||
public Button DebugButton { get; private set; }
|
public Button DebugButton { get; private set; }
|
||||||
|
|
||||||
|
|
@ -36,6 +39,14 @@ public partial class PauseMenu : Control
|
||||||
DebugButton.Pressed += DebugButtonOnPressed;
|
DebugButton.Pressed += DebugButtonOnPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
if (_gameManager.GameState == GameState.Paused && Input.IsActionJustPressed(PauseActionName))
|
||||||
|
{
|
||||||
|
_gameManager.Unpause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void DebugButtonOnPressed()
|
private void DebugButtonOnPressed()
|
||||||
{
|
{
|
||||||
EmitSignal(SignalName.SpawnDebugMenu);
|
EmitSignal(SignalName.SpawnDebugMenu);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue