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

96 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 文件位置建议: Assets/Scripts/TH1_UI/Controller/UIAnnounceMajorEventController.cs
using Logic;
using TH1_Core.Events;
using TH1_Core.Managers;
using TH1_Logic.Core;
using TH1_UI.Controller.Base;
using TH1_UI.View.Bottom;
using TH1_UI.View.Top;
using TH1Renderer;
using UnityEngine;
// 确保这里引用了View脚本的命名空间
namespace TH1_UI.Controller.Top
{
public class UITopWinController : ViewController<UITopWinView> // 泛型参数是对应的View脚本
{
/// <summary>
/// ✅ 【新增】一个空的构造函数,以满足 ViewControllerManager._CreateView 的 new() 泛型约束。
/// </summary>
public UITopWinController() { }
protected override void RegisterEventCallback()
{
base.RegisterEventCallback();
if (WindowScript != null)
{
WindowScript.OnBtnCloseClick += _OnBtnCloseClick;
}
}
protected override void UnregisterEventCallback()
{
if (WindowScript != null)
{
WindowScript.OnBtnCloseClick = null;
}
base.UnregisterEventCallback();
}
protected override void OnOpen()
{
base.OnOpen();
if (WindowScript == null)
{
Debug.LogError("[UITopWinController] WindowScript is null, cannot open win UI");
return;
}
// 无论是否有参数,都尝试设置内容显示胜利界面
// 参数类型检查仅用于日志记录,不影响功能
if (_openParameter is ShowUITopWin evt)
{
Debug.Log("[UITopWinController] Opened with ShowUITopWin parameter");
}
else if (_openParameter != null)
{
Debug.LogWarning($"[UITopWinController] Opened with unexpected parameter type: {_openParameter.GetType().Name}");
}
else
{
Debug.Log("[UITopWinController] Opened without parameters");
}
// 核心调用SetContent来刷新并显示UI
WindowScript.SetContent();
}
public override bool Close()
{
WindowScript?.CloseView();
return base.Close();
}
private void _OnBtnCloseClick()
{
Close();
//这些模块必须放在这里不能放在CLose因为Close不管这些操作的Close只管界面的Close
EventManager.Publish(new ShowUIOutsideMenu());
//TODO MapRenderer的 位置不应该在这里目前服务于废弃的BubbleManager 后续迭代
MapRenderer.Instance.OnMatchEnd();
UIManager.Instance.OnMatchEnd();
Main.Instance.GameLogic.ChangeState(GameState.Menu);
}
public void OnMatchStart()
{
WindowScript?.OnMatchStart();
}
}
}