-- 名将列传一键扫荡设置界面 local UIHeroBiographySweepSetPanel = UIViewClass() function UIHeroBiographySweepSetPanel:OnOpened() self:RegistSystemEvent(EventID.UI_HeroBiography_OneKeySweepRefresh, self.OnRefreshPanel) self:RegistSystemEvent(EventID.UI_PurchaseNumsSuccess, self.UpdateCost) self:RegistSystemEvent(EventID.UI_HeroBiography_ModifySweepList, self.OnSetSweepList) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS["IDS_HeroBiography_Sweep1"]) self.purchaseCount = 0 self.maxPurchaseCount = MDL.OfficialPosition.GetProfitBuyTimes(LuaConst.ActivityType.HeroBiography) self.sweepList = { 0, 0, 0, 0, 0 } MDL.Biography.GetSweepBiographyConfigReq() end function UIHeroBiographySweepSetPanel:OnRefreshPanel() self.sweepSettingInfo = MDL.Biography.GetAutoSweepSettingInfo() for i, v in ipairs(self.sweepSettingInfo.levelId) do self.sweepList[i] = v end UIUtils.SetLabel(self.txt_Num, self.sweepSettingInfo.buyNums) self.purchaseCount = self.sweepSettingInfo.buyNums self:RefreshLevelList() self:UpdateCost() end function UIHeroBiographySweepSetPanel:RefreshLevelList() for index, collection in ipairs(self.group_Hero) do local chapterID = self.sweepList[index] if chapterID > 0 then UIUtils.SetActive(collection.bg_HeroHead.gameObject, true) UIUtils.SetActive(collection.img_HeroHead.gameObject, true) local heroID = DataSheetManager.HeroBiographyData:GetDataByID(chapterID).HeroID UTL.Item.ItemSquareItemIconByHeroId(heroID, collection.img_HeroHead, collection.bg_HeroHead) else UIUtils.SetActive(collection.bg_HeroHead.gameObject, false) UIUtils.SetActive(collection.img_HeroHead.gameObject, false) end end end function UIHeroBiographySweepSetPanel:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIHeroBiographySweepSetPanel:OnButtonClicked(comp) if comp == self.event_Plus then self:UpdateCost(1) elseif comp == self.event_Minus then self:UpdateCost(-1) elseif comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.btn_Set then MDL.Biography.SetSweepBiographyConfigReq(self.sweepList, self.purchaseCount) self:CloseView() else for i, v in ipairs(self.group_Hero) do if comp == v.bg_Empty or comp == v.heroBtn then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroBiographySweepSelectPanel, { slotIndex = i }) return end end end end function UIHeroBiographySweepSetPanel:UpdateCost(deltaCount) deltaCount = deltaCount or 0 local finalVal = self.purchaseCount + deltaCount if finalVal < 0 then self.purchaseCount = 0 elseif finalVal > self.maxPurchaseCount then local desc = MDL.OfficialPosition.GetPurchaseTimesDesc(LuaConst.ActivityType.HeroBiography) if desc then CTL.Tips.AddTipsMsg(desc) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroBiography_NoPayTime"]) end self.purchaseCount = self.maxPurchaseCount else self.purchaseCount = self.purchaseCount + deltaCount end UIUtils.SetLabel(self.txt_Num, self.purchaseCount) UIUtils.SetLabel(self.txt_Cost, CTL.Purchase.GetPreviewCostNums(LuaConst.ActivityType.HeroBiography, self.purchaseCount)) end function UIHeroBiographySweepSetPanel:OnSetSweepList(targetIndex, levelID) local occupiedIndex for i, ID in ipairs(self.sweepList) do if ID == levelID then occupiedIndex = i break end end if occupiedIndex then -- 有被占用的交换 self.sweepList[targetIndex], self.sweepList[occupiedIndex] = self.sweepList[occupiedIndex], self.sweepList[targetIndex] else -- 没有直接替换赋值 self.sweepList[targetIndex] = levelID end self:RefreshLevelList() end return UIHeroBiographySweepSetPanel