diff --git a/Autoloads/GameManager.cs b/Autoloads/GameManager.cs index 40bf0a8..d23822f 100644 --- a/Autoloads/GameManager.cs +++ b/Autoloads/GameManager.cs @@ -1,5 +1,8 @@ +using System.Collections.Generic; +using System.Linq; using Godot; using Godot.Collections; +using Mr.BrickAdventures.scripts.components; using Mr.BrickAdventures.scripts.Resources; namespace Mr.BrickAdventures.Autoloads; @@ -7,6 +10,10 @@ namespace Mr.BrickAdventures.Autoloads; public partial class GameManager : Node { [Export] public Array LevelScenes { get; set; } = new(); + + public PlayerController Player { get; set; } + + private List _sceneNodes = new(); public Dictionary PlayerState { get; set; } = new() { @@ -24,6 +31,29 @@ public partial class GameManager : Node { "skills_unlocked", new Array() } }; + public override void _EnterTree() + { + GetTree().NodeAdded += OnNodeAdded; + GetTree().NodeRemoved += OnNodeRemoved; + } + + public override void _ExitTree() + { + GetTree().NodeAdded -= OnNodeAdded; + GetTree().NodeRemoved -= OnNodeRemoved; + _sceneNodes.Clear(); + } + + private void OnNodeAdded(Node node) + { + _sceneNodes.Add(node); + } + + private void OnNodeRemoved(Node node) + { + _sceneNodes.Remove(node); + } + public void AddCoins(int amount) { PlayerState["coins"] = Mathf.Max(0, (int)PlayerState["coins"] + amount); @@ -192,4 +222,20 @@ public partial class GameManager : Node joined.AddRange((Array)session ?? new Array()); return joined; } + + public PlayerController GetPlayer() + { + if (Player != null) return Player; + + foreach (var node in _sceneNodes) + { + if (node is not PlayerController player) continue; + + Player = player; + return Player; + } + + GD.PrintErr("PlayerController not found in the scene tree."); + return null; + } } \ No newline at end of file diff --git a/scripts/UI/GameOverScreen.cs b/scripts/UI/GameOverScreen.cs index 0a665f9..80e55b7 100644 --- a/scripts/UI/GameOverScreen.cs +++ b/scripts/UI/GameOverScreen.cs @@ -16,7 +16,7 @@ public partial class GameOverScreen : Node { _gameManager = GetNode("/root/GameManager"); RestartButton.Pressed += OnRestartClicked; - MainMenuButton.Pressed += OnMainMenuClicked; + MainMenuButton.Pressed += OnMainMenuClicked; } private void OnMainMenuClicked() diff --git a/scripts/UI/Hud.cs.uid b/scripts/UI/Hud.cs.uid new file mode 100644 index 0000000..15ddc0b --- /dev/null +++ b/scripts/UI/Hud.cs.uid @@ -0,0 +1 @@ +uid://wfj674u4486f diff --git a/scripts/UI/MainMenu.cs b/scripts/UI/MainMenu.cs new file mode 100644 index 0000000..b4b5de0 --- /dev/null +++ b/scripts/UI/MainMenu.cs @@ -0,0 +1,67 @@ +using Godot; +using Mr.BrickAdventures.Autoloads; + +namespace Mr.BrickAdventures.scripts.UI; + +public partial class MainMenu : Node +{ + [Export] public Control MainMenuControl { get; set; } + [Export] public Button NewGameButton { get; set; } + [Export] public Button ContinueButton { get; set; } + [Export] public Button SettingsButton { get; set; } + [Export] public Button CreditsButton { get; set; } + [Export] public Button ExitButton { get; set; } + [Export] public Label VersionLabel { get; set; } + [Export] public Control SettingsControl { get; set; } + [Export] public Control CreditsControl { get; set; } + + private SaveSystem _saveSystem; + private GameManager _gameManager; + private UIManager _uiManager; + + public override void _Ready() + { + _saveSystem = GetNode("/root/SaveSystem"); + _gameManager = GetNode("/root/GameManager"); + _uiManager = GetNode("/root/UIManager"); + + NewGameButton.Pressed += OnNewGamePressed; + ContinueButton.Pressed += OnContinuePressed; + SettingsButton.Pressed += OnSettingsPressed; + CreditsButton.Pressed += OnCreditsPressed; + ExitButton.Pressed += OnExitPressed; + + VersionLabel.Text = $"v. {ProjectSettings.GetSetting("application/config/version")}"; + ContinueButton.Disabled = !_saveSystem.CheckSaveExists(); + + if (_saveSystem.CheckSaveExists()) + ContinueButton.GrabFocus(); + else + NewGameButton.GrabFocus(); + } + + private void OnExitPressed() + { + _gameManager.QuitGame(); + } + + private void OnCreditsPressed() + { + _uiManager.PushScreen(CreditsControl); + } + + private void OnSettingsPressed() + { + _uiManager.PushScreen(SettingsControl); + } + + private void OnContinuePressed() + { + _gameManager.ContinueGame(); + } + + private void OnNewGamePressed() + { + _gameManager.StartNewGame(); + } +} \ No newline at end of file diff --git a/scripts/UI/MainMenu.cs.uid b/scripts/UI/MainMenu.cs.uid new file mode 100644 index 0000000..73f54b3 --- /dev/null +++ b/scripts/UI/MainMenu.cs.uid @@ -0,0 +1 @@ +uid://bna3ggr6n7ycr diff --git a/scripts/UI/Marketplace.cs b/scripts/UI/Marketplace.cs new file mode 100644 index 0000000..1cda6b3 --- /dev/null +++ b/scripts/UI/Marketplace.cs @@ -0,0 +1,113 @@ +using System.Collections.Generic; +using Godot; +using Godot.Collections; +using Mr.BrickAdventures.Autoloads; +using Mr.BrickAdventures.scripts.components; +using Mr.BrickAdventures.scripts.Resources; + +namespace Mr.BrickAdventures.scripts.UI; + +public partial class Marketplace : Node +{ + [Export] public Array Skills { get; set; } = []; + [Export] public GridContainer ToUnlockGrid { get; set; } + [Export] public GridContainer UnlockedGrid { get; set; } + [Export] public Font Font { get; set; } + [Export] public SkillUnlockedComponent SkillUnlockedComponent { get; set; } + [Export] public Array ComponentsToDisable { get; set; } = []; + [Export] public PackedScene MarketplaceButtonScene { get; set; } + [Export] public PackedScene SkillButtonScene { get; set; } + + private GameManager _gameManager; + private List