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

290 lines
12 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 fightLevelConfig = ConfigManager.GetConfig(ConfigName.MainLevelConfig)
local rechargeNum = 0
local cursortingOrder = 0
local curGiftList = {}
local curGiftId = nil
local curEndTime = 0
local curIndex
local curType
local fun --回调
local rechargeData
local activityType = {
[1] = { name = Language[12926], timePos = Vector3.New(0, -255.6, 0), comp = "bg1", showType = 21, Text = Language[12927] },
[2] = { name = Language[12928], timePos = Vector3.New(0, -567, 0), comp = "bg2", showType = 8, Text = "" },
[3] = { name = Language[12929], timePos = Vector3.New(0, -255.6, 0), comp = "bg1", showType = 25, Text = Language[12930] },
[4] = { name = Language[12931], timePos = Vector3.New(0, -255.6, 0), comp = "bg1", showType = 26, Text = Language[12932] },
[5] = { name = Language[12929], timePos = Vector3.New(0, -255.6, 0), comp = "bg1", showType = 101, Text = Language[12930] },
[6] = { name = Language[12929], timePos = Vector3.New(0, -255.6, 0), comp = "bg1", showType = 102, Text = Language[12930] },
[7] = { name = Language[12929], timePos = Vector3.New(0, -255.6, 0), comp = "bg1", showType = 103, Text = Language[12930] },
[8] = { name = Language[12929], timePos = Vector3.New(0, -255.6, 0), comp = "bg1", showType = 104, Text = Language[12930] },
--[5] = {name = "灵兽推送礼包",timePos = Vector3.New(0,-255.6,0),comp = "bg1",showType = 31,Text = "恭喜您获得极品灵兽,这是为您准备的灵兽成长礼包,助您实力飞升"},
--[6] = {name = "惊喜礼包",timePos = Vector3.New(0,-255.6,0),comp = "bg1",showType = 33,Text = "购买惊喜礼盒成功激活限时豪礼,祝您战力飞升,一路通关"},
--[7] = {name = "轩辕宝镜推送礼包",timePos = Vector3.New(0,-255.6,0),comp = "bg1",showType = 36,Text = "恭喜您获得红色宝物,海量宝物强化资源,助您实力飞升"},
--[8] = {name = "神树养成礼包",timePos = Vector3.New(0,-255.6,0),comp = "bg1",showType = 37,Text = "恭喜您宝物精炼小成,更多精炼素材,助您实力飞升"},
--[9] = {name = "四灵试炼推送礼包",timePos = Vector3.New(0,-255.6,0),comp = "bg1",showType = 38,Text = "恭喜您轩辕宝境登顶,稀有宝物献上,助您实力飞升"},
--[10] = {name = "红色品质宝物推送礼包",timePos = Vector3.New(0,-255.6,0),comp = "bg1",showType = 39,Text = "恭喜您四灵试炼成功,大量神树养成资源,助您实力飞升"},
}
--初始化组件(用于子类重写)
function this:InitComponent()
this.spLoader = SpriteLoader.New()
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.oriPrice = Util.GetGameObject(self.gameObject, "show/price/Text1"):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,
"bg1/UI_effect_DailyRechargePanel_particle")
this.times = Util.GetGameObject(self.gameObject, "show/timesLeft"):GetComponent("Text")
this.tip = Util.GetGameObject(self.gameObject, "show/tip"):GetComponent("Text")
end
--绑定事件(用于子类重写)
function this:BindEvent()
Util.AddClick(this.btnClose, function()
self:ClosePanel()
end)
Util.AddClick(this.btnBuy, function()
PayManager.Pay(curGiftId, function(id)
FirstRechargeManager.RefreshAccumRechargeValue(curGiftId)
CheckRedPointStatus(RedPointType.GrowthPackage) --成长礼包的红点检测
rechargeData.dynamicBuyTimes = rechargeData.dynamicBuyTimes - 1
--判断可购买次数是否为零,是剔除礼包信息
-- for i = 1, #curGiftList do
if rechargeData.dynamicBuyTimes < 1 then
OperatingManager.SetHadBuyGoodsId({ curGiftId })
OperatingManager.RemoveItemInfoByType(GoodsTypeDef.DirectPurchaseGift, curGiftId)
end
-- end
this:Refresh()
end)
end)
Util.AddClick(this.arrowsLeft, function()
curIndex = curIndex - 1
if curGiftList[curType][curIndex] then
else
while (curType >= 0) do
if not activityType[curType] then
curType = LengthOfTable(activityType)
else
curType = curType - 1
end
if curGiftList[curType] and #curGiftList[curType] > 0 then
curIndex = #curGiftList[curType]
break
end
end
end
OperatingManager.upGradePackagePanelType = curType
OperatingManager.upGradePackagePanelIndex = curIndex
this:Refresh()
end)
Util.AddClick(this.arrowsRight, function()
curIndex = curIndex + 1
if curGiftList[curType][curIndex] then
else
while (curType <= LengthOfTable(activityType) + 1) do
if not activityType[curType] then
curType = 1
else
curType = curType + 1
end
if curGiftList[curType] and #curGiftList[curType] > 0 then
curIndex = 1
break
end
end
end
OperatingManager.upGradePackagePanelType = curType
OperatingManager.upGradePackagePanelIndex = curIndex
this:Refresh()
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
-- 音效
SoundManager.PlaySound(SoundConfig.Sound_mrhl)
LogError("11111111111111111111111111111111111111111111111111111111111")
end
--获取(自己拼凑)礼包数据
function this:GetInfoList()
local infoList = OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift) --拿取所有类型5礼包信息(包含需要的礼包)
local num = 0
for k, v in pairs(activityType) do
curGiftList[k] = {}
local infoList2 = ConfigManager.TryGetAllConfigsDataByKey(ConfigName.RechargeCommodityConfig, "ShowType",
v.showType)
-- if infoList2==nil or #infoList2==0 then
-- this:ClosePanel()
-- return
-- end
if infoList2 then
for index, value in pairs(infoList) do
for i = 1, #infoList2 do
if infoList2[i].Id == value.goodsId and value.dynamicBuyTimes > 0 then
table.insert(curGiftList[k], value)
num = num + 1
end
end
end
end
end
return num
end
function this:OnShow()
this:Refresh()
end
function this:SetCurTypeAndIndex()
curType = OperatingManager.upGradePackagePanelType and OperatingManager.upGradePackagePanelType or 1
curIndex = OperatingManager.upGradePackagePanelIndex and OperatingManager.upGradePackagePanelIndex or 1
LogError("=======================拍脸展示:"..curType.."/"..curIndex)
if curGiftList[curType] and #curGiftList[curType] > 0 and curGiftList[curType][curIndex] then
elseif curGiftList[curType] and #curGiftList[curType] > 0 and (not curGiftList[curType][curIndex]) then
curIndex = #curGiftList[curType]
return curGiftList[curType][curIndex]
else
for k, v in pairs(curGiftList) do
if v and #v > 0 then
curType = k
curIndex = #curGiftList[curType]
return curGiftList[curType][curIndex]
end
end
end
return curGiftList[curType][curIndex]
end
function this:Refresh()
local num = self:GetInfoList()
if num < 1 then
this:ClosePanel()
return
end
rechargeData = this:SetCurTypeAndIndex()
for k, v in pairs(activityType) do
Util.GetGameObject(self.gameObject, v.comp):SetActive(false)
end
Util.GetGameObject(self.gameObject, activityType[curType].comp):SetActive(true)
rechargeNum = VipManager.GetChargedNum()
curGiftId = rechargeData.goodsId
if curType == 1 then
this.tip.text = string.format(GetLanguageStrById(activityType[curType].Text), GetLanguageStrById(RechargeConfig[curGiftId].Desc))
else
this.tip.text = string.format(GetLanguageStrById(activityType[curType].Text))
end
this.arrowsLeft:SetActive(num > 1)
this.arrowsRight:SetActive(num > 1)
curEndTime = rechargeData.endTime
this.endTime.text = Language[10693] .. TimeToHMS(curEndTime - GetTimeStamp())
this.endTime.gameObject:GetComponent("RectTransform").localPosition = activityType[curType].timePos
this:SetGfitShow(rechargeData)
this:SetTime(rechargeData)
end
--设置奖励
local _ItemViewList = {}
function this:SetGfitShow(rechargeData)
for k, v in pairs(_ItemViewList) do
v.gameObject:SetActive(false)
end
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], 0.95, false)
_ItemViewList[i].gameObject:SetActive(true)
end
this.times.text = Language[10566] .. rechargeData.dynamicBuyTimes .. Language[10048]
this.price.text = string.format(MoneyUtil.GetMoneyUnitName(), MoneyUtil.GetMoney(RechargeConfig[curGiftId].Price)) --..MoneyUtil.GetMoneyUnitName()
if activityType[curType].Rebate and activityType[curType].Rebate ~= 0 then
this.oriPrice.transform.parent.gameObject:SetActive(true)
this.oriPrice = string.format(MoneyUtil.GetMoneyUnitName(), activityType[curType].Rebate)
else
this.oriPrice.transform.parent.gameObject:SetActive(false)
end
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)
this:Refresh()
end
this.endTime.text = Language[10693] .. 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
Timer.New(function()
Game.GlobalEvent:DispatchEvent(GameEvent.PatFace.RefreshRightUp)
end, 1):Start()
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
this.spLoader:Destroy()
cursortingOrder = 0
_ItemViewList = {}
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
end
return UpGradePackagePanel