require("Base/BasePanel") local SurpriseBox = Inherit(BasePanel) local rechargeConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig) local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local ImgName = { [1] = "j_jingxilihe_yuekezhuanxiang", [2] = "j_jingxilihe_yuekezhuanxianghaohua" } function SurpriseBox:InitComponent() self.spLoader = SpriteLoader.New() self.btnBack = Util.GetGameObject(self.gameObject, "panel/btnBack") self.mask = Util.GetGameObject(self.gameObject, "mask") self.scrollItem = Util.GetGameObject(self.gameObject, "panel/kuang/scroll") self.itemPre = Util.GetGameObject(self.gameObject, "ItemPre") self.viewText = Util.GetGameObject(self.gameObject, "panel/view/Text") self.viewList = {} for i = 1, 4 do self.viewList[i] = Util.GetGameObject(self.gameObject, "panel/view/Grid/Item ("..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, 0)) self.scrollView.moveTween.MomentumAmount = 1 self.scrollView.moveTween.Strength = 2 self.itemList = {} self.lightList = {} self.jiantouList = {} self.itemViewList = {} end --绑定事件(用于子类重写) function SurpriseBox:BindEvent() Util.AddClick(self.mask, function() self:ClosePanel() end) Util.AddClick(self.btnBack, function() self:ClosePanel() end) end --添加事件监听(用于子类重写) function SurpriseBox:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Activity.OnActivityProgressStateChange,self.Refresh,self) end --移除事件监听(用于子类重写) function SurpriseBox:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityProgressStateChange,self.Refresh,self) end local fun --界面打开时调用(用于子类重写) function SurpriseBox:OnOpen(_fun) fun = _fun end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function SurpriseBox:OnShow() SurpriseBox:Refresh() end function SurpriseBox:Refresh() self.actData = CommonActPageManager.GetData(ActivityTypeDef.SurpriseBox) PlayerPrefs.SetInt(PlayerManager.uid.."SurpriseBoxPatFaceDay"..self.actData.value,1) SurpriseBox:CheckCurBox() SurpriseBox:SetItemList() self.scrollView:SetIndex(self.curBoxIndex-1 > 0 and self.curBoxIndex-1 or 1) SurpriseBox:SetViewList() end --判断当前第几个箱子亮起 function SurpriseBox:CheckCurBox() for i = 1, #self.actData.rewards do if self.actData.rewards[i].progress ~= 8 then self.curBoxIndex = self.actData.rewards[i].otherData.BuyDay self.PackData = self.actData.rewards[i] return end end end --Set左侧礼盒列表 function SurpriseBox:SetItemList() self.scrollView:SetData(self.actData.rewards, function (index, item) SurpriseBox:ShowSingleData(item, self.actData.rewards[index],index) end) end function SurpriseBox:ShowSingleData(item,data,index) -- Log("PackId:"..tostring(data.otherData.PackId).." State:"..tostring(data.progress)) local box = Util.GetGameObject(item,"box"):GetComponent("Image") local lock = Util.GetGameObject(item,"lock") local getBtn = Util.GetGameObject(item,"getBtn") local img = Util.GetGameObject(item,"Img") local light1 = Util.GetGameObject(item,"light1") local light2 = Util.GetGameObject(item,"light2") local light = data.otherData.BuyDay == 1 and light1 or light2 local tip = Util.GetGameObject(item,"Tip") local tipText = Util.GetGameObject(item,"Tip/Text"):GetComponent("Text") local price = Util.GetGameObject(item,"getBtn/Price") local priceText = Util.GetGameObject(item,"getBtn/Text"):GetComponent("Text") local jiantou = Util.GetGameObject(item,"jiantou") local finished = Util.GetGameObject(item,"finished") if data.otherData.Warning ~= nil then img:SetActive(true) img:GetComponent("Image").sprite = self.spLoader:LoadSprite(ImgName[data.otherData.Rule]) else img:SetActive(false) end box.sprite = self.spLoader:LoadSprite("q_qiankun_xiangzi_01")--有色宝箱 tip:SetActive(false) tipText.text = string.format("%s天后可购买", data.otherData.BuyDay - self.actData.value) price:SetActive(true) priceText.text = string.format("%s元",data.otherData.Price) lock:SetActive(false) light1:SetActive(false) light2:SetActive(false) light:SetActive(self.curBoxIndex == data.otherData.BuyDay) jiantou:SetActive(self.curBoxIndex == data.otherData.BuyDay) self.lightList[item] = light self.jiantouList[item] = jiantou finished:SetActive(false) if data.progress == 1 then--完成所有条件,可购买 elseif data.progress == 2 then--可见了,解锁了,未到购买时间 elseif data.progress == 3 then--可见了,解锁了,到达购买时间,前置礼包未购买 elseif data.progress == 4 then--可见了,解锁了,到达购买时间,前置礼包购买了,未激活月卡特权 elseif data.progress == 6 then--可见了,未解锁,可预览 box.sprite = self.spLoader:LoadSprite("j_jingxilihe_baoxiang2")--灰色宝箱 tip:SetActive(true) lock:SetActive(true) elseif data.progress == 7 then--可见了,未解锁,不可预览 box.sprite = self.spLoader:LoadSprite("j_jingxilihe_baoxiang2")--灰色宝箱 tip:SetActive(true) lock:SetActive(true) elseif data.progress == 8 then--买完了 box.sprite = self.spLoader:LoadSprite("j_jingxilihe_baoxiang2")--灰色宝箱 finished:SetActive(true) end Util.AddOnceClick(getBtn,function () local actData = CommonActPageManager.GetData(ActivityTypeDef.SurpriseBox) if not actData then PopupTipPanel.ShowTip("活动已关闭") self:ClosePanel() return end 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() end) elseif data.progress == 2 then--可见了,解锁了,未到购买时间 PopupTipPanel.ShowTip("礼盒尚未开启,请耐心等待") elseif data.progress == 3 then--可见了,解锁了,到达购买时间,前置礼包未购买 PopupTipPanel.ShowTip("请先购买上一个礼盒") elseif data.progress == 4 then--可见了,解锁了,到达购买时间,前置礼包购买了,未激活月卡特权 PopupTipPanel.ShowTip(data.otherData.Warning) elseif data.progress == 6 then--可见了,未解锁,可预览 PopupTipPanel.ShowTip("礼盒尚未开启,请耐心等待") elseif data.progress == 7 then--可见了,未解锁,不可预览 PopupTipPanel.ShowTip("礼盒尚未开启,请耐心等待") elseif data.progress == 8 then--买完了 PopupTipPanel.ShowTip("已购买该礼盒") end end) Util.AddOnceClick(box.gameObject,function () for key, value in pairs(self.lightList) do value:SetActive(false) end for key, value in pairs(self.jiantouList) do value:SetActive(false) end light:SetActive(true) jiantou:SetActive(true) self.curBoxIndex = data.otherData.BuyDay self.PackData = data SurpriseBox:SetViewList() end) end function SurpriseBox:SetViewList() for i = 1, 4 do self.viewList[i]:SetActive(false) end if self.PackData.progress ~= 7 then self.viewText:SetActive(false) local reward = self.PackData.otherData.Reward for i = 1, #reward do self.viewList[i]:SetActive(true) local icon = Util.GetGameObject(self.viewList[i],"icon"):GetComponent("Image") local name = Util.GetGameObject(self.viewList[i],"Text"):GetComponent("Text") if not self.itemViewList[i] then self.itemViewList[i] = SubUIManager.Open(SubUIConfig.ItemView,self.viewList[i].transform) end self.itemViewList[i]:OnOpen(false, reward[i], 0,false,false,false,self.sortingOrder) icon.sprite = SetIcon(self.spLoader,reward[i][1]) name.text = string.format("%s\n×%s",itemConfig[reward[i][1]].Name,reward[i][2]) Util.AddOnceClick(icon.gameObject,function () self.itemViewList[i]:OnBtnCkickEvent(reward[i][1]) end) end else self.viewText:SetActive(true) self.viewText:GetComponent("Text").text = string.format("%s天后开启,敬请期待···",self.PackData.otherData.BuyDay - self.actData.value) end end function SurpriseBox:OnClose() if fun then fun() fun = nil end PatFaceManager.RefreshPatface() end --界面销毁时调用(用于子类重写) function SurpriseBox:OnDestroy() self.spLoader:Destroy() self.viewList = {} self.itemList = {} self.lightList = {} self.jiantouList = {} self.itemViewList = {} end return SurpriseBox