using System.Collections.Generic; using System.Net; using Logic.Action; using Logic.CrashSight; using Logic.Multilingual; using RuntimeData; using TH1_Core.Events; using TH1_Logic.Core; using TH1_UI.Components; using TH1_UI.HintUI; using TH1Resource; using TMPro; using UI.HintUI; using UnityEngine; using UnityEngine.UI; namespace TH1_UI.View.Info { public class UIInfoHeroView : Base.View { public Button closeButton; public ViDelegateAssisstant.Dele OnBtnCloseClick; [Header("需要动态显示的对象")] public GameObject PickedTitle; public GameObject PoolTitle; public GameObject PoolGroup; public GameObject PoolButtonGroup; [Header("已出战的格子")] public List PickList; [Header("待选择的格子")] public List PoolList; //确认选择出战英雄的按钮 public Button CheckButton; private GiantType _choiceGiantType; protected override void InitStart() { base.InitStart(); InitPickAndPoolGroup(); if (closeButton == null || CheckButton == null) return; closeButton.onClick.RemoveAllListeners(); closeButton.onClick.AddListener(() => { OnBtnCloseClick.Invoke(); }); CheckButton.onClick.RemoveAllListeners(); CheckButton.onClick.AddListener(OnCheckChoice); } //初始化InitPickGroup,将基础5个职阶的图像都设置好。后续Update的时候仅仅是改变谁显示谁不显示罢了 private void InitPickAndPoolGroup() { if (PoolList.Count < 5 || PickList.Count < 3) return; var player = Main.MapData.PlayerMap.SelfPlayerData; var table = Table.Instance.UnitTypeDataAssets; var civ = Table.Instance.TransCivIdToCivEnum(player.PlayerCivId); var force = Table.Instance.TransForceIdToForceEnum(player.PlayerForceId); //Step #1 先设置PoolList的对象图样 for (int i = 0; i < 5; i++) { ChessType ch = i switch { 0 => ChessType.Knight, 1 => ChessType.Queen, 2 => ChessType.King, 3 => ChessType.Bishop, _ => ChessType.Rook, }; PoolList[i].UpdateInfo(isLock:false,isBlank:false,giantType:table.GetGiantType(civ,force,ch),0,true); PoolList[i].InPool = true; PoolList[i].SetClickCallback(OnChoice); } //Step #2 再初始化PickList的锁定条件 PickList[0].InPool = false; PickList[1].SetLockDesc(1); PickList[1].InPool = false; PickList[2].SetLockDesc(2); PickList[2].InPool = false; } //当子节点被点击的时候, public void OnChoice(GiantType giantType) { for(int i= 0;i < PoolList.Count;i++) if(PoolList[i].GetGiantType() != giantType) PoolList[i].Deselect(); _choiceGiantType = giantType; SetPickedList(); } public void SetContent() { //Step #1 设置选择英雄框 SetPoolList(); //Step #2 设置出战框 SetPickedList(); } public void SetPickedList() { var heroData = Main.MapData.PlayerMap.SelfPlayerData.PlayerHeroData; //Step 1设置Title var txt = PickedTitle.gameObject.GetComponent(); var mul = PickedTitle.gameObject.GetComponent(); if(txt != null && mul != null) MultilingualManager.Instance.SetUIText(txt,mul.ID.ToString(),new List{ heroData.HeroList.Count.ToString()}); //Step #2 设置英雄列表 for(int i = 0; i < PickList.Count;i++) { //处理已经出战的英雄 if (i < heroData.HeroList.Count) PickList[i].UpdateInfo(isLock:false,isBlank:false,heroData.HeroList[i].GiantType,heroData.HeroList[i].UnitLevel,false); //处理已经待选择的英雄 else if (i >= heroData.HeroList.Count && i < heroData.MaxHeroCount) PickList[i].UpdateInfo(isLock:false,isBlank:true,_choiceGiantType,0,false); //处理已锁定的英雄槽位 else if (i >= heroData.MaxHeroCount) PickList[i].UpdateInfo(isLock:true,isBlank:false,GiantType.None,0,false); } } public void SetPoolList() { var player = Main.MapData.PlayerMap.SelfPlayerData; var heroData = Main.MapData.PlayerMap.SelfPlayerData.PlayerHeroData; _choiceGiantType = GiantType.None; //确认是否要pick,是否显示相关的模块 bool needPick = heroData.HeroList.Count != heroData.MaxHeroCount; PoolTitle.SetActive(needPick); PoolGroup.SetActive(needPick); PoolButtonGroup.SetActive(needPick); if (!needPick) return; //开始设置具体的pickAvatar //用来设置第一个默认选择的参数 bool firstSelect = true; for (int i = 0; i < 5; i++) { var hasHero = heroData.HasHero(PoolList[i].GetGiantType()); PoolList[i].gameObject.SetActive(!hasHero); if (hasHero) continue; PoolList[i].UpdateInfo(isLock:false,isBlank:false,giantType:PoolList[i].GetGiantType(),0,firstSelect); if (firstSelect) { _choiceGiantType = PoolList[i].GetGiantType(); firstSelect = false; } } } public void OnCheckChoice() { if (_choiceGiantType == GiantType.None) return; var heroData = Main.MapData.PlayerMap.SelfPlayerData.PlayerHeroData; heroData.AddHero(_choiceGiantType); SetContent(); } } }