sk-client/Assets/ManagedResources/~Lua/Modules/EnergyBase/EnergyGiftBag.lua

134 lines
4.1 KiB
Lua

require("Base/BasePanel")
EnergyGiftBag = Inherit(BasePanel)
local this = EnergyGiftBag
local shopType = {311, 312, 313}
local gift = {}
local itemList = {}
function EnergyGiftBag:InitComponent()
this.mask = Util.GetGameObject(this.gameObject, "mask")
this.btnBack = Util.GetGameObject(this.gameObject, "btnBack")
for i = 1, 3 do
local parent = Util.GetGameObject(this.gameObject, "grid/gift"..i)
Util.GetGameObject(parent, "icon"):GetComponent("Image").sprite = Util.LoadSprite("X1_zhoumofuli_libao_0"..i)
gift[i] = {
-- icon = Util.GetGameObject(parent, "icon"):GetComponent("Image"),
go = parent,
costIcon = Util.GetGameObject(parent, "costIcon"),--:GetComponent("Image"),
price = Util.GetGameObject(parent, "price"):GetComponent("Text"),
grid = Util.GetGameObject(parent, "grid"),
title = Util.GetGameObject(parent, "title"):GetComponent("Text"),
mask = Util.GetGameObject(parent, "mask")
}
end
end
function EnergyGiftBag:BindEvent()
Util.AddClick(this.mask, function()
self:ClosePanel()
end)
Util.AddClick(this.btnBack, function()
self:ClosePanel()
end)
end
function EnergyGiftBag:AddListener()
end
function EnergyGiftBag:RemoveListener()
end
function EnergyGiftBag:OnOpen()
end
function EnergyGiftBag:OnShow()
local dataList = this.GetDataList()
for i = 1, #shopType do
local data
for d = 1, #dataList do
if shopType[i] == dataList[d].StoreId then
data = dataList[d]
end
end
-- gift[i].costIcon:SetActive(not not data)
gift[i].mask:SetActive(not data)
-- gift[i].price.text = data and data.Cost[2][4] or GetLanguageStrById("已购买")
if not data then
data = this.GetLastData(shopType[i])
end
gift[i].price.text = data.Cost[2][4]
gift[i].title.text = GetLanguageStrById(data.GoodsName)
if not itemList[i] then
itemList[i] = {}
end
for g = 1, #itemList[i] do
itemList[i][g].gameObject:SetActive(false)
end
for g = 1, #data.Goods do
if not itemList[i][g] then
itemList[i][g] = SubUIManager.Open(SubUIConfig.ItemView, gift[i].grid.transform)
end
itemList[i][g]:OnOpen(false, data.Goods[g], 0.6)
itemList[i][g].gameObject:SetActive(true)
end
Util.AddOnceClick(gift[i].go, function ()
ShopManager.RequestBuyShopItem(data.StoreId, data.Id, 1, 0, function ()
self:OnShow()
end)
end)
end
end
function EnergyGiftBag:OnClose()
end
function EnergyGiftBag:OnDestroy()
gift = {}
itemList = {}
end
--设置数据
function this.GetDataList()
local dataList = {}
for i, v in ipairs(shopType) do
repeat
local config = ConfigManager.GetConfigDataByKey(ConfigName.StoreTypeConfig, "Id", v)
if config.OpenLevel and config.OpenLevel[1] == 3 then
if not ActTimeCtrlManager.SingleFuncState(config.OpenLevel[2]) then
break
end
end
local storeData = ConfigManager.GetAllConfigsDataByKey(ConfigName.StoreConfig, "StoreId", v)
table.sort(storeData, function(a,b)
return a.Sort < b.Sort
end)
local data = this.GetData(storeData)
if data then
table.insert(dataList, data)
end
until true
end
return dataList
end
--若没购买则显示 每一类型礼包显示一个
function this.GetData(storeData)
for index, value in ipairs(storeData) do
local buyNum = ShopManager.GetShopItemData(value.StoreId, value.Id).buyNum
if buyNum == 0 then
return value
end
end
end
--获取最后一条数据
function this.GetLastData(shopType)
local storeData = ConfigManager.GetAllConfigsDataByKey(ConfigName.StoreConfig, "StoreId", shopType)
table.sort(storeData, function(a,b)
return a.Sort < b.Sort
end)
return storeData[#storeData]
end
return this