Add game scene and level catalog interfaces, and implement scene management in AppRoot
This commit is contained in:
40
features/level/ExitDoorComponent.cs
Normal file
40
features/level/ExitDoorComponent.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.app;
|
||||
using Mr.BrickAdventures.game.services;
|
||||
|
||||
namespace Mr.BrickAdventures.features.level;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class ExitDoorComponent : Area2D
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Export] public CollisionShape2D UnlockIndicator { get; set; } = null!;
|
||||
[Export] public bool Unlocked { get; set; } = false;
|
||||
|
||||
[Dependency] public LevelService Levels => this.DependOn<LevelService>();
|
||||
[Dependency] public ILevelCatalog Catalog => this.DependOn<ILevelCatalog>();
|
||||
[Dependency] public IGameScenes Scenes => this.DependOn<IGameScenes>();
|
||||
|
||||
public void OnReady() {
|
||||
BodyEntered += OnBodyEntered;
|
||||
UpdateVisuals();
|
||||
}
|
||||
|
||||
private void OnBodyEntered(Node body) {
|
||||
if (!Unlocked) return;
|
||||
if (body is not CharacterBody2D) return;
|
||||
|
||||
var nextIdx = Levels.CompleteAndAdvance();
|
||||
var next = Catalog.Get(nextIdx);
|
||||
if (next != null) Scenes.Load(next); else Scenes.ReturnToMain(Catalog.MainMenu);
|
||||
}
|
||||
|
||||
private void UpdateVisuals() {
|
||||
if (UnlockIndicator != null) UnlockIndicator.Disabled = !Unlocked;
|
||||
}
|
||||
|
||||
public void SetUnlocked(bool value) { Unlocked = value; UpdateVisuals(); }
|
||||
}
|
1
features/level/ExitDoorComponent.cs.uid
Normal file
1
features/level/ExitDoorComponent.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ddh0jm0heqtc3
|
26
features/ui/menus/GameOverScreen.cs
Normal file
26
features/ui/menus/GameOverScreen.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.app;
|
||||
|
||||
namespace Mr.BrickAdventures.features.ui.menus;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class GameOverScreen : Control
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Export] public Button RestartButton { get; set; } = null!;
|
||||
[Export] public Button MainMenuButton { get; set; } = null!;
|
||||
[Export] public PackedScene MainMenuScene { get; set; } = null!;
|
||||
|
||||
[Dependency] public IGameScenes Scenes => this.DependOn<IGameScenes>();
|
||||
|
||||
public void OnReady() {
|
||||
Visible = false;
|
||||
RestartButton.Pressed += () => Scenes.Restart();
|
||||
MainMenuButton.Pressed += () => Scenes.ReturnToMain(MainMenuScene);
|
||||
}
|
||||
|
||||
public void ShowGameOver() => Show();
|
||||
}
|
1
features/ui/menus/GameOverScreen.cs.uid
Normal file
1
features/ui/menus/GameOverScreen.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b36jv878751ta
|
@@ -1,6 +1,7 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.app;
|
||||
using Mr.BrickAdventures.game.repositories;
|
||||
using Mr.BrickAdventures.game.services;
|
||||
|
||||
@@ -20,10 +21,11 @@ public partial class MainMenu : Control
|
||||
[Export] public Label VersionLabel { get; set; } = null!;
|
||||
[Export] public Control SettingsControl { get; set; } = null!;
|
||||
[Export] public Control CreditsControl { get; set; } = null!;
|
||||
[Export] public PackedScene FirstLevelScene { get; set; } = null!;
|
||||
|
||||
[Dependency] public SaveService Save => this.DependOn<SaveService>();
|
||||
[Dependency] public LevelRepository Levels => this.DependOn<LevelRepository>();
|
||||
[Dependency] public IGameScenes Scenes => this.DependOn<IGameScenes>();
|
||||
[Dependency] public ILevelCatalog Catalog => this.DependOn<ILevelCatalog>();
|
||||
|
||||
public void OnReady() {
|
||||
VersionLabel.Text = $"v. {ProjectSettings.GetSetting("application/config/version")}";
|
||||
@@ -44,15 +46,13 @@ public partial class MainMenu : Control
|
||||
private void OnNewGamePressed() {
|
||||
Save.NewGame();
|
||||
Levels.SetCurrent(0);
|
||||
GetTree().ChangeSceneToPacked(FirstLevelScene);
|
||||
var first = Catalog.First;
|
||||
Scenes.Load(first);
|
||||
}
|
||||
|
||||
private void OnContinuePressed() {
|
||||
if (!Save.TryLoad()) {
|
||||
// Fallback: start new game
|
||||
OnNewGamePressed();
|
||||
return;
|
||||
}
|
||||
GetTree().ChangeSceneToPacked(FirstLevelScene);
|
||||
if (!Save.TryLoad()) { OnNewGamePressed(); return; }
|
||||
var scene = Catalog.Get(Levels.Current) ?? Catalog.First;
|
||||
Scenes.Load(scene);
|
||||
}
|
||||
}
|
@@ -1,6 +1,33 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.app;
|
||||
using Mr.BrickAdventures.game.services;
|
||||
|
||||
namespace Mr.BrickAdventures.features.ui.menus;
|
||||
|
||||
public class PauseMenu
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class PauseMenu : Control
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Export] public Button ResumeButton { get; set; } = null!;
|
||||
[Export] public Button RestartButton { get; set; } = null!;
|
||||
[Export] public Button MainMenuButton { get; set; } = null!;
|
||||
|
||||
[Dependency] public IGameScenes Scenes => this.DependOn<IGameScenes>();
|
||||
[Dependency] public ILevelCatalog Catalog => this.DependOn<ILevelCatalog>();
|
||||
[Dependency] public LevelService Levels => this.DependOn<LevelService>();
|
||||
|
||||
public void OnReady() {
|
||||
Visible = false;
|
||||
ResumeButton.Pressed += () => { GetTree().Paused = false; Hide(); };
|
||||
RestartButton.Pressed += () => { GetTree().Paused = false; Scenes.Restart(); };
|
||||
MainMenuButton.Pressed += () => { GetTree().Paused = false; Scenes.ReturnToMain(Catalog.MainMenu); };
|
||||
}
|
||||
|
||||
public void Toggle() {
|
||||
if (Visible) { GetTree().Paused = false; Hide(); }
|
||||
else { Show(); GetTree().Paused = true; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user