local UIMaterialLevel = UIViewClass() local Image_Path = ConstAssetPathConfig.Image_Path local BG_Path = ConstAssetPathConfig.BG_Path function UIMaterialLevel:OnOpened(context) self:RegistSystemEvent(EventID.UI_MaterialLevel_Refresh,self.Refresh) self:RegistSystemEvent(EventID.UI_LaterEnter_QuickPass, self.RefreshLevel) local activityData = DataSheetManager.ActivityData:GetDataByID(context.id) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title,Const_IDS[activityData.Activity]) self:RefreshLevel() end function UIMaterialLevel:RefreshLevel() self.scroll_MaterialLevel:ClearCells() local selectIndex = nil local levelIndex = 0 for i,v in DataSheetManager.ResourcesChapterStage:GetEnumerator() do if v.DungeonType == self.context.id then self.scroll_MaterialLevel:AddData(v,0) if MDL.MaterialLevel.CanChallenge(v.ID) then selectIndex = levelIndex end levelIndex = levelIndex + 1 end end selectIndex = selectIndex or 0 self.scroll_MaterialLevel:SelectIndex(selectIndex, true) end function UIMaterialLevel:Refresh() self:SetCount() end function UIMaterialLevel:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIMaterialLevel:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_Attack then self:OnClickAttackBtn() elseif comp == self.btn_Sweep then self:OnClickSweep() elseif comp == self.btn_Skip then MDL.LaterEnter.LaterEnterQuickPassReq(MDL.LaterEnter.LaterEnterQuickPassType.ResourceLevel, {self.chapterId}) elseif comp == self.add_Count then CTL.MaterialLevel.OpenTimeUpView(self.chapterId) elseif comp == self.UITemplateTitlePanel.btn_Info then local materialData = DataSheetManager.ResourcesChapterBase:GetDataByID(self.chapterId) local timeStr = UTL.Time.GetDiffLocalStrById(1) UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = materialData.guidanceId, params = {timeStr}}) else for i,v in ipairs(self.cell_Reward) do if comp == v.event_Click then UTL.ItemTips.ShowCommonTipsById(self.rewardId) end end end end function UIMaterialLevel:OnClickSweep() local count,totalCount = MDL.MaterialLevel.GetCount(self.chapterId) if count == 0 then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ResourcesChapter_RewardReminder_1) return end local nextId = self.levelId + 1 if MDL.MaterialLevel.CanChallenge(nextId) then local data = DataSheetManager.ResourcesChapterStage:GetDataByID(nextId) local stageName = string.FormatByIdsId(Const_IDS[data.StageName], UIUtils.GetLocalizedTxt(Const_IDS["IDS_Number_Written_"..data.StageNum])) local str = string.FormatByIdsId(Const_IDS.IDS_ResourcesChapter_ConfirmReminder_6, stageName) UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_WARNING, str, function () MDL.MaterialLevel.Sweep(self.levelId) end,nil) elseif not MDL.MaterialLevel.IsThreeStars(self.levelId) then local data = DataSheetManager.ResourcesChapterStage:GetDataByID(self.levelId) local stageName = string.FormatByIdsId(Const_IDS[data.StageName], UIUtils.GetLocalizedTxt(Const_IDS["IDS_Number_Written_"..data.StageNum])) local str = string.FormatByIdsId(Const_IDS.IDS_ResourcesChapter_ConfirmReminder_3, stageName) UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_WARNING, str, function () MDL.MaterialLevel.Sweep(self.levelId) end,nil) else MDL.MaterialLevel.Sweep(self.levelId) end end function UIMaterialLevel:OnClickAttackBtn() if MDL.LaterEnter.IsCanQuickSkip(MDL.LaterEnter.LaterEnterQuickPassType.ResourceLevel, self.levelId) then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_COMMON_PROMPT, Const_IDS.IDS_LaterEnter_Hint_14, function () MDL.LaterEnter.LaterEnterQuickPassReq(MDL.LaterEnter.LaterEnterQuickPassType.ResourceLevel, {self.chapterId}) end, function () self:OnClickAttack() end, Const_IDS.IDS_LaterEnter_Hint_12, Const_IDS.IDS_LaterEnter_Hint_15 ) else self:OnClickAttack() end end function UIMaterialLevel:OnClickAttack() local count,totalCount = MDL.MaterialLevel.GetCount(self.chapterId) if count == 0 then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_WARNING, Const_IDS.IDS_ResourcesChapter_ConfirmReminder_1, function () MDL.MaterialLevel.Challenge(self.levelId,self.chapterId) end,nil) return end local nextId = self.levelId + 1 if MDL.MaterialLevel.CanChallenge(nextId) then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_WARNING, Const_IDS.IDS_ResourcesChapter_ConfirmReminder_2, function () MDL.MaterialLevel.Challenge(self.levelId,self.chapterId) end,nil) else MDL.MaterialLevel.Challenge(self.levelId,self.chapterId) end end function UIMaterialLevel:OnCellSelect(scrollRect, index, cellTable, data) local isOpen = MDL.Unlock.IsComplete(data.StageUnlockType,data.StageUnlockValue) if isOpen then if self.curSelectIndex ~= index then self:SetSelectInfo(data) self.curSelectIndex = index end else self.scroll_MaterialLevel:SelectIndex(self.curSelectIndex) end end function UIMaterialLevel:OnCellInit(scrollRect, index, cellTable, data) local isOpen = MDL.Unlock.IsComplete(data.StageUnlockType,data.StageUnlockValue) UIUtils.SetGray(cellTable.img_MaterialLevel,not isOpen) cellTable.img_Locked.gameObject:SetActive(not isOpen) local namePath = string.format(Image_Path, data.StageNameImage) local path = string.format(Image_Path, data.StageImage) --ConstAssetPathConfig.path2..heroData.SquareHead..".png" UIUtils.SetLabelText(cellTable.txt_Level, Const_IDS[data.StageNameImage]) UIUtils.SetImageByAssetBundle(cellTable.img_MaterialLevel, path) local noStar = true if not isOpen then cellTable.stars.gameObject:SetActive(false) local stageUnlockValue = UTL.Item.GetNobilityByTeamLevel(tonumber(data.StageUnlockValue), 1) -- 爵位转换 cellTable.txt_LevelLock.text = string.FormatByIdsId(Const_IDS.IDS_ResourcesChapter_UnlockReminder_3,UTL.Color.FormatRedColor(stageUnlockValue)) else cellTable.txt_LevelLock.text = nil for i,v in ipairs(MDL.MaterialLevel.GetLevelStars(data.ID)) do if v == 1 then cellTable.group_Stars[i].gameObject:SetActive(true) noStar = false else cellTable.group_Stars[i].gameObject:SetActive(false) end end cellTable.stars.gameObject:SetActive(true) end -- body cellTable.posSwitch:SetState(index % 2) cellTable.cell:SetRedPoint(noStar and isOpen) end function UIMaterialLevel:OnCellClicked(scrollRect, index, cellTable, target, data) local isOpen = MDL.Unlock.IsComplete(data.StageUnlockType,data.StageUnlockValue) if not isOpen then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ResourcesChapter_UnlockReminder_2) CTL.Sound.PlayGameSound("UI_invalid") return end --CTL.Sound.PlayGameSound("UI_sound_xuanguan") end function UIMaterialLevel:SetSelectInfo(data) for i=1,3 do local evaluationList = DataSheetManager.LevelEvaluationData:GetDataByLevelID_Order(data.StageId,i) UIUtils.SetLabel(self.group_LockCondition[i], self:FormatEvaluationText(evaluationList)) end local rewards = DataSheetManager.ResourcesChapterStageReward:GetDataByID(data.StageUnlockReward) for i,v in ipairs(rewards.Item_Table) do UTL.Item.SetItemCell(self.cell_Reward[i],v.ItemID,v.ItemNum) self.rewardId = v.ItemID end self.levelId = data.ID self.chapterId = data.DungeonType self:SetCount() end function UIMaterialLevel:SetCount( ) local count,totalCount = MDL.MaterialLevel.GetCount(self.chapterId) if count == 0 then count = UTL.Color.FormatRedColor(count) self.lab_Times.text = string.FormatByIdsId(Const_IDS.IDS_ResourcesChapter_RewardTimes,count,totalCount) else count = UTL.Color.FormatGreenColor(count) self.lab_Times.text = string.FormatByIdsId(Const_IDS.IDS_ResourcesChapter_RewardTimes,count,totalCount) end local payData = DataSheetManager.ActivityData:GetDataByID(self.chapterId).PayNum UIUtils.SetGray(self.img_AddCount, #payData <= MDL.MaterialLevel.GetDataBychapterId(self.chapterId).purchaseNums) local value,str = MDL.MaterialLevel.CanChallenge(self.levelId) if value then self.btn_Attack.gameObject:SetActive(true) if MDL.MaterialLevel.IsPass(self.levelId) then self.btn_Sweep.gameObject:SetActive(true) UIUtils.SetActive(self.btn_Skip, false) else self.btn_Sweep.gameObject:SetActive(false) UIUtils.SetActive(self.btn_Skip, MDL.LaterEnter.IsCanQuickSkip(MDL.LaterEnter.LaterEnterQuickPassType.ResourceLevel, self.levelId)) end self.lab_Unlock.text = nil else self.lab_Unlock.text = str self.btn_Attack.gameObject:SetActive(false) self.btn_Sweep.gameObject:SetActive(false) UIUtils.SetActive(self.btn_Skip, false) end end function UIMaterialLevel:FormatEvaluationText(evaluateData) return string.FormatByIdsId(Const_IDS[evaluateData.EvaluationNextIDS], evaluateData.Param1, evaluateData.Param2, evaluateData.Param3) end return UIMaterialLevel