refactor: implement singleton pattern for key managers and improve resource access
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures;
|
||||
using Mr.BrickAdventures.Autoloads;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.UI;
|
||||
@@ -14,13 +13,11 @@ public partial class PauseMenu : Control
|
||||
[Export] public Button SettingsButton { get; set; }
|
||||
[Export] public PackedScene MainMenuScene { get; set; }
|
||||
|
||||
private GameManager _gameManager;
|
||||
private UIManager _uiManager;
|
||||
private GameManager GameManager => GameManager.Instance;
|
||||
private UIManager UIManager => UIManager.Instance;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GameManager.Instance;
|
||||
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
||||
|
||||
ResumeButton.Pressed += OnResumePressed;
|
||||
MainMenuButton.Pressed += OnMainMenuPressed;
|
||||
@@ -33,36 +30,36 @@ public partial class PauseMenu : Control
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (!@event.IsActionPressed("pause")) return;
|
||||
if (_uiManager.IsVisibleOnStack(PauseMenuControl))
|
||||
if (UIManager.IsVisibleOnStack(PauseMenuControl))
|
||||
OnResumePressed();
|
||||
else
|
||||
{
|
||||
_uiManager.PushScreen(PauseMenuControl);
|
||||
_gameManager.PauseGame();
|
||||
UIManager.PushScreen(PauseMenuControl);
|
||||
GameManager.PauseGame();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSettingsPressed()
|
||||
{
|
||||
_uiManager.PushScreen(SettingsControl);
|
||||
_gameManager.PauseGame();
|
||||
UIManager.PushScreen(SettingsControl);
|
||||
GameManager.PauseGame();
|
||||
}
|
||||
|
||||
private void OnQuitPressed()
|
||||
{
|
||||
_gameManager.QuitGame();
|
||||
GameManager.QuitGame();
|
||||
}
|
||||
|
||||
private void OnMainMenuPressed()
|
||||
{
|
||||
_gameManager.ResumeGame();
|
||||
_gameManager.ResetCurrentSessionState();
|
||||
GameManager.ResumeGame();
|
||||
GameManager.ResetCurrentSessionState();
|
||||
GetTree().ChangeSceneToPacked(MainMenuScene);
|
||||
}
|
||||
|
||||
private void OnResumePressed()
|
||||
{
|
||||
_uiManager.PopScreen();
|
||||
_gameManager.ResumeGame();
|
||||
UIManager.PopScreen();
|
||||
GameManager.ResumeGame();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user