92 lines
2.2 KiB
C#
92 lines
2.2 KiB
C#
using Godot;
|
|
|
|
namespace Milimoe.GodotGame;
|
|
|
|
public partial class MenuController : ColorRect
|
|
{
|
|
[Export]
|
|
public Node Parent;
|
|
|
|
[Export]
|
|
public Button ContinueGame;
|
|
|
|
[Export]
|
|
public Button GameSettings;
|
|
|
|
[Export]
|
|
public Button BackToTitle;
|
|
|
|
[Export]
|
|
public Button ExitGame;
|
|
|
|
[Export]
|
|
public ConfirmationDialog ExitConfirmationDialog;
|
|
|
|
[Export]
|
|
public ConfirmationDialog BackToTitleConfirmationDialog;
|
|
|
|
[Export]
|
|
public string TitleScenePath = "res://scenes/TitleScreen.tscn"; // 标题场景的路径
|
|
|
|
public override void _Ready()
|
|
{
|
|
if (ExitConfirmationDialog != null)
|
|
{
|
|
ExitConfirmationDialog.GetOkButton().Pressed += () => GetTree().Quit();
|
|
}
|
|
if (BackToTitleConfirmationDialog != null)
|
|
{
|
|
BackToTitleConfirmationDialog.GetOkButton().Pressed += async () =>
|
|
{
|
|
if (Parent is IFadeInFadeOutBlack fade)
|
|
{
|
|
await fade.FadeInBlack(1f);
|
|
// 加载标题场景
|
|
GD.Print("LoadTitleScene!");
|
|
GetTree().ChangeSceneToFile(TitleScenePath);
|
|
}
|
|
};
|
|
}
|
|
if (ContinueGame != null)
|
|
{
|
|
ContinueGame.Pressed += ContinueGame_Pressed;
|
|
}
|
|
if (BackToTitle != null)
|
|
{
|
|
BackToTitle.Pressed += BackToTitle_Pressed;
|
|
}
|
|
if (ExitGame != null)
|
|
{
|
|
ExitGame.Pressed += ExitGame_Pressed;
|
|
}
|
|
}
|
|
|
|
private void ContinueGame_Pressed()
|
|
{
|
|
if (Parent is IMenuObject obj)
|
|
{
|
|
obj.ChangeState();
|
|
}
|
|
}
|
|
|
|
private void BackToTitle_Pressed()
|
|
{
|
|
// 返回标题界面
|
|
BackToTitleConfirmationDialog?.PopupCentered(); // 弹出对话框
|
|
}
|
|
|
|
private void ExitGame_Pressed()
|
|
{
|
|
// 退出游戏
|
|
if (ExitConfirmationDialog != null)
|
|
{
|
|
ExitConfirmationDialog.PopupCentered(); // 弹出对话框
|
|
}
|
|
else
|
|
{
|
|
GD.PrintErr("ExitConfirmationDialog is not connected!");
|
|
GetTree().Quit(); // 如果对话框未连接,则直接退出
|
|
}
|
|
}
|
|
}
|