miduo_client/Assets/ManagedResources/~Lua/Modules/Mission/MissionDailyPanel_QingLongS...

385 lines
16 KiB
Lua

----- 日常任务弹窗 -----
local this = {}
--传入父脚本模块
local parent
--传入特效层级
local sortingOrder=0
local curScore = 0--当前分数
local treasureState = 0
local itemsList={}
local maskList={}
local isPlayAnim = true
function this:InitComponent(gameObject)
this.spLoader = SpriteLoader.New()
--topBar/btnBack
this.gameObject = gameObject
this.quesBtn = Util.GetGameObject(this.gameObject, "bg/quesBtn")
this.helpPosition= this.quesBtn:GetComponent("RectTransform").localPosition
this.time = Util.GetGameObject(this.gameObject, "bg/topBar/time"):GetComponent("Text")
this.buyBtn = Util.GetGameObject(this.gameObject, "bg/topBar/button/buyBtn")
this.buyBtnText = Util.GetGameObject(this.buyBtn, "Text"):GetComponent("Text")
this.jiesuoBtn = Util.GetGameObject(this.gameObject, "bg/topBar/button/jiesuoBtn")
this.jiesuoBtnText = Util.GetGameObject(this.jiesuoBtn, "Text"):GetComponent("Text")
this.lv = Util.GetGameObject(this.gameObject, "bg/topBar/Image/lv"):GetComponent("Text")
--Content
this.progress = Util.GetGameObject(this.gameObject, "bg/topBar/progress/Image"):GetComponent("Image")
this.scoreText = Util.GetGameObject(this.gameObject, "bg/topBar/progress/Text"):GetComponent("Text")
this.remainTime = Util.GetGameObject(this.gameObject, "bg/topBar/remainTime/Text"):GetComponent("Text")
this.box = Util.GetGameObject(this.gameObject, "topBar/box")
this.extra = Util.GetGameObject(this.gameObject, "topBar/extraBox")
this.canOpenExtra = Util.GetGameObject(this.gameObject, "topBar/UI_Effect_BaoXiang_KeKaiQi")
this.canOpenExtra.gameObject:SetActive(false)
this.openExtra = Util.GetGameObject(this.gameObject, "topBar/UI_Effect_BaoXiang_KaiQi")
this.openExtra.gameObject:SetActive(false)
this.treasureList = Util.GetGameObject(this.gameObject, "bg/pageContent/treasureList")
local v2 = this.treasureList:GetComponent("RectTransform").sizeDelta
this.itemPre = Util.GetGameObject(this.treasureList, "itemPro")
--设置滚动条
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,this.treasureList.transform,
this.itemPre,nil,Vector2.New(v2.x, v2.y),1,1,Vector2.New(100,3.5))
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 this:BindEvent()
Util.AddClick(this.quesBtn,function()
--LogGreen(this.helpPosition.x.."+"..this.helpPosition.y)
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.QingLongSerectTreasure,this.helpPosition.x,this.helpPosition.y)
end)
end
function this:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.TreasureOfHeaven.BuyQinglongSerectLevelSuccess, this.refresh)
Game.GlobalEvent:AddEvent(GameEvent.TreasureOfHeaven.RechargeQinglongSerectSuccess, this.refresh)
Game.GlobalEvent:AddEvent(GameEvent.Activity.OnActivityOpenOrClose,this.Closefunction)
Game.GlobalEvent:AddEvent(GameEvent.MoneyPay.OnPayResultSuccess, this.refresh)
end
function this:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.TreasureOfHeaven.BuyQinglongSerectLevelSuccess, this.refresh)
Game.GlobalEvent:RemoveEvent(GameEvent.TreasureOfHeaven.RechargeQinglongSerectSuccess, this.refresh)
Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityOpenOrClose,this.Closefunction)
Game.GlobalEvent:RemoveEvent(GameEvent.MoneyPay.OnPayResultSuccess, this.refresh)
end
this.Closefunction = function()
isPlayAnim = true
Timer.New(function()
if not ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.TreasureOfSomeBody) then
PopupTipPanel.ShowTip(Language[10471])
if parent then
parent:ClosePanel()
end
return
else
this.refresh(false,false)
end
end,1):Start()
end
function this:OnShow(_parent,...)
isPlayAnim = true
parent=_parent
sortingOrder = _parent.sortingOrder
if not ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.TreasureOfSomeBody) then
parent:ClosePanel()
return
end
local startTime,endTime,endTimeScale = QinglongSerectTreasureManager.GetTimeStartToEnd()
-- this.timeTxt.text = "活动时间:"
-- this.time.text = startTime.."-"..endTime
this.time.text = string.format(Language[10584].." %s-%s",startTime,endTime)
this.remainTime.text = Language[10470]..TimeToDHMS(tonumber(endTimeScale) - GetTimeStamp())
this:ShowTime(endTimeScale)
this.refresh(true,true)
end
function this:OnSortingOrderChange(sortingOrder)
for i, v in pairs(itemsList) do
for j = 1, #itemsList[i] do
if itemsList[i][j] and itemsList[i][j].gameObject then
itemsList[i][j]:SetEffectLayer(sortingOrder)
end
end
end
Util.SetParticleSortLayer(this.canOpenExtra, sortingOrder)
Util.SetParticleSortLayer(this.openExtra, sortingOrder)
end
function this:OnClose()
end
function this:OnDestroy()
this.spLoader:Destroy()
itemsList={}
maskList={}
if self.timer then
self.timer :Stop()
self.timer = nil
end
end
this.refresh = function(isTop,isAni)
QinglongSerectTreasureManager.UpdateTreasureState2()
this:topBar()
this:showTaskList(isTop,isAni)
CheckRedPointStatus(RedPointType.QinglongSerectTreasure)
end
--topBar按钮状态
function this:topBar()
--设置礼包购买按钮状态
treasureState = QinglongSerectTreasureManager.GetTreasureState()--秘宝礼包状态 false:可购买 true:已购买
curScore = QinglongSerectTreasureManager.GetScore()
local lv = QinglongSerectTreasureManager.GetLevel()
this.lv.text = lv
local rewardData = QinglongSerectTreasureManager.GetRewardData(lv)
local needScore
if lv > 0 then
local lastRewardData = QinglongSerectTreasureManager.GetRewardData(lv - 1)
if not lastRewardData then
needScore = 0
else
needScore = lastRewardData.needScore
end
else
needScore = 0
end
if rewardData.needScore and rewardData.needScore ~= 0 then
this.scoreText.text = curScore .."/"..rewardData.needScore - needScore
this.progress.fillAmount = curScore/(rewardData.needScore - needScore)
this.buyBtn:GetComponent("Button").enabled = true
this.buyBtnText.text = Language[11324]
Util.AddOnceClick(this.buyBtn,function()
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.QinglongSerectTreasureBuyLevel)
end)
else
this.scoreText.text = Language[11325]
this.progress.fillAmount = 1
this.buyBtn:GetComponent("Button").enabled = false
this.buyBtnText.text = Language[11325]
end
this.jiesuoBtn:GetComponent("Button").enabled = (not treasureState)
this.jiesuoBtnText.text = ((not treasureState) and Language[11326] or Language[11327])
Util.AddOnceClick(this.jiesuoBtn,function()
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.HeavenUnlockExtraRewardPanel,2)
end)
local times = PrivilegeManager.GetPrivilegeRemainValue(1007)
this.box :GetComponent("Image").enabled = (not treasureState)
this.extra:GetComponent("Button").enabled = ((treasureState) and (times > 0))
this.canOpenExtra.gameObject:SetActive((treasureState) and (times > 0))
this.openExtra:GetComponent("Animator").enabled = false
this.openExtra.gameObject:SetActive((treasureState) and (times <= 0))
Util.GetGameObject(this.openExtra,"MeiKaiQi"):SetActive(false)
Util.GetGameObject(this.openExtra,"KaiQi"):SetActive(true)
Util.AddOnceClick(this.extra,function()
this.extra:GetComponent("Button").enabled = false
this.canOpenExtra.gameObject:SetActive(false)
this.openExtra.gameObject:SetActive(true)
Util.GetGameObject(this.openExtra,"KaiQi"):SetActive(false)
Util.GetGameObject(this.openExtra,"MeiKaiQi"):SetActive(true)
this.openExtra:GetComponent("Animator").enabled = true
Timer.New(function()
local id = ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.TreasureOfSomeBody)
NetManager.GetActivityRewardRequest(-2,id,function(msg)
PrivilegeManager.RefreshPrivilegeUsedTimes(1007, 1)
PopupTipPanel.ShowTip(Language[11328])
Timer.New(function()
LogBlue("level:"..QinglongSerectTreasureManager.GetLevel())
this.refresh(false,false)
end,1):Start()
end)
end,1.5):Start()
end)
end
--任务列表
function this:showTaskList(isTop,isAni)
local rewardData = QinglongSerectTreasureManager.GetAllRewardData()
this.ScrollView:SetData(rewardData,function(index, rewardItem)
this:SingleTask(rewardItem, rewardData[index])
end,not isTop,not isAni)
local index = 0
if QinglongSerectTreasureManager.GetLevel() == 1 then
index = 1
else
for k,v in ipairs(rewardData) do
if v.state == 1 and treasureState then
index = k
break
elseif v.state == 0 and treasureState then
index = k
break
elseif v.state == 0 and (not treasureState) and (k < 35) then
index = k
break
elseif v.state == 0 and (not treasureState) and (k >= 35) then
index = 35
break
end
end
if index == 0 then
for i = #rewardData , 1 , -1 do
if (rewardData[i].state == -1) or (rewardData[i].state == 1 and not treasureState) then
index = i
break
end
end
end
end
this.ScrollView:SetIndex(index)
-- if isPlayAnim then
-- SecTorPlayAnimByScroll(this.ScrollView)
-- isPlayAnim = false
-- end
end
--单个任务
function this:SingleTask(rewardItem, rewardSingleData)
-- if isPlayAnim then
-- rewardItem:SetActive(false)
-- else
-- rewardItem:SetActive(true)
-- end
local scoreLevel = Util.GetGameObject(rewardItem, "scoreLevel"):GetComponent("Text")
local box1 = Util.GetGameObject(rewardItem, "box1")
local box2 = Util.GetGameObject(rewardItem, "box2")
local mask = Util.GetGameObject(rewardItem, "mask")
if not itemsList[rewardItem] then
itemsList[rewardItem] = {}
maskList[rewardItem] = {}
end
for i = 1, #itemsList[rewardItem] do
itemsList[rewardItem][i].gameObject:SetActive(false)
maskList[rewardItem][i].gameObject:SetActive(false)
end
scoreLevel.text = rewardSingleData.level
local SetMask = function (item,i,type)
maskList[rewardItem][i].gameObject:SetActive(false)
if type == 1 then
if rewardSingleData.state == 1 or rewardSingleData.state == -1 then
maskList[rewardItem][i].gameObject:SetActive(true)
end
else
if rewardSingleData.state == -1 then
maskList[rewardItem][i].gameObject:SetActive(true)
end
end
end
for i = 1, #rewardSingleData.Reward do
if not itemsList[rewardItem][i] then
itemsList[rewardItem][i] = SubUIManager.Open(SubUIConfig.ItemView,box1.transform)
itemsList[rewardItem][i].gameObject:SetActive(false)
maskList[rewardItem][i] = newObjToParent(mask, itemsList[rewardItem][i])
maskList[rewardItem][i].transform:DOAnchorPos(Vector3(0.7,-3,0),0)
end
if rewardSingleData.Reward[i] then
if rewardSingleData.Reward[i].type == 1 then
itemsList[rewardItem][i].gameObject.transform:SetParent(box1.transform)
else
itemsList[rewardItem][i].gameObject.transform:SetParent(box2.transform)
end
itemsList[rewardItem][i].gameObject:GetComponent("RectTransform").localPosition = Vector3.zero
itemsList[rewardItem][i].gameObject:SetActive(true)
itemsList[rewardItem][i]:OnOpen(false, rewardSingleData.Reward[i].item, 0.8,false,false,false,sortingOrder)
SetMask(rewardItem,i,rewardSingleData.Reward[i].type)
else
itemsList[rewardItem][i].gameObject:SetActive(false)
end
end
--初始化按钮状态
this:InitButtonState(rewardItem, rewardSingleData)
end
local type={
[-2]={sprite = "s_slbz_1anniuhuise",text = Language[10303]},
[-1]={sprite = "s_slbz_1anniuhuise",text = Language[10101]},
[0]={sprite = "s_slbz_1anniuongse",text = Language[10018]},
[1]={sprite = "s_slbz_1anniuhuangse",text = Language[11329]}
}
--初始化按钮状态
function this:InitButtonState(rewardItem, rewardSingleData)
local btnDeal = Util.GetGameObject(rewardItem, "btnDeal")
local get = Util.GetGameObject(rewardItem, "btnDeal/get"):GetComponent("Image")
local text = Util.GetGameObject(get.gameObject, "Text"):GetComponent("Text")
local redPoint = Util.GetGameObject(rewardItem, "btnDeal/redPoint")
--当前任务领取情况
local state = rewardSingleData.state
Util.GetGameObject(get.gameObject, "Image"):SetActive(false)--state == -1)
redPoint:SetActive(state == 0 or (state == 1 and treasureState))
get.sprite = this.spLoader:LoadSprite(type[state].sprite)
get.enabled = true
text.text = type[state].text
-- if state == -1 then
-- btnDeal:GetComponent("Button").enabled = false
-- get.enabled = false
-- else
-- btnDeal:GetComponent("Button").enabled = true
Util.AddOnceClick(btnDeal,function()
this:OnBtnDealClicked(rewardItem,rewardSingleData)
end)
-- end
end
--按钮事件
function this:OnBtnDealClicked(rewardItem,rewardSingleData)
if rewardSingleData.state ~= -2 then--分数达到要求
if (rewardSingleData.state == 0) or--任务未领取
(rewardSingleData.state == 1 and treasureState) then--任务未领取+礼包已购买
local id = ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.TreasureOfSomeBody)
LogBlue("activityId:"..id)
NetManager.GetActivityRewardRequest(rewardSingleData.level,id,function(msg)
UIManager.OpenPanel(UIName.RewardItemPopup,msg,1)
--需要刷新界面
if not treasureState then--判断是否已经购买了礼包
QinglongSerectTreasureManager.SetSingleRewardState(rewardSingleData.level,1)
else
QinglongSerectTreasureManager.SetSingleRewardState(rewardSingleData.level,-1)
end
this.refresh(false,false)--刷新界面
end)
elseif rewardSingleData.state == 1 and (not treasureState) then----任务已领取+礼包未购买(弹出购买界面)
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.HeavenUnlockExtraRewardPanel,2)
end
else--分数未达到要求
PopupTipPanel.ShowTip(Language[11330])
end
end
function this:ShowTime(endtime)
if self.timer then
self.timer:Stop()
self.timer = nil
end
local timeDown= endtime - GetTimeStamp()
this.remainTime.text = Language[10470]..TimeToDHMS(timeDown)
self.timer = Timer.New(function()
if timeDown < 1 then
this.remainTime.text = Language[10470]..TimeToDHMS(0)
self.timer:Stop()
self.timer = nil
return
end
timeDown = timeDown - 1
this.remainTime.text = Language[10470]..TimeToDHMS(timeDown)
end, 1, -1, true)
self.timer:Start()
end
return this