miduo_client/Assets/ManagedResources/~Lua/Modules/TreasureOfHeaven/HeavenUnlockExtraRewardPane...

213 lines
7.1 KiB
Lua

-- local HeavenUnlockExtraRewardPanel = quick_class("HeavenUnlockExtraRewardPanel", BasePanel)
require("Base/BasePanel")
local HeavenUnlockExtraRewardPanel = Inherit(BasePanel)
local this = HeavenUnlockExtraRewardPanel
local rewardStateData = {}
local treasureState--礼包状态
local rewardData--表内活动数据
local rewardData1--表内活动数据
local curType = 0
local type = {
[1]={name=Language[11561],id = 106,goodsType = GoodsTypeDef.TreasureOfHeaven},
[2] = {name=Language[11316],id = 5001,goodsType = GoodsTypeDef.FindBaby},
[2] = {name = "无尽秘宝",id = 5001,goodsType = GoodsTypeDef.FindBaby},
}
--初始化组件(用于子类重写)
function HeavenUnlockExtraRewardPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.btnBack = Util.GetGameObject(this.transform, "frame/bg/closeBtn")
this.btnBack2 = Util.GetGameObject(this.transform, "frame")
this.dealBtn = Util.GetGameObject(this.transform, "frame/bg/dealBtn")
this.Content = Util.GetGameObject(this.transform, "rewardPart/Viewport/Content")
this.box1 = Util.GetGameObject(this.Content, "box1")
this.box2 = Util.GetGameObject(this.Content, "box2")
this.taskList = {}
end
--绑定事件(用于子类重写)
function HeavenUnlockExtraRewardPanel:BindEvent()
Util.AddClick(this.btnBack, function()
this:ClosePanel()
end)
Util.AddClick(this.btnBack2, function()
this:ClosePanel()
end)
Util.AddOnceClick(this.dealBtn,function()
PayManager.Pay(type[curType].id, function(id)
this.RechargeSuccessFunc()
end)
end)
end
function HeavenUnlockExtraRewardPanel:OnSortingOrderChange()
end
--界面打开时调用(用于子类重写)
function HeavenUnlockExtraRewardPanel:OnOpen(_type)
curType = _type
end
-- 打开,重新打开时回调
function HeavenUnlockExtraRewardPanel:OnShow()
LogGreen("curType:"..curType)
if curType == 1 then
rewardStateData = TreasureOfHeavenManger.GetState()
rewardData = TreasureOfHeavenManger.GetAllRewardData()
HeavenUnlockExtraRewardPanel:showRewardTianGong()
elseif curType == 2 then
rewardData = QinglongSerectTreasureManager.GetAllRewardData()
HeavenUnlockExtraRewardPanel:showRewardQinglong()
elseif curType == 3 then
rewardData,rewardData1 = EndLessMapManager.GetAllRewardData()
HeavenUnlockExtraRewardPanel:showRewardWuJin()
end
end
--充值成功
function HeavenUnlockExtraRewardPanel:RechargeSuccessFunc()
PopupTipPanel.ShowTip(Language[11564])
FirstRechargeManager.RefreshAccumRechargeValue(type[curType].id)
OperatingManager.RefreshGiftGoodsBuyTimes(type[curType].goodsType,type[curType].id)
if curType == 1 then
TreasureOfHeavenManger.SetTreasureState()
Game.GlobalEvent:DispatchEvent(GameEvent.TreasureOfHeaven.RechargeSuccess)
elseif curType == 2 then
Game.GlobalEvent:DispatchEvent(GameEvent.TreasureOfHeaven.RechargeQinglongSerectSuccess,false,false)
elseif curType == 3 then
EndLessMapManager.SetTreasureGiftState(1)
EndLessMapManager.SetTreasureState()
Game.GlobalEvent:DispatchEvent(GameEvent.EndLess.RechargeQinglongSerectSuccess,false,false)
end
this:ClosePanel()
end
--直接/间接奖励
function HeavenUnlockExtraRewardPanel:showRewardTianGong()
local direct = {}
local indirect ={}
for i = 1, #rewardData do
if rewardStateData[i].state == 1 then--已达成但不能领取的
-- body
local reward = rewardData[i]
local k1 = reward.TreasureReward[1][1]
local v1 = reward.TreasureReward[1][2]
local k2 = reward.TreasureReward[2][1]
local v2 = reward.TreasureReward[2][2]
if not direct[k1] then
direct[k1] = 0
end
direct[k1] = direct[k1] + v1
if not direct[k2] then
direct[k2] = 0
end
direct[k2] = direct[k2] + v2
elseif rewardStateData[i].state == 0 then--未达成且不能领取的
local reward = rewardData[i]
local k1 = reward.TreasureReward[1][1]
local v1 = reward.TreasureReward[1][2]
local k2 = reward.TreasureReward[2][1]
local v2 = reward.TreasureReward[2][2]
if not indirect[k1] then
indirect[k1] = 0
end
indirect[k1] = indirect[k1] + v1
if not indirect[k2] then
indirect[k2] = 0
end
indirect[k2] = indirect[k2] + v2
end
end
HeavenUnlockExtraRewardPanel:SetItem(direct,indirect)
end
function HeavenUnlockExtraRewardPanel:SetItem(direct,indirect)
if not this.taskList then
this.taskList = {}
end
for i = 1,#this.taskList do
this.taskList.gameObject:SetActive(false)
end
local index = 0
for key, value in pairs(direct) do
index = index + 1
if not this.taskList[index] then
this.taskList[index] = SubUIManager.Open(SubUIConfig.ItemView, this.box1.transform)
end
this.taskList[index]:OnOpen(false,{key, value},0.9)
this.taskList[index].gameObject:SetActive(true)
end
for key, value in pairs(indirect) do
index = index + 1
if not this.taskList[index] then
this.taskList[index] = SubUIManager.Open(SubUIConfig.ItemView, this.box1.transform)
end
this.taskList[index]:OnOpen(false,{key, value},0.9)
this.taskList[index].gameObject:SetActive(true)
end
end
--直接/间接奖励
function HeavenUnlockExtraRewardPanel:showRewardQinglong()
local direct = {}
local indirect ={}
for i = 1, #rewardData do
-- body
local reward = rewardData[i]
for j=1,#reward.Reward do
local id = reward.Reward[j].item[1]
local num = reward.Reward[j].item[2]
if reward.Reward[j].type == 2 then
if rewardData[i].state == 1 or rewardData[i].state == 0 then
if not direct[id] then
direct[id] = 0
end
direct[id] = direct[id] + num
elseif rewardData[i].state == -2 then
if not indirect[id] then
indirect[id] = 0
end
indirect[id] = indirect[id] + num
end
end
end
end
HeavenUnlockExtraRewardPanel:SetItem(direct,indirect)
end
--直接/间接奖励
function HeavenUnlockExtraRewardPanel:showRewardWuJin()
local direct = rewardData
local indirect = rewardData1
HeavenUnlockExtraRewardPanel:SetItem(direct,indirect)
end
--界面关闭时调用(用于子类重写)
function HeavenUnlockExtraRewardPanel:OnClose()
for i = 1,#this.taskList do
SubUIManager.Close(this.taskList[i])
end
this.taskList = {}
end
--界面销毁时调用(用于子类重写)
function HeavenUnlockExtraRewardPanel:OnDestroy()
this.spLoader:Destroy()
end
return HeavenUnlockExtraRewardPanel