local UIAccumulatedCharge = UIViewClass() local WeekType = 1 local MonthType = 2 local function SortWeekFunc(a, b) local aIsGet = MDL.CycleRecharge.IsGetWeekReward(a.StageID) local bIsGet = MDL.CycleRecharge.IsGetWeekReward(b.StageID) local curScore = MDL.CycleRecharge.GetWeekActivityInfo().point if aIsGet == bIsGet then if aIsGet then return a.StageID < b.StageID else if curScore >= a.RechargeNum and curScore >= b.RechargeNum then return a.StageID < b.StageID elseif curScore >= a.RechargeNum then return true elseif curScore >= b.RechargeNum then return false else return a.StageID < b.StageID end end else return not aIsGet end end local function SortMonthFunc(a, b) local aIsGet = MDL.CycleRecharge.IsGetMonthReward(a.StageID) local bIsGet = MDL.CycleRecharge.IsGetMonthReward(b.StageID) local curScore = MDL.CycleRecharge.GetMonthActivityInfo().point if aIsGet == bIsGet then if aIsGet then return a.StageID < b.StageID else if curScore >= a.RechargeNum and curScore >= b.RechargeNum then return a.StageID < b.StageID elseif curScore >= a.RechargeNum then return true elseif curScore >= b.RechargeNum then return false else return a.StageID < b.StageID end end else return not aIsGet end end function UIAccumulatedCharge:OnCreated() UIUtils.SetLabelText(self.txt_Info, Const_IDS.IDS_TotalCharge_ChargeTips) end function UIAccumulatedCharge:OnOpened(context) self.itemBtnDict = {} self:RegistSystemEvent(EventID.UI_WeekCharge_RefreshCharge, self.RefreshCharge) local weekIsOpen = MDL.CycleRecharge.IsOpenWeekActivity() local monthIsOpen = MDL.CycleRecharge.IsOpenMonthActivity() local weekStr = UIUtils.GetLocalizedTxt(Const_IDS.IDS_TotalCharge_Title1) -- "周期累充" local monthStr = UIUtils.GetLocalizedTxt(Const_IDS.IDS_TotalCharge_Title2) --"月累充" if weekIsOpen then self.group_ToggleGroup:SetToggleText(1, "txt_Selected", weekStr) self.group_ToggleGroup:SetToggleText(1, "txt_Unselected", weekStr) self.group_ToggleGroup:SetToggleText(1, "loc_SelectedTxt", weekStr) self.group_ToggleGroup:SetToggleText(1, "loc_UnselectedTxt", weekStr) self.group_ToggleGroup:SetRedPoint(0, CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.WeekTotalCharge_Week)) if monthIsOpen then self.group_ToggleGroup:SetToggleText(2, "txt_Selected", monthStr) self.group_ToggleGroup:SetToggleText(2, "txt_Unselected", monthStr) self.group_ToggleGroup:SetToggleText(2, "loc_SelectedTxt", monthStr) self.group_ToggleGroup:SetToggleText(2, "loc_UnselectedTxt", monthStr) self.group_ToggleGroup:SetRedPoint(1, CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.WeekTotalCharge_Month)) self.group_ToggleGroup:SetToggleActive(1, true) self.group_ToggleGroup:SetToggleActive(2, true) self.state_toogel:SetState(0) else self.group_ToggleGroup:SetToggleActive(1, false) self.group_ToggleGroup:SetToggleActive(2, false) self.state_toogel:SetState(1) end self.firstType = WeekType elseif monthIsOpen then self.group_ToggleGroup:SetToggleText(1, "txt_Selected", monthStr) self.group_ToggleGroup:SetToggleText(1, "txt_Unselected", monthStr) self.group_ToggleGroup:SetToggleText(1, "loc_SelectedTxt", monthStr) self.group_ToggleGroup:SetToggleText(1, "loc_UnselectedTxt", monthStr) self.firstType = MonthType self.group_ToggleGroup:SetRedPoint(0, CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.WeekTotalCharge_Month)) self.group_ToggleGroup:SetToggleActive(1, false) self.group_ToggleGroup:SetToggleActive(2, false) self.state_toogel:SetState(1) end self.group_ToggleGroup:SelectIndex(0) end function UIAccumulatedCharge:RefreshCharge() if self.curType == WeekType then self:RefreshWeakData() else self:RefreshMonthData() end if self.firstType == WeekType then self.group_ToggleGroup:SetRedPoint(0, CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.WeekTotalCharge_Week)) if MDL.CycleRecharge.IsOpenMonthActivity() then self.group_ToggleGroup:SetRedPoint(1, CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.WeekTotalCharge_Month)) end else self.group_ToggleGroup:SetRedPoint(0, CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.WeekTotalCharge_Month)) end end function UIAccumulatedCharge:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.Btn_CloseClick then UIUtils.SetActive(self.group_TipsPanel, false) UIUtils.SetActive(self.Btn_CloseClick, false) elseif comp == self.btn_help then UIUtils.SetActive(self.group_TipsPanel, true) UIUtils.SetActive(self.Btn_CloseClick, true) end end function UIAccumulatedCharge:OnValueChanged(comp, index) if comp == self.group_ToggleGroup then if index == 0 then if self.firstType == WeekType then self:RefreshWeakData() else self:RefreshMonthData() end else self:RefreshMonthData() end end end function UIAccumulatedCharge:RefreshWeakData() self.curType = WeekType local list = {} local activityInfo = MDL.CycleRecharge.GetWeekActivityInfo() local showCount = activityInfo.unLockRewardNum local isGetAll = true for index, v in MDL.OperationActivity.WeekCycleRecharge:GetEnumeratorByActivityID(activityInfo.activityId) do if v.GroupID == activityInfo.RewardGroupId then if showCount <=0 then break end showCount = showCount - 1 table.insert(list, v) if isGetAll then isGetAll = MDL.CycleRecharge.IsGetWeekReward(v.StageID) end end end table.sort(list, SortWeekFunc) self.loop_Info:ClearCells() self.loop_Info:ReloadAll(list) self.txt_GoldNum.text = activityInfo.point self:SetCdTime(activityInfo.endTime - UTL.Time.GetServerTimestamp()) UTL.Item.SetLocalizationImage(self.loc_State, self.img_Title, "UI_AccumulateCharge/ljcz_msz_02.png") UIUtils.SetImageByAssetBundle(self.img_reward, ConstAssetPathConfig.AssetPath119) self.img_Title:SetNativeSize() self.img_reward:SetNativeSize() UIUtils.SetLabelText(self.lab_Title, Const_IDS.IDS_TotalCharge_Title1) if isGetAll then self.loop_Info:MoveEnd() end end function UIAccumulatedCharge:RefreshMonthData() self.curType = MonthType local list = {} local activityInfo = MDL.CycleRecharge.GetMonthActivityInfo() local showCount = activityInfo.unLockRewardNum local isGetAll = true for index, v in MDL.OperationActivity.MonthCycleRecharge:GetEnumeratorByActivityID(activityInfo.activityId) do if showCount <=0 then break end showCount = showCount - 1 table.insert(list, v) if isGetAll then isGetAll = MDL.CycleRecharge.IsGetMonthReward(v.StageID) end end table.sort(list, SortMonthFunc) self.loop_Info:ClearCells() self.loop_Info:ReloadAll(list) self.txt_GoldNum.text = activityInfo.point self:SetCdTime(activityInfo.endTime - UTL.Time.GetServerTimestamp()) UTL.Item.SetLocalizationImage(self.loc_State, self.img_Title, "UI_AccumulateCharge/ljcz_msz_01.png") UIUtils.SetImageByAssetBundle(self.img_reward, ConstAssetPathConfig.Path20) self.img_Title:SetNativeSize() self.img_reward:SetNativeSize() UIUtils.SetLabelText(self.lab_Title, Const_IDS.IDS_TotalCharge_Title2) if isGetAll then self.loop_Info:MoveEnd() end end function UIAccumulatedCharge:OnCellInit(scrollRect, index, cellTable, data) local curScore = self.curType == WeekType and MDL.CycleRecharge.GetWeekActivityInfo().point or MDL.CycleRecharge.GetMonthActivityInfo().point local curScoreStr = "" local rewardNeedScore = data.RechargeNum if curScore < rewardNeedScore then curScoreStr = UTL.Color.FormatRedColor(curScore) else curScoreStr = UTL.Color.FormatGreenColor(rewardNeedScore) end cellTable.txt_TaskNum.text = curScoreStr cellTable.txt_TaskTotal.text = string.format("/%s", rewardNeedScore) local content = cellTable.content for i, v in ipairs(data.Reward_Table) do self:CreateCellItemObj(cellTable.cell.gameObject, content, i, v.RewardID, v.RewardNum) end for i = #data.Reward_Table + 1, #content do UIUtils.SetActive(content[i].gameObject, false) end if curScore >= rewardNeedScore then local isGet = false if self.curType == WeekType then isGet = MDL.CycleRecharge.IsGetWeekReward(data.StageID) else isGet = MDL.CycleRecharge.IsGetMonthReward(data.StageID) end if isGet then cellTable.state_Got:SetState(2) else cellTable.state_Got:SetState(1) cellTable.btn_Get:SetRedPoint(true) end else cellTable.state_Got:SetState(0) end end function UIAccumulatedCharge:CreateCellItemObj(cellOjb, content, index, id, num) local item = content[index] if not item then item = self:InstantiateCellCollection(cellOjb, content, self.cell_item.gameObject) end UIUtils.SetActive(item.gameObject, true) UTL.Item.SetItemCell(item.item, id, num) self.itemBtnDict[item.item.event_Click] = id end function UIAccumulatedCharge:OnCellClicked(scrollRect, index, cellTable, target, data) if target and self.itemBtnDict[target] then UTL.ItemTips.ShowCommonTipsById(self.itemBtnDict[target]) elseif target == cellTable.btn_Get then local activityId = self.curType == WeekType and MDL.CycleRecharge.GetWeekActivityID() or MDL.CycleRecharge.GetMonthActivityID() MDL.CycleRecharge.ContinuousCycleRechargeRewardReq(activityId, data.StageID) elseif target == cellTable.btn_Recharge then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIPayMallBasePanel, {tabId = CTL.PayMall.ShopTabType.Recharge}) end end function UIAccumulatedCharge:SetCdTime(timer) if timer >= UTL.Time.TotalSecondsOneDay then self.group_Time:SetCustomString(UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeroFund_Timer), 1, 1) self.group_Time:ResetAndBeginTimer(false, timer) else self.group_Time:SetCustomString(UIUtils.GetLocalizedTxt(Const_IDS.IDS_GuildWar_Time1), 1, 2) self.group_Time:ResetAndBeginTimer(false, timer) end end return UIAccumulatedCharge