miduo_client/Assets/ManagedResources/~Lua/Modules/Battle/View/GuideBattlePanel.lua

212 lines
6.1 KiB
Lua
Raw Normal View History

2021-04-21 13:12:04 +08:00
require("Base/BasePanel")
2020-11-01 15:46:48 +08:00
require("Base/Stack")
require("Modules.Battle.Config.PokemonEffectConfig")
local BattleView = require("Modules/Battle/View/BattleView")
2021-03-19 18:14:52 +08:00
local GuideBattleLogic = require("Modules/Battle/View/GuideBattleLogic")
2020-11-01 15:46:48 +08:00
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()
2021-04-21 13:12:04 +08:00
this.spLoader = SpriteLoader.New()
2021-03-15 20:16:03 +08:00
BattleView:InitComponent(self, self.gameObject)
2020-11-01 15:46:48 +08:00
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.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)
2021-04-25 11:41:15 +08:00
Util.AddClick(this.BtnGM, function ()
if BattleManager.IsCanOperate() and not BattleLogic.IsEnd then
BattleView.EndBattle()
BattleLogic.IsEnd = true
end
end)
2020-11-01 15:46:48 +08:00
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
--界面打开时调用(用于子类重写)
2021-03-19 18:14:52 +08:00
function this:OnOpen(_fightData, _endFunc, guideType)
GuideBattleLogic:Init(guideType)
2020-11-01 15:46:48 +08:00
BattleView:OnOpen(_fightData)
2021-03-19 18:14:52 +08:00
this.guideType = guideType
2020-11-01 15:46:48 +08:00
endFunc = _endFunc
2021-03-19 18:14:52 +08:00
2020-11-01 15:46:48 +08:00
fightType = BATTLE_TYPE.Test --判定战斗类型
2021-11-15 16:39:38 +08:00
if _fightData.bg then
this.BG:GetComponent("Image").sprite = this.spLoader:LoadSprite(_fightData.bg)
2021-11-10 11:03:18 +08:00
else
2021-11-15 16:39:38 +08:00
this.BG:GetComponent("Image").sprite = this.spLoader:LoadSprite(BattleManager.GetBattleBg(fightType))
2021-11-10 11:03:18 +08:00
end
2020-11-01 15:46:48 +08:00
2021-04-25 11:41:15 +08:00
this.BtnGM:SetActive(true)
2020-11-01 15:46:48 +08:00
this.ButtonLock:SetActive(false)
this.BtnTimeScale:SetActive(false)
this.damagePanel:SetActive(false)
-- SoundManager.PlayMusic(SoundConfig.BGM_Battle_1, true, function()
2020-11-01 15:46:48 +08:00
SoundManager.PlayMusic(SoundConfig.BGM_Battle_2, false)
-- end)
2020-11-01 15:46:48 +08:00
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()
2021-03-02 16:53:12 +08:00
this.roundText.text = string.format(Language[10211], curRound, maxRound)
2020-11-01 15:46:48 +08:00
-- 初始化战斗时间,刷新前端显示
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 = {},
}
2020-11-01 15:46:48 +08:00
-- 战斗结束时,如果元素光环面板还开着,则先关闭
if UIManager.IsOpen(UIName.ElementPopup) then
UIManager.ClosePanel(UIName.ElementPopup)
end
-- 检测需要在战斗结束时显示的引导
GuideBattleLogic:OnBattleEnd(function()
-- 直接显示结果
this:ClosePanel()
end)
2020-11-01 15:46:48 +08:00
end
2021-11-10 11:03:18 +08:00
function this.OnBattleStart(order)
--显示波次
GuideBattleLogic:OnBattleStart()
end
2020-11-01 15:46:48 +08:00
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()
2021-03-02 16:53:12 +08:00
this.roundText.text = string.format(Language[10211], curRound, maxRound)
2020-11-01 15:46:48 +08:00
end
-- 角色轮转回调
function this.RoleTurnChange(role)
2021-03-19 18:14:52 +08:00
GuideBattleLogic:RoleTurnChange(this.curRound, role)
2020-11-01 15:46:48 +08:00
end
-- 由BattleView驱动
function this.OnUpdate()
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
BattleView:OnClose()
if endFunc then
endFunc(this.lastBattleResult)
end
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
BattleView:OnDestroy()
2021-04-21 13:12:04 +08:00
this.spLoader:Destroy()
2020-11-01 15:46:48 +08:00
end
return GuideBattlePanel