TH1/Unity/Assets/Scripts/TH1_UI/Controller/Info/UIInfoGridInfoController.cs
2026-04-01 11:31:20 +08:00

111 lines
3.1 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 RuntimeData;
using TH1_Core.Events;
using TH1_Logic.Core;
using TH1_UI.Controller.Base;
using TH1_UI.View.Info;
using UnityEngine;
// 确保这里引用了View脚本的命名空间
namespace TH1_UI.Controller.Info
{
public class UIInfoGridInfoController : ViewController<UIInfoGridInfoView>, IEscClosable // 泛型参数是对应的View脚本
{
/// <summary>
/// ✅ 【新增】一个空的构造函数,以满足 ViewControllerManager._CreateView 的 new() 泛型约束。
/// </summary>
public UIInfoGridInfoController() { }
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();
ApplyContent();
}
/// <summary>
/// 面板已经在显示时再次收到Open请求会走这里而非OnOpen
/// 基类_TryOpen中IsShow()==true时调用UpdateView而不是OnOpen。
/// </summary>
public override void UpdateView()
{
ApplyContent();
}
private void ApplyContent()
{
if (_openParameter is ShowUIInfoGridInfo evt)
{
if (WindowScript != null)
{
WindowScript.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
WindowScript.SetContent(evt);
}
}
else
{
Debug.LogWarning("[UIInfoGridInfo] Opened without valid parameters.");
}
}
public override bool Close()
{
WindowScript.CloseView();
return base.Close();
}
//用于UI执行相关
public void ExecuteAction(ExecuteUIInfoGridInfo evt)
{
WindowScript.ExecuteAction(evt);
}
/// <summary>
/// 外部调用: 刷新当前展示的Unit的ActionPoint显示
/// 当玩家做完一个action后应调用此方法来更新APBox
/// </summary>
public void RefreshActionPoints(RuntimeData.UnitData unitData)
{
if (WindowScript != null)
WindowScript.RefreshActionPoints(unitData);
}
void _OnBtnCloseClick()
{
Main.Instance.MapInteractionLogic.CancelAllHighlight();
Close();
}
public bool CanCloseByEsc()
{
return true;
}
public void CancelMapHighlightsOrDoNothing()
{
Main.Instance.MapInteractionLogic.CancelAllHighlight();
}
}
}