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

263 lines
9.9 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.

----- 日常任务弹窗 -----
local this = {}
--传入父脚本模块
local parent
--传入特效层级
local sortingOrder=0
local curType = 1
local treasureState
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
function this:InitComponent(gameObject)
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.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(curType)
end)
Util.AddClick(this.finalTrailBtn,function()
curType = 2
this.refresh(curType)
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,curType)
Game.GlobalEvent:AddEvent(GameEvent.TreasureOfHeaven.TaskRefresh, this.refresh,curType)
Game.GlobalEvent:AddEvent(GameEvent.Activity.OnActivityOpenOrClose,this.CloseFunction)
end
function this:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.TreasureOfHeaven.RechargeQinglongSerectSuccess,this.refresh,curType)
Game.GlobalEvent:RemoveEvent(GameEvent.TreasureOfHeaven.TaskRefresh, this.refresh,curType)
Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityOpenOrClose,this.Closefunction)
end
this.Closefunction = function()
Timer.New(function()
local id = ActivityGiftManager.GetActivityIdByType(8)
LogBlue("收到了关闭活动的消息id:"..id)
if not ActivityGiftManager.GetActivityOpenStatus(id) then
parent.SwitchView(1)
return
else
this.refresh(curType)
end
end,1):Start()
end
function this:OnShow(_parent,...)
parent=_parent
sortingOrder = _parent.sortingOrder
this.refresh(curType)
end
--topBar按钮状态
function this:SetTopBar()
treasureState = QinglongSerectTreasureManager.GetTreasureState()--秘宝礼包状态 0:可购买 1:已购买
this.jiesuoBtn:GetComponent("Button").enabled = (treasureState == 0)
this.jiesuoBtnText.text = ((treasureState == 0) and "解锁秘宝" or "已解锁")
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 = (treasureState == 0)
this.extra:GetComponent("Button").enabled = ((not (treasureState == 0)) and (times > 0))
this.canOpenExtra.gameObject:SetActive((not (treasureState == 0)) and (times > 0))
this.openExtra:GetComponent("Animator").enabled = false
this.openExtra.gameObject:SetActive((not (treasureState == 0)) 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(8)
NetManager.GetActivityRewardRequest(-2,id,function(msg)
PrivilegeManager.RefreshPrivilegeUsedTimes(1007, 1)
this.refresh(curType)
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.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
end
function this:OnDestroy()
end
function this.refresh(type)
this:SetTopBar()
this:SetSelect()
this:ShowTime(type)
this:showTaskList(type)
CheckRedPointStatus(RedPointType.QinglongSerectTreasureTrail)
end
--任务列表
function this:showTaskList(type)
local rewardData = QinglongSerectTreasureManager.GetQinglongTaskData(type)
this.ScrollView:SetData(rewardData,function(index, rewardItem)
this:SingleTask(rewardItem, rewardData[index])
end)
end
local type={
[0]={sprite = "s_slbz_1anniuhuangse",text = "前往"},
[1]={sprite = "s_slbz_1anniuongse",text = "领取"},
[2]={sprite = "s_slbz_1anniuhuise",text = "已领取"},
}
--单个任务
function this:SingleTask(go, rewardSingleData)
local activityRewardGo = go
activityRewardGo:SetActive(true)
local sConFigData = rewardSingleData
local strs = string.split(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]..sConFigData.integral[1][2]..itemConfig[tonumber(sConFigData.integral[1][1])].Name .."/次"
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 = Util.LoadSprite(type[state].sprite)
text.text = type[state].text
if state == 1 then
text.text = sConFigData.integral[1][2]..itemConfig[tonumber(sConFigData.integral[1][1])].Name
end
Util.AddOnceClick(lingquButton, function()
if state == 1 then
NetManager.TakeMissionRewardRequest(TaskTypeDef.TreasureOfSomeBody,sConFigData.id, function(msg)
Timer.New(function()
this.refresh(curType)
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(8)
LogBlue("endtime:"..endtime)
local timeDown = endtime - GetTimeStamp()
this.remainTime.text = "剩余时间:"..TimeToDHMS(timeDown)
self.timer = Timer.New(function()
if timeDown < 1 then
self.timer:Stop()
self.timer = nil
return
end
timeDown = timeDown - 1
this.remainTime.text = "剩余时间:"..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