miduo_client/Assets/ManagedResources/~Lua/Modules/Fight/View/InvadeMonsterView.lua

491 lines
19 KiB
Lua

InvadeMonsterView = {}
local this = InvadeMonsterView
local StoreConfig = ConfigManager.GetConfig(ConfigName.StoreConfig)
local orginLayer = 0
-- 上一个宝箱的状态
local lastBoxState = 0
-- 是否已经点击了宝箱
local hadClicked = false
--初始化组件(用于子类重写)
function InvadeMonsterView:InitComponent(gameObject, fightPointPassMainPanel)
this.spLoader = SpriteLoader.New()
self.gameObject = gameObject
this.adventureMainPanel = fightPointPassMainPanel
--极速探险
this.expeditionsBtn = Util.GetGameObject(self.gameObject, "Bg/invadeBtn/expeditionsBtn")
-- 宝箱的根节点
this.rewardBox = Util.GetGameObject(self.gameObject, "Bg/getBoxReward")
-- 宝箱的4个动画
--this.rewardBox1 = Util.GetGameObject(self.gameObject, "boxRoot/UI_effect_GuaJi_Box_01")
--this.rewardBox2 = Util.GetGameObject(self.gameObject, "boxRoot/UI_effect_GuaJi_Box_02")
--this.rewardBox3 = Util.GetGameObject(self.gameObject, "boxRoot/UI_effect_GuaJi_Box_03")
this.btnFastExplore = Util.GetGameObject(self.gameObject, "Bg/btnDown/btnFastExplore")
--红点
this.expeditionRedPoint = Util.GetGameObject(self.gameObject, "Bg/btnDown/btnFastExplore/redPoint")
this.rewardBoxRedPoint = Util.GetGameObject(self.gameObject, "Bg/getBoxReward/rewardBoxRedPoint")
this.rewardBoxTimeObj = Util.GetGameObject(this.rewardBox, "time")
this.rewardBoxTimeObj:SetActive(true)
this.rewardBoxTime = this.rewardBoxTimeObj:GetComponent("Text")
this.rewardBoxTimeProgress = Util.GetGameObject(this.rewardBox, "getBoxReward/fill"):GetComponent("Image")
this.chapterRedPoint = Util.GetGameObject(self.gameObject, "Bg/btnGroup/btnRewrdChapter/redPoint")
this.btnRewrdChapter = Util.GetGameObject(self.gameObject, "Bg/btnGroup/btnRewrdChapter")
Util.GetGameObject(self.gameObject, "Bg/btnGroup/btnRewrdChapter/Image"):GetComponent("Image").sprite=this.spLoader:LoadSprite("UI_hz_zhonghe54")
this.btnRewrdChapterText = Util.GetGameObject(self.gameObject, "Bg/btnGroup/btnRewrdChapter/Text"):GetComponent("Text")
this.btnRewrdChapterTextGo = Util.GetGameObject(self.gameObject, "Bg/btnGroup/btnRewrdChapter/Image")
this.btnRewardOnline = Util.GetGameObject(self.gameObject, "Bg/btnGroup/btnRewrdOnline")
this.onlineRedPoint = Util.GetGameObject(this.btnRewardOnline, "redPoint")
this.onlineRewardQuality = Util.GetGameObject(this.btnRewardOnline, "quality"):GetComponent("Image")
this.onlineRewardIcon = Util.GetGameObject(this.btnRewardOnline, "icon"):GetComponent("Image")
this.onlineRewardNum = Util.GetGameObject(this.btnRewardOnline, "num"):GetComponent("Text")
this.onlineRewardTime = Util.GetGameObject(this.btnRewardOnline, "time"):GetComponent("Text")
this.onlineRewardEffect = Util.GetGameObject(this.btnRewardOnline, "effect")
effectAdapte(Util.GetGameObject(this.onlineRewardEffect, "ziti mask (1)"))
this.onlineRewardData = nil
this.onlineRewardState = nil
--缥缈之旅
this.btnJourneyWithWind = Util.GetGameObject(self.gameObject, "Bg/LeftUp/box/btnJoureyWithWind")
this.btnJourneyWithWindRedPoint = Util.GetGameObject(this.btnJourneyWithWind, "redPoint")
this.btnJourneyWithWindTime = Util.GetGameObject(this.btnJourneyWithWind, "time"):GetComponent("Text")
Util.GetGameObject(this.btnJourneyWithWind, "info"):GetComponent("Text").text = "飘邈之旅"
-- 新人商城
this.btnXinRen = Util.GetGameObject(self.gameObject, "Bg/LeftUp/box/btnXinRen")
this.btnXinRenTime = Util.GetGameObject(this.btnXinRen, "time"):GetComponent("Text")
end
--绑定事件(用于子类重写)
function InvadeMonsterView:BindEvent()
--点击宝箱领取奖励
Util.AddClick(this.rewardBox, function()
if not hadClicked then
hadClicked = true
FightPointPassManager.oldLevel = PlayerManager.level
local boxState = this.GetBoxShowState(AdventureManager.stateTime)
if boxState > 0 then
local isPopUp = RedPointManager.PlayerPrefsGetStr(PlayerManager.uid .. "mazeTreasureMax")
local currentTime = os.date("%Y%m%d", PlayerManager.serverTime)
local mazeTreasureMax = ConfigManager.GetConfigData(ConfigName.PlayerLevelConfig,PlayerManager.level).MazeTreasureMax
local str = Language[10597]..BagManager.GetItemCountById(FindTreasureManager.materialItemId).."/"..mazeTreasureMax..
Language[10598]..GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.ItemConfig,FindTreasureManager.materialItemId).Name)..
Language[10623]
if BagManager.GetItemCountById(FindTreasureManager.materialItemId) >= mazeTreasureMax and isPopUp ~= currentTime then
MsgPanel.ShowTwo(str, nil, function(isShow)
if (isShow) then
local currentTime = os.date("%Y%m%d", PlayerManager.serverTime)
RedPointManager.PlayerPrefsSetStr(PlayerManager.uid .."mazeTreasureMax", currentTime)
end
FightPointPassManager.isBeginFight = true
AdventureManager.GetAventureRewardRequest(2, false, false)
this.InitBoxShow()
end,nil,nil,nil,true)
else
FightPointPassManager.isBeginFight = true
AdventureManager.GetAventureRewardRequest(2, false, false)
this.InitBoxShow()
end
else
PopupTipPanel.ShowTip(Language[10624])
end
hadClicked = false
end
end)
--点击极速探险
Util.AddClick(this.btnFastExplore, function()
FightPointPassManager.isBeginFight = true
UIManager.OpenPanel(UIName.FastExploreInfoPopup)
end)
-- 在线奖励
Util.AddClick(this.btnRewardOnline, function()
--UIManager.OpenPanel(UIName.CourtesyDressPanel, ActivityTypeDef.OnlineGift, true)
UIManager.OpenPanel(UIName.OnlineRewardPanel, ActivityTypeDef.OnlineGift, true)
end)
-- 通关奖励
Util.AddClick(this.btnRewrdChapter, function()
UIManager.OpenPanel(UIName.CourtesyDressPanel, ActivityTypeDef.ChapterAward, true)
end)
-- 缥缈之旅
Util.AddClick(this.btnJourneyWithWind, function()
UIManager.OpenPanel(UIName.JourneyWithWindPanel)
end)
-- 缥缈之旅
Util.AddClick(this.btnXinRen, function()
JumpManager.GoJump(36012)
end)
end
--更新宝箱状态
function InvadeMonsterView.UpdataBoxStateShow()
-- 避免频繁使用SetActive
-- 判断当前挂机使用,发出冲击状态发生改变时,设置一下宝箱状态
local state = this.GetBoxShowState(AdventureManager.stateTime)
this.SetBoxShow(state)
end
----@param hangupTime 已经挂机时长
---@return 0 -- 无奖励 1 -- 第一个奖励 2 -- 第二个奖励 3 -- 满奖励 没有奖励也显示这个该死的宝箱
function this.GetBoxShowState(hangupTime)
-- Log("挂机时长 hangupTime " .. hangupTime)
local state = 0
if hangupTime < AdventureManager.adventureRefresh then
state = 0
elseif hangupTime >= AdventureManager.adventureRefresh and hangupTime < AdventureManager.adventureBoxShow[1] then
state = 1
elseif hangupTime >= AdventureManager.adventureRefresh and hangupTime < AdventureManager.adventureBoxShow[2] then
state = 2
else
state = 3
end
FightPointPassManager.SetBoxState(state)
if hangupTime > (AdventureManager.adventureOffline*3600) then
hangupTime = AdventureManager.adventureOffline*3600
end
if hangupTime < 0 then
hangupTime = 0
end
this.rewardBoxTime.text = TimeToHM(hangupTime)
this.rewardBoxTimeProgress.fillAmount = hangupTime / (AdventureManager.adventureOffline*3600)
return state
end
function this.SetBoxShow(curState)
if curState ~= lastBoxState then
-- 设置一次宝箱状态
--Log("更新一次宝箱状态 state == " .. curState)
this.rewardBox:SetActive(true)
--[[
if curState == 0 or curState == 1 then
this.rewardBox1:SetActive(true)
else
this.rewardBox1:SetActive(false)
end
this.rewardBox2:SetActive(curState == 2)
this.rewardBox3:SetActive(curState == 3)
]]
this.rewardBoxRedPoint:SetActive(curState == 3)
end
lastBoxState = curState
end
-- 初始化宝箱状态
function this.InitBoxShow()
--this.rewardBox:SetActive(true)
--this.rewardBox1:SetActive(true)
--this.rewardBox2:SetActive(false)
--this.rewardBox3:SetActive(false)
--this.rewardBoxRedPoint:SetActive(false)
end
function InvadeMonsterView:OnSortingOrderChange()
--[[
Util.AddParticleSortLayer(self.rewardBox1, this.adventureMainPanel.sortingOrder - orginLayer)
Util.AddParticleSortLayer(self.rewardBox2, this.adventureMainPanel.sortingOrder - orginLayer)
Util.AddParticleSortLayer(self.rewardBox3, this.adventureMainPanel.sortingOrder - orginLayer)
]]
Util.AddParticleSortLayer(this.onlineRewardEffect, this.adventureMainPanel.sortingOrder - orginLayer)
orginLayer = this.adventureMainPanel.sortingOrder
end
--添加事件监听(用于子类重写)
function InvadeMonsterView:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Adventure.OnRefeshBoxRewardShow, this.UpdataBoxStateShow)
Game.GlobalEvent:AddEvent(GameEvent.Adventure.OnRefreshRedShow, this.OnRefreshRedPoint)
Game.GlobalEvent:AddEvent(GameEvent.Adventure.OnFastBattleChanged, this.OnRefreshRedPoint)
Game.GlobalEvent:AddEvent(GameEvent.OnlineGift.GetOnlineRewardSuccess, this.RefreshOnlineRewardShow)
Game.GlobalEvent:AddEvent(GameEvent.OnlineGift.GetOnlineRewardSuccess, this.OnRefreshRedPoint)
Game.GlobalEvent:AddEvent(GameEvent.Activity.OnActivityOpenOrClose, this.CheckBtnShow)
end
--移除事件监听(用于子类重写)
function InvadeMonsterView:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Adventure.OnRefeshBoxRewardShow, this.UpdataBoxStateShow)
Game.GlobalEvent:RemoveEvent(GameEvent.Adventure.OnRefreshRedShow, this.OnRefreshRedPoint)
Game.GlobalEvent:RemoveEvent(GameEvent.Adventure.OnFastBattleChanged, this.OnRefreshRedPoint)
Game.GlobalEvent:RemoveEvent(GameEvent.OnlineGift.GetOnlineRewardSuccess, this.RefreshOnlineRewardShow)
Game.GlobalEvent:RemoveEvent(GameEvent.OnlineGift.GetOnlineRewardSuccess, this.OnRefreshRedPoint)
Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityOpenOrClose, this.CheckBtnShow)
end
--界面打开时调用(用于子类重写)
function InvadeMonsterView:OnShow(...)
lastBoxState = 0
this:OnRefreshRedPoint()
this.SetBoxShow(1)
this:UpdataBoxStateShow()
-- 在线奖励
this.RefreshOnlineRewardShow()
--判断章节奖励是全部领完
if ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.Chapter_Reward) then
if not ActivityGiftManager.chapterOpen or ActivityGiftManager.ActivityIsHaveGetFinally(ActivityGiftManager.chapterGetRewardState) then
this.btnRewrdChapter:SetActive(false)
else
this.btnRewrdChapter:SetActive(true)
end
else
this.btnRewrdChapter:SetActive(false)
end
-- 检测部分按钮显示状态
this.CheckBtnShow()
end
-- 刷新在线奖励显示
function this.RefreshOnlineRewardShow()
--判断在线礼包是全部领完
if ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.Online_Reward) then
if not ActivityGiftManager.onlineOpen or ActivityGiftManager.ActivityIsHaveGetFinally(ActivityGiftManager.onlineGetRewardState) then
this.btnRewardOnline:SetActive(false)
else
this.btnRewardOnline:SetActive(true)
CheckRedPointStatus(RedPointType.CourtesyDress_Online)
end
else
this.btnRewardOnline:SetActive(false)
end
-- 获取在线奖励状态
this.onlineRewardData, this.onlineRewardState = ActivityGiftManager.GetNextOnlineRewardData()
this.CheckOnlineRewardShow()
end
--倒计时时间格式化
function this.ForamtionCountDownTime(remainTime)
local hour = 0
local min = 0
local sec = 0
sec = math.floor(remainTime % 60)
hour = math.floor(remainTime / 3600)
min = 0
if (hour >= 1) then
min = math.floor((remainTime - hour * 3600) / 60)
else
min = math.floor(remainTime / 60)
end
return string.format("%02d:%02d:%02d", hour, min, sec)
end
-----============================ 外敌相关 ==============================
--刷新红点
function this:OnRefreshRedPoint()
-- 探索红点
local hadExplore = AdventureManager.GetSandFastBattleCount() ~= 0
-- 在线红点
local hadOnline = ActivityGiftManager.CheckOnlineRed()
-- 章节红点
local hadChpater = ActivityGiftManager.CheckChapterRed()
-- 缥缈之旅红点
if MonthCardManager.GetMonthCardIsOpen(MONTH_CARD_TYPE.LUXURYMONTHCARD) and MonthCardManager.GetMonthCardIsOpen(MONTH_CARD_TYPE.GIFT) then
local hadJourneyWithWind = ActivityGiftManager.JourneyWithWindAllRedPointState()
this.btnJourneyWithWindRedPoint:SetActive(hadJourneyWithWind)
else
local aaa=PlayerPrefs.GetInt(PlayerManager.uid.."piaomiaozhilv")
this.btnJourneyWithWindRedPoint:SetActive(aaa==0)
end
this.expeditionRedPoint:SetActive(hadExplore)
this.onlineRedPoint:SetActive(hadOnline)
this.chapterRedPoint:SetActive(hadChpater)
this.btnRewrdChapterTextGo:SetActive(true)
if hadChpater then
this.btnRewrdChapterText.text = Language[10477]
else
local needLevelNum = ActivityGiftManager.GetRewardNeedLevel()
local str = ""
if needLevelNum > 0 then
str = Language[10625].. needLevelNum ..Language[10626]
this.btnRewrdChapterText.text = str
else
this.btnRewrdChapterTextGo:SetActive(false)
end
end
end
-- 检测在线奖励状态
function this.CheckOnlineRewardShow()
if not this.onlineRewardData then
this.onlineRewardEffect:SetActive(false)
this.onlineRewardTime.text = Language[10319]
if this.timer then
this.timer:Stop()
this.timer = nil
end
else
local itemId = this.onlineRewardData.Reward[1][1]
this.onlineRewardQuality.sprite = SetFrame(this.spLoader, itemId)
this.onlineRewardIcon.sprite = SetIcon(this.spLoader, itemId)
this.onlineRewardNum.text = this.onlineRewardData.Reward[1][2]
if this.onlineRewardState == 0 then
this.onlineRewardEffect:SetActive(true)
this.OnRefreshRedPoint()
this.onlineRewardTime.text = Language[10477]
if this.timer then
this.timer:Stop()
this.timer = nil
end
elseif this.onlineRewardState == -1 then
this.onlineRewardEffect:SetActive(false)
if not this.timer then
this.TimeUpdate()
this.timer = Timer.New(this.TimeUpdate, 1, -1, true)
this.timer:Start()
end
end
end
end
-- 定时器回调
function this.TimeUpdate()
if this.onlineRewardState == -1 then
local curOnlineTime = GetTimeStamp() - ActivityGiftManager.cuOnLineTimestamp
local needTime = this.onlineRewardData.Values[1][1]*60
local remainTime = needTime - curOnlineTime
if remainTime >= 0 then
this.onlineRewardTime.text = TimeToMS(remainTime)
else
this.RefreshOnlineRewardShow()
end
else
if this.timer then
this.timer:Stop()
this.timer = nil
end
end
end
-- 检测在缥缈之旅状态
function this.RefreshJourneyWithWindShow()
local endtime = ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.JourneyWithWind)
local timeDown = endtime - GetTimeStamp()
if this.timer2 then
this.timer2:Stop()
this.timer2 = nil
end
if timeDown > 0 then
this.btnJourneyWithWindTime.text = GetLeftTimeStrByDeltaTime2(timeDown)--string.format("剩余%s",GetLeftTimeStrByDeltaTime2(timeDown))
this.timer2 = Timer.New(function()
this.btnJourneyWithWindTime.text = GetLeftTimeStrByDeltaTime2(timeDown)--string.format("剩余%s",GetLeftTimeStrByDeltaTime2(timeDown))
if timeDown < 0 then
if this.btnJourneyWithWind then
this.btnJourneyWithWind:SetActive(false)
end
this.timer2:Stop()
this.timer2 = nil
end
timeDown = timeDown - 1
end, 1, -1, true)
this.timer2:Start()
else
if this.btnJourneyWithWind then
this.btnJourneyWithWind:SetActive(false)
end
end
end
-- 按钮状态检测
function this.CheckBtnShow()
--缥缈之旅显示判断
local idJourneyWithWind = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.JourneyWithWind)
if idJourneyWithWind and idJourneyWithWind > 0 then
this.btnJourneyWithWind:SetActive(true)
this.RefreshJourneyWithWindShow()
else
this.btnJourneyWithWind:SetActive(false)
end
-- 新人商城显示判断
local xrId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.XinRenShop)
if xrId and xrId > 0 then
this.btnXinRen:SetActive(false)
this.RefreshXinRenShow()
else
this.btnXinRen:SetActive(false)
end
end
-- 检测在缥缈之旅状态
function this.RefreshXinRenShow()
local endtime = ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.XinRenShop)
local timeDown = endtime - GetTimeStamp()
if this.timer3 then
this.timer3:Stop()
this.timer3 = nil
end
if timeDown > 0 then
this.btnXinRenTime.text = GetLeftTimeStrByDeltaTime2(timeDown)--string.format("剩余%s",GetLeftTimeStrByDeltaTime2(timeDown))
this.timer3 = Timer.New(function()
this.btnXinRenTime.text = GetLeftTimeStrByDeltaTime2(timeDown)--string.format("剩余%s",GetLeftTimeStrByDeltaTime2(timeDown))
if timeDown < 0 then
if this.btnXinRen then
this.btnXinRen:SetActive(false)
end
this.timer3:Stop()
this.timer3 = nil
end
timeDown = timeDown - 1
end, 1, -1, true)
this.timer3:Start()
else
if this.btnXinRen then
this.btnXinRen:SetActive(false)
end
end
end
--界面关闭时调用(用于子类重写)
function InvadeMonsterView:OnClose()
if this.timerEffect then
this.timerEffect:Stop()
end
this.timerEffect = nil
if this.timer then
this.timer:Stop()
this.timer = nil
end
if this.timer2 then
this.timer2:Stop()
this.timer2 = nil
end
if this.timer3 then
this.timer3:Stop()
this.timer3 = nil
end
end
--界面销毁时调用(用于子类重写)
function InvadeMonsterView:OnDestroy()
this.spLoader:Destroy()
end
return InvadeMonsterView