miduo_client/Assets/ManagedResources/~Lua/Modules/TreasureOfHeaven/GodsWayTreasurePanel.lua

309 lines
12 KiB
Lua

require("Base/BasePanel")
local GodsWayTreasurePanel = Inherit(BasePanel)
local this = GodsWayTreasurePanel
-- local curScore = 0--当前分数
-- local rewardStateData = {}
local treasureState = nil
local curType=0
local rewardData--后端活动数据
local ConfigData = ConfigManager.GetConfig(ConfigName.SummonTreasure)
local curId=0
--初始化组件(用于子类重写)
function GodsWayTreasurePanel:InitComponent()
this.spLoader = SpriteLoader.New()
--topBar/btnBack
this.btnBack = Util.GetGameObject(this.transform, "bg/btnBack")
this.buyBtn = Util.GetGameObject(this.transform, "bg/topBar/buyBtn")
this.Text1 = Util.GetGameObject(this.buyBtn, "buy")
this.Text2 = Util.GetGameObject(this.buyBtn, "hadbuy")
this.tips = Util.GetGameObject(this.transform, "bg/topBar/tips"):GetComponent("Text")
this.time = Util.GetGameObject(this.transform, "bg/topBar/tips/actTime"):GetComponent("Text")
this.quesBtn = Util.GetGameObject(this.transform, "bg/quesBtn")
this.helpPosition=this.quesBtn:GetComponent("RectTransform").localPosition
this.titleImg = Util.GetGameObject(this.transform,"bg/topBar/titleName"):GetComponent("Image")
--Content
this.scoreText = Util.GetGameObject(this.transform, "bg/pageContent/bg/score/number"):GetComponent("Text")
this.treasureList = Util.GetGameObject(this.transform, "bg/pageContent/treasureList")
this.itemPre = Util.GetGameObject(this.treasureList, "itemPro")
this.btn_qmfl=Util.GetGameObject(this.transform, "bg/topBar/btn_qmfl")
this.btn_qmfl:GetComponent("Image").sprite=this.spLoader:LoadSprite("GM_qmfl_botton_zh")
--设置滚动条
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,this.treasureList.transform,this.itemPre,nil,Vector2.New(950, 1000),1,1,Vector2.New(100, 25))
this.ScrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, 0)
this.ScrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5)
this.ScrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5)
this.ScrollView.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5)
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 2
end
--绑定事件(用于子类重写)
function GodsWayTreasurePanel:BindEvent()
Util.AddClick(this.btnBack,function()
this:ClosePanel()
end)
Util.AddClick(this.quesBtn,function()
--LogGreen(this.helpPosition.x.."+"..this.helpPosition.y)
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.GodsWayTreasure,this.helpPosition.x,this.helpPosition.y)
end)
Util.AddClick(this.btn_qmfl,function()
--LogGreen(this.helpPosition.x.."+"..this.helpPosition.y)
UIManager.OpenPanel(UIName.QuanMinFLPanel,curId)
end)
end
function GodsWayTreasurePanel:OnSortingOrderChange()
end
--添加事件监听(用于子类重写)
function GodsWayTreasurePanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.TreasureOfHeaven.RechargeSuccess, self.refresh,self)
end
--移除事件监听(用于子类重写)
function GodsWayTreasurePanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.TreasureOfHeaven.RechargeSuccess, self.refresh,self)
end
--界面打开时调用(用于子类重写)
function GodsWayTreasurePanel:OnOpen(...)
--初始化数据
local args=...
curType=args
end
local activityType=0
local curFloor=0
local giftId
-- 打开,重新打开时回调
function GodsWayTreasurePanel:OnShow()
this.tips.text = "一次购买永久激活 激活秘宝后可领取额外奖励"
curFloor=GodsWayTowerManager.GetTowerFloorByType(curType)
--this.time.text=TimeToDHMS(TreasureOfHeavenManger.resetTime - GetTimeStamp())
local config=ConfigManager.GetConfigData(ConfigName.DuoDuiTowerConfig,curType)
giftId=config.RechargeCommodity
--local activityType=0
if curType==1 then
this.titleImg.sprite= this.spLoader:LoadSprite("godsWayTower_mb_title1_zh")
activityType=ActivityTypeDef.godsWayTowerTreasure_two
curId=ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.godsWayTowerTreasure_two)
else
this.titleImg.sprite= this.spLoader:LoadSprite("godsWayTower_mb_title2_zh")
activityType=ActivityTypeDef.godsWayTowerTreasure_three
curId=ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.godsWayTowerTreasure_three)
end
LogError("curid==============="..curId)
this.btn_qmfl:SetActive(false)
this:refresh()
end
function GodsWayTreasurePanel:refresh()
treasureState = OperatingManager.IsBuyGift(giftId) and 1 or 0
local info=ActivityGiftManager.GetActivityTypeInfo(activityType)
if info.mission then
rewardData = info.mission
end
this:topBar()
this:showTaskList()
end
--topBar按钮状态
function GodsWayTreasurePanel:topBar()
--设置礼包购买按钮状态
this.buyBtn:GetComponent("Button").interactable = treasureState == 0
this.Text1.gameObject:SetActive(treasureState == 0)
this.Text2.gameObject:SetActive(treasureState == 1)
if treasureState == 0 then
Util.AddOnceClick(this.buyBtn,function()
--UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.HeavenUnlockExtraRewardPanel,1)
PayManager.Pay(giftId, function()
treasureState=1
this.Text1.gameObject:SetActive(false)
this.Text2.gameObject:SetActive(true)
this:refresh()
end)
end)
end
this.scoreText.text = curFloor
end
--任务列表
function GodsWayTreasurePanel:showTaskList()
this.ScrollView:SetData(rewardData,function(index, rewardItem)
this:SingleTask(rewardItem, rewardData[index])
end)
--定位打开界面时位置
local t = 0
if curFloor == 0 then
for i = 1, #rewardData do
if rewardData[i].state == 0 then
t = i
break
end
end
elseif curFloor == 1 then
for i = 1, #rewardData do
if rewardData[i].state == 1 or rewardData[i].state == 0 then
t = i
break
end
end
end
this.ScrollView:SetIndex(t-2)
end
local itemsList={}
--单个任务
function GodsWayTreasurePanel:SingleTask(rewardItem, singleData)
local scoreLevel = Util.GetGameObject(rewardItem, "scoreLevel"):GetComponent("Text")
local pos1 = Util.GetGameObject(rewardItem, "itemPos_1")
local pos3 = Util.GetGameObject(rewardItem, "itemPos_3")
local pos4 = Util.GetGameObject(rewardItem, "itemPos_4")
if not itemsList[rewardItem] then
local item1 = SubUIManager.Open(SubUIConfig.ItemView, pos1.transform)
local item3 = SubUIManager.Open(SubUIConfig.ItemView, pos3.transform)
local item4 = SubUIManager.Open(SubUIConfig.ItemView, pos4.transform)
itemsList[rewardItem] ={item1,item3,item4}
end
scoreLevel.text = ConfigData[singleData.missionId].Count
itemsList[rewardItem][1]:OnOpen(false, {ConfigData[singleData.missionId].Reward[1][1], ConfigData[singleData.missionId].Reward[1][2]}, 0.8, false)
itemsList[rewardItem][2]:OnOpen(false, {ConfigData[singleData.missionId].TreasureReward[1][1], ConfigData[singleData.missionId].TreasureReward[1][2]}, 0.8, false)
-- itemsList[rewardItem][3]:OnOpen(false, {ConfigData[singleData.missionId].TreasureReward[2][1], ConfigData[singleData.missionId].TreasureReward[2][2]}, 0.8, false)
itemsList[rewardItem][3].gameObject:SetActive(false )
--初始化按钮状态
GodsWayTreasurePanel:InitButtonState(rewardItem, singleData)
end
--初始化按钮状态
function GodsWayTreasurePanel:InitButtonState(rewardItem, singleData)
local btnDeal = Util.GetGameObject(rewardItem, "btnDeal")
local get = Util.GetGameObject(rewardItem, "btnDeal/get")
local getAgain = Util.GetGameObject(rewardItem, "btnDeal/getAgain")
local unfinished = Util.GetGameObject(rewardItem, "btnDeal/unfinished")
local finished = Util.GetGameObject(rewardItem, "finished")
local redPoint = Util.GetGameObject(rewardItem, "btnDeal/redPoint")
--当前任务领取情况
local state = singleData.state
--判断
if curFloor >= ConfigData[singleData.missionId].Count then
if (state == -1) then
btnDeal.gameObject:SetActive(false)
get.gameObject:SetActive(false)
getAgain.gameObject:SetActive(false)
unfinished.gameObject:SetActive(false)
finished.gameObject:SetActive(true)
elseif (state == 1) then
btnDeal.gameObject:SetActive(true)
get.gameObject:SetActive(false)
getAgain.gameObject:SetActive(true)
unfinished.gameObject:SetActive(false)
finished.gameObject:SetActive(false)
else --rewardSingleData.state == 0
btnDeal.gameObject:SetActive(true)
get.gameObject:SetActive(true)
getAgain.gameObject:SetActive(false)
unfinished.gameObject:SetActive(false)
finished.gameObject:SetActive(false)
end
else
btnDeal.gameObject:SetActive(true)
get.gameObject:SetActive(false)
getAgain.gameObject:SetActive(false)
unfinished.gameObject:SetActive(true)
finished.gameObject:SetActive(false)
end
--添加点击事件
Util.AddOnceClick(btnDeal,function()
this:OnBtnDealClicked(rewardItem,singleData)
end)
--红点状态
--redPoint:SetActive(TreasureOfHeavenManger.RedPointState(singleData,treasureState))
end
--按钮事件
function GodsWayTreasurePanel:OnBtnDealClicked(rewardItem,singleData)
local btnDeal = Util.GetGameObject(rewardItem, "btnDeal")
local get = Util.GetGameObject(rewardItem, "btnDeal/get")
local getAgain = Util.GetGameObject(rewardItem, "btnDeal/getAgain")
local unfinished = Util.GetGameObject(rewardItem, "btnDeal/unfinished")
local finished = Util.GetGameObject(rewardItem, "btnDeal/finished")
if curFloor >= ConfigData[singleData.missionId].Count then--分数达到要求
if (singleData.state == 0 and treasureState == 0) or--任务未领取+礼包未购买
(singleData.state == 1 and treasureState == 1) or--任务已领取+礼包已购买
(singleData.state == 0 and treasureState == 1)then--任务未领取+礼包已购买
-- NetManager.GetTreasureOfHeavenRewardRequest(singleData.id,function(msg)
-- UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1)
-- --需要刷新界面
-- if treasureState == 0 then--判断是否已经购买了礼包
-- TreasureOfHeavenManger.SetSingleRewardState(singleData.id,1)
-- else
-- TreasureOfHeavenManger.SetSingleRewardState(singleData.id,-1)
-- end
-- end)
NetManager.GetActivityRewardRequest(singleData.missionId,curId,function(msg)
UIManager.OpenPanel(UIName.RewardItemPopup, msg, 1,function ()
end)
--ActivityGiftManager.SetActivityInfo()
this:refresh()--刷新界面
end)
elseif singleData.state == 1 and treasureState == 0 then----任务已领取+礼包未购买(弹出购买界面)
-- UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.HeavenUnlockExtraRewardPanel,1)
end
else--分数未达到要求
PopupTipPanel.ShowTip(Language[11330])
end
end
function GodsWayTreasurePanel:ShowTime()
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
local t = TreasureOfHeavenManger.resetTime
local time
self.localTimer = Timer.New(function()
time = t - GetTimeStamp()
if t - GetTimeStamp() <= 0 then
time = 0
t = TreasureOfHeavenManger.resetTime
treasureState = nil
this.ScrollView:SetIndex(1)
--TreasureOfHeavenPanel:refresh()--不刷新了,直接踢出去
ExpeditionManager.RefreshPanelShowByState()
end
this.time.text=TimeToDHMS(time)
end,1,-1,true)
self.localTimer:Start()
end
--界面关闭时调用(用于子类重写)
function GodsWayTreasurePanel:OnClose()
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
end
--界面销毁时调用(用于子类重写)
function GodsWayTreasurePanel:OnDestroy()
this.spLoader:Destroy()
rewardData = {}
end
return GodsWayTreasurePanel