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(); } /// /// 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. /// private void OnRunEnded() { GameOverPanel.Show(); if (InputDeviceManager.Instance?.IsPointerless == true) RestartButton.GrabFocus(); } }