92 lines
3.4 KiB
C#
92 lines
3.4 KiB
C#
using System;
|
||
using Continentis;
|
||
using Continentis.MainGame;
|
||
using I2.Loc;
|
||
using SLSUtilities.General;
|
||
using UnityEngine;
|
||
using UnityEngine.SceneManagement;
|
||
using UnityEngine.Serialization;
|
||
using UnityEngine.UI;
|
||
|
||
namespace Continentis.Menu
|
||
{
|
||
public class MenuManager : Singleton<MenuManager>
|
||
{
|
||
private const string CombatSceneName = "GameScene";
|
||
|
||
[Header("主菜单按钮")]
|
||
[FormerlySerializedAs("enterGameButton")]
|
||
public Button newGameButton;
|
||
public Button loadGameButton;
|
||
|
||
[Header("面板")]
|
||
public ConfirmOverrideRunPanel confirmOverrideRunPanel;
|
||
|
||
[Header("跑局配置")]
|
||
[Tooltip("新游戏使用的 RunConfig 资产")]
|
||
public RunConfig runConfig;
|
||
|
||
[Header("语言设置")]
|
||
public string languageToSet;
|
||
|
||
// ── 生命周期 ──────────────────────────────────────────────────────
|
||
|
||
private void Start()
|
||
{
|
||
if (string.IsNullOrEmpty(languageToSet))
|
||
languageToSet = "Simplified Chinese";
|
||
LocalizationManager.CurrentLanguage = languageToSet;
|
||
|
||
newGameButton.onClick.AddListener(OnNewGameClicked);
|
||
loadGameButton.onClick.AddListener(OnContinueClicked);
|
||
|
||
RefreshButtons();
|
||
}
|
||
|
||
// ── 按钮事件 ──────────────────────────────────────────────────────
|
||
|
||
/// <summary>
|
||
/// 新游戏按钮:若已有进行中的跑局则弹出确认框,否则直接开始。
|
||
/// </summary>
|
||
private void OnNewGameClicked()
|
||
{
|
||
if (SaveManager.Instance.HasActiveRun())
|
||
confirmOverrideRunPanel.Show(StartNewRun);
|
||
else
|
||
StartNewRun();
|
||
}
|
||
|
||
/// <summary>继续游戏按钮:设置意图后加载战斗场景。</summary>
|
||
private void OnContinueClicked()
|
||
{
|
||
InfoTransistor.Instance.menuToMainGame.menuIntent = InfoTransistor.Menu.MenuIntent.ContinueRun;
|
||
InfoTransistor.Instance.menuToMainGame.pendingRunConfig = null;
|
||
SceneManager.LoadScene(CombatSceneName);
|
||
}
|
||
|
||
// ── 内部方法 ──────────────────────────────────────────────────────
|
||
|
||
/// <summary>根据存档状态刷新按钮可交互性。</summary>
|
||
private void RefreshButtons()
|
||
{
|
||
bool hasActiveRun = SaveManager.Instance.HasActiveRun();
|
||
newGameButton.interactable = true;
|
||
loadGameButton.interactable = hasActiveRun;
|
||
}
|
||
|
||
/// <summary>写入意图并加载战斗场景,由新游戏流程调用。</summary>
|
||
private void StartNewRun()
|
||
{
|
||
if (runConfig == null)
|
||
{
|
||
Debug.LogError("[Menu] 未指定 RunConfig,无法开始新跑局。请在 MenuManager Inspector 中赋值。");
|
||
return;
|
||
}
|
||
|
||
InfoTransistor.Instance.menuToMainGame.menuIntent = InfoTransistor.Menu.MenuIntent.StartNewRun;
|
||
InfoTransistor.Instance.menuToMainGame.pendingRunConfig = runConfig;
|
||
SceneManager.LoadScene(CombatSceneName);
|
||
}
|
||
}
|
||
}
|