require("Base/BasePanel") require("Base/Stack") require("Modules.Battle.Config.PokemonEffectConfig") local BattleView = require("Modules/Battle/View/BattleView") GuideBattlePanel = Inherit(BasePanel) local this = GuideBattlePanel local timeCount local endFunc local isBack = false --是否为战斗回放 local fightType -- 1关卡 2副本 3限时怪, 5兽潮, 6新关卡, 7公会boss local orginLayer --初始化组件(用于子类重写) function this:InitComponent() BattleView:InitComponent(self) orginLayer = 0 this.BG = Util.GetGameObject(self.gameObject, "BG") this.UpRoot = Util.GetGameObject(self.gameObject, "UpRoot") this.Option = Util.GetGameObject(this.UpRoot, "option") this.DownRoot = Util.GetGameObject(self.gameObject, "DownRoot") this.roundText = Util.GetGameObject(this.Option, "timeCount"):GetComponent("Text") this.orderText = Util.GetGameObject(this.Option, "order/text"):GetComponent("Text") this.BtnTimeScale = Util.GetGameObject(this.DownRoot, "option/BtnTimeScale") this.BtnExit = Util.GetGameObject(this.DownRoot, "option/BtnExit") this.ButtonLock = Util.GetGameObject(this.DownRoot, "option/Button/lock") this.BtnGM = Util.GetGameObject(this.DownRoot, "option/Button") this.submit = Util.GetGameObject(this.DownRoot, "bg") this.DefResult = Util.GetGameObject(this.UpRoot, "result") this.AtkResult = Util.GetGameObject(this.DownRoot, "result") this.damagePanel = Util.GetGameObject(this.UpRoot, "damage") this.damageBoxBg = Util.GetGameObject(this.damagePanel, "bg") this.damageBoxIcon = Util.GetGameObject(this.damagePanel, "bg/iconRoot/icon"):GetComponent("Image") this.damageBoxLevel = Util.GetGameObject(this.damagePanel, "lv"):GetComponent("Text") this.damageProgress = Util.GetGameObject(this.damagePanel, "progress/Fill") this.damageText = Util.GetGameObject(this.damagePanel, "progress/Text"):GetComponent("Text") end --绑定事件(用于子类重写) function this:BindEvent() Util.AddLongPressClick(this.submit, function() BattleRecordManager.SubmitBattleRecord() end, 0.5) end --添加事件监听(用于子类重写) function this:AddListener() end --移除事件监听(用于子类重写) function this:RemoveListener() end function this:OnSortingOrderChange() Util.AddParticleSortLayer(this.gameObject, this.sortingOrder - orginLayer) orginLayer = this.sortingOrder BattleView:OnSortingOrderChange(this.sortingOrder) end --界面打开时调用(用于子类重写) function this:OnOpen(_fightData, _endFunc) BattleView:OnOpen(_fightData) endFunc = _endFunc fightType = BATTLE_TYPE.Test --判定战斗类型 this.BG:GetComponent("Image").sprite = Util.LoadSprite(BattleManager.GetBattleBg(fightType)) this.BtnGM:SetActive(false) this.BtnExit:SetActive(false) this.ButtonLock:SetActive(false) this.BtnTimeScale:SetActive(false) this.damagePanel:SetActive(false) SoundManager.PlayMusic(SoundConfig.BGM_Battle_1, true, function() SoundManager.PlayMusic(SoundConfig.BGM_Battle_2, false) end) this.fightResult = nil -- 清空名字数据 this.DefResult:SetActive(false) this.AtkResult:SetActive(false) -- 开始战斗 BattleView:StartBattle() this.InitPanelData() end -- 初始化 function this.InitPanelData() this.InitOption() end function this.InitOption() --显示倒计时 local curRound, maxRound = BattleLogic.GetCurRound() this.roundText.text = string.format(Language[10252], curRound, maxRound) -- 初始化战斗时间,刷新前端显示 Time.timeScale = BATTLE_TIME_SCALE_ONE end function this.SwitchTimeScale() local _scale = BattleManager.GetTimeScale() local child = this.BtnTimeScale.transform.childCount - 3 -- 3倍速时-2 local s = "x".. math.floor(_scale) for i=1, child do local g = this.BtnTimeScale.transform:GetChild(i-1).gameObject g:SetActive(g.name == s) end end function this.BattleEnd(result) BattleManager.PauseBattle() -- 强制停止倍速 Time.timeScale = 1 -- 设置音效播放的速度 SoundManager.SetAudioSpeed(1) --用一个变量接收最近的战斗结果 this.lastBattleResult = { result = result, hpList = {}, drop = {}, } -- 直接显示结果 this.ShowBattleResult(result) end function this.ShowBattleResult(result, msg) SoundManager.StopMusic() -- 战斗结束时,如果元素光环面板还开着,则先关闭 if UIManager.IsOpen(UIName.ElementPopup) then UIManager.ClosePanel(UIName.ElementPopup) end -- 播放结算音效 if result == 0 then this.resultSoundAudio = SoundManager.PlaySound(SoundConfig.Sound_BattleLose) else this.resultSoundAudio = SoundManager.PlaySound(SoundConfig.Sound_BattleWin) end if result == 0 then -- 失败 local haveRecord = BattleRecordManager.isHaveRecord() UIManager.OpenPanel(UIName.BattleFailPopup, this, haveRecord,nil,fightType) else -- 胜利 UIManager.OpenPanel(UIName.BattleWinPopup, this, isBack, fightType, this.lastBattleResult) end end function this.OnOrderChanged(order) --显示波次 this.orderText.text = string.format("%d/%d", order, BattleLogic.TotalOrder) end -- 战斗回合变化回调 this.curRound = 1 function this.OnRoundChanged(round) -- 轮数变化 this.curRound = round --显示波次 local curRound, maxRound = BattleLogic.GetCurRound() this.roundText.text = string.format(Language[10252], curRound, maxRound) end -- 引导节点配置 local _GuideConfig = { -- 轮数 = {阵营 = { 释放位置 = 对话id}}} [1] = { [0] = { [1] = 300008, [4] = 300010, } }, [2] = { [0] = { [1] = 300012, [2] = 300014, [3] = 300016, } } } -- 角色轮转回调 function this.RoleTurnChange(role) local curCamp = role.camp local curPos = role.position if not _GuideConfig[this.curRound] then return end if not _GuideConfig[this.curRound][curCamp] then return end if not _GuideConfig[this.curRound][curCamp][curPos] then return end BattleManager.SetGuidePause(true) StoryManager.EventTrigger(_GuideConfig[this.curRound][curCamp][curPos], function() BattleManager.SetGuidePause(false) end) end -- 由BattleView驱动 function this.OnUpdate() end --界面关闭时调用(用于子类重写) function this:OnClose() BattleView:OnClose() if endFunc then endFunc(this.lastBattleResult) end end --界面销毁时调用(用于子类重写) function this:OnDestroy() BattleView:OnDestroy() end return GuideBattlePanel