TH1/Unity/Assets/Scripts/TH1_UI/Controller/Interaction/UIInteractionCityLevelupController.cs
2026-06-05 21:01:46 +08:00

178 lines
5.9 KiB
C#

// 文件位置建议: Assets/Scripts/TH1_UI/Controller/UIAnnounceMajorEventController.cs
using System;
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 UI.Common;
using UnityEngine;
// 确保这里引用了View脚本的命名空间
namespace TH1_UI.Controller.Interaction
{
/// <summary>
/// 重大事件公告界面的控制器。
/// 它的职责是处理玩家相遇、玩家被消灭之类的宣告
/// </summary>
public class UIInteractionCityLevelupController : ViewController<UIInteractionCityLevelupView> // 泛型参数是对应的View脚本
{
CommonActionId _actionA;
CommonActionId _actionB;
CommonActionParams _paramA;
CommonActionParams _paramB;
public UIInteractionCityLevelupController() { }
public override bool OpenWithParam(object param)
{
_openParameter = param;
if (WindowScript != null)
{
ApplyOpenParameterToView(param);
}
return Open();
}
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)
{
ApplyOpenParameterToView(evt);
}
}
else
{
// 如果没有参数或参数类型不符,可以提供默认内容或打印警告
Debug.LogWarning("[UIAnnounceMajorEventController] Opened without valid parameters.");
if (WindowScript != null)
{
//WindowScript.SetContent("警告", "内容未提供");
}
}
}
void _OnBtnCloseClick()
{
Close();
}
private void ApplyOpenParameterToView(object param)
{
if (param is not ShowUIInteractionCityUpgrade evt) return;
if (!PrepareActionChoice((uint)evt.CityId, (uint)evt.CityLevel)) return;
//Param1 = cid Param2 = cityLv
WindowScript.SetContent(evt.CityId, _actionA,_actionB,_paramA,_paramB,OnChoice);
}
private bool PrepareActionChoice(uint cid,uint cityLevel)
{
if (!Main.MapData.CityMap.GetCityById(cid, out var cityData)) return false;
_paramA = new CommonActionParams(Main.MapData, cityData: cityData,playerData : cityData.Player(Main.MapData));
_paramB = new CommonActionParams(Main.MapData, cityData: cityData,playerData : cityData.Player(Main.MapData));
if (cityLevel == 2)
{
_actionB = new CommonActionId()
{
ActionType = CommonActionType.CityLevelUpAction,
CityLevelUpActionType = CityLevelUpActionType.Explorer
};
_actionA = new CommonActionId()
{
ActionType = CommonActionType.CityLevelUpAction,
CityLevelUpActionType = CityLevelUpActionType.Workshop
};
}
if (cityLevel == 3)
{
_actionA = new CommonActionId()
{
ActionType = CommonActionType.CityLevelUpAction,
CityLevelUpActionType = CityLevelUpActionType.CityWall
};
_actionB = new CommonActionId()
{
ActionType = CommonActionType.CityLevelUpAction,
CityLevelUpActionType = CityLevelUpActionType.CityWealth
};
}
if (cityLevel == 4)
{
_actionA = new CommonActionId()
{
ActionType = CommonActionType.CityLevelUpAction,
CityLevelUpActionType = CityLevelUpActionType.Population
};
_actionB = new CommonActionId()
{
ActionType = CommonActionType.CityLevelUpAction,
CityLevelUpActionType = CityLevelUpActionType.Expand
};
}
if (cityLevel >= 5)
{
_actionA = new CommonActionId()
{
ActionType = CommonActionType.CityLevelUpAction,
CityLevelUpActionType = CityLevelUpActionType.Park
};
_actionB = new CommonActionId()
{
ActionType = CommonActionType.CityLevelUpAction,
CityLevelUpActionType = CityLevelUpActionType.BigGuy
};
}
return true;
}
//点击城市升级选项后,走这个函数
private void OnChoice(CommonActionId actionId,CommonActionParams param)
{
var action = ActionLogicFactory.GetActionLogic(actionId);
action.CompleteExecute(param);
Close();
}
public bool GetPos(CityLevelUpActionType actionType, out Vector3 pos)
{
return WindowScript.GetPos(actionType, out pos);
}
}
}