320 lines
12 KiB
Lua
320 lines
12 KiB
Lua
----- 日常任务弹窗 -----
|
|
local this = {}
|
|
--传入父脚本模块
|
|
local parent
|
|
--传入特效层级
|
|
local sortingOrder=0
|
|
local curType = 1
|
|
local treasureState
|
|
local isPlayAnim = true
|
|
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
function this:InitComponent(gameObject)
|
|
this.spLoader = SpriteLoader.New()
|
|
this.gameObject = gameObject
|
|
this.jiesuoBtn = Util.GetGameObject(this.gameObject, "topBar/jiesuoBtn")
|
|
this.jiesuoBtnText = Util.GetGameObject(this.jiesuoBtn, "Text"):GetComponent("Text")
|
|
this.select = Util.GetGameObject(this.gameObject, "topBar/select")
|
|
this.weekTrailBtn = Util.GetGameObject(this.gameObject, "topBar/button/weekTrail")
|
|
this.finalTrailBtn = Util.GetGameObject(this.gameObject, "topBar/button/finalTrail")
|
|
this.weekTrailBtnRed = Util.GetGameObject(this.weekTrailBtn , "redPoint")
|
|
this.finalTrailBtnRed = Util.GetGameObject(this.finalTrailBtn, "redPoint")
|
|
this.remainTime = Util.GetGameObject(this.gameObject, "topBar/remainTime/Text"):GetComponent("Text")
|
|
|
|
this.treasureList = Util.GetGameObject(this.gameObject, "itemList")
|
|
local v2 = this.treasureList:GetComponent("RectTransform").sizeDelta
|
|
this.itemPre = Util.GetGameObject(this.gameObject, "rewardPre")
|
|
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.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,this.treasureList.transform,
|
|
this.itemPre,nil,Vector2.New(v2.x, v2.y),1,1,Vector2.New(100,0))
|
|
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
|
|
curType = 1
|
|
|
|
end
|
|
|
|
function this:BindEvent()
|
|
Util.AddClick(this.weekTrailBtn,function()
|
|
curType = 1
|
|
this.refresh(true,true)
|
|
end)
|
|
Util.AddClick(this.finalTrailBtn,function()
|
|
curType = 2
|
|
this.refresh(true,true)
|
|
end)
|
|
|
|
end
|
|
|
|
function this:SetSelect()
|
|
local temp
|
|
if curType == 1 then
|
|
temp = this.weekTrailBtn.transform
|
|
else
|
|
temp = this.finalTrailBtn.transform
|
|
end
|
|
this.select.transform:SetParent(temp)
|
|
this.select:GetComponent("RectTransform").anchoredPosition = Vector3.zero
|
|
this.select.transform:SetAsFirstSibling()
|
|
end
|
|
|
|
function this:AddListener()
|
|
Game.GlobalEvent:AddEvent(GameEvent.TreasureOfHeaven.RechargeQinglongSerectSuccess, this.refresh)
|
|
Game.GlobalEvent:AddEvent(GameEvent.TreasureOfHeaven.TaskRefresh, this.RefreshTime)
|
|
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.RechargeQinglongSerectSuccess, this.refresh)
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.TreasureOfHeaven.TaskRefresh, this.RefreshTime)
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityOpenOrClose,this.CloseFunction)
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.MoneyPay.OnPayResultSuccess, this.refresh)
|
|
end
|
|
|
|
function this.RefreshTime()
|
|
NetManager.RefreshTimeSLRequest(function (msg)
|
|
this.refresh(false,false)
|
|
end)
|
|
end
|
|
|
|
this.CloseFunction = function()
|
|
Timer.New(function()
|
|
if not ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.TreasureOfSomeBody) then
|
|
LogBlue("22222222222")
|
|
PopupTipPanel.ShowTip(Language[10471])
|
|
if parent then
|
|
parent:ClosePanel()
|
|
end
|
|
return
|
|
else
|
|
this.RefreshTime()
|
|
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
|
|
this.refresh(true,true)
|
|
end
|
|
|
|
--topBar按钮状态
|
|
function this:SetTopBar()
|
|
treasureState = QinglongSerectTreasureManager.GetTreasureState()--秘宝礼包状态 0:可购买 1:已购买
|
|
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])
|
|
this.refresh(false,false)
|
|
end)
|
|
end,1.5):Start()
|
|
end)
|
|
end
|
|
|
|
function this:OnSortingOrderChange(sortingOrder)
|
|
Util.SetParticleSortLayer(this.canOpenExtra, sortingOrder)
|
|
Util.SetParticleSortLayer(this.openExtra, sortingOrder)
|
|
end
|
|
|
|
function this:OnClose()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
end
|
|
function this:OnDestroy()
|
|
if self.timer then
|
|
this.spLoader:Destroy()
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
end
|
|
|
|
function this.refresh(isTop,isAni)
|
|
QinglongSerectTreasureManager.UpdateTreasureState2()
|
|
this:SetTopBar()
|
|
this:SetSelect()
|
|
this:ShowTime(curType)
|
|
this:showTaskList(curType,isTop,isAni)
|
|
this:SetRedPoint()
|
|
CheckRedPointStatus(RedPointType.QinglongSerectTreasureTrail)
|
|
CheckRedPointStatus(RedPointType.QinglongSerectTreasure)
|
|
|
|
end
|
|
|
|
function this:SetRedPoint()
|
|
this.weekTrailBtnRed:SetActive(QinglongSerectTreasureManager.GetSerectTreasureTrailSingleRedPot(1))
|
|
this.finalTrailBtnRed:SetActive(QinglongSerectTreasureManager.GetSerectTreasureTrailSingleRedPot(2))
|
|
end
|
|
|
|
local state = {
|
|
[1] = 0,
|
|
[0] = 1,
|
|
[2] = 2,
|
|
}
|
|
--任务列表
|
|
function this:showTaskList(type,isTop,isAni)
|
|
local rewardData = QinglongSerectTreasureManager.GetQinglongTaskData(type)
|
|
table.sort(rewardData,function(a,b)
|
|
if state[a.state] == state[b.state] then
|
|
return a.id > b.id
|
|
else
|
|
return a.state > b.state
|
|
end
|
|
end)
|
|
this.ScrollView:SetData(rewardData,function(index, rewardItem)
|
|
this:SingleTask(rewardItem, rewardData[index])
|
|
end,not isTop,not isAni)
|
|
-- this.ScrollView:SetIndex(1)
|
|
-- if isPlayAnim then
|
|
-- SecTorPlayAnimByScroll(this.ScrollView)
|
|
-- isPlayAnim = false
|
|
-- end
|
|
end
|
|
local type={
|
|
[0]={sprite = "Btn_hz_cheng_01",text = Language[10019]},
|
|
[1]={sprite = "Btn_hz_cheng_01",text = Language[10018]},
|
|
[2]={sprite = "Btn_hz_lan_01",text = Language[10101]},
|
|
}
|
|
--单个任务
|
|
function this:SingleTask(go, rewardSingleData)
|
|
local activityRewardGo = go
|
|
-- if isPlayAnim then
|
|
-- activityRewardGo:SetActive(false)
|
|
-- else
|
|
-- activityRewardGo:SetActive(true)
|
|
-- end
|
|
local sConFigData = rewardSingleData
|
|
local strs = string.split(GetLanguageStrById(sConFigData.show))
|
|
local titleText = Util.GetGameObject(activityRewardGo, "content"):GetComponent("Text")
|
|
local value = sConFigData.taskValue[2][1]
|
|
titleText.text = strs[1].."("..(math.abs(sConFigData.progress) > math.abs(value) and math.abs(value) or math.abs(sConFigData.progress)) .."/"..math.abs(value)..")"
|
|
local rewardText = Util.GetGameObject(activityRewardGo, "reward"):GetComponent("Text")
|
|
rewardText.text = (strs[2] and strs[2] or "")..sConFigData.integral[1][2]..GetLanguageStrById(itemConfig[tonumber(sConFigData.integral[1][1])].Name) ..Language[11331]
|
|
local state = sConFigData.state
|
|
local lingquButton = Util.GetGameObject(activityRewardGo.gameObject, "lingquButton")
|
|
local red = Util.GetGameObject(lingquButton.gameObject, "redPoint")
|
|
red:SetActive(state == 1)
|
|
local text = Util.GetGameObject(lingquButton.gameObject, "Text") :GetComponent("Text")
|
|
lingquButton:GetComponent("Image").sprite = this.spLoader:LoadSprite(type[state].sprite)
|
|
Util.SetGray(lingquButton,state == 2)
|
|
lingquButton:GetComponent("Button").enabled = state ~= 2
|
|
text.text = type[state].text
|
|
Util.AddOnceClick(lingquButton, function()
|
|
if state == 1 then
|
|
NetManager.TakeMissionRewardRequest(TaskTypeDef.TreasureOfSomeBody,sConFigData.id, function(msg)
|
|
PopupTipPanel.ShowTip(Language[11332]..sConFigData.integral[1][2]..GetLanguageStrById(itemConfig[tonumber(sConFigData.integral[1][1])].Name))
|
|
Timer.New(function()
|
|
this.refresh(false,false)
|
|
end,1):Start()
|
|
end)
|
|
elseif state == 0 then
|
|
if sConFigData.jump then
|
|
JumpManager.GoJump(sConFigData.jump[1])
|
|
end
|
|
end
|
|
end)
|
|
|
|
end
|
|
|
|
function this:ShowTime(curType)
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
local endtime = curType == 1
|
|
and QinglongSerectTreasureManager.GetTrailWeekTime()
|
|
or ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.TreasureOfSomeBody)
|
|
-- LogBlue("endtime:"..endtime)
|
|
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
|
|
this.RefreshTime()
|
|
return
|
|
end
|
|
|
|
timeDown = timeDown - 1
|
|
this.remainTime.text = Language[10470]..TimeToDHMS(timeDown)
|
|
end, 1, -1, true)
|
|
self.timer:Start()
|
|
end
|
|
|
|
function this:NewItemView(config, gameObject, ...)
|
|
local view = reimport(config.script)
|
|
if gameObject then
|
|
this:playUIAnimsOnStart(gameObject)
|
|
end
|
|
local sub = view:New(gameObject)
|
|
sub.assetName = config.assetName
|
|
if sub.Awake then
|
|
sub:Awake()
|
|
end
|
|
if sub.InitComponent then
|
|
sub:InitComponent()
|
|
end
|
|
if sub.BindEvent then
|
|
sub:BindEvent()
|
|
end
|
|
if sub.AddListener then
|
|
sub:AddListener()
|
|
end
|
|
if sub.Update then
|
|
UpdateBeat:Add(sub.Update, sub)
|
|
end
|
|
if sub.OnOpen then
|
|
sub:OnOpen(...)
|
|
end
|
|
return sub
|
|
end
|
|
function this:playUIAnimsOnStart(gameObject)
|
|
local anims = gameObject:GetComponentsInChildren(typeof(PlayFlyAnim))
|
|
if anims.Length > 0 then
|
|
for i = 0, anims.Length - 1 do
|
|
local anim = anims[i]
|
|
if anim.isPlayOnOpen then
|
|
anim:PlayAnim(false)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return this |