local UIActivityDailyRechargeROBTView = require("UIActivity/UIActivityDailyRechargeROBTView_Generate") local IconItemCtr = require("Common/IconItemCtr") function UIActivityDailyRechargeROBTView:OnAwake(data) self.controller = require("UIActivity/UIActivityDailyRechargeROBTCtr"):new() self.controller:Init(self) self.controller:SetData(data) end function UIActivityDailyRechargeROBTView:AddEventListener() ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Activity_Data_Change,self,self.ActivityRefresh) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Activity_Day_Change,self,self.ActivityRefresh) end function UIActivityDailyRechargeROBTView:FillContent(data, uiBase) self.uiBase = uiBase local gameObject = self.uiBase:GetRoot() if gameObject ~= nil then self.gameObject = gameObject self.transform = gameObject.transform end self:InitGenerate(self.transform, data) self:Init() end function UIActivityDailyRechargeROBTView:Init() local data = self.controller:GetData() CommonUtil.LoadIcon(self, data.pageBg, function (sprite) self.bg.image.sprite = sprite end) self.controller:InitData() self.taskListScroll.loopListView:InitListView(0, function(gridView, itemIndex, row, column) return self:GetItemByRowColumn(gridView, itemIndex, row, column) end, nil) local curIdx = self.controller:GetCurIdx() local toggleGroup = self.toggleGroup.toggleGroup local oldAllowSwitchOff = toggleGroup.allowSwitchOff toggleGroup.allowSwitchOff = true self.dailyTaskToggle.toggle.isOn = (curIdx == 1) self.weekTaskToggle.toggle.isOn = (curIdx == 2) toggleGroup.allowSwitchOff = oldAllowSwitchOff end function UIActivityDailyRechargeROBTView:RemoveEventListener() ManagerContainer.LuaEventMgr:Unregister(self.uiData.name) end function UIActivityDailyRechargeROBTView:AddUIEventListener() self.uiBase:AddButtonEventListener(self.AnyBtn.button,self, self.OnClickCloseBtn) self.uiBase:AddButtonEventListener(self.backBtn.button,self, self.OnClickCloseBtn) self.uiBase:AddToggleUniqueEventListener(self.dailyTaskToggle.toggle, self, self.OnClickTaskToggle, 1) self.uiBase:AddToggleUniqueEventListener(self.weekTaskToggle.toggle, self, self.OnClickTaskToggle, 2) end function UIActivityDailyRechargeROBTView:OnHide() end function UIActivityDailyRechargeROBTView:OnShow(data) self.controller:SetData(data) end function UIActivityDailyRechargeROBTView:OnClose() end function UIActivityDailyRechargeROBTView:OnDispose() self.taskListScroll.loopListView:Dispose() self:StopRemainTime() self.controller:OnDispose() end function UIActivityDailyRechargeROBTView:OnPageInEnd() self:RefreshShow() self:RefreshToggleRP() end function UIActivityDailyRechargeROBTView:OnClickCloseBtn() ManagerContainer.LuaUIMgr:ClosePage(self.uiBase.PageId) if self.uiBase.MSourceUIID > 0 then ManagerContainer.LuaUIMgr:Open(self.uiBase.MSourceUIID) end end function UIActivityDailyRechargeROBTView:OnClickTaskGoto(_,param) local taskData = param[0] local parentPageId = 0 if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIMainCity1) then parentPageId = Enum.UIPageName.UIMainCity1 elseif ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIBattle) then parentPageId = Enum.UIPageName.UIBattle end if taskData:CanJump() then if taskData.gotoPageId > 0 then if taskData.gotoPageId == Enum.UIPageName.UIDojo2D then ManagerContainer.DataMgr.ArenaData:SendArenaDataReq(Enum.UIPageName.UIDojo2D, parentPageId) elseif taskData.gotoPageId == Enum.UIPageName.UIRuneShopBT then ManagerContainer.LuaUIMgr:Open(taskData.gotoPageId,{Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold},parentPageId) else ManagerContainer.LuaUIMgr:Open(taskData.gotoPageId,nil,parentPageId) end local uiData = ManagerContainer.CfgMgr:GetUIData(taskData.gotoPageId) if uiData.type == 0 then ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UIMAINVIEW_CHANGE_NOTICE, uiData.mainViewType) end self:UIClose() end else ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("DailyTaskText") end end function UIActivityDailyRechargeROBTView:OnClickTaskGet(_,param) local taskId = param[0] ManagerContainer.DataMgr.ActsDataMgr:SendGetActivityRewardReq(self.controller:GetActivityActId(),taskId) end function UIActivityDailyRechargeROBTView:OnClickTaskToggle(toggle, params, isOn) if not isOn then return end local idx = params[0] if self.controller:ChangeCurIdx(idx) then self:RefreshShow() end end function UIActivityDailyRechargeROBTView:RefreshToggleRP() self.weekTaskToggle.redpoint:SetActive(self.controller:HasWeekTaskRP()) self.dailyTaskToggle.redpoint:SetActive(self.controller:HasDayTaskRP()) end function UIActivityDailyRechargeROBTView:ActivityRefresh(actid) if self.controller:GetActivityActId() == actid then self:RefreshShow() self:RefreshToggleRP() end end function UIActivityDailyRechargeROBTView:RefreshShow() local taskList = self.controller:GetTaskList() local length = taskList ~= nil and #taskList or 0 self.taskListScroll.loopListView:SetListItemCount(0) self.taskListScroll.loopListView:SetListItemCount(length) self:RefreshRemainTime() end function UIActivityDailyRechargeROBTView:RefreshRemainTime() if not self.controller then self:StopRemainTime() return end local remainTime = self.controller:GetRemainTime() if not self.updateTimer then self.updateTimer = Timer.New(slot(self.RefreshRemainTime, self), 60, -1) self.updateTimer.time = remainTime % 60 end if not self.updateTimer.running then self.updateTimer:Start() end self.leftTimeNode.leftTimeTxt.text.text = DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, false, false) end function UIActivityDailyRechargeROBTView:StopRemainTime() if self.updateTimer then self.updateTimer:Stop() self.updateTimer = nil end end function UIActivityDailyRechargeROBTView:GetItemByRowColumn(gridView, itemIndex, row, column) local taskData = self.controller:GetTaskListDataByIdx(itemIndex + 1) if not taskData then return nil end local item = gridView:NewListViewItem('TaskItemActivity') local taskLua = CommonUtil.BindGridViewItem2Lua(self, 'TaskItemActivity', item.gameObject) taskLua.taskName.text.text = I18N.T(taskData.name) taskLua.progress.scrollbar.size = taskData.progress and taskData.progress or (taskData.doNum / taskData.finishedNum) taskLua.doNumTxt.text.text = taskData.doNum .. "/" .. taskData.finishedNum self:ShowTaskReward(taskLua,taskData:ShowRewards()) self.uiBase:AddButtonUniqueEventListener(taskLua.gotoBtn.button,self, self.OnClickTaskGoto, taskData) self.uiBase:AddButtonUniqueEventListener(taskLua.getBtn.button,self, self.OnClickTaskGet, taskData.taskId) if taskData:IsOutofDate() then if not taskData:IsFinished() then taskLua.gotoBtn:SetActive(false) taskLua.getBtn:SetActive(false) taskLua.sealBtn:SetActive(false) taskLua.endBtn:SetActive(true) elseif not taskData:IsGotReward() then taskLua.gotoBtn:SetActive(false) taskLua.getBtn:SetActive(true) taskLua.sealBtn:SetActive(false) taskLua.endBtn:SetActive(false) else taskLua.gotoBtn:SetActive(false) taskLua.getBtn:SetActive(false) taskLua.sealBtn:SetActive(true) taskLua.endBtn:SetActive(false) end else if not taskData:IsFinished() then taskLua.gotoBtn:SetActive(true) taskLua.getBtn:SetActive(false) taskLua.sealBtn:SetActive(false) taskLua.endBtn:SetActive(false) elseif not taskData:IsGotReward() then taskLua.gotoBtn:SetActive(false) taskLua.getBtn:SetActive(true) taskLua.sealBtn:SetActive(false) taskLua.endBtn:SetActive(false) else taskLua.gotoBtn:SetActive(false) taskLua.getBtn:SetActive(false) taskLua.sealBtn:SetActive(true) taskLua.endBtn:SetActive(false) end end return item end function UIActivityDailyRechargeROBTView:ShowTaskReward(taskLua,rewards) if taskLua.itemList == nil then taskLua.itemList = {} taskLua.itemList[#taskLua.itemList+1] = taskLua.iconSmallItem end for i = 1, #taskLua.itemList do taskLua.itemList[i]:SetActive(false) end if rewards == nil then return end for i = 1, #rewards do local itemLua = taskLua.itemList[i] if itemLua == nil then local itemGo = UnityEngine.GameObject.Instantiate(taskLua.iconSmallItem.gameObject) itemLua = CommonUtil.BindGridViewItem2Lua(self, "IconItem", itemGo) itemLua.prefabName = "IconItem" itemGo.name = "IconItem" itemLua.transform:SetParent(taskLua.rewardsNode.transform) itemLua.transform.localScale = Vector3(1,1,1) itemLua.rectTransform.anchoredPosition3D = Vector3(0,0,0) taskLua.itemList[#taskLua.itemList+1] = itemLua end local rewardData = {cfgId = rewards[i][1], num = rewards[i][2] } IconItemCtr:SetData(self, itemLua, rewardData, nil, self, self.OnClickItem) itemLua:SetActive(true) end end function UIActivityDailyRechargeROBTView:OnClickItem(btn,params) local logicData = params[0] ManagerContainer.LuaUIMgr:OpenTips(logicData) end return UIActivityDailyRechargeROBTView