miduo_client/Assets/ManagedResources/~Lua/Modules/UpGradePackage/UpGradePackagePanel.lua

220 lines
7.7 KiB
Lua

require("Base/BasePanel")
local UpGradePackagePanel = Inherit(BasePanel)
local this = UpGradePackagePanel
local RechargeConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)--整表数据
local upgradeConfig = ConfigManager.GetAllConfigsDataByKey(ConfigName.RechargeCommodityConfig,"ShowType",21)--五档奖励数据
local rechargeNum = 0
local cursortingOrder = 0
local curGiftList = {}
local curGiftId = nil
local curEndTime = 0
local curIndex
local fun--回调
--初始化组件(用于子类重写)
function this:InitComponent()
this.btnClose = Util.GetGameObject(self.gameObject,"show/btnBack")
this.btnBuy = Util.GetGameObject(self.gameObject,"show/Button")
this.grid = Util.GetGameObject(self.gameObject,"show/rewards/Grid")
this.endTime = Util.GetGameObject(self.gameObject,"show/endTime"):GetComponent("Text")
this.price = Util.GetGameObject(self.gameObject,"show/Button/Text"):GetComponent("Text")
this.arrowsLeft = Util.GetGameObject(self.gameObject,"show/arrows/left")
this.arrowsRight = Util.GetGameObject(self.gameObject,"show/arrows/right")
this.UI_effect_DailyRechargePanel_particle = Util.GetGameObject(self.gameObject, "UI_effect_DailyRechargePanel_particle")
this.times = Util.GetGameObject(self.gameObject,"bg/timesLeft"):GetComponent("Text")
this.Text = Util.GetGameObject(self.gameObject,"bg/hero/Image/Text"):GetComponent("Text")
end
--绑定事件(用于子类重写)
function this:BindEvent()
Util.AddClick(this.btnClose,function()
self:ClosePanel()
end)
Util.AddClick(this.btnBuy,function()
if AppConst.isSDKLogin then
PayManager.Pay({ Id = curGiftId })
else
NetManager.RequestBuyGiftGoods(curGiftId, function()
FirstRechargeManager.RefreshAccumRechargeValue(curGiftId)
CheckRedPointStatus(RedPointType.GrowthPackage)--成长礼包的红点检测
curGiftList[curIndex].dynamicBuyTimes = curGiftList[curIndex].dynamicBuyTimes - 1
--判断可购买次数是否为零,是剔除礼包信息
-- for i = 1, #curGiftList do
if curGiftList[curIndex].dynamicBuyTimes == 0 then
OperatingManager.SetHadBuyGoodsId({curGiftId})
OperatingManager.RemoveItemInfoByType(GoodsTypeDef.DirectPurchaseGift, curGiftId)
if curGiftList[curIndex-1] then
curIndex = curIndex -1
-- LogBlue("QWEQWEQWEWQ")
-- elseif curGiftList[curIndex+1] then
-- curIndex = curIndex +1
-- LogRed("ZXCZXCZX")
end
end
-- end
--判断是否有礼包
self:GetInfoList()
if #curGiftList == 0 then
self:ClosePanel()
else
if curIndex then
self:Refresh(curIndex)
-- LogGreen("没换界面")
else
if not not curGiftList[curIndex-1] then
self:Refresh(curIndex-1)
-- LogRed("界面-1")
elseif not not curGiftList[curIndex+1] then
self:Refresh(curIndex+1)
-- LogBlue("界面+1")
end
end
end
end)
end
end)
Util.AddClick(this.arrowsLeft,function()
self:Refresh(curIndex-1)
end)
Util.AddClick(this.arrowsRight,function()
self:Refresh(curIndex+1)
end)
end
--添加事件监听(用于子类重写)
function this:AddListener()
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
end
function this:OnSortingOrderChange()
Util.AddParticleSortLayer( self.UI_effect_DailyRechargePanel_particle, self.sortingOrder - cursortingOrder)
cursortingOrder = self.sortingOrder
end
--界面打开时调用(用于子类重写)
function this:OnOpen(_fun)
fun = _fun
end
--获取(自己拼凑)礼包数据
function this:GetInfoList()
-- body
local list={}
local infoList = OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift)--拿取所有类型5礼包信息(包含需要的礼包)
local infoList2 = ConfigManager.GetAllConfigsDataByKey(ConfigName.RechargeCommodityConfig,"ShowType",21)
for index, value in pairs(infoList) do
for i = 1, #infoList2 do
if infoList2[i].Id == value.goodsId then
table.insert(list,value)
end
end
end
curGiftList = list
end
function this:OnShow()
local index = 1
this:Refresh(index)
end
function this:Refresh(index)
curIndex = index
rechargeNum= VipManager.GetChargedNum()
self:GetInfoList()
this.Text.text = Language[12000]..PlayerManager.level..Language[12001]
this.arrowsLeft:SetActive(not not curGiftList[curIndex-1])
this.arrowsRight:SetActive(not not curGiftList[curIndex+1])
curGiftId = curGiftList[curIndex].goodsId
curEndTime = curGiftList[curIndex].endTime
this.endTime.text = Language[10028]..TimeToHMS(curEndTime-GetTimeStamp())
this:SetGfitShow()
this:SetTime()
end
--设置奖励
local _ItemViewList = {}
function this:SetGfitShow()
for i=1, #RechargeConfig[curGiftId].RewardShow do
if not _ItemViewList[i] then
local view = SubUIManager.Open(SubUIConfig.ItemView,this.grid.transform)
_ItemViewList[i] = view
end
_ItemViewList[i]:OnOpen(false,RechargeConfig[curGiftId].RewardShow[i],1,false)
_ItemViewList[i].gameObject:SetActive(true)
end
this.times.text = Language[10535]..curGiftList[curIndex].dynamicBuyTimes..Language[10054]
this.price.text = RechargeConfig[curGiftId].Price..Language[10538]
end
--设置剩余时间,取剩余时间最短的礼包(第一个礼包的剩余时间)
function this:SetTime()
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
self.localTimer = Timer.New(function()
-- curEndTime= curEndTime-1
--时间到了之后
if curEndTime-GetTimeStamp() < 0 then
OperatingManager.RemoveItemInfoByType(GoodsTypeDef.DirectPurchaseGift, curGiftId)
if curGiftList[curIndex-1] then
curIndex = curIndex -1
end
self:GetInfoList()
if #curGiftList == 0 then
self:ClosePanel()
else
if curIndex then
self:Refresh(curIndex)
else
if not not curGiftList[curIndex-1] then
self:Refresh(curIndex-1)
elseif not not curGiftList[curIndex+1] then
self:Refresh(curIndex+1)
end
end
end
end
this.endTime.text = Language[10028]..TimeToHMS(curEndTime-GetTimeStamp())
end,1,-1,true)
self.localTimer:Start()
end
function this:Hide()
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
if fun then
fun()
fun = nil
end
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
cursortingOrder = 0
_ItemViewList = {}
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
end
return UpGradePackagePanel