miduo_client/Assets/ManagedResources/~Lua/Modules/SurpriseBox/SurpriseBoxPanel.lua

210 lines
8.6 KiB
Lua
Raw Normal View History

2021-06-16 11:59:52 +08:00
require("Base/BasePanel")
local SurpriseBox = Inherit(BasePanel)
2021-06-17 17:09:36 +08:00
local rechargeConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
2021-06-16 11:59:52 +08:00
function SurpriseBox:InitComponent()
self.spLoader = SpriteLoader.New()
2021-06-16 19:56:10 +08:00
self.btnBack = Util.GetGameObject(self.gameObject, "panel/btnBack")
self.mask = Util.GetGameObject(self.gameObject, "mask")
2021-06-17 15:26:10 +08:00
self.scrollItem = Util.GetGameObject(self.gameObject, "panel/kuang/scroll")
self.itemPre = Util.GetGameObject(self.gameObject, "ItemPre")
2021-06-17 17:43:56 +08:00
self.viewText = Util.GetGameObject(self.gameObject, "panel/view/Text")
2021-06-17 15:26:10 +08:00
self.viewList = {}
for i = 1, 4 do
2021-06-17 17:09:36 +08:00
self.viewList[i] = Util.GetGameObject(self.gameObject, "panel/view/Grid/Item ("..i..")")
2021-06-17 15:26:10 +08:00
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 = {}
2021-06-17 17:09:36 +08:00
self.jiantouList = {}
self.itemViewList = {}
2021-06-16 11:59:52 +08:00
end
--绑定事件(用于子类重写)
function SurpriseBox:BindEvent()
2021-06-16 19:56:10 +08:00
Util.AddClick(self.mask, function()
self:ClosePanel()
2021-06-16 11:59:52 +08:00
end)
Util.AddClick(self.btnBack, function()
self:ClosePanel()
end)
end
--添加事件监听(用于子类重写)
function SurpriseBox:AddListener()
end
--移除事件监听(用于子类重写)
function SurpriseBox:RemoveListener()
end
--界面打开时调用(用于子类重写)
function SurpriseBox:OnOpen()
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function SurpriseBox:OnShow()
2021-06-16 19:56:10 +08:00
SurpriseBox:Refresh()
2021-06-16 11:59:52 +08:00
end
function SurpriseBox:Refresh()
2021-06-16 19:56:10 +08:00
self.actData = CommonActPageManager.GetData(ActivityTypeDef.SurpriseBox)
PlayerPrefs.SetInt(PlayerManager.uid.."SurpriseBoxPatFaceDay"..self.actData.value,1)
2021-06-17 15:26:10 +08:00
SurpriseBox:CheckCurBox()
SurpriseBox:SetItemList()
2021-06-17 17:09:36 +08:00
self.scrollView:SetIndex(self.curBoxIndex-1 > 0 and self.curBoxIndex-1 or 1)
2021-06-17 15:26:10 +08:00
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
2021-06-17 17:09:36 +08:00
self.PackData = self.actData.rewards[i]
2021-06-17 15:26:10 +08:00
return
end
end
2021-06-16 11:59:52 +08:00
end
2021-06-17 15:26:10 +08:00
--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)
LogGreen("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")
2021-06-17 17:09:36 +08:00
local jiantou = Util.GetGameObject(item,"jiantou")
local finished = Util.GetGameObject(item,"finished")
2021-06-17 15:26:10 +08:00
2021-06-17 17:09:36 +08:00
img:SetActive(data.otherData.Warning ~= nil)
2021-06-17 15:26:10 +08:00
box.sprite = self.spLoader:LoadSprite("q_qiankun_xiangzi_01")--有色宝箱
tip:SetActive(false)
2021-06-17 17:43:56 +08:00
tipText.text = string.format("%s天后可购买", data.otherData.BuyDay - self.actData.value)
2021-06-17 15:26:10 +08:00
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)
2021-06-17 17:09:36 +08:00
jiantou:SetActive(self.curBoxIndex == data.otherData.BuyDay)
2021-06-17 15:26:10 +08:00
self.lightList[item] = light
2021-06-17 17:09:36 +08:00
self.jiantouList[item] = jiantou
finished:SetActive(false)
2021-06-17 15:26:10 +08:00
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)
2021-06-17 17:43:56 +08:00
lock:SetActive(true)
2021-06-17 15:26:10 +08:00
elseif data.progress == 7 then--可见了,未解锁,不可预览
box.sprite = self.spLoader:LoadSprite("j_jingxilihe_baoxiang2")--灰色宝箱
tip:SetActive(true)
2021-06-17 17:43:56 +08:00
lock:SetActive(true)
2021-06-17 15:26:10 +08:00
elseif data.progress == 8 then--买完了
box.sprite = self.spLoader:LoadSprite("j_jingxilihe_baoxiang2")--灰色宝箱
2021-06-17 17:09:36 +08:00
finished:SetActive(true)
2021-06-17 15:26:10 +08:00
end
Util.AddOnceClick(getBtn,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()
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
2021-06-17 17:09:36 +08:00
for key, value in pairs(self.jiantouList) do
value:SetActive(false)
end
2021-06-17 15:26:10 +08:00
light:SetActive(true)
2021-06-17 17:09:36 +08:00
jiantou:SetActive(true)
2021-06-17 15:26:10 +08:00
self.curBoxIndex = data.otherData.BuyDay
2021-06-17 17:09:36 +08:00
self.PackData = data
SurpriseBox:SetViewList()
2021-06-17 15:26:10 +08:00
end)
end
function SurpriseBox:SetViewList()
2021-06-17 17:09:36 +08:00
for i = 1, 4 do
self.viewList[i]:SetActive(false)
end
2021-06-17 17:43:56 +08:00
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×%s",itemConfig[reward[i][1]].Name,reward[i][2])
Util.AddOnceClick(icon.gameObject,function ()
self.itemViewList[i]:OnBtnCkickEvent(reward[i][1])
end)
2021-06-17 17:09:36 +08:00
end
2021-06-17 17:43:56 +08:00
else
self.viewText:SetActive(true)
self.viewText:GetComponent("Text").text = string.format("%s天后开启敬请期待···",self.PackData.otherData.BuyDay - self.actData.value)
2021-06-17 17:09:36 +08:00
end
2021-06-17 15:26:10 +08:00
end
2021-06-16 11:59:52 +08:00
function SurpriseBox:OnClose()
end
--界面销毁时调用(用于子类重写)
function SurpriseBox:OnDestroy()
2021-06-17 15:26:10 +08:00
self.viewList = {}
self.itemList = {}
self.lightList = {}
2021-06-17 17:09:36 +08:00
self.jiantouList = {}
self.itemViewList = {}
2021-06-16 11:59:52 +08:00
end
return SurpriseBox