104 lines
3.3 KiB
C#
104 lines
3.3 KiB
C#
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;
|
||
|
||
namespace TH1_UI.View.Interaction
|
||
{
|
||
public class UIInteractionCityUpgradeView : Base.View
|
||
{
|
||
|
||
public Transform Title;
|
||
[Header("Interaction Items")]
|
||
[Tooltip("在Editor中,将预制件内所有预置的Item拖拽到这里")]
|
||
public List<UIInteractionCityUpgradeItem> AllItems;
|
||
|
||
//当选择了一个选项item后,执行的action
|
||
public Action<CommonActionId> OnChoiceMade;
|
||
|
||
public int CurrentCityID { get; private set; }
|
||
|
||
private Material _grayScaleMat;
|
||
|
||
private Dictionary<CommonActionId, UIInteractionCityUpgradeItem> _itemMap;
|
||
|
||
public ViDelegateAssisstant.Dele OnItemClick;
|
||
protected override void InitStart()
|
||
{
|
||
base.InitStart();
|
||
|
||
//step #2 建立actionId到每一个item选项所挂在的脚本的关联
|
||
if (AllItems == null) return;
|
||
_itemMap = new Dictionary<CommonActionId, UIInteractionCityUpgradeItem>();
|
||
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);
|
||
}
|
||
|
||
//step #3 修改title
|
||
var txt = Title.GetComponent<TextMeshProUGUI>();
|
||
var mul = Title.GetComponent<MultilingualTextMono>();
|
||
|
||
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<string>(){MultilingualManager.Instance.GetMultilingualText(mid)});
|
||
|
||
|
||
}
|
||
|
||
private HashSet<CommonActionId> GetValidChoices(int cid, int level)
|
||
{
|
||
var ret = new HashSet<CommonActionId>();
|
||
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);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
}
|