| using System.Collections.Generic; | 
| using Cysharp.Threading.Tasks; | 
| using UnityEngine; | 
| using UnityEngine.UI; | 
|   | 
|   | 
| /// <summary> | 
| /// 武将洗炼界面 | 
| /// </summary> | 
| public class HeroGiftWashWin : UIBase | 
| { | 
|     [SerializeField] HeroShowBaseCell heroShow; | 
|     [SerializeField] GameObject currentGo; | 
|     [SerializeField] GameObject changeGo; | 
|   | 
|   | 
|     [SerializeField] HeroGiftWashCell[] currentGiftCells; | 
|   | 
|     [SerializeField] Button washBtn; | 
|     [SerializeField] Image itemIcon; | 
|     [SerializeField] Text itemCountText; | 
|   | 
|     [SerializeField] GiftBaseCell[] beforeGiftCells; | 
|     [SerializeField] GiftBaseCell[] afterGiftCells; | 
|     [SerializeField] Button cancelBtn; | 
|     [SerializeField] Button saveBtn; | 
|   | 
|   | 
|     HeroInfo hero; | 
|   | 
|     protected override void InitComponent() | 
|     { | 
|         washBtn.AddListener(WashGift); | 
|         cancelBtn.AddListener(CancelWash); | 
|         saveBtn.AddListener(SaveWash); | 
|         btnClickEmptyCloseEvent = OnCloseWin; | 
|     } | 
|   | 
|     protected override void OnPreOpen() | 
|     { | 
|         hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectWashHeroGUID); | 
|         if (hero == null) | 
|         { | 
|             return; | 
|         } | 
|         HeroManager.Instance.onHeroChangeEvent += OnHeroChangeEvent; | 
|         HeroUIManager.Instance.changeLockEvent += ChangeLockEvent; | 
|         Display(); | 
|     } | 
|   | 
|     protected override void OnPreClose() | 
|     { | 
|         hero = null; | 
|         HeroManager.Instance.onHeroChangeEvent -= OnHeroChangeEvent; | 
|         HeroUIManager.Instance.changeLockEvent -= ChangeLockEvent; | 
|     } | 
|   | 
|     void OnHeroChangeEvent(HeroInfo hero) | 
|     { | 
|         if (hero.itemHero.guid != HeroUIManager.Instance.selectWashHeroGUID) | 
|         { | 
|             return; | 
|         } | 
|         Display(); | 
|     } | 
|   | 
|   | 
|     public void Display() | 
|     { | 
|         heroShow.Init(hero.heroId, hero.SkinID, hero.breakLevel, hero.heroStar, hero.awakeLevel, hero.heroLevel); | 
|   | 
|         if (hero.talentRandomIDList.Count == 0) | 
|         { | 
|             currentGo.SetActive(true); | 
|             changeGo.SetActive(false); | 
|             for (int i = 0; i < currentGiftCells.Length; i++) | 
|             { | 
|                 if (i < hero.talentIDList.Count) | 
|                 { | 
|                     currentGiftCells[i].SetActive(true); | 
|                     currentGiftCells[i].Display(hero, i); | 
|                 } | 
|                 else | 
|                 { | 
|                     currentGiftCells[i].SetActive(false); | 
|                 } | 
|             } | 
|             itemIcon.SetItemSprite(HeroUIManager.Instance.washItemID); | 
|             int useCount = HeroUIManager.Instance.GetTalentLockUseWashCount(hero); | 
|             var itemCount = PackManager.Instance.GetItemCountByID(PackType.Item, HeroUIManager.Instance.washItemID); | 
|             itemCountText.text = UIHelper.AppendColor(itemCount >= useCount ? TextColType.Green : TextColType.Red, | 
|                 UIHelper.ReplaceLargeNum(itemCount) + "/" + useCount); | 
|         } | 
|         else | 
|         { | 
|             currentGo.SetActive(false); | 
|             changeGo.SetActive(true); | 
|             HeroUIManager.Instance.RefreshGiftCell(beforeGiftCells, hero);  //当前天赋 | 
|             ShowChangeGift(hero);   //随机未保存的天赋 | 
|   | 
|         } | 
|     } | 
|   | 
|   | 
|     void WashGift() | 
|     { | 
|         var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectWashHeroGUID); | 
|         if (hero == null) | 
|         { | 
|             return; | 
|         } | 
|   | 
|         //洗炼和觉醒的天赋未处理不可吞噬 | 
|         if (hero.talentRandomIDList.Count > 0) | 
|         { | 
|             SysNotifyMgr.Instance.ShowTip("HeroGift4"); | 
|             return; | 
|         } | 
|   | 
|         if (hero.talentAwakeRandomIDList.Count > 0) | 
|         { | 
|             SysNotifyMgr.Instance.ShowTip("HeroGift5"); | 
|             return; | 
|         } | 
|   | 
|   | 
|         //根据锁状态判断材料是否足够 | 
|         if (!ItemLogicUtility.CheckItemCount(PackType.Item, HeroUIManager.Instance.washItemID, | 
|         HeroUIManager.Instance.GetTalentLockUseWashCount(hero), 2)) | 
|         { | 
|             return; | 
|         } | 
|   | 
|         for (int i = 0; i < currentGiftCells.Length; i++) | 
|         { | 
|             if (i < hero.talentIDList.Count) | 
|             { | 
|                 currentGiftCells[i].ShowEffect(hero, i); | 
|             } | 
|         } | 
|   | 
|         closeTime = Time.time; | 
|         //做特效表现 | 
|         SendPack().Forget(); | 
|     } | 
|     float closeTime; | 
|   | 
|   | 
|     async UniTask SendPack() | 
|     { | 
|         //延迟0.5秒发包 | 
|         await UniTask.Delay(500); | 
|         var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectWashHeroGUID); | 
|         if (hero == null) | 
|         { | 
|             return; | 
|         } | 
|   | 
|   | 
|         HeroUIManager.Instance.SendWash(hero, 0); | 
|     } | 
|   | 
|   | 
|     void ShowChangeGift(HeroInfo hero) | 
|     { | 
|         for (int i = 0; i < afterGiftCells.Length; i++) | 
|         { | 
|             if (i >= hero.talentRandomIDList.Count) | 
|             { | 
|                 afterGiftCells[i].SetActive(false); | 
|                 continue; | 
|             } | 
|   | 
|             afterGiftCells[i].SetActive(true); | 
|   | 
|   | 
|             afterGiftCells[i].Init(hero.talentRandomIDList[i], hero.talentLvList[i], 0, hero.heroId, i, hero.awakeLevel); | 
|   | 
|             //对比变化的天赋显示特效 | 
|             if (hero.talentRandomIDList[i] != hero.talentIDList[i]) | 
|             { | 
|                 afterGiftCells[i].GetComponentInChildren<UIEffectPlayer>().Play(); | 
|             } | 
|             else | 
|             { | 
|                 afterGiftCells[i].GetComponentInChildren<UIEffectPlayer>().Stop(); | 
|             } | 
|         } | 
|     } | 
|   | 
|   | 
|     void CancelWash() | 
|     { | 
|         //取消洗炼 | 
|         ConfirmCancel.ToggleConfirmCancelByType(ToggleCheckType.WashCancel, Language.Get("HeroGift20"), () => | 
|         { | 
|             var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectWashHeroGUID); | 
|             if (hero == null) | 
|             { | 
|                 return; | 
|             } | 
|             HeroUIManager.Instance.SendWash(hero, 2); | 
|         }); | 
|     } | 
|   | 
|     void SaveWash() | 
|     { | 
|         var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectWashHeroGUID); | 
|         if (hero == null) | 
|         { | 
|             return; | 
|         } | 
|         HeroUIManager.Instance.SendWash(hero, 1); | 
|   | 
|     } | 
|   | 
|   | 
|     void OnCloseWin() | 
|     { | 
|         if (Time.time - closeTime < 1f) | 
|         { | 
|             return; | 
|         } | 
|         //洗炼结果未处理 | 
|         var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectWashHeroGUID); | 
|         if (hero == null) | 
|         { | 
|             return; | 
|         } | 
|   | 
|         if (hero.talentRandomIDList.Count > 0) | 
|         { | 
|             return; | 
|         } | 
|         else | 
|         { | 
|             CloseWindow(); | 
|         } | 
|     } | 
|   | 
|   | 
|     void ChangeLockEvent() | 
|     {  | 
|         int useCount = HeroUIManager.Instance.GetTalentLockUseWashCount(hero); | 
|         var itemCount = PackManager.Instance.GetItemCountByID(PackType.Item, HeroUIManager.Instance.washItemID); | 
|         itemCountText.text = UIHelper.AppendColor(itemCount >= useCount ? TextColType.Green : TextColType.Red, | 
|             itemCount + "/" + useCount); | 
|     } | 
| } |