sk-client/Assets/ManagedResources/~Lua/Modules/FestivalActivity/Festival_Gift.lua

133 lines
4.8 KiB
Lua

local Festival_Gift = quick_class("Festival_Gift")
local this = Festival_Gift
local GlobalActivity = ConfigManager.GetConfig(ConfigName.GlobalActivity)
local AcitvityShowTheme = ConfigManager.GetConfig(ConfigName.AcitvityShowTheme)
local itemList = {}
function Festival_Gift:InitComponent(gameObject)
this.gameObject = gameObject
this.banner = Util.GetGameObject(gameObject, "banner"):GetComponent("Image")
this.time = Util.GetGameObject(gameObject, "time")
this.timeTxt = Util.GetGameObject(gameObject, "time/Text"):GetComponent("Text")
this.scroll = Util.GetGameObject(gameObject, "scroll")
this.pre = Util.GetGameObject(gameObject, "scroll/ItemPre")
local rootHight = this.scroll.transform.rect.height
local width = this.scroll.transform.rect.width
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scroll.transform,
this.pre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 7))
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 2
end
--绑定事件(用于子类重写)
function this:BindEvent()
end
function this:AddListener()
end
function this:RemoveListener()
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function this:OnShow(parent)
this.activityId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.Festival_Gift)
local allData = {}
for i = 1, #GlobalActivity[this.activityId].CanBuyRechargeId do
local data = ConfigManager.GetConfigDataByKey(ConfigName.RechargeCommodityConfig, "Id", GlobalActivity[this.activityId].CanBuyRechargeId[i])
table.insert(allData,data)
end
table.sort(allData, function(a,b)
local aboughtNum = a.Limit - OperatingManager.GetGoodsBuyTime(a.Type, a.Id) > 0 and 2 or 1
local bboughtNum = b.Limit - OperatingManager.GetGoodsBuyTime(b.Type, b.Id) > 0 and 2 or 1
if aboughtNum == bboughtNum then
return a.Id < b.Id
else
return aboughtNum > bboughtNum
end
end)
table.insert(allData, {})
this.ScrollView:SetData(allData, function (index, go)
if index == #allData then
go:SetActive(false)
return
end
go:SetActive(true)
this.SingleDataShow(go, allData[index])
end)
local info = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.Festival_Gift)
CardActivityManager.TimeDown(this.timeTxt, info.endTime - GetTimeStamp())
local showArt = AcitvityShowTheme[GlobalActivity[this.activityId].ShowArt]
this.banner.sprite = Util.LoadSprite(GetPictureFont(showArt.Compent))
end
--界面打开时调用(用于子类重写)
function this:OnOpen()
end
function this:OnClose()
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
end
function this:OnHide()
CardActivityManager.StopTimeDown()
end
function this.SingleDataShow(go, configData)
local grid = Util.GetGameObject(go, "grid/rect")
local buyInfo = Util.GetGameObject(go, "buyInfo"):GetComponent("Text")
local btn = Util.GetGameObject(go, "btn")
local price = Util.GetGameObject(go, "btn/price"):GetComponent("Text")
if not itemList[go] then
itemList[go] = {}
end
for i = 1, #itemList[go] do
itemList[go][i].gameObject:SetActive(false)
end
for i = 1, #configData.RewardShow do
if not itemList[go][i] then
itemList[go][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform)
end
itemList[go][i]:OnOpen(false, configData.RewardShow[i], 0.65)
itemList[go][i].gameObject:SetActive(true)
end
local boughtNum = OperatingManager.GetGoodsBuyTime(configData.Type, configData.Id) or 0
buyInfo.text = GetLanguageStrById(11454).."("..configData.Limit-boughtNum.."/"..configData.Limit..")"..GetLanguageStrById(10054)
if configData.Limit - boughtNum > 0 then
price.text = MoneyUtil.GetMoney(configData.Price)
btn:GetComponent("Button").enabled = true
Util.SetGray(btn, false)
else
price.text = GetLanguageStrById(10526)
btn:GetComponent("Button").enabled = false
Util.SetGray(btn, true)
end
Util.AddOnceClick(btn, function ()
if configData.Limit <= boughtNum then
PopupTipPanel.ShowTipByLanguageId(10540)
else
--直购商品
-- if AppConst.isSDKLogin then
PayManager.Pay({ Id = configData.Id }, function ()
FirstRechargeManager.RefreshAccumRechargeValue(configData.Id)
this:OnShow()
end)
-- else
-- NetManager.RequestBuyGiftGoods(configData.Id, function(msg)
-- FirstRechargeManager.RefreshAccumRechargeValue(configData.Id)
-- this:OnShow()
-- end)
-- end
end
end)
end
return Festival_Gift