Traveller/scripts/loader/uiLoader/GameOverLoaderMenuLoader.cs
Cold-Mint a7a5a309a2
Migrate TileMap to TileMapLayer. Development using version 4.3 of Godot.
迁移TileMap到TileMapLayer。使用4.3版本Godot进行研发。
2024-07-26 22:38:18 +08:00

58 lines
1.4 KiB
C#

using ColdMint.scripts.map.events;
using Godot;
namespace ColdMint.scripts.loader.uiLoader;
/// <summary>
/// <para>GameOverLoaderMenuLoader</para>
/// <para>游戏结束菜单加载器</para>
/// </summary>
public partial class GameOverLoaderMenuLoader : UiLoaderTemplate
{
private Label? _deathInfoLabel;
private Button? _restartButton;
public override void InitializeUi()
{
Hide();
}
public override void InitializeData()
{
_restartButton = GetNodeOrNull<Button>("CenterContainer/VBoxContainer/MarginContainer2/RestartButton");
_deathInfoLabel =
GetNode<Label>("CenterContainer/VBoxContainer/MarginContainer/CenterContainer2/DeathInfoLabel");
EventManager.GameOverEvent += OnGameOver;
}
public override void LoadUiActions()
{
if (_restartButton != null)
{
_restartButton.Pressed += () =>
{
var replayEvent = new GameReplayEvent();
EventManager.GameReplayEvent?.Invoke(replayEvent);
Hide();
};
}
}
private void OnGameOver(GameOverEvent gameOverEvent)
{
if (_deathInfoLabel == null)
{
return;
}
Show();
_deathInfoLabel.Text = gameOverEvent.DeathInfo;
}
public override void _ExitTree()
{
base._ExitTree();
EventManager.GameOverEvent -= OnGameOver;
}
}