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

280 lines
11 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Base/BasePanel")
local TreasureOfHeavenPanel = Inherit(BasePanel)
local this = TreasureOfHeavenPanel
-- local curScore = 0--当前分数
-- local rewardStateData = {}
local treasureState = nil
local rewardData--后端活动数据
local ConfigData = ConfigManager.GetConfig(ConfigName.WorldBossTreasureConfig)
local curId=0
--初始化组件(用于子类重写)
function TreasureOfHeavenPanel: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
--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 TreasureOfHeavenPanel: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.TreasureOfHeaven,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 TreasureOfHeavenPanel:OnSortingOrderChange()
end
--添加事件监听(用于子类重写)
function TreasureOfHeavenPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.TreasureOfHeaven.RechargeSuccess, self.refresh,self)
end
--移除事件监听(用于子类重写)
function TreasureOfHeavenPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.TreasureOfHeaven.RechargeSuccess, self.refresh,self)
end
--界面打开时调用(用于子类重写)
function TreasureOfHeavenPanel:OnOpen(...)
--初始化数据
end
-- 打开,重新打开时回调
function TreasureOfHeavenPanel:OnShow()
this.tips.text = Language[11924]
this.time.text=TimeToDHMS(TreasureOfHeavenManger.resetTime - GetTimeStamp())
curId=ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.TreasureOfHeaven)
LogError("curid==============="..curId)
this.btn_qmfl:SetActive(ActivityGiftManager.GetActivityInfoByType(10502)~=nil and ActivityGiftManager.CheckIsHaveHaveQMFL(ActivityTypeDef.TreasureOfHeaven,curId))
TreasureOfHeavenPanel:ShowTime()
TreasureOfHeavenPanel:refresh()
end
function TreasureOfHeavenPanel:refresh()
treasureState = TreasureOfHeavenManger.TreasrueState
rewardData = TreasureOfHeavenManger.rewardStateData
-- --LogGreen("#rewardData长度"..#rewardData)
if #TreasureOfHeavenManger.rewardStateData <= 0 then
TreasureOfHeavenPanel:topBar()
TreasureOfHeavenPanel:showTaskList()
else
TreasureOfHeavenPanel:topBar()
TreasureOfHeavenPanel:showTaskList()
end
end
--topBar按钮状态
function TreasureOfHeavenPanel: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)
end)
end
this.scoreText.text = TreasureOfHeavenManger.curScore
end
--任务列表
function TreasureOfHeavenPanel:showTaskList()
this.ScrollView:SetData(rewardData,function(index, rewardItem)
TreasureOfHeavenPanel:SingleTask(rewardItem, rewardData[index])
end)
--定位打开界面时位置
local t = 0
if TreasureOfHeavenManger.TreasrueState == 0 then
for i = 1, #rewardData do
if rewardData[i].state == 0 then
t = i
break
end
end
elseif TreasureOfHeavenManger.TreasrueState == 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 TreasureOfHeavenPanel: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.id].Integral
itemsList[rewardItem][1]:OnOpen(false, {ConfigData[singleData.id].Reward[1][1], ConfigData[singleData.id].Reward[1][2]}, 0.8, false)
itemsList[rewardItem][2]:OnOpen(false, {ConfigData[singleData.id].TreasureReward[1][1], ConfigData[singleData.id].TreasureReward[1][2]}, 0.8, false)
itemsList[rewardItem][3]:OnOpen(false, {ConfigData[singleData.id].TreasureReward[2][1], ConfigData[singleData.id].TreasureReward[2][2]}, 0.8, false)
--初始化按钮状态
TreasureOfHeavenPanel:InitButtonState(rewardItem, singleData)
end
--初始化按钮状态
function TreasureOfHeavenPanel: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 TreasureOfHeavenManger.curScore >= ConfigData[singleData.id].Integral 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()
TreasureOfHeavenPanel:OnBtnDealClicked(rewardItem,singleData)
end)
--红点状态
redPoint:SetActive(TreasureOfHeavenManger.RedPointState(singleData,treasureState))
end
--按钮事件
function TreasureOfHeavenPanel: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 TreasureOfHeavenManger.curScore >= ConfigData[singleData.id].Integral 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
TreasureOfHeavenPanel: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 TreasureOfHeavenPanel: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 TreasureOfHeavenPanel:OnClose()
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
end
--界面销毁时调用(用于子类重写)
function TreasureOfHeavenPanel:OnDestroy()
this.spLoader:Destroy()
rewardData = {}
end
return TreasureOfHeavenPanel