local PeriodicQuestCtrl = class("PeriodicQuestCtrl", BaseCtrl) local TimerManager = require("GameCore.Timer.TimerManager") PeriodicQuestCtrl._mapNodeConfig = { loopSv = { sNodeName = "srGuideQuest", sComponentName = "LoopScrollView" }, rtDays = {}, PerActGroupItem = { nCount = 7, sCtrlName = "Game.UI.Activity.PeriodicQuest.PeriodicQuestGroupCtrl" }, btnGroup = { sNodeName = "PerActGroupItem", nCount = 7, sComponentName = "UIButton", callback = "OnBtnClick_Group" }, btnGroupLock = { sNodeName = "btnGroupLock", nCount = 7, sComponentName = "UIButton", callback = "OnBtnClick_GroupLock" }, btnDetail = { sComponentName = "UIButton", callback = "OnBtnClick_Detail" }, txtBtnDetail = { sComponentName = "TMP_Text", sLanguageId = "Activity_Btn_Detail" }, btnQuickRec = { sComponentName = "UIButton", callback = "OnBtnClick_QuickRec" }, txtBtnQuickRec = { sComponentName = "TMP_Text", sLanguageId = "Activity_Btn_Quick_Receive" }, goActTime = {}, txtActivityTime = {sComponentName = "TMP_Text"} } PeriodicQuestCtrl._mapEventConfig = {} function PeriodicQuestCtrl:RefreshRemainTime() local endTime = self.actData:GetActEndTime() local curTime = CS.ClientManager.Instance.serverTimeStamp local remainTime = endTime - curTime if remainTime < 0 then TimerManager.Remove(self.remainTimer) self.remainTimer = nil EventManager.Hit(EventId.OpenMessageBox, { nType = AllEnum.MessageBox.Alert, sContent = ConfigTable.GetUIText("Activity_Invalid_Tip_1"), callbackConfirm = function() EventManager.Hit(EventId.ClosePanel, PanelId.ActivityList) end }) return end local sTimeStr = "" if remainTime <= 60 then local sec = math.floor(remainTime) sTimeStr = orderedFormat(ConfigTable.GetUIText("Activity_Remain_Time_Sec") or "", sec) elseif 60 < remainTime and remainTime <= 3600 then local min = math.floor(remainTime / 60) local sec = math.floor(remainTime - min * 60) if sec == 0 then min = min - 1 sec = 60 end sTimeStr = orderedFormat(ConfigTable.GetUIText("Activity_Remain_Time_Min") or "", min, sec) elseif 3600 < remainTime and remainTime <= 86400 then local hour = math.floor(remainTime / 3600) local min = math.floor((remainTime - hour * 3600) / 60) if min == 0 then hour = hour - 1 min = 60 end sTimeStr = orderedFormat(ConfigTable.GetUIText("Activity_Remain_Time_Hour") or "", hour, min) elseif 86400 < remainTime then local day = math.floor(remainTime / 86400) local hour = math.floor((remainTime - day * 86400) / 3600) if hour == 0 then day = day - 1 hour = 24 end sTimeStr = orderedFormat(ConfigTable.GetUIText("Activity_Remain_Time_Day") or "", day, hour) end NovaAPI.SetTMPText(self._mapNode.txtActivityTime, orderedFormat(ConfigTable.GetUIText("PerActivity_Remain_Time") or "", sTimeStr)) end function PeriodicQuestCtrl:RefreshQuestList() self.tbAllQuestList = self.actData:GetQuestListByGroup() if nil == self.tbAllQuestList[self._panel.nSelectGroup] then printLog(string.format("任务列表为空!!!actId = %s, group = %s", self.nActId, self._panel.nSelectGroup)) return end self.tbQuestList = self.tbAllQuestList[self._panel.nSelectGroup] table.sort(self.tbQuestList, function(a, b) if a.nStatus == b.nStatus then return a.Id < b.Id end return a.nStatus < b.nStatus end) for k, v in pairs(self.tbGridCtrl) do self:UnbindCtrlByNode(v) self.tbGridCtrl[k] = nil end if nil ~= self.tbQuestList then self.nPageCount = 0 self._mapNode.loopSv:SetAnim(0.06) self._mapNode.loopSv:Init(#self.tbQuestList, self, self.OnGridRefresh, nil, false, self.GetGridPageCount) EventManager.Hit(EventId.TemporaryBlockInput, 0.2) end local _, _, canReceive = self.actData:GetQuestProgress() self._mapNode.btnQuickRec.gameObject:SetActive(0 < canReceive) for k, v in ipairs(self._mapNode.PerActGroupItem) do local nAllQuest, nReceivedQuest = self.actData:GetDayQuestStatus(k) v:RefreshStatus(nAllQuest <= nReceivedQuest and 0 < nReceivedQuest) end end function PeriodicQuestCtrl:GetGridPageCount(pageCount) self.nPageCount = pageCount > #self.tbQuestList and #self.tbQuestList or pageCount end function PeriodicQuestCtrl:InitGroupList() local nCurDay = self.actData:GetCurOpenDay() self.nMaxOpenGroup = 0 local tbNextOpenGroupList = {} if nil ~= CacheTable.GetData("_PeriodicQuestGroup", self.nActId) then local tbGroup = CacheTable.GetData("_PeriodicQuestGroup", self.nActId)[nCurDay] if nil ~= tbGroup then for _, v in ipairs(tbGroup) do if v > self.nMaxOpenGroup then self.nMaxOpenGroup = v end end end if nil ~= CacheTable.GetData("_PeriodicQuestGroup", self.nActId)[nCurDay + 1] then for _, v in ipairs(CacheTable.GetData("_PeriodicQuestGroup", self.nActId)[nCurDay + 1]) do tbNextOpenGroupList[v] = 1 end end end local nSelectGroup = self.actData:GetCanReceiveRewardGroup() if 0 == nSelectGroup then nSelectGroup = self.nMaxOpenGroup end for k, v in ipairs(self._mapNode.PerActGroupItem) do v:Init(self.nActId, k, self.nMaxOpenGroup) if nil ~= tbNextOpenGroupList[k] then local nHour = self.actData:GetNextDayOpenTime() if nHour < 1 then v:SetTime(orderedFormat(ConfigTable.GetUIText("PerActivity_Quest_Open_Time_2") or "", 1)) else v:SetTime(orderedFormat(ConfigTable.GetUIText("PerActivity_Quest_Open_Time_1") or "", nHour)) end end end if nil == self._panel.nSelectGroup then self._panel.nSelectGroup = nSelectGroup end self._mapNode.PerActGroupItem[self._panel.nSelectGroup]:SetSelect(true) end function PeriodicQuestCtrl:OnGridRefresh(goGrid, gridIndex) local nIndex = gridIndex + 1 local nInstanceId = goGrid:GetInstanceID() if not self.tbGridCtrl[nInstanceId] then self.tbGridCtrl[nInstanceId] = self:BindCtrlByNode(goGrid, "Game.UI.Activity.PeriodicQuest.PeriodicQuestItemCtrl") end self.tbGridCtrl[nInstanceId]:SetData(self.nActId, self.tbQuestList[nIndex]) end function PeriodicQuestCtrl:InitActData(actData, bResetGroup) self.actData = actData if bResetGroup then self._panel.nSelectGroup = nil end self.nActId = actData:GetActId() self.bQuestAnim = false self:InitGroupList() local tbAllQuestList = self.actData:GetQuestListByGroup() if nil == tbAllQuestList[self._panel.nSelectGroup] then EventManager.Hit(EventId.OpenMessageBox, { nType = AllEnum.MessageBox.Tips, sContent = ConfigTable.GetUIText("Activity_Invalid_Tip_1") }) EventManager.Hit(EventId.ClosePanel, PanelId.ActivityList) return end local actCfg = self.actData:GetActCfgData() if actCfg.EndType == GameEnum.activityEndType.NoLimit then self._mapNode.goActTime.gameObject:SetActive(false) else self._mapNode.goActTime.gameObject:SetActive(true) self:RefreshRemainTime() if nil == self.remainTimer then self.remainTimer = self:AddTimer(0, 1, "RefreshRemainTime", true, true, false) end end end function PeriodicQuestCtrl:Awake() self.tbGridCtrl = {} self.tbSequences = {} end function PeriodicQuestCtrl:FadeIn() end function PeriodicQuestCtrl:FadeOut() end function PeriodicQuestCtrl:OnEnable() end function PeriodicQuestCtrl:OnDisable() for nInstanceId, objCtrl in pairs(self.tbGridCtrl) do self:UnbindCtrlByNode(objCtrl) self.tbGridCtrl[nInstanceId] = nil end self.tbGridCtrl = {} end function PeriodicQuestCtrl:OnDestroy() end function PeriodicQuestCtrl:OnRelease() end function PeriodicQuestCtrl:OnBtnClick_Group(_, nIndex) if self._panel.nSelectGroup == nIndex then return end if nIndex > self.nMaxOpenGroup then return end if nil == self.tbAllQuestList[nIndex] or nil == next(self.tbAllQuestList[nIndex]) then printError(string.format("当前任务组下没有任务!!! 活动id = %d, 任务组 = %s", self.nActId, nIndex)) return end self._mapNode.PerActGroupItem[self._panel.nSelectGroup]:SetSelect(false) if nil ~= self._mapNode.PerActGroupItem[nIndex] then self._mapNode.PerActGroupItem[nIndex]:SetSelect(true) end self._panel.nSelectGroup = nIndex self.bQuestAnim = true self:RefreshQuestList() end function PeriodicQuestCtrl:OnBtnClick_GroupLock() EventManager.Hit(EventId.OpenMessageBox, ConfigTable.GetUIText("PerActivity_Not_Open")) end function PeriodicQuestCtrl:OnBtnClick_Detail() local perQuestActCfg = self.actData:GetPerQuestCfg() local msg = { nType = AllEnum.MessageBox.Desc, sContent = perQuestActCfg.DesText, sTitle = ConfigTable.GetUIText("Activity_Btn_Detail") } EventManager.Hit(EventId.OpenMessageBox, msg) end function PeriodicQuestCtrl:OnBtnClick_QuickRec() local callback = function() EventManager.Hit("RefreshPeriodicAct", self.nActId) PlayerData.Base:TryOpenWorldClassUpgrade() end PlayerData.Activity:SendReceivePerQuest(self.nActId, 0, callback) end return PeriodicQuestCtrl