require("Base/BasePanel") local ContinueGiftPanel = Inherit(BasePanel) local rechargeConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig) local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local artResourcesConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig) local textName = { [1100023] = "t_tehuishenzhuang_suiwukong_zh", --孙悟空 [1100026] = "t_tehuishenzhuang_suiwukong_zh", --青阳先知 [1100003] = "t_tehuishenzhuang_zhubajie_zh", --猪八戒 [1100041] = "t_tehuishenzhuang_tongtian_zh", --通天 [1110026] = "t_tehuishenzhuang_yuhuangdadi_zh", --玉皇大帝 } function ContinueGiftPanel:InitComponent() self.spLoader = SpriteLoader.New() self.btnBack = Util.GetGameObject(self.gameObject, "btnBack") self.mask = Util.GetGameObject(self.gameObject, "Bg/mask") self.scrollItem = Util.GetGameObject(self.gameObject, "panel/scroll") self.itemPre = Util.GetGameObject(self.gameObject, "ItemPre") local rootHight = self.scrollItem.transform.rect.height local width = self.scrollItem.transform.rect.width self.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollItem.transform, self.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 0)) self.scrollView.moveTween.MomentumAmount = 1 self.scrollView.moveTween.Strength = 2 self.leftTime = Util.GetGameObject(self.gameObject, "panel/leftTime"):GetComponent("Text") self.liveRoot = Util.GetGameObject(self.gameObject, "live/liveRoot") self.liveText = Util.GetGameObject(self.gameObject, "live/Image"):GetComponent("Image") self.effect = Util.GetGameObject(self.gameObject, "UI_Effect_ShenYiTianJiang") self.itemViewList = {} self.sortingOrder = 0 end --绑定事件(用于子类重写) function ContinueGiftPanel:BindEvent() Util.AddClick(self.mask, function() self:ClosePanel() end) Util.AddClick(self.btnBack, function() self:ClosePanel() end) end --添加事件监听(用于子类重写) function ContinueGiftPanel:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Activity.OnActivityProgressStateChange, self.Refresh, self) end --移除事件监听(用于子类重写) function ContinueGiftPanel:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityProgressStateChange, self.Refresh, self) end function ContinueGiftPanel:OnSortingOrderChange() Util.SetParticleSortLayer(self.effect, self.sortingOrder + 1) end local fun --界面打开时调用(用于子类重写) function ContinueGiftPanel:OnOpen(_linkActId, _fun) self.linkActId = _linkActId fun = _fun end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function ContinueGiftPanel:OnShow() ContinueGiftPanel:Refresh(true, true) end function ContinueGiftPanel:Refresh(isTop, isAni) self.actData = CommonActPageManager.GetData(ActivityTypeDef.ContinueGift) self:SetRewardShow(isTop, isAni) -- self:SetLiveShow() self:SetTime() end function ContinueGiftPanel:SetLiveShow() local skinId = self.actData.rewards[1].otherData.skinArtId self.rootName = artResourcesConfig[skinId].Name if self.Live then poolManager:UnLoadLive(self.rootName, self.Live) end local data = ConfigManager.GetConfigDataByKey(ConfigName.HeroSkin, "Live", skinId) local pos = data.PositionView local scale = data.Scale self.Live = poolManager:LoadLive(self.rootName, self.liveRoot.transform, Vector3.one * scale, Vector2.New(pos[1], pos[2])) -- self.liveText.sprite = self.spLoader:LoadSprite(textName[skinId]) end function ContinueGiftPanel:SetRewardShow(isTop, isAni) -- 拿到对应活动的数据 local rewards = {} for _, r in ipairs(self.actData.rewards) do if r.otherData.LinkActivityId == self.linkActId then table.insert(rewards, r) end end -- 显示 self.scrollView:SetData(rewards, function(index, item) self:ShowSingleHero(item, rewards[index], index) end, not isTop, not isAni) for i = 1, #rewards do if rewards[i].progress == 1 then local num = i - 1 > 0 and i - 1 or 1 self.scrollView:SetIndex(num) break end end end function ContinueGiftPanel:ShowSingleHero(go, data, index) local grid = Util.GetGameObject(go, "Grid") local btnGet = Util.GetGameObject(go, "btnGet") local btnText = Util.GetGameObject(go, "btnGet/Text"):GetComponent("Text") local btnImg = Util.GetGameObject(go, "btnGet"):GetComponent("Image") local buyDayImg = Util.GetGameObject(go, "bugDay") local buyDayText = Util.GetGameObject(buyDayImg, "Text"):GetComponent("Text") if not self.itemViewList[go] then self.itemViewList[go] = {} end for k, v in ipairs(self.itemViewList[go]) do v.gameObject:SetActive(false) end for i = 1, #data.otherData.Reward do local rewardData = data.otherData.Reward[i] if not self.itemViewList[go][i] then self.itemViewList[go][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform) end self.itemViewList[go][i]:OnOpen(false, rewardData, 0.9, false, false, false, self.sortingOrder) self.itemViewList[go][i].gameObject:SetActive(true) end -- LogBlue("data.progress:"..tostring(data.progress)) Util.SetGray(btnGet, false) btnText.text = string.format(Language[10490], MoneyUtil.GetMoney(data.otherData.Price)) btnImg.sprite = self.spLoader:LoadSprite("s_slbz_1anniuhuangse") buyDayImg:SetActive(false) if data.progress == 8 then btnImg.sprite = self.spLoader:LoadSprite("s_slbz_1anniuhuise") btnText.text = Language[10491] elseif data.progress == 3 then Util.SetGray(btnGet, true) elseif data.progress == 2 then Util.SetGray(btnGet, true) buyDayImg:SetActive(true) buyDayText.text = string.format(Language[10492], data.otherData.canBuyDay) end -- LogYellow("PackId:"..tostring(data.otherData.PackId).." progress:"..tostring(data.progress)) Util.AddOnceClick(btnGet, function() if data.progress == 1 then PayManager.Pay(data.otherData.PackId, function(id) FirstRechargeManager.RefreshAccumRechargeValue(data.otherData.PackId) OperatingManager.SetHadBuyGoodsId({ data.otherData.PackId }) OperatingManager.RemoveItemInfoByType(GoodsTypeDef.DirectPurchaseGift, data.otherData.PackId) self:Refresh(false, false) end) elseif data.progress == 3 then PopupTipPanel.ShowTip(Language[10493]) elseif data.progress == 2 then PopupTipPanel.ShowTip(Language[10494]) end end) end function ContinueGiftPanel:SetTime() local time = self.actData.endTime - GetTimeStamp() local func = function() if time <= 0 then self:ClosePanel() end self.leftTime.text = Language[10495] .. TimeToFelaxible(time) time = time - 1 end func() if self.timer then self.timer:Stop() self.timer = nil end self.timer = Timer.New(function() func() end, 1, -1, true) self.timer:Start() end function ContinueGiftPanel:OnClose() if self.timer then self.timer:Stop() self.timer = nil end -- if self.Live then -- poolManager:UnLoadLive(self.rootName, self.Live) -- end self.Live = nil PatFaceManager.RefreshPatface() self.sortingOrder = 0 if fun then fun() fun = nil end end --界面销毁时调用(用于子类重写) function ContinueGiftPanel:OnDestroy() if self.Live then poolManager:UnLoadLive(self.rootName, self.Live) end self.Live = nil self.spLoader:Destroy() -- self.viewList = {} -- self.itemList = {} -- self.lightList = {} -- self.jiantouList = {} self.itemViewList = {} end return ContinueGiftPanel