local UIHegemonyActivity = UIViewClass() local CanDragDayLimit = 7 local CanDragPageLimit = 4 function UIHegemonyActivity:OnOpened(context) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_7DayActivity_Title_2) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) self.activityType = MDL.OperationActivity.ActivityType.Hegemony CTL.Hegemony.SetHegemonyNewDayValue() self:RegistSystemEvent(EventID.UI_OperationActivity_DataChanged, self.InitPanel) self:RegistSystemEvent(EventID.UI_OperationActivity_InfoChanged, self.RefreshPanel) --self:RegistSystemEvent(EventID.UI_Hegemony_InfoRefresh, self.RefreshPanel) --self:RegistSystemEvent(EventID.UI_OperationActivity_InfoChanged, self.RefreshAfterCollectReward) self:RegistSystemEvent(EventID.UI_Hegemony_AcquireReward, self.RefreshAfterCollectReward) self:RegistSystemEvent(EventID.UI_Hegemony_AcquireReward, self.PlayScoreEffect) self:RegistSystemEvent(EventID.UI_Hegemony_AcquirePointReward, self.RefreshScorePart) self.activityId = MDL.Hegemony.GetHegemonyActivityId() local group --获得默认选中的组 if context then --跳转回来的选中 group = context.group self.oldDay = context.day self.oldPage = context.page end self:InitPanel(group) end function UIHegemonyActivity:RefreshAfterCollectReward() self.loop_HegemonyGroup:UpdateIndex(self.group - 1) self.loop_HegemonyDay:UpdateIndex(self.day - 1 - MDL.Hegemony.GetDayNumBeforeGroup(self.group)) self.loop_HegemonyPage:UpdateIndex(self.page - 1) self:RefreshTaskList() end function UIHegemonyActivity:RefreshPanel() local info = MDL.OperationActivity.GetOperationActivityInfo(self.activityType, self.activityId) if not CTL.OperationActivity.IsOperationActivityOpen(info) then self:CloseView(true) return end self.group = nil self.loop_HegemonyGroup:RefreshCells() self.loop_HegemonyDay:RefreshCells() self.loop_HegemonyPage:RefreshCells() self.loop_HegemonyTask:RefreshCells() self.loop_HegemonyGroup:SelectIndex(self.group - 1) self:RefreshScorePart(self.group) self:RefreshHeroPart(self.group) end function UIHegemonyActivity:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIHegemonyActivity: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_Hero then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroSelectShowPanel, {showHeroID = self.heroId}) else for i, v in ipairs(self.group_Reward) do if comp == v.Item.event_Click then local isReceived = MDL.Hegemony.GetScoreInfoByGroupId(self.group)[i] or false local data = MDL.OperationActivity.HegemonyPoints:GetDataByActivityID_GroupID_StageID(self.activityId, self.group, i) local totalScore = MDL.Hegemony.GetScoreByGroupId(self.group) if isReceived or totalScore < data.NeedPoint then UTL.ItemTips.ShowCommonTipsById(data.RewardID) else MDL.Hegemony.AcquireHegemonyScoreRewardReq(self.group, i) end end end end end function UIHegemonyActivity:InitPanel(group) --检测活动是否已经结束 local info = MDL.OperationActivity.GetOperationActivityInfo(self.activityType, self.activityId) if not CTL.OperationActivity.IsOperationActivityOpen(info) then self:CloseView(true) return end self:RefreshGroupLoop(group) self:RefreshLeftTimePart() --刷新总剩余时间 end function UIHegemonyActivity:RefreshGroupLoop(group) if self.loop_HegemonyGroup.Count > 0 then self.loop_HegemonyGroup:ClearCells() end local groupData = MDL.OperationActivity.HegemonyBackGround:GetDataByActivityID(self.activityId) for i, v in ipairs(groupData.Group_Table) do self.loop_HegemonyGroup:AddData(v, 0) end local defaultGroup = self.group or (group or CTL.Hegemony.GetDefaultSelectGroup()) self.group = nil self.loop_HegemonyGroup:SelectIndex(defaultGroup - 1) end function UIHegemonyActivity:RefreshHeroPart(groupId) local groupData = MDL.OperationActivity.HegemonyBackGround:GetDataByActivityID(self.activityId).Group_Table local data = groupData[groupId] UIUtils.SetImageByAssetBundle(self.img_Hero, data.ActivityBundlePath) self.lab_HeroName.text = Localization.GetOperationActivityLabel(data.DisplayFirstPath) --武将名字文字 self.lab_TaskInfo.text = Localization.GetOperationActivityLabel(data.DisplaySecondPath) --获取说明文字 self.heroId = data.DisplayFirstParam --武将ID end function UIHegemonyActivity:RefreshScorePart(groupId) if not groupId then groupId = self.group end local scoreInfo = MDL.Hegemony.GetScoreInfoByGroupId(groupId) local totalScore = MDL.Hegemony.GetScoreByGroupId(groupId) self.txt_TotalPoints.text = totalScore local pointData = MDL.OperationActivity.HegemonyPoints:GetDataByActivityID_GroupID_StageID(self.activityId, groupId) local pointUITotalLength = 5 --根据图片推算总的积分进度的长度 local isSetCountProgress = false for i, v in ipairs(pointData) do local pointNode = self.group_Reward[i] UTL.Item.SetItemCell(pointNode.Item, v.RewardID, v.RewardNum) local needPoint = v.NeedPoint --当前段所需积分 pointNode.txt_Point.text = needPoint local isReceived = scoreInfo[i] or false UIUtils.SetActive(pointNode.mask_ItemReceived, isReceived) UIUtils.SetActive(pointNode.img_Point, totalScore >= needPoint) if not isReceived and totalScore >= needPoint then pointNode.effect_Collect:PlayUIEffect() else pointNode.effect_Collect:StopUIEffect() end if not isSetCountProgress and totalScore < needPoint then local curLength = 0 --当前的积分长度 if i == 1 then curLength = totalScore / needPoint else local lastNeedPoint = pointData[i-1].NeedPoint --上一段的所需积分 --当前长度 = 上一段的长度(i-1)+ 当前段达到的长度 --当前段达到的长度 = 当前段内的剩余分值/ 当前段的积分差值 curLength = (i - 1) + (totalScore - lastNeedPoint)/(needPoint - lastNeedPoint) end self.img_PointProgress.fillAmount = curLength/ pointUITotalLength --当前长度/总长度 isSetCountProgress = true end end if totalScore >= pointData[#pointData].NeedPoint then self.img_PointProgress.fillAmount = 1 end end function UIHegemonyActivity:RefreshDayLoop(group) if self.loop_HegemonyDay.Count > 0 then self.loop_HegemonyDay:ClearCells() end local groupDayNum = MDL.Hegemony.GetDayNumInGroup(group) local beforeDayNum = MDL.Hegemony.GetDayNumBeforeGroup(group) for i = 1, groupDayNum do local data = MDL.OperationActivity.HegemonyTab:GetDataByActivityID_GroupID_StageID_PageID(self.activityId, group, beforeDayNum + i) self.loop_HegemonyDay:AddData(data[1], 0) end if groupDayNum > CanDragDayLimit then --天数大于7天时才可以拖拽 self.loop_HegemonyDay:SetMovementType(1) else self.loop_HegemonyDay:SetMovementType(3) end end function UIHegemonyActivity:RefreshPageToggle(groupId, day) if self.loop_HegemonyPage.Count > 0 then self.loop_HegemonyPage:ClearCells() end local pagesData = MDL.OperationActivity.HegemonyTab:GetDataByActivityID_GroupID_StageID_PageID(self.activityId, groupId, day) local oldPage = 0 for i, v in ipairs(pagesData) do if v.PageID ~= oldPage then oldPage = v.PageID self.loop_HegemonyPage:AddData(v, 0) end end if #pagesData > CanDragPageLimit then --页签大于4个时才可以拖拽 self.loop_HegemonyPage:SetMovementType(1) else self.loop_HegemonyPage:SetMovementType(3) end end function UIHegemonyActivity:RefreshTaskList() if self.returnDay then self.returnDay = false return end if self.loop_HegemonyTask.Count > 0 then self.loop_HegemonyTask:ClearCells() end for i, v in MDL.Hegemony.GetSortedTaskEnumerator(self.day, self.page) do self.loop_HegemonyTask:AddData(v, 0) end end function UIHegemonyActivity:PlayScoreEffect() self.effect_Points:PlayUIEffect() end function UIHegemonyActivity:RefreshLeftTimePart() local leftTime = CTL.Hegemony.GetLeftTime() self.txt_LeftTime:ResetAndBeginCustomTimer(false, leftTime, 0, UIUtils.GetLocalizedTxt(Const_IDS["IDS_BossChallenge_SeasonLeftTime"]), 1) end function UIHegemonyActivity:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.loop_HegemonyGroup then local isUnlock = MDL.Hegemony.GetDayInfo(data.OpenDay) or false if isUnlock then if self.group ~= data.GroupID then self.group = data.GroupID --默认选中天数逻辑 self.day = self.oldDay or CTL.Hegemony.GetDefaultSelectDay(self.group) self.oldDay = nil ---选中的index需要处理一下,因为第二组开始就是第八天self.day = 8,选中的index需要减去前边组里的天数 self:RefreshDayLoop(self.group) self.loop_HegemonyDay:SelectIndex(self.day - 1 - MDL.Hegemony.GetDayNumBeforeGroup(self.group)) self:RefreshHeroPart(self.group) self:RefreshScorePart(self.group) end else local group = self.group or (data.GroupID - 1) self.loop_HegemonyGroup:SelectIndex(group - 1) --打开弹窗界面 end elseif scrollRect == self.loop_HegemonyDay then --刷新页签栏,并选中一个默认的 local day = data.StageID if MDL.Hegemony.GetDayInfo(day) then local oldDay = self.day self.day = day if oldDay then self.loop_HegemonyDay:UpdateIndex(oldDay - 1 - MDL.Hegemony.GetDayNumBeforeGroup(self.group)) end self:RefreshPageToggle(self.group, self.day) --默认选中页签逻辑 self.page = self.oldPage or CTL.Hegemony.GetDefaultSelectPage(self.day) self.oldPage = nil self.loop_HegemonyPage:SelectIndex(self.page - 1) cellTable.state_LabDate:SetState(1) else self.returnDay = true CTL.Tips.AddTipsMsg(Const_IDS["IDS_7DayActivity_Hint_4"]) self.loop_HegemonyDay:SelectIndex(self.day - 1 - MDL.Hegemony.GetDayNumBeforeGroup(self.group)) end elseif scrollRect == self.loop_HegemonyPage then --刷新任务栏 self.page = data.PageID self:RefreshTaskList() self:SaveSelectedDayAndPage(self.group, self.day, self.page) end end function UIHegemonyActivity:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_HegemonyGroup then local group = data.GroupID UIUtils.SetImageByAssetBundle(cellTable.img_FinalReward, data.PredictionSmallPic) UIUtils.SetActive(cellTable.img_Lock, not CTL.Hegemony.IsGroupUnlock(group)) UIUtils.SetActive(cellTable.img_arrow, MDL.Hegemony.GetDayNumInGroup(group + 1) > 0) cellTable.img_arrow:SetState(CTL.Hegemony.IsGroupUnlock(group + 1) and 0 or 1) UIUtils.SetActive(cellTable.img_Finish, CTL.Hegemony.IsGroupFinished(group)) local isShowRp = MDL.RedPoint.GetNodeStateByMultiKey(CTL.Hegemony.HegemonyRpEventId.TownHome, group) cellTable.cell:SetRedPoint(isShowRp) elseif scrollRect == self.loop_HegemonyDay then local day = data.StageID if self.day and self.day == day then cellTable.state_LabDate:SetState(1) else cellTable.state_LabDate:SetState(0) end UIUtils.SetLabelText(cellTable.lab_Date, Const_IDS["IDS_7DayActivity_Day_"..day]) local isUnlock = MDL.Hegemony.GetDayInfo(day) or false local isFinished = CTL.Hegemony.IsDayFinished(day) or false UIUtils.SetActive(cellTable.img_Lock, not isUnlock) UIUtils.SetActive(cellTable.img_Finish, isUnlock and isFinished) local isShowRp = MDL.RedPoint.GetNodeStateByMultiKey(CTL.Hegemony.HegemonyRpEventId.TownHome, self.group, day) cellTable.cell:SetRedPoint(isShowRp and not isFinished) if isShowRp == true and isFinished == true then logging.error(LTAG.ERROR, "又有红点又全部完成同时为TRUE,此情况不应该出现,请排查!!! Day: ,", day, " | DayInfo:", MDL.Hegemony.GetDayInfo(day)) end elseif scrollRect == self.loop_HegemonyPage then local tabData = MDL.OperationActivity.HegemonyTab:GetDataByActivityID_GroupID_StageID_PageID(self.activityId, self.group, data.StageID, data.PageID) cellTable.lab_Page.text = tabData.DisplayIconPath cellTable.lab_PageSelect.text = tabData.DisplayIconPath --判断任务是否全部完成 UIUtils.SetActive(cellTable.img_Finish, CTL.Hegemony.IsPageFinished(data.StageID, data.PageID)) local isShowRp = MDL.RedPoint.GetNodeStateByMultiKey(CTL.Hegemony.HegemonyRpEventId.TownHome, self.group, data.StageID, data.PageID) cellTable.cell:SetRedPoint(isShowRp) elseif scrollRect == self.loop_HegemonyTask then local taskIndex = MDL.Hegemony.GetTaskIndexByData(data) local taskInfo = MDL.Hegemony.GetTaskInfo(self.day, self.page, taskIndex) local taskState = taskInfo.state local isAchieve = taskState ~= MDL.Hegemony.HegemonyTaskState.Doing local rewardTable = data.Reward_Table[1] --只有一个奖励 UTL.Item.SetItemCell(cellTable.Item, rewardTable.RewardID, rewardTable.RewardNum) local targetNum, des = CTL.Hegemony.GetTriggerContentById(data.CondID) cellTable.txt_TaskName.text = des UIUtils.SetActive(cellTable.lab_TaskProgress, isAchieve) UIUtils.SetLabelText(cellTable.lab_TaskProgress, Const_IDS["IDS_Activity_AlreadyDone"]) UIUtils.SetActive(cellTable.txt_TaskProgress, not isAchieve) if isAchieve then cellTable.img_ProgressBar.fillAmount = 1 local isReceived = taskState == MDL.Hegemony.HegemonyTaskState.Claimed UIUtils.SetActive(cellTable.img_CanCollect, not isReceived) if not isReceived then cellTable.cell_State:SetState(1) --cellTable.btn_Collect:SetRedPoint(true) else cellTable.cell_State:SetState(2) --cellTable.btn_Collect:SetRedPoint(false) end else UIUtils.SetActive(cellTable.img_CanCollect, false) local progress = taskInfo.finishCount cellTable.img_ProgressBar.fillAmount = progress / targetNum cellTable.txt_TaskProgress.text = progress .."/".. targetNum cellTable.cell_State:SetState(0) --cellTable.btn_Collect:SetRedPoint(false) end local isShowRp = taskState == MDL.Hegemony.HegemonyTaskState.Finished cellTable.btn_Collect:SetRedPoint(isShowRp) if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.EntryRedPoint) and isShowRp ~= MDL.RedPoint.GetNodeStateByLogicParams(CTL.Hegemony.HegemonyRpEventId.TownHome, self.day, self.page, taskIndex) then logging.error(LTAG.ERROR, "节点红点状态与实际不符!!! Day: ", self.day, "Page: ", self.page, "TaskIndex: ", taskIndex, "TaskInfo: ", taskInfo, "Node: ", MDL.RedPoint.GetNodeByLogicParams(CTL.Hegemony.HegemonyRpEventId.TownHome, self.day, self.page, taskIndex)) end end end function UIHegemonyActivity:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_HegemonyTask then if target == cellTable.btn_Collect then MDL.Hegemony.AcquireHegemonyRewardReq(self.day, self.page, MDL.Hegemony.GetTaskIndexByData(data)) elseif target == cellTable.btn_GoTo then local conditionData = MDL.OperationActivity.HotGenCondID:GetDataByCondID(data.CondID) local triggerData = conditionData.Task_Table[1] local sourceId = DataSheetManager.TriggerType:GetDataByID(triggerData.Trigger).ItemSourceID local unlockId = DataSheetManager.ItemSource:GetDataByID(sourceId).UnlockID if unlockId > 0 and not MDL.Unlock.IsUnlock(unlockId) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_7DayActivity_Hint_6"]) return end CTL.ItemSources.ExecuteSourceFunctionById(sourceId) elseif target == cellTable.Item.event_Click then UTL.ItemTips.ShowCommonTipsById(data.Reward_Table[1].RewardID) end elseif scrollRect == self.loop_HegemonyGroup then if target == cellTable.img_Lock then UIManager.OpenView(MDL.Hegemony.GetHegemonyPushInterFace(index + 1), data, Const_UI_Lua.UIEnum.UIPushInterfaceHegemony) end end end function UIHegemonyActivity:SaveSelectedDayAndPage(group, day, page) if self.context then self.context.group = group self.context.day = day self.context.page = page else self.context = {group = group, day = day, page = page} end end function UIHegemonyActivity:OnClosed() UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) end function UIHegemonyActivity:RefreshGroupCellRedPoint(state, data) self.loop_HegemonyGroup:UpdateIndex(data.group - 1) end function UIHegemonyActivity:RefreshDayCellRedPoint(state, data) local group = data.group if self.group == group then self.loop_HegemonyDay:UpdateIndex(data.day - 1 - MDL.Hegemony.GetDayNumBeforeGroup(group)) end end function UIHegemonyActivity:RefreshPageCellRedPoint(state, data) if self.group == data.group and self.day == data.day then self.loop_HegemonyPage:UpdateIndex(data.page - 1) end end return UIHegemonyActivity