local UIActivitiesCalendar = UIViewClass() local EventSystem = require('Event/EventSystem') -------------------- function UIActivitiesCalendar:OnOpened(context) self:RegistSystemEvent(EventID.UI_Activity_Refresh_Calender, self.RefreshActivitiesCalendar) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.RefreshAllPanel) self:RefreshAllPanel() -- 刷新运营活动 MDL.Activities.WeeklyCalendarInfoReq() end function UIActivitiesCalendar:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIActivitiesCalendar:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() end end function UIActivitiesCalendar:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Week then local ids = Const_IDS["IDS_Activity_Calendar_Day0" .. data] UIUtils.SetLabelText(cellTable.txt_Week01, ids) UIUtils.SetLabelText(cellTable.txt_Week02, ids) UIUtils.SetActive(cellTable.group_Now, UTL.Time.GetServerWeekday() == data) elseif scrollRect == self.loop_Time then UIUtils.SetLabel(cellTable.txt_01, UTL.Time.GetLocalTimeDesc(data.TimeID)) UIUtils.SetActive(cellTable.group_Sign, data.ActivaionType == CTL.Activities.CalendarType.Country) elseif scrollRect == self.loop_WeekActivity then for i, v in DataSheetManager.ActivationCalendar:GetEnumerator() do local objTable = cellTable.activity[i] if not objTable then objTable = self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.activity, self.activityTemp.gameObject) UIUtils.SetActive(objTable.gameObject, true) end UIUtils.SetActive(objTable.img_Even, i % 2 == 0) UIUtils.SetActive(objTable.img_Now, false) if v.ActivaionType == CTL.Activities.CalendarType.Operation then -- 运营活动 local offsetTimestamp = (UTL.Time.GetServerWeekday() - data) * UTL.Time.TotalSecondsOneDay local timestamp = UTL.Time.GetConfigTimestampById(v.TimeID) - offsetTimestamp local funcId = MDL.Activities.GetWeeklyCalendarInfo(timestamp) if funcId > 0 then objTable.UIState:SetState(0) UIUtils.SetLabelText(objTable.txt_Activity, CTL.Unlock.GetFuncNameById(funcId)) UIUtils.SetActive(objTable.img_Now, UTL.Time.GetServerWeekday() == data) else objTable.UIState:SetState(1) end elseif v.ActivaionType == CTL.Activities.CalendarType.Country then if CTL.WarZone.IsWarZoneOpen() then local timestamp = self:GetTimestampByWeekNum(data) if not MDL.Country.CanJoinActivity(timestamp) then objTable.UIState:SetState(1) else self:SetActivityInfo(v, data, objTable) end else objTable.UIState:SetState(1) end else self:SetActivityInfo(v, data, objTable) end end end end function UIActivitiesCalendar:SetActivityInfo(calendarCfg, day, objTable) local activityId = calendarCfg[CTL.Activities.WeekFieldName[day]] activityId = CTL.Activities.DealwithCalender(activityId, day) if activityId > 0 then local activityData = DataSheetManager.ActivityData:GetDataByID(activityId) if activityData and MDL.Unlock.IsServerUnlock(activityData.FuctionUnlockID) then objTable.UIState:SetState(0) UIUtils.SetLabelText(objTable.txt_Activity, Const_IDS[activityData.Activity]) UIUtils.SetActive(objTable.img_Now, UTL.Time.GetServerWeekday() == day) else objTable.UIState:SetState(1) end else objTable.UIState:SetState(1) end end -------------------- function UIActivitiesCalendar:RefreshAllPanel() -- 初始化星期几 for i, v in ipairs(CTL.Activities.WeekFieldName) do self.loop_Week:AddData(i, 0) self.loop_WeekActivity:AddData(i, 0) end -- 初始化活动时刻 for _, v in DataSheetManager.ActivationCalendar:GetEnumerator() do self.loop_Time:AddData(v, 0) end -- 是否开放了战区 UIUtils.SetActive(self.obj_CountryEmpty, not CTL.WarZone.IsWarZoneOpen()) end function UIActivitiesCalendar:RefreshActivitiesCalendar() local funcId = 0 for i, _ in ipairs(CTL.Activities.WeekFieldName) do for _, v in DataSheetManager.ActivationCalendar:GetEnumerator() do if v.ActivaionType == CTL.Activities.CalendarType.Operation then -- 运营活动 local offsetTimestamp = (UTL.Time.GetServerWeekday() - i) * UTL.Time.TotalSecondsOneDay local timestamp = UTL.Time.GetConfigTimestampById(v.TimeID) - offsetTimestamp local _funcId = MDL.Activities.GetWeeklyCalendarInfo(timestamp) if _funcId > 0 then funcId = _funcId break end end end if funcId > 0 then break end end if funcId > 0 then UIUtils.SetActive(self.obj_Empty, false) else UIUtils.SetActive(self.obj_Empty, true) end self.loop_WeekActivity:RefreshCells() end -- 根据星期几 获取国战活动开启的时间戳 function UIActivitiesCalendar:GetTimestampByWeekNum(weekNum) -- 计算当天国战活动开启的时间 local timestamp = UTL.Time.GetServerZeroTimestamp() for i, v in DataSheetManager.ActivationCalendar:GetEnumerator() do if v.ActivaionType == CTL.Activities.CalendarType.Country then local data = DataSheetManager.TimeRefresh:GetDataByID(v.TimeID) if data then timestamp = timestamp + data.HMS end break end end -- 计算对应星期的时间 local diffTimestamp = (weekNum - UTL.Time.GetServerWeekday()) * UTL.Time.TotalSecondsOneDay return timestamp + diffTimestamp end return UIActivitiesCalendar