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

302 lines
12 KiB
Lua
Raw Normal View History

2020-08-25 15:46:38 +08:00
----- 日常任务弹窗 -----
2020-08-19 10:05:01 +08:00
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")
2020-08-27 14:53:27 +08:00
this.select = Util.GetGameObject(this.gameObject, "topBar/select")
2020-08-19 10:05:01 +08:00
this.weekTrailBtn = Util.GetGameObject(this.gameObject, "topBar/button/weekTrail")
this.finalTrailBtn = Util.GetGameObject(this.gameObject, "topBar/button/finalTrail")
2020-08-27 14:53:27 +08:00
this.weekTrailBtnRed = Util.GetGameObject(this.weekTrailBtn , "redPoint")
this.finalTrailBtnRed = Util.GetGameObject(this.finalTrailBtn, "redPoint")
2020-08-19 10:05:01 +08:00
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.RefreshTime)
2020-08-19 10:05:01 +08:00
Game.GlobalEvent:AddEvent(GameEvent.Activity.OnActivityOpenOrClose,this.CloseFunction)
Game.GlobalEvent:AddEvent(GameEvent.MoneyPay.OnPayResultSuccess, this.refresh,curType)
2020-08-19 10:05:01 +08:00
end
function this:RemoveListener()
2020-08-26 20:30:52 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.TreasureOfHeaven.RechargeQinglongSerectSuccess, this.refresh,curType)
Game.GlobalEvent:RemoveEvent(GameEvent.TreasureOfHeaven.TaskRefresh, this.RefreshTime)
Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityOpenOrClosen,this.CloseFunction)
2020-08-27 14:53:27 +08:00
2020-08-26 20:30:52 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.MoneyPay.OnPayResultSuccess, this.refresh,curType)
2020-08-19 10:05:01 +08:00
end
function this.RefreshTime()
NetManager.RefreshTimeSLRequest(function (msg)
this.refresh(curType)
end)
end
2020-08-19 10:05:01 +08:00
this.Closefunction = function()
Timer.New(function()
2020-09-23 17:41:48 +08:00
if not ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.TreasureOfSomeBody) then
2020-08-25 15:46:38 +08:00
PopupTipPanel.ShowTip(Language[12320])
2020-08-22 15:48:01 +08:00
parent:ClosePanel()
2020-08-19 10:05:01 +08:00
return
else
this.refresh(curType)
end
end,1):Start()
end
function this:OnShow(_parent,...)
parent=_parent
sortingOrder = _parent.sortingOrder
2020-08-26 18:29:27 +08:00
if not ActivityGiftManager.GetActivityOpenStatus(ActivityTypeDef.TreasureOfSomeBody) then
parent:ClosePanel()
return
end
2020-08-19 10:05:01 +08:00
this.refresh(curType)
end
--topBar按钮状态
function this:SetTopBar()
treasureState = QinglongSerectTreasureManager.GetTreasureState()--秘宝礼包状态 0:可购买 1:已购买
this.jiesuoBtn:GetComponent("Button").enabled = (treasureState == 0)
2020-08-25 15:46:38 +08:00
this.jiesuoBtnText.text = ((treasureState == 0) and Language[12352] or Language[12353])
2020-08-19 10:05:01 +08:00
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()
2020-08-28 16:36:08 +08:00
local id = ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.TreasureOfSomeBody)
2020-08-19 10:05:01 +08:00
NetManager.GetActivityRewardRequest(-2,id,function(msg)
PrivilegeManager.RefreshPrivilegeUsedTimes(1007, 1)
2020-08-25 15:46:38 +08:00
PopupTipPanel.ShowTip(Language[12355])
2020-08-19 10:05:01 +08:00
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()
2020-09-28 05:01:06 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
2020-08-19 10:05:01 +08:00
end
function this:OnDestroy()
2020-08-22 16:55:27 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
2020-08-19 10:05:01 +08:00
end
2020-08-26 18:29:27 +08:00
2020-08-19 10:05:01 +08:00
function this.refresh(type)
2020-08-26 18:29:27 +08:00
QinglongSerectTreasureManager.UpdateTreasureState2()
2020-08-19 10:05:01 +08:00
this:SetTopBar()
this:SetSelect()
this:ShowTime(type)
this:showTaskList(type)
2020-08-27 14:53:27 +08:00
this:SetRedPoint()
2020-08-19 14:12:42 +08:00
CheckRedPointStatus(RedPointType.QinglongSerectTreasureTrail)
2020-08-27 14:53:27 +08:00
2020-08-19 10:05:01 +08:00
end
2020-08-27 14:53:27 +08:00
function this:SetRedPoint()
this.weekTrailBtnRed:SetActive(QinglongSerectTreasureManager.GetSerectTreasureTrailSingleRedPot(1))
this.finalTrailBtnRed:SetActive(QinglongSerectTreasureManager.GetSerectTreasureTrailSingleRedPot(2))
end
2020-08-19 10:05:01 +08:00
2020-09-07 16:09:29 +08:00
local state = {
[1] = 0,
[0] = 1,
[2] = 2,
}
2020-08-19 10:05:01 +08:00
--任务列表
function this:showTaskList(type)
local rewardData = QinglongSerectTreasureManager.GetQinglongTaskData(type)
2020-09-07 16:09:29 +08:00
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)
2020-08-19 10:05:01 +08:00
this.ScrollView:SetData(rewardData,function(index, rewardItem)
this:SingleTask(rewardItem, rewardData[index])
end)
end
local type={
2020-08-25 15:46:38 +08:00
[0]={sprite = "s_slbz_1anniuhuangse",text = Language[10023]},
[1]={sprite = "s_slbz_1anniuongse",text = Language[10022]},
[2]={sprite = "s_slbz_1anniuhuise",text = Language[10350]},
2020-08-19 10:05:01 +08:00
}
--单个任务
function this:SingleTask(go, rewardSingleData)
2020-08-20 17:36:19 +08:00
local activityRewardGo = go
2020-08-19 10:05:01 +08:00
activityRewardGo:SetActive(true)
local sConFigData = rewardSingleData
2020-08-20 17:36:19 +08:00
local strs = string.split(sConFigData.show)
2020-08-19 10:05:01 +08:00
local titleText = Util.GetGameObject(activityRewardGo, "content"):GetComponent("Text")
local value = sConFigData.taskValue[2][1]
2020-08-20 17:36:19 +08:00
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")
2020-08-25 15:46:38 +08:00
rewardText.text = (strs[2] and strs[2] or "")..sConFigData.integral[1][2]..itemConfig[tonumber(sConFigData.integral[1][1])].Name ..Language[12357]
2020-08-28 11:05:31 +08:00
local state = sConFigData.state
2020-08-19 10:05:01 +08:00
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
Util.AddOnceClick(lingquButton, function()
if state == 1 then
NetManager.TakeMissionRewardRequest(TaskTypeDef.TreasureOfSomeBody,sConFigData.id, function(msg)
2020-08-25 15:46:38 +08:00
PopupTipPanel.ShowTip(Language[12358]..sConFigData.integral[1][2]..itemConfig[tonumber(sConFigData.integral[1][1])].Name)
2020-08-19 10:05:01 +08:00
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(ActivityTypeDef.TreasureOfSomeBody)
2020-08-19 10:05:01 +08:00
LogBlue("endtime:"..endtime)
local timeDown = endtime - GetTimeStamp()
2020-08-25 15:46:38 +08:00
this.remainTime.text = Language[12321]..TimeToDHMS(timeDown)
2020-08-19 10:05:01 +08:00
self.timer = Timer.New(function()
if timeDown < 1 then
self.timer:Stop()
self.timer = nil
this.RefreshTime()
2020-08-26 20:04:36 +08:00
if ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.TreasureOfSomeBody) - GetTimeStamp() < 1 then
this.Closefunction()
end
2020-08-19 10:05:01 +08:00
return
end
timeDown = timeDown - 1
2020-08-25 15:46:38 +08:00
this.remainTime.text = Language[12321]..TimeToDHMS(timeDown)
2020-08-19 10:05:01 +08:00
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