local UIHeroSubstituteChooseView = UIViewClass() local EventSystem = require('Event/EventSystem') function UIHeroSubstituteChooseView:OnOpened(context) self.countryLimit = context.countryLimit or 0 self.isSelectedTargetSolt = context.isSelectedTargetSolt or false self.limitHeroId = self.isSelectedTargetSolt and context.selectedSourceHeroId or context.selectedTargetHeroId self.slotHeroId = self.isSelectedTargetSolt and context.selectedTargetHeroId or context.selectedSourceHeroId UIUtils.SetActive(self.toggle_bg.gameObject, false) UIUtils.SetActive(self.UICommonPopUp.img_Info, false) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_HeroFund_ChooseHero) UIUtils.SetLabelText(self.lab_NoHero, Const_IDS.IDS_HeroFund_Null) self:RefreshHeroLoopScroll() end local function SortHeroOrder(a, b) local aStarLv = MDL.HeroStar.GetHeroStarLevel(a.ID) local bStarLv = MDL.HeroStar.GetHeroStarLevel(b.ID) if aStarLv ~= bStarLv then return aStarLv > bStarLv else return a.ID < a.ID end end function UIHeroSubstituteChooseView:RefreshHeroLoopScroll() local filterList = DataSheetManager.ConstData:GetDataByID("ISNotHeroSubstitute").IntListValue local heroList = {} if self.limitHeroId == 0 then for k, v in DataSheetManager.GoldHeroActivityModeData:GetEnumerator() do if v.SynergyBossHeroID ~= self.slotHeroId and not table.containValue(filterList, v.SynergyBossHeroID) and MDL.HeroSelect.IsHasHero(v.SynergyBossHeroID) and not MDL.HeroAwaken.GetIsHeroAwaken(v.SynergyBossHeroID) then local heroData = DataSheetManager.HeroNum:GetDataByID(v.SynergyBossHeroID) if self.countryLimit == 0 or heroData.Kingdom == self.countryLimit then table.insert(heroList, heroData) end end end else local limitHeroData = DataSheetManager.HeroNum:GetDataByID(self.limitHeroId) if limitHeroData.HeroQuality == LuaConst.QualityColor.Gold then for k, v in DataSheetManager.GoldHeroActivityModeData:GetEnumerator() do if v.SynergyBossHeroID ~= self.slotHeroId and not table.containValue(filterList, v.SynergyBossHeroID) and v.SynergyBossHeroID ~= self.limitHeroId and MDL.HeroSelect.IsHasHero(v.SynergyBossHeroID) and not MDL.HeroAwaken.GetIsHeroAwaken(v.SynergyBossHeroID) then local heroData = DataSheetManager.HeroNum:GetDataByID(v.SynergyBossHeroID) if self.countryLimit == 0 or heroData.Kingdom == self.countryLimit then table.insert(heroList, heroData) end end end end end table.sort(heroList , SortHeroOrder) if self.slotHeroId ~= 0 then table.insert(heroList, 1, DataSheetManager.HeroNum:GetDataByID(self.slotHeroId)) end self.loop_ChangeHeroScroll:ClearCells() for i, v in ipairs(heroList) do self.loop_ChangeHeroScroll:AddData(v, 0) end if self.loop_ChangeHeroScroll.Count == 0 then UIUtils.SetActive(self.group_NoHero.gameObject, true) else UIUtils.SetActive(self.group_NoHero.gameObject, false) end end function UIHeroSubstituteChooseView:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIHeroSubstituteChooseView:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() end end function UIHeroSubstituteChooseView:OnCellInit(scrollRect, index, cellTable, data) self:RefreshHeroInfo(cellTable, data) -- 按钮文本 if data.ID == self.slotHeroId then UIUtils.SetLabelText(cellTable.btn_txt, Const_IDS.IDS_Title_Remove) elseif self.slotHeroId == 0 then UIUtils.SetLabelText(cellTable.btn_txt, Const_IDS.IDS_UI_Word29) else UIUtils.SetLabelText(cellTable.btn_txt, Const_IDS.IDS_Formation_ChangeHero_ButtonInside) end end function UIHeroSubstituteChooseView:RefreshHeroInfo(cellTable, data) local heroData = DataSheetManager.HeroNum:GetDataByID(data.ID) UTL.Color.SetQualityImageByType(cellTable.bg_HeroHead, CTL.HeroAwaken.GetHeroQuality(data.ID, MDL.HeroAwaken.GetIsHeroAwaken(data.ID)), UTL.Color.QualityType.Square) UTL.Item.SetHeroIconByHeroId(cellTable.img_HeroHead, data.ID, MDL.HeroAwaken.GetIsHeroAwaken(data.ID)) UIUtils.SetLabel(cellTable.txt_Quality, CTL.HeroSelect.GetHeroIntelligence(data.ID)) local name = CTL.HeroSelect.GetHeroQualityName(data.ID) UIUtils.SetLabel(cellTable.txt_HeroName, name) local heroBreak = MDL.HeroStar.GetHeroStarLevel(data.ID) if heroBreak == 0 then UIUtils.SetActive(cellTable.bg_Break, false) else UIUtils.SetActive(cellTable.bg_Break, true) UIUtils.SetLabel(cellTable.lab_Break, "+"..heroBreak) end end function UIHeroSubstituteChooseView:OnCellClicked(scrollRect, index, cellTable, target, data) if target == cellTable.btn_Change then --派发事件刷新置换界面数据 if data.ID == self.slotHeroId then -- 卸下 EventSystem.Dispatch(EventID.UI_HeroSubstitute_UpdateSlotHero, self.isSelectedTargetSolt, 0) else -- 选择/更换 EventSystem.Dispatch(EventID.UI_HeroSubstitute_UpdateSlotHero, self.isSelectedTargetSolt, data.ID) end self:CloseView() end end return UIHeroSubstituteChooseView