sk-client/Assets/ManagedResources/~Lua/Modules/NewcomerDiscounts/NewcomerDiscountsPanel.lua

88 lines
3.1 KiB
Lua

require("Base/BasePanel")
NewcomerDiscountsPanel = Inherit(BasePanel)
local this = NewcomerDiscountsPanel
local GlobalActivity = ConfigManager.GetConfig(ConfigName.GlobalActivity)
local itemList = {}
function this:InitComponent()
this.mask = Util.GetGameObject(this.gameObject, "mask")
this.btnBack = Util.GetGameObject(this.gameObject, "btnBack")
this.gift = Util.GetGameObject(this.gameObject, "gift")
this.gifts = {}
for i = 1, 3 do
this.gifts[i] = Util.GetGameObject(this.gameObject, "gift"..i)
end
end
function this:BindEvent()
Util.AddClick(this.mask, function()
self:ClosePanel()
Game.GlobalEvent:DispatchEvent(GameEvent.Main.ActivityRefresh)
end)
Util.AddClick(this.btnBack, function()
self:ClosePanel()
Game.GlobalEvent:DispatchEvent(GameEvent.Main.ActivityRefresh)
end)
end
function this:AddListener()
end
function this:RemoveListener()
end
function this:OnOpen()
end
function this:OnShow()
local allData = {}
local curActId = ActivityGiftManager.IsActivityTypeOpen(6004)
for i = 1, #GlobalActivity[curActId].CanBuyRechargeId do
local data = ConfigManager.GetConfigDataByKey(ConfigName.RechargeCommodityConfig, "Id", GlobalActivity[curActId].CanBuyRechargeId[i])
table.insert(allData, data)
end
for i = 1, #allData do
if not itemList[i] then
itemList[i] = {}
end
for g = 1, #itemList[i] do
itemList[i][g].gameObject:SetActive(false)
end
for g = 1, 4 do
Util.GetGameObject(this.gifts[i], "grid").transform:GetChild(g-1).gameObject:SetActive(false)
end
for g = 1, #allData[i].RewardShow do
if not itemList[i][g] then
itemList[i][g] = SubUIManager.Open(SubUIConfig.ItemView, Util.GetGameObject(this.gifts[i], "grid").transform:GetChild(g-1))
end
itemList[i][g]:OnOpen(false, allData[i].RewardShow[g], 0.6)
itemList[i][g].transform.localPosition = Vector3.New(0, 18, 0)
itemList[i][g].gameObject:SetActive(true)
Util.GetGameObject(this.gifts[i], "grid").transform:GetChild(g-1).gameObject:SetActive(true)
end
local boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, allData[i].Id) or 0
local canBuy = allData[i].Limit - boughtNum > 0
Util.GetGameObject(this.gifts[i], "btnBuy"):SetActive(canBuy)
Util.GetGameObject(this.gifts[i], "received"):SetActive(not canBuy)
Util.GetGameObject(this.gifts[i], "btnBuy/Text"):GetComponent("Text").text = MoneyUtil.GetMoney(allData[i].Price)
Util.GetGameObject(this.gifts[i], "Text"):GetComponent("Text").text = GetLanguageStrById(allData[i].Name)
Util.AddOnceClick(Util.GetGameObject(this.gifts[i], "btnBuy"), function ()
PayManager.Pay({Id = allData[i].Id}, function ()
self:OnShow()
end)
end)
end
end
function this:OnSortingOrderChange()
end
function this:OnClose()
end
function this:OnDestroy()
itemList = {}
end
return NewcomerDiscountsPanel