TH1/Unity/Assets/Scripts/TH1_UI/Controller/Outside/UIOutsideMenuController.cs
2026-03-05 15:26:15 +08:00

140 lines
4.4 KiB
C#

// 文件位置建议: Assets/Scripts/TH1_UI/Controller/UIAnnounceMajorEventController.cs
using Logic;
using Logic.Action;
using TH1_Core.Events;
using TH1_Core.Managers;
using TH1_Logic.Action;
using TH1_Logic.Core;
using TH1_UI.Controller.Base;
using TH1_UI.View.Interaction;
using TH1_UI.View.Outside;
using UnityEngine;
// 确保这里引用了View脚本的命名空间
namespace TH1_UI.Controller.Interaction
{
/// <summary>
/// 重大事件公告界面的控制器。
/// 它的职责是处理玩家相遇、玩家被消灭之类的宣告
/// </summary>
public class UIOutsideMenuController : ViewController<UIOutsideMenuView> // 泛型参数是对应的View脚本
{
public UIOutsideMenuController() { }
private ShowUIOutsideMenu _evt;
protected override void RegisterEventCallback()
{
base.RegisterEventCallback();
if (WindowScript != null)
{
WindowScript.OnBtnCloseClick += _OnBtnCloseClick;
WindowScript.OnStartGame += _OnStartGameClick;
WindowScript.ShutdownPanel.OnPanelClose += _OnShutdownPanelClose;
WindowScript.ShutdownPanel.OnShutdownConfirm += _OnShutdownConfirm;
}
}
public override void UpdateView()
{
if (WindowScript != null)
{
//Debug.Log("Update View Success!!!!");
}
base.UpdateView();
}
protected override void UnregisterEventCallback()
{
if (WindowScript != null)
{
WindowScript.OnBtnCloseClick -= _OnBtnCloseClick;
WindowScript.OnStartGame -= _OnStartGameClick;
WindowScript.ShutdownPanel.OnPanelClose -= _OnShutdownPanelClose;
WindowScript.ShutdownPanel.OnShutdownConfirm -= _OnShutdownConfirm;
}
base.UnregisterEventCallback();
}
protected override void OnOpen()
{
base.OnOpen();
// 检查暂存的参数是否存在且类型正确
if (_openParameter is ShowUIOutsideMenu evt)
{
_evt = evt;
// 使用接收到的数据设置UI内容
if (WindowScript != null)
{
//Param1 = cid Param2 = cityLv
WindowScript.SetContent(evt);
}
}
else
{
// 如果没有参数或参数类型不符,可以提供默认内容或打印警告
Debug.LogWarning("[UIAnnounceMajorEventController] Opened without valid parameters.");
if (WindowScript != null)
{
//WindowScript.SetContent("警告", "内容未提供");
}
}
}
void _OnBtnCloseClick()
{
//EventManager.Publish(new ShowUIOutsideMenu());
//UIManager.Instance.GameUI.MainUI.NeedShow = true;
Close();
}
void _OnStartGameClick()
{
//UIManager.Instance.GameUI.MainUI.NeedShow = false;
EventManager.Publish(new HideUIOutsideMenu());
//这里打开Loading
//Debug.Log("Click is " + Time.time);
EventManager.Publish(new ShowUIOutsideLoading());
//WindowScript.gameObject.SetActive(false);
//Close();
Timer.Instance.TimerRegister(this, () =>
{
Close();
Main.Instance.StartMatch();
},0.5f,"UIOutsideSelectController");
Timer.Instance.TimerRegister(this, () =>
{
EventManager.Publish(new HideUIOutsideLoading());
},2.5f,"UIOutsideSelectController");
}
private void _OnShutdownPanelClose()
{
// 面板关闭时的回调,目前不需要特殊处理
Debug.Log("[UIOutsideMenuController] Shutdown panel closed");
}
private void _OnShutdownConfirm()
{
Debug.Log("[UIOutsideMenuController] Shutdown confirmed, quitting game");
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
public override bool Close()
{
WindowScript?.OnCloseView();
return base.Close();
}
}
}