require("Base/BasePanel") local ContinuePackagePanel = Inherit(BasePanel) local rechargeConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig) local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local artResourcesConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig) local BTNS = { [1] = {bg1 = "b_baibao_andi",bg2 = "b_baibao_liangdi",text1 = "b_baibao_liangouhaoli-a",text2 = "b_baibao_liangouhaoli",title = "b_baibao_liangouhaoli-b"}, [2] = {bg1 = "b_baibao_andi",bg2 = "b_baibao_liangdi",text1 = "b_baibao_meiritehui-a",text2 = "b_baibao_meiritehui",title = "b_baibao_meiritehui-b"}, [3] = {bg1 = "b_baibao_andi",bg2 = "b_baibao_liangdi",text1 = "b_baibao_chaozhitehui-a",text2 = "b_baibao_chaozhitehui",title = "b_baibao_chaozhitehui-b"}, } local btnType = { LianGou = 1, Meiri = 2, ChaoZhi = 3, } function ContinuePackagePanel:InitComponent() self.spLoader = SpriteLoader.New() self.scrollItem = Util.GetGameObject(self.gameObject, "Bg/scroll") self.itemPre = Util.GetGameObject(self.gameObject, "Bg/scroll/ItemPre") self.backArena = Util.GetGameObject(self.gameObject, "backArena") self.itemPre:SetActive(false) self.leftTime = Util.GetGameObject(self.gameObject, "Bg/time/leftTime"):GetComponent("Text") self.title = Util.GetGameObject(self.gameObject, "Bg/NameBg/Image"):GetComponent("Image") self.btnList = {} for i = 1, 3 do self.btnList[i] = Util.GetGameObject(self.gameObject, "Bg/btns/btn"..i) end 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, -5)) self.scrollView.moveTween.MomentumAmount = 1 self.scrollView.moveTween.Strength = 2 self.scrollView.elastic = false self.itemViewList = {} self.sortingOrder = 0 self.curPage = btnType.LianGou end --绑定事件(用于子类重写) function ContinuePackagePanel:BindEvent() for i = 1, self.backArena.transform.childCount do Util.AddOnceClick(self.backArena.transform:GetChild(i-1).gameObject, function() self:ClosePanel() end) end for j = 1, 3 do Util.AddOnceClick(self.btnList[j], function() if self.curPage ~= j then self.curPage = j ContinuePackagePanel:Refresh(true,true) end end) end end --添加事件监听(用于子类重写) function ContinuePackagePanel:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Activity.OnActivityProgressStateChange,self.Refresh,self) end --移除事件监听(用于子类重写) function ContinuePackagePanel:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityProgressStateChange,self.Refresh,self) end function ContinuePackagePanel:OnSortingOrderChange() end local fun --界面打开时调用(用于子类重写) function ContinuePackagePanel:OnOpen(_linkActId, _fun) self.linkActId = _linkActId self.fun = _fun end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function ContinuePackagePanel:OnShow() self.curPage = 1 ContinuePackagePanel:Refresh(true,true) end function ContinuePackagePanel:Refresh(isTop,isAni) self.actData = CommonActPageManager.GetData(ActivityTypeDef.ContinuePackage,self.linkActId) self:SetBtns() self:SetRewardShow(isTop,isAni) self:SetTime() end function ContinuePackagePanel:SetBtns() self.title.sprite = self.spLoader:LoadSprite(BTNS[self.curPage].title) for i = 1, 3 do if not self.actData.rewards[i] or #self.actData.rewards[i] <= 0 then self.btnList[i]:SetActive(false) else self.btnList[i]:SetActive(true) if self.curPage == i then Util.GetGameObject(self.btnList[i],"Image"):GetComponent("Image").sprite = self.spLoader:LoadSprite(BTNS[i].text2) self.btnList[i]:GetComponent("Image").sprite = self.spLoader:LoadSprite(BTNS[i].bg2) else Util.GetGameObject(self.btnList[i],"Image"):GetComponent("Image").sprite = self.spLoader:LoadSprite(BTNS[i].text1) self.btnList[i]:GetComponent("Image").sprite = self.spLoader:LoadSprite(BTNS[i].bg1) end end end end function ContinuePackagePanel:SetRewardShow(isTop,isAni) -- 显示 self.scrollView:SetData(self.actData.rewards[self.curPage], function (index, item) if self.actData.rewards[self.curPage][index].otherData.Type == self.curPage then self:ShowSingleHero(item, self.actData.rewards[self.curPage][index],index) end end,not isTop,not isAni) end function ContinuePackagePanel: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") local obj = Util.GetGameObject(btnGet, "Obj") local icon = Util.GetGameObject(obj, "icon"):GetComponent("Image") local cost = Util.GetGameObject(obj, "cost"):GetComponent("Text") local canBuyTime = Util.GetGameObject(go, "times"):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("Id:"..tostring(data.missionId).." state:"..tostring(data.state).." progress:"..tostring(data.progress)) Util.SetGray(btnGet,false) buyDayImg:SetActive(false) btnText.gameObject:SetActive(false) obj:SetActive(false) canBuyTime.text = string.format( "剩余:%s次",data.progress) canBuyTime.gameObject:SetActive(self.curPage ~= btnType.LianGou)--第一页连购好礼不显示剩余次数 btnImg.sprite = self.spLoader:LoadSprite("s_slbz_anniu") if data.otherData.GoodType == 1 then--直购 btnText.gameObject:SetActive(true) btnText.text = string.format("%s 元",data.otherData.Price) if data.state == 8 then btnImg.sprite = self.spLoader:LoadSprite("s_slbz_1anniuhuise") btnText.text = Language[10514] canBuyTime.text = "" elseif data.state == 3 then Util.SetGray(btnGet,true) elseif data.state == 2 then Util.SetGray(btnGet,true) buyDayImg:SetActive(true) buyDayText.text = string.format("%s日后可购",data.otherData.canBuyDay) end elseif data.otherData.GoodType == 2 then--商品 obj:SetActive(true) icon.sprite = self.spLoader:LoadSprite(GetSpriteNameByItemId(data.otherData.Price[1])) cost.text = data.otherData.Price[2] if data.state == 8 then obj:SetActive(false) btnText.gameObject:SetActive(true) btnImg.sprite = self.spLoader:LoadSprite("s_slbz_1anniuhuise") btnText.text = Language[10514] canBuyTime.text = "" elseif data.state == 3 then Util.SetGray(btnGet,true) elseif data.state == 2 then Util.SetGray(btnGet,true) buyDayImg:SetActive(true) buyDayText.text = string.format("%s日后可购",data.otherData.canBuyDay) end end Util.AddOnceClick(btnGet,function () if data.state == 1 then if data.otherData.GoodType == 1 then--直购 PayManager.Pay(data.otherData.GoodId, function(id) FirstRechargeManager.RefreshAccumRechargeValue(data.otherData.GoodId) OperatingManager.SetHadBuyGoodsId({data.otherData.GoodId}) -- OperatingManager.RemoveItemInfoByType(GoodsTypeDef.DirectPurchaseGift, data.otherData.GoodId) self:Refresh(false,false) end) elseif data.otherData.GoodType == 2 then--商品 NetManager.ContinueBuyItemRequest(data.otherData.GoodId,function (drop) UIManager.OpenPanel(UIName.RewardItemPopup,drop,1,function() self:Refresh(false,false) end) end) end elseif data.state == 3 then PopupTipPanel.ShowTip("请先购买上一礼包,即可解锁此礼包") elseif data.state == 2 then PopupTipPanel.ShowTip("礼包尚未开启,请耐心等待") end end) end function ContinuePackagePanel:SetTime() if self.timer then self.timer:Stop() self.timer = nil end local time = self.actData.endTime - GetTimeStamp() local leftTime = time - 86280 if self.curPage == btnType.Meiri and leftTime > 0 then--如果是每日特惠显示每日倒计时 time = CalculateSecondsNowTo_N_OClock(24) end --每日特惠处理 self.leftTime.text = Language[10512]..TimeToFelaxible(time) if self.curPage == btnType.Meiri then self.leftTime.text = Language[10023]..TimeToFelaxible(time) end self.timer = Timer.New(function () if time <= 0 then if self.curPage == btnType.Meiri and leftTime > 0 then self:Refresh(false,false) return end self:ClosePanel() end self.leftTime.text = Language[10512]..TimeToFelaxible(time) if self.curPage == btnType.Meiri then self.leftTime.text = Language[10023]..TimeToFelaxible(time) end time = time -1 end, 1, -1, true) self.timer:Start() end function ContinuePackagePanel:OnClose() if self.timer then self.timer:Stop() self.timer = nil end self.sortingOrder = 0 if self.fun then self.fun() self.fun = nil end end --界面销毁时调用(用于子类重写) function ContinuePackagePanel:OnDestroy() self.spLoader:Destroy() self.itemViewList = {} end return ContinuePackagePanel