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

339 lines
13 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.weekTrailBtn.gameObject:SetActive(false)
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.box.gameObject:SetActive(false)
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.extra.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 = 2
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")
LogError("活动已结束")
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)
local config = ConfigManager.GetConfigData(ConfigName.RechargeCommodityConfig, 5001)
this.jiesuoBtnText.text = ((not treasureState) and MoneyUtil.GetMoneyUnitNameWithMoney(config.Price) or Language[11870])
--this.jiesuoBtnText.text = ((not treasureState) and Language[11869] or Language[11870])
Util.AddOnceClick(this.jiesuoBtn, function()
--UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.HeavenUnlockExtraRewardPanel, 2)
PayManager.Pay(5001, function(id)
--this.RechargeSuccessFunc()
this.jiesuoBtnText.text = Language[11870]
Game.GlobalEvent:DispatchEvent(GameEvent.TreasureOfHeaven.RechargeQinglongSerectSuccess, false, false)
end)
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[11871])
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 = "s_slbz_1anniuhuangse", text = Language[10019] },
[1] = { sprite = "s_slbz_1anniuongse", text = Language[10018] },
[2] = { sprite = "s_slbz_1anniuhuise", text = Language[10025] },
}
--单个任务
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(sConFigData.show)
local titleText = Util.GetGameObject(activityRewardGo, "content"):GetComponent("Text")
local value = sConFigData.taskValue[2][1]
titleText.text = GetLanguageStrById(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 = (GetLanguageStrById(strs[2]) and GetLanguageStrById(strs[2]) or "") ..
sConFigData.integral[1][2] ..
GetLanguageStrById(itemConfig[tonumber(sConFigData.integral[1][1])].Name) .. Language[11873]
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[11874] ..
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[10570] .. TimeToDHMS(timeDown)
self.timer = Timer.New(function()
if timeDown < 1 then
this.remainTime.text = Language[10570] .. TimeToDHMS(0)
self.timer:Stop()
self.timer = nil
this.RefreshTime()
return
end
timeDown = timeDown - 1
this.remainTime.text = Language[10570] .. 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