198 lines
6.9 KiB
Lua
198 lines
6.9 KiB
Lua
local LingShowTeHui = {}
|
|
local spiritAnimalConfig = ConfigManager.GetConfig(ConfigName.SpiritAnimal)
|
|
|
|
function LingShowTeHui:New(gameObject)
|
|
local b = {}
|
|
b.gameObject = gameObject
|
|
b.transform = gameObject.transform
|
|
setmetatable(b, { __index = LingShowTeHui })
|
|
return b
|
|
end
|
|
|
|
function LingShowTeHui:InitComponent()
|
|
self.spLoader = SpriteLoader.New()
|
|
self.time = Util.GetGameObject(self.gameObject, "time/times"):GetComponent("Text")
|
|
self.buyBtn = Util.GetGameObject(self.gameObject, "layout/buyBtn")
|
|
self.buyBtnText = Util.GetGameObject(self.gameObject, "layout/buyBtn/Text"):GetComponent("Text")
|
|
self.scrollItem = Util.GetGameObject(self.gameObject, "scroller/grid")
|
|
self.buytimes = Util.GetGameObject(self.gameObject, "layout/buytimes"):GetComponent("Text")
|
|
self.giftItemView = {}
|
|
for i = 1, 4 do
|
|
self.giftItemView[i] = Util.GetGameObject(self.gameObject, "layout/obj" .. i)
|
|
end
|
|
end
|
|
|
|
--绑定事件(用于子类重写)
|
|
function LingShowTeHui:BindEvent()
|
|
Util.AddOnceClick(self.buyBtn, function()
|
|
if self.rechargeData.buyTimes >= self.rechargeData.dynamicBuyTimes then
|
|
return
|
|
end
|
|
--直购商品
|
|
PayManager.Pay(self.rechargeConfigId, function(id)
|
|
self:RechargeSuccessFunc(id)
|
|
end)
|
|
end)
|
|
end
|
|
|
|
function LingShowTeHui:RechargeSuccessFunc(id)
|
|
FirstRechargeManager.RefreshAccumRechargeValue(id)
|
|
self:OnShowData()
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function LingShowTeHui:AddListener()
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function LingShowTeHui:RemoveListener()
|
|
end
|
|
|
|
local sortingOrder = 0
|
|
--界面打开时调用(用于子类重写)
|
|
function LingShowTeHui:OnOpen(_activityConfig, _index, parent)
|
|
self.actConfig = _activityConfig
|
|
self.pageIndex = _index
|
|
self.parent = parent
|
|
end
|
|
|
|
function LingShowTeHui:OnSortingOrderChange()
|
|
end
|
|
|
|
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
|
|
function LingShowTeHui:OnShow(_sortingOrder, _parent)
|
|
self.parent.tabbox:SetActive(false)
|
|
self.gameObject:SetActive(true)
|
|
sortingOrder = _sortingOrder
|
|
self:Refresh()
|
|
end
|
|
|
|
function LingShowTeHui:Refresh()
|
|
self.actId = self.actConfig.ActId
|
|
self.actType = self.actConfig.ActiveType > 0 and self.actConfig.ActiveType or self.actConfig.FunType
|
|
if self.actConfig.IfBack == 1 then
|
|
if self.actConfig.ActiveType > 0 then
|
|
local id = ActivityGiftManager.IsActivityTypeOpen(self.actConfig.ActiveType)
|
|
if id and id > 0 then
|
|
self.actId = id
|
|
local config = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups, "PageType",
|
|
self.actConfig.PageType, "ActiveType", self.actConfig.ActiveType, "ActId", id)
|
|
if config then
|
|
self.actConfig = config
|
|
end
|
|
end
|
|
end
|
|
end
|
|
self:OnShowData()
|
|
self:SetTime()
|
|
end
|
|
|
|
local FrameSprite = {
|
|
[3] = "l_lishoutehui_ziyuan",
|
|
[4] = "l_lishoutehui_ziyuan",
|
|
[5] = "l_lishoutehui_huangyuan",
|
|
}
|
|
function LingShowTeHui:OnShowData()
|
|
local activityConfig = ConfigManager.GetConfigData(ConfigName.GlobalActivity, self.actId)
|
|
self.rechargeConfigId = activityConfig.CanBuyRechargeId[1]
|
|
LogGreen("self.rechargeConfigId:" .. tostring(self.rechargeConfigId))
|
|
self.allData = ConfigManager.GetConfigData(ConfigName.RechargeCommodityConfig, self.rechargeConfigId)
|
|
self.buyBtnText.text = MoneyUtil.GetMoneyUnitNameWithMoney(self.allData.Price)
|
|
if not self.itemsGrid then
|
|
self.itemsGrid = {}
|
|
end
|
|
for k, v in ipairs(self.itemsGrid) do
|
|
v.gameObject:SetActive(false)
|
|
end
|
|
for k, v in ipairs(self.allData.RewardShow) do
|
|
if not self.itemsGrid[k] then
|
|
self.itemsGrid[k] = SubUIManager.Open(SubUIConfig.ItemView, self.scrollItem.transform)
|
|
end
|
|
self.itemsGrid[k].gameObject:SetActive(true)
|
|
self.itemsGrid[k]:OnOpen(false, { v[1], v[2] }, 1, false, false, false, sortingOrder)
|
|
end
|
|
|
|
for _, v in pairs(self.giftItemView) do
|
|
v.gameObject:SetActive(false)
|
|
end
|
|
|
|
local strs = string.split(activityConfig.ExpertDec, '#')
|
|
for i = 1, #strs do
|
|
local itemLocalConfig = spiritAnimalConfig[tonumber(strs[i])]
|
|
if not itemLocalConfig then
|
|
if self.giftItemView[i] then
|
|
self.giftItemView[i].gameObject:SetActive(false)
|
|
end
|
|
else
|
|
if self.giftItemView[i] then
|
|
self.giftItemView[i].gameObject:SetActive(true)
|
|
self.giftItemView[i]:GetComponent("Image").sprite = self.spLoader:LoadSprite(FrameSprite
|
|
[itemLocalConfig.Quality])
|
|
if not self.itemViewList then
|
|
self.itemViewList = {}
|
|
end
|
|
if not self.itemViewList[i] then
|
|
self.itemViewList[i] = SubUIManager.Open(SubUIConfig.ItemView, self.giftItemView[i].transform)
|
|
end
|
|
self.itemViewList[i].gameObject:SetActive(true)
|
|
self.itemViewList[i].gameObject:GetComponent("RectTransform").anchoredPosition = Vector3.New(36.03,
|
|
-29.37, 0)
|
|
self.itemViewList[i]:OnOpen(false, { itemLocalConfig.Id, 0 }, 1.1, false, false, false, sortingOrder)
|
|
end
|
|
end
|
|
end
|
|
|
|
self.rechargeData = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.DirectPurchaseGift, self.rechargeConfigId)
|
|
if self.rechargeData then
|
|
local freetimes = self.rechargeData.dynamicBuyTimes - self.rechargeData.buyTimes
|
|
self.buytimes.text = Language[10591] .. (freetimes < 0 and 0 or freetimes)
|
|
else
|
|
--LogGreen("找不到数据了:"..self.rechargeConfigId)
|
|
end
|
|
end
|
|
|
|
function LingShowTeHui:SetTime()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
local startTime = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.LingShowTeHui).startTime
|
|
local endTime = math.ceil((GetTimeStamp() - startTime) / 604800) * 604800 + startTime
|
|
local timeDown = endTime - GetTimeStamp()
|
|
self.time.text = Language[10570] .. TimeToDHMS(timeDown)
|
|
self.timer = Timer.New(function()
|
|
if timeDown <= 0 then
|
|
self:Refresh()
|
|
end
|
|
timeDown = timeDown - 1
|
|
self.time.text = Language[10570] .. TimeToDHMS(timeDown)
|
|
end, 1, -1, true)
|
|
self.timer:Start()
|
|
end
|
|
|
|
function LingShowTeHui:OnClose()
|
|
self.spLoader:Destroy()
|
|
self.gameObject:SetActive(false)
|
|
self.parent.tabbox:SetActive(true)
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
end
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
function LingShowTeHui:OnDestroy()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
sortingOrder = 0
|
|
for k, v in pairs(self.itemsGrid) do
|
|
SubUIManager.Close(v)
|
|
end
|
|
self.itemsGrid = {}
|
|
self.itemViewList = {}
|
|
end
|
|
|
|
return LingShowTeHui
|