local UISubjectMonthHonorOrderReward = UIViewClass() local HonorOrderGrade = MDL.MonthHonorOrder.HonorOrderGrade function UISubjectMonthHonorOrderReward:OnOpened(context) self:RegistSystemEvent(EventID.UI_SubjectMonth_UpdateHonorOrderInfo, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_SubjectMonth_CloseUISubjectMonthHonorOrderBuy, self.PlayNewGradeEffect) self.cellIndexList = {} self:RefreshPanel() end function UISubjectMonthHonorOrderReward:RefreshPanel() local isGrade1Unlock = MDL.MonthHonorOrder.IsUnlockGrade(HonorOrderGrade.Grade1) local isGrade2Unlock = MDL.MonthHonorOrder.IsUnlockGrade(HonorOrderGrade.Grade2) UIUtils.SetActive(self.img_Lock2, not isGrade1Unlock) UIUtils.SetActive(self.img_Lock3, not isGrade2Unlock) self:RefreshLevelList() end function UISubjectMonthHonorOrderReward:PlayNewGradeEffect() if MDL.MonthHonorOrder.IsPlayNewGradeEffect(HonorOrderGrade.Grade1) then self.effect2:PlayUIEffect() end if MDL.MonthHonorOrder.IsPlayNewGradeEffect(HonorOrderGrade.Grade2) then self.effect3:PlayUIEffect() end end function UISubjectMonthHonorOrderReward:RefreshLevelList() if self.loop_Reward.Count > 0 then self.loop_Reward:ClearCells() end self.curLoadTopIndex = 0 local battlePassId = CTL.MonthHonorOrder.GetBattlePassId() for k, v in DataSheetManager.VersionsBattlePassReward:GetDataByBattlePassID_RewardID(battlePassId) do self.loop_Reward:AddData(v, 0) end self.loop_Reward:AddData({ isAdditional = true }, 1) self.loop_Reward:MoveIndex(self:GetMoveIndex()) end function UISubjectMonthHonorOrderReward:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Reward then if data.isAdditional then local battlePassId = CTL.MonthHonorOrder.GetBattlePassId() local eachLevelExp = DataSheetManager.VersionsBattlePassData:GetDataByBattlePassID(battlePassId).EachLevelExp if CTL.MonthHonorOrder.IsMaxLevel() then local score = MDL.MonthHonorOrder.GetScore() cellTable.filledBar.fillAmount = score / eachLevelExp UIUtils.SetLabel(cellTable.txt_Num, string.format("%s/%s", MDL.MonthHonorOrder.GetScore(), eachLevelExp)) else cellTable.filledBar.fillAmount = 0 UIUtils.SetLabel(cellTable.txt_Num, string.format("0/%s", eachLevelExp)) end UIUtils.SetActive(self.group_Show.gameObject, false) if CTL.MonthHonorOrder.CanReceiveExtra() then cellTable.effect:PlayUIEffect() else cellTable.effect:StopUIEffect() end else table.insert(self.cellIndexList, index + 1 + self.curLoadTopIndex) UIUtils.SetLabel(cellTable.txt_Day, data.RewardID) UTL.Item.SetItemCell(cellTable.group_Free.item, data.FreeItem, data.FreeNum) UTL.Item.SetItemCell(cellTable.group_Grade1.item, data.PaidItem1, data.PaidNum1) UTL.Item.SetItemCell(cellTable.group_Grade2.item, data.PaidItem2, data.PaidNum2) self:SetRewardState(cellTable.group_Free, data, HonorOrderGrade.Free) self:SetRewardState(cellTable.group_Grade1, data, HonorOrderGrade.Grade1) self:SetRewardState(cellTable.group_Grade2, data, HonorOrderGrade.Grade2) end end if #self.cellIndexList > 5 then self:CheckShowSeniorIndex() else UIUtils.SetActive(self.group_Show.gameObject, false) end end function UISubjectMonthHonorOrderReward:SetRewardState(collection, data, grade) local isLock = not MDL.MonthHonorOrder.IsUnlockGrade(grade) local isReceived = MDL.MonthHonorOrder.IsLevelRewardReceived(grade, data.RewardID) if isLock then collection.state_Reward:SetState(1) elseif isReceived then collection.state_Reward:SetState(2) else collection.state_Reward:SetState(0) local level = MDL.MonthHonorOrder.GetLevel() if collection.effect_Receive then if level >= data.RewardID then collection.effect_Receive:PlayUIEffect() else collection.effect_Receive:StopUIEffect() end end end end function UISubjectMonthHonorOrderReward:OnCellClicked(scrollRect, index, cellTable, target, data) if data.isAdditional then if cellTable.btn_ExtraInfo == target then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.MonthHonorOrderExtraReward}) elseif cellTable.btn_ExtraReceive == target then if CTL.MonthHonorOrder.CanReceiveExtra() then MDL.MonthHonorOrder.GetSubjectMonthBattlePassLevelRewardReq(0, 0, true) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroMatch1v1_NotFit"]) end end else if target == cellTable.group_Free.item.event_Click then local canReceive = CTL.MonthHonorOrder.CanReceiveLevelReward(HonorOrderGrade.Free, data.RewardID) if canReceive then MDL.MonthHonorOrder.GetSubjectMonthBattlePassLevelRewardReq(HonorOrderGrade.Free, data.RewardID) else UTL.ItemTips.ShowCommonTipsById(data.FreeItem) end elseif target == cellTable.group_Grade1.item.event_Click then local canReceive = CTL.MonthHonorOrder.CanReceiveLevelReward(HonorOrderGrade.Grade1, data.RewardID) if canReceive then MDL.MonthHonorOrder.GetSubjectMonthBattlePassLevelRewardReq(HonorOrderGrade.Grade1, data.RewardID) else UTL.ItemTips.ShowCommonTipsById(data.PaidItem1) end elseif target == cellTable.group_Grade2.item.event_Click then local canReceive = CTL.MonthHonorOrder.CanReceiveLevelReward(HonorOrderGrade.Grade2, data.RewardID) if canReceive then MDL.MonthHonorOrder.GetSubjectMonthBattlePassLevelRewardReq(HonorOrderGrade.Grade2, data.RewardID) else UTL.ItemTips.ShowCommonTipsById(data.PaidItem2) end end end end function UISubjectMonthHonorOrderReward:CheckShowSeniorIndex() local showMaxIndex = 0 local seniorRewardInfoList = self:GetSeniorRewardInfoList() local firstSeniorRewardID = seniorRewardInfoList[1].RewardID if self.isInit then showMaxIndex = firstSeniorRewardID < self.cellIndexList[#self.cellIndexList] and firstSeniorRewardID or self.cellIndexList[#self.cellIndexList] self.isInit = false else if #self.cellIndexList > 5 then if self.cellIndexList[#self.cellIndexList] < self.cellIndexList[#self.cellIndexList - 1] then local number = self.cellIndexList[#self.cellIndexList] + 5 self.cellIndexList = {} for i = 1, 5 do self.cellIndexList[i] = number - i end elseif self.cellIndexList[#self.cellIndexList] == self.cellIndexList[#self.cellIndexList - 1] then table.remove(self.cellIndexList, #self.cellIndexList) else table.remove(self.cellIndexList, 1) end end if self.cellIndexList[#self.cellIndexList] <= self.cellIndexList[#self.cellIndexList - 1] then showMaxIndex = self.cellIndexList[#self.cellIndexList] + 4 elseif self.cellIndexList[#self.cellIndexList] == self.cellIndexList[#self.cellIndexList - 1] then showMaxIndex = math.max(table.unpack(self.cellIndexList)) else showMaxIndex = self.cellIndexList[#self.cellIndexList] end end UIUtils.SetActive(self.group_Show.gameObject, false) if showMaxIndex ~= seniorRewardInfoList[#seniorRewardInfoList].RewardID then for k,v in pairs(seniorRewardInfoList) do if (k == 1 and v.RewardID <= firstSeniorRewardID and showMaxIndex <= firstSeniorRewardID) then self:ShowSeniorItem(v) return elseif k == #seniorRewardInfoList then if v.RewardID >= showMaxIndex then self:ShowSeniorItem(v) return end else if v.RewardID >= showMaxIndex and seniorRewardInfoList[k - 1].RewardID <= showMaxIndex then self:ShowSeniorItem(v) return end end end end end function UISubjectMonthHonorOrderReward:ShowSeniorItem(data) self.seniorItemData = data local collection = self.group_Show UIUtils.SetLabel(collection.txt_Day, data.RewardID) UIUtils.SetActive(collection.gameObject, true) UTL.Item.SetItemCell(collection.group_Free.item, data.FreeItem, data.FreeNum) UTL.Item.SetItemCell(collection.group_Grade1.item, data.PaidItem1, data.PaidNum1) UTL.Item.SetItemCell(collection.group_Grade2.item, data.PaidItem2, data.PaidNum2) self:SetRewardState(collection.group_Free, data, HonorOrderGrade.Free) self:SetRewardState(collection.group_Grade1, data, HonorOrderGrade.Grade1) self:SetRewardState(collection.group_Grade2, data, HonorOrderGrade.Grade2) end function UISubjectMonthHonorOrderReward:GetSeniorRewardInfoList() return CTL.MonthHonorOrder.GetSeniorRewardInfoList() end function UISubjectMonthHonorOrderReward:GetMoveIndex() return CTL.MonthHonorOrder.GetLevelRewardMoveIndex() - 1 end function UISubjectMonthHonorOrderReward:OnButtonClicked(comp) if comp == self.group_Show.group_Free.event_Click then UTL.ItemTips.ShowCommonTipsById(self.seniorItemData.FreeItem) elseif comp == self.group_Show.group_Grade1.event_Click then UTL.ItemTips.ShowCommonTipsById(self.seniorItemData.PaidItem1) elseif comp == self.group_Show.group_Grade2.event_Click then UTL.ItemTips.ShowCommonTipsById(self.seniorItemData.PaidItem2) end end return UISubjectMonthHonorOrderReward