87 lines
2.7 KiB
C#
87 lines
2.7 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using Logic.Action;
|
||
using RuntimeData;
|
||
using TH1_UI.View.Announce;
|
||
using UnityEngine;
|
||
|
||
namespace TH1_UI.View.Interaction
|
||
{
|
||
public class UIInteractionCityUpgradeView : Base.View
|
||
{
|
||
|
||
|
||
[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)
|
||
{
|
||
item.gameObject.SetActive(validChoices.TryGetValue(item.ChoiceId,out var _));
|
||
}
|
||
|
||
}
|
||
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 当任何一个选项按钮被点击时,所有Item都指向此回调
|
||
/// </summary>
|
||
// 🔄 [修改] 参数类型和命名
|
||
private void HandleItemClicked(CommonActionId choiceId)
|
||
{
|
||
OnChoiceMade?.Invoke(choiceId);
|
||
}
|
||
}
|
||
|
||
}
|