fixes the regression commit B introduced: coins and skills lived in the Attempt ledger, but nothing discarded it, because LivesStateHandler still called the old store and HandlePlayerDeath was never invoked. Dying kept everything earned that level. Discard-on-death is the ledger's purpose, so it could not be separated from it. new AttemptFailed(remaining, runOver) event, raised after the life is spent and the ledger discarded. DeathScreen and GameOverScreen react to that instead of being wired to HealthComponent.Death by scene connections which fired *before* the life was charged - on the last life game-over saw one life left and showed nothing, then the death screen saw zero and refused to reload. 18 scene connections deleted; the race is now unrepresentable rather than fixed. DeathScreen also had two read paths for lives - a signal and a direct store read - because neither was reliable alone. Now one. Hud reads both facts from signals; only health still polls, and that belongs to the component rather than to progression. GameManager no longer touches GameStateStore or SaveSystem at all.
66 lines
2.0 KiB
C#
66 lines
2.0 KiB
C#
using Godot;
|
|
using Mr.BrickAdventures;
|
|
using Mr.BrickAdventures.Autoloads;
|
|
|
|
namespace Mr.BrickAdventures.scripts.UI;
|
|
|
|
public partial class GameOverScreen : Control
|
|
{
|
|
[Export] public Control GameOverPanel { get; set; }
|
|
[Export] public Button RestartButton { get; set; }
|
|
[Export] public Button MainMenuButton { get; set; }
|
|
[Export] public PackedScene MainMenuScene { get; set; }
|
|
|
|
public override void _Ready()
|
|
{
|
|
RestartButton.FocusMode = Control.FocusModeEnum.All;
|
|
MainMenuButton.FocusMode = Control.FocusModeEnum.All;
|
|
|
|
RestartButton.Pressed += OnRestartClicked;
|
|
MainMenuButton.Pressed += OnMainMenuClicked;
|
|
|
|
if (InputDeviceManager.Instance != null)
|
|
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
|
|
|
|
EventBus.Instance.RunEnded += OnRunEnded;
|
|
}
|
|
|
|
public override void _ExitTree()
|
|
{
|
|
if (InputDeviceManager.Instance != null)
|
|
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
|
|
|
|
if (EventBus.Instance != null)
|
|
EventBus.Instance.RunEnded -= OnRunEnded;
|
|
}
|
|
|
|
private void OnDeviceChanged(int device)
|
|
{
|
|
var d = (InputDeviceManager.InputDevice)device;
|
|
if (d != InputDeviceManager.InputDevice.Mouse && GameOverPanel.IsVisibleInTree())
|
|
RestartButton.GrabFocus();
|
|
}
|
|
|
|
private void OnMainMenuClicked()
|
|
{
|
|
SpeedRunManager.Instance?.StopTimer();
|
|
GetTree().ChangeSceneToPacked(MainMenuScene);
|
|
}
|
|
|
|
private void OnRestartClicked()
|
|
{
|
|
GameManager.Instance?.RestartGame();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Shown when the run is actually over. Previously this read Lives from a scene connection that
|
|
/// fired before the life was charged, so on the last life it saw one remaining and showed nothing —
|
|
/// leaving the death screen up forever.
|
|
/// </summary>
|
|
private void OnRunEnded()
|
|
{
|
|
GameOverPanel.Show();
|
|
if (InputDeviceManager.Instance?.IsPointerless == true)
|
|
RestartButton.GrabFocus();
|
|
}
|
|
} |