using System; using System.Collections.Generic; using Logic; using Logic.Action; using Logic.Multilingual; using RuntimeData; using TH1_Logic.Core; using TH1_UI.View.Announce; using TMPro; using UnityEngine; using UnityEngine.UI; namespace TH1_UI.View.Interaction { public class UIInteractionCityUpgradeView : Base.View { public Transform Title; [Header("Interaction Items")] [Tooltip("在Editor中,将预制件内所有预置的Item拖拽到这里")] public List AllItems; //当选择了一个选项item后,执行的action public Action OnChoiceMade; public int CurrentCityID { get; private set; } private Material _grayScaleMat; private Dictionary _itemMap; public ViDelegateAssisstant.Dele OnItemClick; protected override void OnInit() { base.OnInit(); //step #2 建立actionId到每一个item选项所挂在的脚本的关联 if (AllItems == null) return; _itemMap = new Dictionary(); foreach (var item in AllItems) _itemMap.TryAdd(item.ChoiceId, item); } public void SetContent(int cid, int cityLevel) { CurrentCityID = cid; //step #1 获取当前citylevel所有可能得选项 var validChoices = GetValidChoices(cid, cityLevel); //step #2 将可能得选项显示true,没有的选项显示false foreach (var item in AllItems) { bool show = validChoices.TryGetValue(item.ChoiceId, out var _); item.gameObject.SetActive(show); if (!show) continue; item.Setup(HandleItemClicked); //TODO 这里用legacy方法处理了根据不同阵营召唤不同bigguy,替换bigguy图标的情况。今后要迭代处理 var actionId = item.GetComponent().ActionId; var selfPlayer = Main.MapData.PlayerMap.SelfPlayerData; if (actionId.CityLevelUpActionType == CityLevelUpActionType.BigGuy) { //bigGuy特殊处理 var fullType = new UnitFullType(UnitType.BigGuy, GiantType.None, 0); //处理辉夜阵营的竹林狼 if (selfPlayer.PlayerCivId == 1 && selfPlayer.PlayerForceId == 1) fullType = new UnitFullType(UnitType.KaguyaFrenchWolf, GiantType.None, 0); //处理蕾米阵营的小恶魔 if (selfPlayer.PlayerCivId == 0 && selfPlayer.PlayerForceId == 0) fullType = new UnitFullType(UnitType.RemiliaEgyptianKoakuma, GiantType.None, 0); Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(fullType, out var info); Table.Instance.UnitTypeDataAssets.GetUnitSpriteByInfo(info,selfPlayer,out var sprite); item.transform.Find("Image").GetComponent().sprite = sprite; MultilingualManager.Instance.SetUIText(item.transform.Find("Text").GetComponent(),info.Name); } if (actionId.CityLevelUpActionType == CityLevelUpActionType.Expand) { var gridSpType = GridSpType.None; if (selfPlayer.PlayerCivId == 1) gridSpType = GridSpType.KaguyaGrid; var sprite = Table.Instance.GridAndResourceDataAssets.GetGroundSprite( Table.Instance.TransCivIdToCivEnum(selfPlayer.PlayerCivId), gridSpType); item.transform.Find("Image1").GetComponent().sprite = sprite; item.transform.Find("Image2").GetComponent().sprite = sprite; item.transform.Find("Image3").GetComponent().sprite = sprite; item.transform.Find("Image4").GetComponent().sprite = sprite; } if (actionId.CityLevelUpActionType == CityLevelUpActionType.Population) { var gridSpType = GridSpType.None; Table.Instance.PlayerDataAssets.GetPlayerInfoByCivId(selfPlayer.PlayerCivId, selfPlayer.PlayerForceId, out var info); var sprite = info?.PopulationSprite ?? null; item.transform.Find("Image1").GetComponent().sprite = sprite; item.transform.Find("Image2").GetComponent().sprite = sprite; item.transform.Find("Image3").GetComponent().sprite = sprite; } } //step #3 修改title var txt = Title.GetComponent(); var mul = Title.GetComponent(); if (txt != null && mul != null && Main.MapData.CityMap.GetCityById((uint)cid, out var city) && Table.Instance.CivDataAssets.GetCityInfo(city.Name, out var cityInfo) && uint.TryParse(cityInfo.CityName, out var mid)) MultilingualManager.Instance.SetUIText(txt,mul.ID.ToString(),new List(){MultilingualManager.Instance.GetMultilingualText(mid)}); } private HashSet GetValidChoices(int cid, int level) { var ret = new HashSet(); var dict = ActionLogicFactory.GetActionLogicDict(); foreach (var actionId in dict.Keys) { if (actionId.ActionType != CommonActionType.CityLevelUpAction) continue; switch (actionId.CityLevelUpActionType) { case CityLevelUpActionType.Explorer: if (level == 2) ret.Add(actionId); break; case CityLevelUpActionType.Workshop: if (level == 2) ret.Add(actionId); break; case CityLevelUpActionType.CityWall: if (level == 3) ret.Add(actionId); break; case CityLevelUpActionType.CityWealth: if (level == 3) ret.Add(actionId); break; case CityLevelUpActionType.Expand: if (level == 4) ret.Add(actionId); break; case CityLevelUpActionType.Population: if (level == 4) ret.Add(actionId); break; case CityLevelUpActionType.Park: if (level > 4) ret.Add(actionId); break; case CityLevelUpActionType.BigGuy: if (level > 4) ret.Add(actionId); break; } } return ret; } private void HandleItemClicked(CommonActionId choiceId) { OnChoiceMade?.Invoke(choiceId); } } }