-- 军需试炼关一键扫荡设置界面 local UIMaterialLevelSweepPanel = UIViewClass() function UIMaterialLevelSweepPanel:OnOpened(context) self:RegistSystemEvent(EventID.UI_MaterialLevel_SweepRefresh, self.OnRefreshData) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS["IDS_ResourcesChapter_Sweep1"]) self.sweepList = {} self.chapterDataDic = {} for i, v in DataSheetManager.ResourcesChapterBase:GetEnumerator() do table.insert(self.chapterDataDic, v) end MDL.MaterialLevel.GetSweepResourceLevelConfigReq() end function UIMaterialLevelSweepPanel:OnRefreshData() local settingInfo = MDL.MaterialLevel.GetAutomateSweepSetting() if settingInfo then for i, v in ipairs(settingInfo) do self.sweepList[i] = { levelId = v.levelId, buyNums = v.buyNums or 0 } end else for i = 1, 3 do self.sweepList[i] = { levelId = self.chapterDataDic[i].ID, buyNums = 0 } end end self:RefreshCostShow() end function UIMaterialLevelSweepPanel:RefreshCostShow() local totalConsume = 0 for i, v in DataSheetManager.ResourcesChapterBase:GetEnumerator() do local uiCollection = self.group_Level[i] if uiCollection then local settingInfo = self.sweepList[i] if settingInfo then UIUtils.SetLabel(uiCollection.txt_PayNum, settingInfo.buyNums) totalConsume = totalConsume + CTL.Purchase.GetPreviewCostNums(v.ID, settingInfo.buyNums) else UIUtils.SetLabel(uiCollection.txt_PayNum, 0) totalConsume = totalConsume + CTL.Purchase.GetPreviewCostNums(v.ID, 0) end end end -- 计算总共消耗 UIUtils.SetLabel(self.txt_Cost, totalConsume) end function UIMaterialLevelSweepPanel:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIMaterialLevelSweepPanel:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.btn_Set then MDL.MaterialLevel.SetSweepResourceLevelConfigReq(self.sweepList) self:CloseView() else for idx, v in ipairs(self.group_Level) do if comp == v.event_Minus then self:UpdateCost(idx, -1) elseif comp == v.event_Plus then self:UpdateCost(idx, 1) end end end end function UIMaterialLevelSweepPanel:UpdateCost(index, deltaCount) local count, totalCount, availableBuyCount = MDL.MaterialLevel.GetCount(self.chapterDataDic[index].ID) local currentVal = self.sweepList[index].buyNums or 0 local targetVal = currentVal + deltaCount if targetVal > totalCount then CTL.Tips.AddTipsMsg(Const_IDS["IDS_ResourcesChapter_Sweep3"]) self.sweepList[index].buyNums = currentVal elseif targetVal < 0 then self.sweepList[index].buyNums = 0 else self.sweepList[index].buyNums = targetVal end self:RefreshCostShow() end return UIMaterialLevelSweepPanel