TH1/Unity/Assets/Scripts/TH1_UI/Controller/Interaction/UIInterationCityUpgradeController.cs
2025-08-26 14:32:20 +08:00

95 lines
3.0 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.Core;
using TH1_UI.Controller.Base;
using TH1_UI.View.Interaction;
using UnityEngine;
// 确保这里引用了View脚本的命名空间
namespace TH1_UI.Controller.Interaction
{
/// <summary>
/// 重大事件公告界面的控制器。
/// 它的职责是处理玩家相遇、玩家被消灭之类的宣告
/// </summary>
public class UIInteractionCityUpgradeController : ViewController<UIInteractionCityUpgradeView> // 泛型参数是对应的View脚本
{
/// <summary>
/// ✅ 【新增】一个空的构造函数,以满足 ViewControllerManager._CreateView 的 new() 泛型约束。
/// </summary>
public UIInteractionCityUpgradeController() { }
protected override void RegisterEventCallback()
{
base.RegisterEventCallback();
if (WindowScript != null)
{
WindowScript.OnChoiceMade += _OnChoiceMadeHandler;
}
}
protected override void UnregisterEventCallback()
{
if (WindowScript != null)
{
WindowScript.OnChoiceMade -= _OnChoiceMadeHandler;
}
base.UnregisterEventCallback();
}
protected override void OnOpen()
{
base.OnOpen();
// 检查暂存的参数是否存在且类型正确
if (_openParameter is ShowUIInteractionCityUpgrade evt)
{
// 使用接收到的数据设置UI内容
if (WindowScript != null)
{
//Param1 = cid Param2 = cityLv
WindowScript.SetContent(evt.CityId, evt.CityLevel);
}
}
else
{
// 如果没有参数或参数类型不符,可以提供默认内容或打印警告
Debug.LogWarning("[UIAnnounceMajorEventController] Opened without valid parameters.");
if (WindowScript != null)
{
//WindowScript.SetContent("警告", "内容未提供");
}
}
}
private void _OnChoiceMadeHandler(CommonActionId choiceId)
{
if (WindowScript != null)
{
var eventData = new ChoiceUIInteractionCityUpgrade
{
Map = Main.MapData,
CityId = (uint)WindowScript.CurrentCityID,
ChoiceActionId = choiceId
};
EventManager.Publish(eventData);
Debug.Log($"玩家对城市 {eventData.CityId} 做出了选择, 选项ID: {eventData.ChoiceActionId}. 事件已发布。");
}
Close();
}
void _OnBtnCloseClick()
{
Close();
}
}
}