local CommonActPage = {} local rechargeNum = 0 local GlobalActConfig = ConfigManager.GetConfig(ConfigName.GlobalActivity) function CommonActPage:New(gameObject) local b = {} b.gameObject = gameObject b.transform = gameObject.transform setmetatable(b, { __index = CommonActPage }) return b end --添加事件监听(用于子类重写) function CommonActPage:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, self.EventRefreshData, self) Game.GlobalEvent:AddEvent(GameEvent.DynamicTask.OnMissionChange, self.EventRefreshData, self) end --移除事件监听(用于子类重写) function CommonActPage:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, self.EventRefreshData, self) Game.GlobalEvent:RemoveEvent(GameEvent.DynamicTask.OnMissionChange, self.EventRefreshData,self) end function CommonActPage:EventRefreshData() self:RefreshData(true,false,false) end function CommonActPage:InitComponent() self.spLoader = SpriteLoader.New() self.bg = Util.GetGameObject(self.gameObject, "Bg/banner") self.titleBgIma = self.bg:GetComponent("Image") self.titleIma = Util.GetGameObject(self.bg,"titleIma"):GetComponent("Image") self.titleTipBg = Util.GetGameObject(self.bg,"titleTipBg"):GetComponent("Image") self.titleTip = Util.GetGameObject(self.bg,"titleTip"):GetComponent("Text") self.scrollItem = Util.GetGameObject(self.gameObject, "scrollItem") self.scrollItemPos = self.scrollItem.transform.localPosition self.scrollItemRect = self.scrollItem.transform.rect self.time = Util.GetGameObject(self.gameObject, "time") self.timeText = Util.GetGameObject(self.time, "timeText"):GetComponent("Text") self.btnHelp = Util.GetGameObject(self.gameObject, "btnHelp") self.helpPosition = self.btnHelp:GetComponent("RectTransform").localPosition self.itemPre = Util.GetGameObject(self.gameObject, "ItemPre") self.sortingOrder = 0 --大圣升星 self.dasheng = Util.GetGameObject(self.gameObject, "Bg/dasheng") self.timeDashengkuang = Util.GetGameObject(self.dasheng, "time1") self.timeDasheng = Util.GetGameObject(self.timeDashengkuang, "timeText"):GetComponent("Text") self.itemPreDasheng = Util.GetGameObject(self.dasheng, "ItemPre") self.ItemList = {} end function CommonActPage:BindEvent() Util.AddClick(self.btnHelp,function() UIManager.OpenPanel(UIName.HelpPopup,self.actConfig.HelpId,self.helpPosition.x,self.helpPosition.y) end) end --界面打开时调用(用于子类重写) function CommonActPage:OnOpen(_activityConfig,_index,parent) self.actConfig = _activityConfig self.pageIndex = _index self.parent = parent self.gameObject.name = "CommonActPage"..self.actConfig.Id PlayerPrefs.SetInt(PlayerManager.uid.."CommonActPage"..self.actConfig.ActiveType,1) end function CommonActPage:OnSortingOrderChange() end -- 打开,重新打开时回调 function CommonActPage:OnShow(_sortingOrder) self.gameObject:SetActive(true) self.sortingOrder = _sortingOrder or self.sortingOrder self.actId = self.actConfig.ActId self.actType = self.actConfig.ActiveType --每日每周任务页签拆分用 if self.actConfig.ShopData and self.actConfig.ShopData[1][1] == -9999 then self.actType = 20000 end if self.actConfig.IfBack == 1 then if self.actType > 0 then local id = ActivityGiftManager.IsActivityTypeOpen(self.actType) if id and id > 0 then self.actId = id local actConfig local actConfig = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups,"ActId",GlobalActConfig[id].ShowArt,"PageType",self.actConfig.PageType,"ActiveType",self.actConfig.ActiveType) if not actConfig then actConfig = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups,"ActId",id,"PageType",self.actConfig.PageType,"ActiveType",self.actConfig.ActiveType) end if actConfig then self.actConfig = actConfig end else LogRed("活动类型:"..tostring(self.actType).."的活动未开启") end end end if self.actConfig.Icon[3] and self.actConfig.Icon[3] ~= "" then self.titleBgIma.sprite = self.spLoader:LoadSprite(self.actConfig.Icon[3]) self.titleBgIma:SetNativeSize() end if self.actConfig.Icon[4] and self.actConfig.Icon[4] ~= "" then self.titleIma.gameObject:SetActive(true) self.titleIma.sprite = self.spLoader:LoadSprite(self.actConfig.Icon[4]) self.titleIma:SetNativeSize() self.titleIma.transform.localPosition = Vector3.New(self.actConfig.TitleImapos[1],self.actConfig.TitleImapos[2],self.actConfig.TitleImapos[3]) else self.titleIma.gameObject:SetActive(false) end if self.actConfig.Icon[5] and self.actConfig.Icon[5] ~= "" then self.titleTipBg.gameObject:SetActive(true) else self.titleTipBg.gameObject:SetActive(false) end if self.actConfig.TitleText and self.actConfig.TitleText ~= "" then local str = string.split(GetLanguageStrById(self.actConfig.TitleText),"|") self.titleTip.text = str[1] self.titleTip.transform.localPosition = Vector3.New((str[2] or 0),(str[3] or 0),(str[4] or 0)) self.titleTip.gameObject:SetActive(true) else self.titleTip.gameObject:SetActive(false) end local space if self.actType == ActivityTypeDef.ChaoFanRuSheng then self.dasheng.gameObject:SetActive(true) space = Vector2.New(0, 10) self.parent.tabbox.gameObject:SetActive(false) else self.dasheng.gameObject:SetActive(false) space = Vector2.New(0, -40) self.parent.tabbox.gameObject:SetActive(true) end if not self.scrollView then local rootHight = self.scrollItemRect.height local width = self.scrollItemRect.width if self.actType == ActivityTypeDef.DynamicAct then self.itemPre:GetComponent("RectTransform").sizeDelta = Vector2.New(1080,225) local vec = self.scrollItem.transform.localPosition vec.y = self.scrollItemPos.y - 30 self.scrollItem.transform.localPosition = vec elseif self.actType == ActivityTypeDef.ChaoFanRuSheng then self.itemPre:GetComponent("RectTransform").sizeDelta = Vector2.New(1080,162) local vec = self.scrollItem.transform.localPosition vec.y = self.scrollItemPos.y - 100 self.scrollItem.transform.localPosition = vec else self.itemPre:GetComponent("RectTransform").sizeDelta = Vector2.New(1080,265) self.scrollItem.transform.localPosition = self.scrollItemPos end self.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollItem.transform, self.itemPre, nil, Vector2.New(width, rootHight), 1, 1, space) self.scrollView.moveTween.MomentumAmount = 1 self.scrollView.moveTween.Strength = 2 end if self.actConfig.HelpId and self.actConfig.HelpId > 0 then self.btnHelp.gameObject:SetActive(true) else self.btnHelp.gameObject:SetActive(false) end --拿取数据 self:RefreshData(true,true,true) end --刷新数据 function CommonActPage:RefreshData(isUpdata,isTop,isAni) self.ActData = CommonActPageManager.GetData(self.actType) if self.actConfig.RpType > 0 then CheckRedPointStatus(self.actConfig.RpType) end self:RefreshActData(isTop,isAni) self:RefreshTime() end --刷新活动数据 function CommonActPage:RefreshActData(isTop,isAni) self.scrollView:ForeachItemGO(function(index, go) go.gameObject:SetActive(false) end) self.scrollView:SetData(self.ActData.rewards, function (index, item) self:ShowSingleData(item, self.ActData.rewards[index],index) end,not isTop,not isAni) end function CommonActPage:ShowSingleData(item,sdata,index) if not self.ItemList then self.ItemList = {} end if not self.ItemList[item] then local subConfig = SubUIConfig[self.actConfig.UIName[2]] self.ItemList[item] = SubUIManager.Open(subConfig,item.transform) end if not sdata then item.gameObject:SetActive(false) return end item.gameObject:SetActive(true) self.ItemList[item]:SetData(sdata,self,self.sortingOrder,self.ActData,self.actConfig) end function CommonActPage:RefreshTime() self.timeDashengkuang:SetActive(false) self.time:SetActive(false) if self.actConfig.ShowTime == 0 then return end if self.localTimer then self.localTimer:Stop() self.localTimer = nil end local time ,timeText if self.actType == ActivityTypeDef.ChaoFanRuSheng then time = self.timeDashengkuang timeText = self.timeDasheng else time = self.time timeText = self.timeText end time:SetActive(true) local freshTime if self.actType == ActivityTypeDef.AccumulativeRechargeExper then freshTime = CalculateSecondsNowTo_N_OClock(24) elseif self.actConfig.ActiveType == ActivityTypeDef.DynamicAct and self.actConfig.Sort == 2 then if (self.ActData.endTime - GetTimeStamp()) <= 86280 then freshTime = CalculateSecondsNowTo_N_OClock(24) - 120 else freshTime = CalculateSecondsNowTo_N_OClock(24) end else freshTime = self.ActData.endTime - GetTimeStamp() end local update = function() if self.actConfig.ShowTime == 1 then timeText.text = Language[10023]..TimeToFelaxible(freshTime) elseif self.actConfig.ShowTime == 2 then timeText.text = Language[10023]..TimeToDHMS(freshTime) elseif self.actConfig.ShowTime == 3 then timeText.text = Language[10023]..TimeToHMS(freshTime) end end update() self.localTimer = Timer.New(function () freshTime = freshTime - 1 update() if freshTime <= 0 then self.parent:ClosePanel() end end, 1, -1, true) self.localTimer:Start() end function CommonActPage:OnClose() self.parent.tabbox.gameObject:SetActive(true) self.gameObject:SetActive(false) if self.localTimer then self.localTimer:Stop() self.localTimer = nil end end function CommonActPage:OnDestroy() self.spLoader:Destroy() if self.localTimer then self.localTimer:Stop() self.localTimer = nil end for k,v in pairs(self.ItemList) do SubUIManager.Close(v) end self.ItemList = {} if self.scrollView then SubUIManager.Close(self.scrollView) end self.scrollView=nil self.scrollItem.transform.localPosition = self.scrollItemPos end return CommonActPage