| using System; | 
| using System.Collections.Generic; | 
| using System.Linq; | 
| using UnityEngine; | 
| using UnityEngine.UI; | 
|   | 
|   | 
| /// <summary> | 
| /// 武将遣散界面 | 
| /// </summary> | 
| public class HeroDeleteWin : UIBase | 
| { | 
|     [SerializeField] Button storeBtn; | 
|     [SerializeField] ScrollerController scroller; | 
|     [SerializeField] HeroSelectBehaviour heroSelectBehaviour; | 
|     [SerializeField] GameObject noHeroObj; | 
|     [SerializeField] Button quickSelectBtn; | 
|     [SerializeField] Button deleteBtn; | 
|   | 
|     protected override void InitComponent() | 
|     { | 
|         storeBtn.AddListener(() => | 
|         { | 
|             // UIManager.Instance.OpenWindow<StoreWin>(); | 
|         }); | 
|         quickSelectBtn.AddListener(QuickSelect); | 
|         deleteBtn.AddListener(DeleteHero); | 
|     } | 
|   | 
|     protected override void OnPreOpen() | 
|     { | 
|         scroller.OnRefreshCell += OnRefreshCell; | 
|         TeamManager.Instance.OnTeamChange += OnTeamChange; | 
|         PackManager.Instance.RefreshItemLockEvent += RefreshItemLockEvent; | 
|         ItemLogicUtility.Instance.OnGetItemShowEvent += OnGetItemShowEvent; | 
|   | 
|         HeroUIManager.Instance.selectHeroDeleteListJob = 0; | 
|         HeroUIManager.Instance.selectHeroDeleteListCountry = 0; | 
|   | 
|         HeroUIManager.Instance.SortHeroDeleteList(); | 
|         heroSelectBehaviour.Display(0, HeroUIManager.Instance.selectHeroDeleteListJob, HeroUIManager.Instance.selectHeroDeleteListCountry, SelectJobCountry); | 
|         RefreshEmptyTip(); | 
|         CreateScroller(); | 
|     } | 
|   | 
|     protected override void OnPreClose() | 
|     { | 
|         scroller.OnRefreshCell -= OnRefreshCell; | 
|         TeamManager.Instance.OnTeamChange -= OnTeamChange; | 
|         PackManager.Instance.RefreshItemLockEvent -= RefreshItemLockEvent; | 
|         ItemLogicUtility.Instance.OnGetItemShowEvent -= OnGetItemShowEvent; | 
|         HeroUIManager.Instance.selectDeleteHeroList.Clear(); | 
|     } | 
|   | 
|     void CreateScroller() | 
|     { | 
|         scroller.Refresh(); | 
|         for (int i = 0; i < HeroUIManager.Instance.heroDeleteSortList.Count; i++) | 
|         { | 
|             if (i % 5 == 0) | 
|             { | 
|                 scroller.AddCell(ScrollerDataType.Header, i); | 
|             } | 
|         } | 
|         scroller.Restart(); | 
|     } | 
|   | 
|     void OnRefreshCell(ScrollerDataType type, CellView cell) | 
|     { | 
|         var _cell = cell as HeroDeleteLineCell; | 
|         _cell.Display(cell.index); | 
|     } | 
|   | 
|     void SelectJobCountry(int job, int country) | 
|     { | 
|         HeroUIManager.Instance.selectHeroDeleteListJob = job; | 
|         HeroUIManager.Instance.selectHeroDeleteListCountry = country; | 
|         HeroUIManager.Instance.SortHeroDeleteList(); | 
|         CreateScroller(); | 
|         RefreshEmptyTip(); | 
|     } | 
|   | 
|     void RefreshEmptyTip() | 
|     { | 
|         if (HeroUIManager.Instance.heroDeleteSortList.Count <= 0) | 
|         { | 
|             noHeroObj.SetActive(true); | 
|             scroller.SetActive(false); | 
|         } | 
|         else | 
|         { | 
|             noHeroObj.SetActive(false); | 
|             scroller.SetActive(true); | 
|         } | 
|     } | 
|   | 
|     void OnTeamChange(TeamType type) | 
|     { | 
|         scroller.m_Scorller.RefreshActiveCellViews(); | 
|     } | 
|   | 
|     void RefreshItemLockEvent(PackType type, string guid, bool lockState) | 
|     { | 
|         scroller.m_Scorller.RefreshActiveCellViews(); | 
|     } | 
|   | 
|     void QuickSelect() | 
|     { | 
|         //只选精英 | 
|         for (int i = 0; i < HeroUIManager.Instance.heroDeleteSortList.Count; i++) | 
|         { | 
|             HeroInfo hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.heroDeleteSortList[i]); | 
|             if (hero == null) | 
|                 continue; | 
|   | 
|             if (hero.Quality > 2) | 
|                 continue; | 
|             if (hero.awakeLevel > 0) | 
|                     continue; | 
|             if (hero.isLock) | 
|                 continue; | 
|             if (hero.IsInAnyTeam()) | 
|                 continue; | 
|   | 
|             if (HeroUIManager.Instance.selectDeleteHeroList.Contains(hero.itemHero.guid)) | 
|                 continue; | 
|   | 
|             HeroUIManager.Instance.selectDeleteHeroList.Add(hero.itemHero.guid); | 
|         } | 
|   | 
|         if (HeroUIManager.Instance.selectDeleteHeroList.Count == 0) | 
|         { | 
|             SysNotifyMgr.Instance.ShowTip("HeroReborn2"); | 
|             return; | 
|         } | 
|   | 
|         scroller.m_Scorller.RefreshActiveCellViews(); | 
|     } | 
|   | 
|     void DeleteHero() | 
|     { | 
|         if (HeroUIManager.Instance.selectDeleteHeroList.Count == 0) | 
|         { | 
|             SysNotifyMgr.Instance.ShowTip("HeroReborn3"); | 
|             return; | 
|         } | 
|   | 
|         bool hasStarHero = false; | 
|         for (int i = 0; i < HeroUIManager.Instance.selectDeleteHeroList.Count; i++) | 
|         { | 
|             HeroInfo hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectDeleteHeroList[i]); | 
|             if (hero == null) | 
|                 continue; | 
|             if (hero.heroStarMaxBefore > 1) | 
|             { | 
|                 hasStarHero = true; | 
|                 break; | 
|             } | 
|         } | 
|   | 
|         if (hasStarHero) | 
|         { | 
|             ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("herocard67"), (bool isOK) => | 
|                 { | 
|                     if (isOK) | 
|                     { | 
|                         ShowDeleteItems(); | 
|                     } | 
|                 }); | 
|             return; | 
|         } | 
|   | 
|         ShowDeleteItems(); | 
|   | 
|     } | 
|   | 
|     void ShowDeleteItems() | 
|     { | 
|         Dictionary<int, long> allItemDict = new Dictionary<int, long>(); | 
|         for (int i = 0; i < HeroUIManager.Instance.selectDeleteHeroList.Count; i++) | 
|         { | 
|             HeroInfo hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectDeleteHeroList[i]); | 
|             if (hero == null) | 
|                 continue; | 
|   | 
|   | 
|             allItemDict = CommonFunc.AddDict(allItemDict, CommonFunc.AddDict(HeroUIManager.Instance.GetHeroLVPayBack(hero.Quality, hero.heroLevel), | 
|             HeroUIManager.Instance.GetHeroBreakPayBack(hero.Quality, hero.breakLevel))); | 
|   | 
|             Dictionary<int, long> tmpDict = new Dictionary<int, long>(); | 
|   | 
|             foreach (var itemInfo in hero.qualityConfig.DismissReturnItems) | 
|             { | 
|                 if (!tmpDict.ContainsKey(itemInfo[0])) | 
|                 { | 
|                     tmpDict.Add(itemInfo[0], itemInfo[1] * (1 + hero.heroStarMaxBefore)); | 
|                 } | 
|                 else | 
|                 { | 
|                     tmpDict[itemInfo[0]] += itemInfo[1] * (1 + hero.heroStarMaxBefore); | 
|                 } | 
|             } | 
|   | 
|             allItemDict = CommonFunc.AddDict(allItemDict, tmpDict); | 
|         } | 
|   | 
|         //计算返还比例 | 
|         var _list = allItemDict.Keys.ToList(); | 
|         foreach (var key in _list) | 
|         { | 
|             allItemDict[key] = Math.Max((long)(allItemDict[key] * HeroUIManager.Instance.deletePayBackPer / 100.0), 1); | 
|         } | 
|   | 
|   | 
|   | 
|         List<Item> items = CommonFunc.ChangeToItemList(allItemDict); | 
|         ConfirmCancel.ShowItemsConfirm(items, Language.Get("herocard25"), Language.Get("herocard26"), (bool isOk) => | 
|         { | 
|             if (isOk) | 
|             { | 
|                 //发包 | 
|                 var pack = new CB240_tagCSHeroDismiss(); | 
|                 List<ushort> indexList = new List<ushort>(); | 
|                 for (int i = 0; i < HeroUIManager.Instance.selectDeleteHeroList.Count; i++) | 
|                 { | 
|                     indexList.Add((ushort)HeroManager.Instance.GetHero(HeroUIManager.Instance.selectDeleteHeroList[i]).itemHero.gridIndex); | 
|                 } | 
|                 pack.ItemIndexList = indexList.ToArray(); | 
|                 pack.Count = (ushort)pack.ItemIndexList.Length; | 
|                 GameNetSystem.Instance.SendInfo(pack); | 
|                 HeroUIManager.Instance.selectDeleteHeroList.Clear(); | 
|             } | 
|         }, itemName:$"( {HeroUIManager.Instance.deletePayBackPer}% )"); | 
|   | 
|     } | 
|   | 
|     void OnGetItemShowEvent() | 
|     {  | 
|         HeroUIManager.Instance.SortHeroDeleteList(); | 
|         CreateScroller(); | 
|     } | 
| } |