c1_lua/lua/app/ui/battle/battle_ui.lua
2023-06-28 21:24:15 +08:00

427 lines
17 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local BattleBaseUI = require "app/ui/battle/battle_base_ui"
local BattleUI = class("BattleUI", BattleBaseUI)
local GRID_CELL = "app/ui/battle/cell/grid_cell"
local SELECT_SKILL_CELL = "app/ui/battle/cell/select_skill_cell"
local BATTLE_SELECT_SKILL_COMP = "app/ui/battle/battle_skill_select_comp"
local DEFAULT_X = 10000
local BOARD_POS_UP = BF.Vector2(0, 0)
local BOARD_POS_DOWN = BF.Vector2(0, 0)
local CacheVector2 = CS.UnityEngine.Vector2(0, 0)
---------------------------------必须重写的方法----------------------------------
function BattleUI:initBaseInfo()
local uiMap = self.root:genAllChildren()
self.uiMap = uiMap
self.gridNode = uiMap["battle_ui.bg_2.board_node.grid_node"]
self.boardNode = uiMap["battle_ui.bg_2.board_node"]
self.boardCenterNode = uiMap["battle_ui.bg_2.board_node.board_center_node"]
self.boardNode:setAnchoredPositionX(DEFAULT_X)
self.boardMask2D = self.gridNode:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_RECT_MASK_2D)
self.boardMask = uiMap["battle_ui.bg_2.board_node.grid_node.board_mask"]
self.boardMask:setVisible(false)
self.boardCacheNode = uiMap["battle_ui.bg_2.board_cache_node"]
self.boardCacheNode:setVisible(false)
self.boardCacheBox = uiMap["battle_ui.bg_2.board_cache_node.skill_box"]
self.boardCacheBox:setAnchoredPositionX(DEFAULT_X)
self.battleRoot = uiMap["battle_ui.battle_root"]
self.maxLayerNode = uiMap["battle_ui.battle_root.battle_node.max_layer_show_node"]
end
function BattleUI:initBg()
self.bg = self.uiMap["battle_ui.battle_root.bg"]
self.bg:setLocalScale(0, 0, 0)
local width = self.bg:fastGetSizeDelta()
self.bg:setAnchoredPositionX(width/4)
end
function BattleUI:initSkill()
local uiMap = self.root:genAllChildren()
local atkNode = uiMap["battle_ui.bg_2.skill_node"]
local atkCellPrefix = "battle_ui.bg_2.skill_node.skill_node_cell_"
self:_initSkill(atkNode, atkCellPrefix, nil, nil)
end
function BattleUI:initBuff()
local atkBuffPrefix = "battle_ui.top_node.buff_l.tiny_buff_cell_"
local defBuffPrefix = "battle_ui.top_node.buff_r.tiny_buff_cell_"
local battleBuffTipsRoot = self.uiMap["battle_ui.battle_buff_tips"]
local battleBuffTipsMask = self.uiMap["battle_ui.battle_buff_tips.mask"]
local battleBuffTipsBg = self.uiMap["battle_ui.battle_buff_tips.bg"]
local battleBuffTipsBuff = self.uiMap["battle_ui.battle_buff_tips.bg.buff"]
self:_initBuff(atkBuffPrefix, defBuffPrefix, battleBuffTipsRoot, battleBuffTipsMask, battleBuffTipsBg, battleBuffTipsBuff)
end
function BattleUI:initBattlefield()
self.battleNode = self.uiMap["battle_ui.battle_root.battle_node"]
end
function BattleUI:initNumberNode()
self.battleNumberNode = self.uiMap["battle_ui.battle_root.battle_number_node"]
self.battleNumberRed = self.uiMap["battle_ui.cache_node.battle_number_red"]
self.battleNumberGreen = self.uiMap["battle_ui.cache_node.battle_number_green"]
self.battleNumberBlue = self.uiMap["battle_ui.cache_node.battle_number_blue"]
self.battleNumberWhite = self.uiMap["battle_ui.cache_node.battle_number_white"]
self.battleNumberSpecial = self.uiMap["battle_ui.cache_node.battle_number_special"]
end
function BattleUI:initComboNode()
self.comboNode = self.uiMap["battle_ui.top_node.combo"]
self.comboBg1 = self.uiMap["battle_ui.top_node.combo.bg.bg_1"]
self.comboTx1 = self.uiMap["battle_ui.top_node.combo.number.text.text_1"]
self.comboTx2 = self.uiMap["battle_ui.top_node.combo.number.text.text_2"]
self.comboFx1 = self.uiMap["battle_ui.top_node.combo.bg.vfx_ui_hit_b01"]
self.comboFx2 = self.uiMap["battle_ui.top_node.combo.bg.vfx_ui_hit_b02"]
self.comboFx3 = self.uiMap["battle_ui.top_node.combo.bg.vfx_ui_hit_b03"]
self:_initComboNode()
end
function BattleUI:initHpNode()
self.hpProgressLeft = self.uiMap["battle_ui.top_node.bg_l.atk_slider_green"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
self.hpProgressRight = self.uiMap["battle_ui.top_node.bg_r.def_slider_red"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
self.hpProgressYellowLeft = self.uiMap["battle_ui.top_node.bg_l.atk_slider_yellow"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
self.hpProgressYellowRight = self.uiMap["battle_ui.top_node.bg_r.def_slider_yellow"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
self.hpTextLeft = self.uiMap["battle_ui.top_node.atk_hp"]
self.hpTextRight = self.uiMap["battle_ui.top_node.def_hp"]
self:_initHpNode()
end
function BattleUI:initFxNode()
self.fxNode = self.uiMap["battle_ui.battle_root.batttle_fx_node"]
end
function BattleUI:hideGenerateSkillGridCells()
local generateSkillCellPrefix = "battle_ui.bg_2.ani_node.grid_cell_"
self:_hideGenerateSkillGridCells(generateSkillCellPrefix)
end
function BattleUI:initSkillLineSfx()
local uiMap = self.root:genAllChildren()
if not self.skillLineSfxs then
self.skillLineSfxs = {}
self.skillLineSfxs[13] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b01_2_1h"]
self.skillLineSfxs[11] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b01_2_1v"]
self.skillLineSfxs[15] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b01_2_1l"]
self.skillLineSfxs[17] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b01_2_1r"]
self.skillLineSfxs[23] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b01_1_2h"]
self.skillLineSfxs[21] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b01_1_2v"]
self.skillLineSfxs[25] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b01_1_2l"]
self.skillLineSfxs[27] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b01_1_2r"]
self.skillLineSfxs[33] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b01_3h"]
self.skillLineSfxs[31] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b01_3v"]
self.skillLineSfxs[35] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b01_3l"]
self.skillLineSfxs[37] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b01_3r"]
end
if not self.skillLightSfxs then
self.skillLightSfxs = {}
self.skillLightSfxs.point = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b03"]
self.skillLightSfxs[11] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b04_1"]
self.skillLightSfxs[12] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b04_2"]
self.skillLightSfxs[13] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b04_3"]
self.skillLightSfxs[14] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b04_4"]
self.skillLightSfxs[15] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b04_5"]
self.skillLightSfxs[21] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b05_1"]
self.skillLightSfxs[22] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b05_2"]
self.skillLightSfxs[23] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b05_3"]
self.skillLightSfxs[24] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b05_4"]
self.skillLightSfxs[25] = uiMap["battle_ui.bg_2.board_node.grid_node.sfx_skill_b05_5"]
end
self:_initSkillLineSfx()
end
function BattleUI:initGenerateSkillEffect()
local generateSkillEffecPrefix = "battle_ui.bg_2.ani_node.sfx_piece_skill_b01_"
self:_initGenerateSkillEffect(generateSkillEffecPrefix)
end
function BattleUI:initCounterAttack()
self.counterAttackNode = self.uiMap["battle_ui.battle_root.battle_number_node.counter_attack"]
self.counterTx = self.uiMap["battle_ui.battle_root.battle_number_node.counter_attack.text_number"]
self.counterTxbgComp = self.uiMap["battle_ui.battle_root.top_node.counter_attack.bg"]
self.counterAttackNode:setVisible(false)
end
--------------------------------end必须重写的方法--------------------------------
----------------------------------按需重写的方法 可以为nil已容错----------------
function BattleUI:initTutorialNode()
local uiMap = self.root:genAllChildren()
self.tutorialNode = uiMap["battle_ui.tutorial_node"]
self.tutorialFinger = uiMap["battle_ui.tutorial_node.board_node.finger"]
self:showTutorialFinger()
end
function BattleUI:initCommonSkillDescTips()
local uiMap = self.root:genAllChildren()
self.skillDescTipsNode = uiMap["battle_ui.bg_2.lv_node.skill_desc_tips"]
self.skillDescTips = uiMap["battle_ui.bg_2.lv_node.skill_desc_tips.desc"]
self.skillDescTipsNode:setVisible(false)
end
function BattleUI:initSelectSkillNode()
if not self.selectSkillComp then
local uiMap = self.root:genAllChildren()
local obj = uiMap["battle_ui.bg_2.battle_select_skill_comp"]
obj:initPrefabHelper()
obj:genAllChildren()
self.selectSkillComp = obj:addLuaComponent(BATTLE_SELECT_SKILL_COMP)
self.selectSkillComp:hide()
end
end
function BattleUI:initBossEnterAni()
local uiMap = self.root:genAllChildren()
self.bossEnterNode = uiMap["battle_ui.bg_2.boss_enter_node"]
self.bossEnterImg = uiMap["battle_ui.bg_2.boss_enter_node.ui_spine_obj"]
self.bossName = uiMap["battle_ui.bg_2.boss_enter_node.boss_name"]
self.bossEnterNodeAnimator = self.bossEnterNode:getComponent(GConst.TYPEOF_UNITY_CLASS.ANIMATOR)
self.bossEnterNodeAnimator.enabled = false
self.bossEnterNodeCanvasGroup = self.bossEnterNode:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS_GROUP)
self.bossEnterNode:setVisible(false)
end
function BattleUI:initSkillSelectCells()
if not self.skillSelectCell then
local uiMap = self.root:genAllChildren()
self.skillSelectCell = CellManager:addCellComp(uiMap["battle_ui.bg_2.ani_node.skill_select_cell"], SELECT_SKILL_CELL)
self.skillSelectCell:getBaseObject():setAnchoredPositionX(DEFAULT_X)
end
end
function BattleUI:showTutorialFinger(posIdList)
if self.showTutorialFingerSeq then
self.showTutorialFingerSeq:Kill()
self.showTutorialFingerSeq = nil
self.battleController:clearGridSequence()
end
if not self.tutorialFinger then
return
end
local show = false
if posIdList and posIdList[1] then
show = true
end
self.tutorialNode:setVisible(show)
if not show then
return
end
self.showTutorialFingerSeq = self.root:createBindTweenSequence()
local path = {}
local count = 0
for index, posId in ipairs(posIdList) do
local curPos = self:getPosInfo(posId)
if index == 1 then
self.tutorialFinger:setAnchoredPosition(curPos.x, curPos.y)
else
table.insert(path, curPos)
count = count + 1
end
end
self.showTutorialFingerSeq:Append(self.tutorialFinger:getTransform():DOLocalPath(path, count * 0.5):SetEase(CS.DG.Tweening.Ease.Linear))
for index, posId in ipairs(posIdList) do
local time = (index - 1.2) * 0.5
if time < 0 then
time = 0
end
self.showTutorialFingerSeq:InsertCallback(time, function()
local eventType
if index == 1 then
eventType = GConst.ELIMINATION_TOUCH_EVENT.DOWN
else
eventType = GConst.ELIMINATION_TOUCH_EVENT.ENTER
end
self.battleController:onTouchEvent(eventType, posId, true)
end)
end
self.showTutorialFingerSeq:AppendInterval(0.15)
self.showTutorialFingerSeq:AppendCallback(function()
self.battleController:clearGridSequence()
self.tutorialFinger:setAnchoredPositionX(DEFAULT_X)
self:showBoardMask(nil)
end)
self.showTutorialFingerSeq:AppendInterval(1)
self.showTutorialFingerSeq:SetLoops(-1)
end
--------------------------------end按需重写的方法--------------------------------
function BattleUI:getPrefabPath()
return "assets/prefabs/ui/battle/battle_ui.prefab"
end
function BattleUI:_display()
BattleBaseUI._display(self)
self:refreshTaskBtn()
end
function BattleUI:_addListeners()
local uiMap = self.root:genAllChildren()
uiMap["battle_ui.top_node.close_btn"]:addClickListener(function()
ModuleManager.BattleManager:showPauseUI(self.battleController.battleType)
end)
self:addEventListener(EventManager.CUSTOM_EVENT.SHOW_ELIMINATION_TUTORAIL, function(posIdList)
self:showTutorialFinger(posIdList)
end)
self:addEventListener(EventManager.CUSTOM_EVENT.SKILL_REFRESH_SUCC, function(posIdList)
if self.selectSkillComp then
self.selectSkillComp:getNewRandomSkill()
end
end)
end
function BattleUI:_bind()
self:bind(self.battleData, "lvDirty", function()
self:refreshLv()
end, true)
end
function BattleUI:moveBattlefield(time)
local width = self.bg:fastGetSizeDelta()
self.bg:setAnchoredPositionX(width/4)
if self.bgMoveTween == nil then
self.bgMoveTween = self.bg:getTransform():DOAnchorPosX(-width/4, time)
self.bgMoveTween:SetIntId(GConst.DOTWEEN_IDS.BATTLE)
self.bgMoveTween:SetAutoKill(false)
else
local x, y = self.bg:fastGetAnchoredPosition()
CacheVector2.x = -width/4
CacheVector2.y = y
self.bgMoveTween:ChangeEndValue(CacheVector2, time, true)
self.bgMoveTween:Restart()
end
end
function BattleUI:showLeftBuffTips(buffList, autoClose)
local x = self.battleBuffTipsBg:fastGetAnchoredPosition()
if x > 0 then
self.battleBuffTipsBg:setAnchoredPositionX(-x)
end
self:showBuffTips(buffList, autoClose)
end
function BattleUI:showRightBuffTips(buffList, autoClose)
local x = self.battleBuffTipsBg:fastGetAnchoredPosition()
if x < 0 then
self.battleBuffTipsBg:setAnchoredPositionX(-x)
end
self:showBuffTips(buffList, autoClose)
end
function BattleUI:onInitGridCellOver(...)
BattleBaseUI.onInitGridCellOver(self, ...)
---- 检查引导
ModuleManager.TutorialManager:checkFuncTutorial(GConst.TutorialConst.START_TUTORIAL)
end
function BattleUI:switchBoard(downCallback, callback, isFirst)
if self.switchBoardSeq then
self.switchBoardSeq:Kill()
self.switchBoardSeq = nil
end
if isFirst then
if downCallback then
downCallback()
end
if callback then
callback()
end
self.boardNode:setAnchoredPositionY(BOARD_POS_UP.y)
return
end
self.switchBoardSeq = self.root:createBindTweenSequence()
self.switchBoardSeq:Append(self.boardNode:getTransform():DOAnchorPos(BOARD_POS_DOWN, 0.5))
self.switchBoardSeq:AppendCallback(function()
if downCallback then
downCallback()
end
end)
self.switchBoardSeq:Append(self.boardNode:getTransform():DOAnchorPos(BOARD_POS_UP, 0.5))
self.switchBoardSeq:AppendCallback(function()
if callback then
callback()
end
end)
end
function BattleUI:hideMonsterSkillGridCells()
if not self.monsterSkillGridEntities then
local uiMap = self.root:genAllChildren()
self.monsterSkillGridEntities = {}
for name, elementType in pairs(GConst.BattleConst.ELEMENT_TYPE) do
local obj = uiMap["battle_ui.bg_2.ani_node.grid_cell_m" .. elementType]
if obj then
local cell = CellManager:addCellComp(obj, GRID_CELL)
local entity = self.battleData:getNewGridEntity()
entity:setCell(cell)
self.monsterSkillGridEntities[elementType] = entity
end
end
end
for _, entity in pairs(self.monsterSkillGridEntities) do
if entity:getCell() then
entity:getCell():getBaseObject():setAnchoredPositionX(DEFAULT_X)
end
end
end
function BattleUI:refreshLv()
local uiMap = self.root:genAllChildren()
if not self.lvSlider then
self.lvSlider = uiMap["battle_ui.bg_2.lv_node.slider"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
self.lvDesc = uiMap["battle_ui.bg_2.lv_node.icon.lv_desc"]
end
local curExp = self.battleData:getBattleExp()
local curNeedExp = self.battleData:getBattleNeedExp()
self.lvSlider.value = curExp / curNeedExp
local lv = self.battleData:getBattleLv()
self.lvDesc:setText(lv)
local sfx = uiMap["battle_ui.bg_2.lv_node.icon.vfx_ui_battle_progress_light_b01"]
if not self.lastLv then
sfx:setActive(true)
sfx:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_EFFECT_HELPER):SetSortingOrder(self:getUIOrder(), GConst.UI_EFFECT_ORDER.LEVEL5)
sfx:setActive(false)
elseif self.lastLv ~= lv then
sfx:setActive(true)
sfx:play()
end
self.lastLv = lv
end
function BattleUI:refreshWave(wave, iconAtlas, iconName)
local uiMap = self.root:genAllChildren()
local icon = uiMap["battle_ui.top_node.wave_icon"]
local desc = uiMap["battle_ui.top_node.wave_desc"]
desc:setText(wave)
GFunc.centerImgAndTx(icon, desc, 10)
iconAtlas = iconAtlas or GConst.ATLAS_PATH.COMMON
iconName = iconName or "common_dec_3"
icon:setSprite(iconAtlas, iconName)
end
function BattleUI:refreshTaskBtn()
local uiMap = self.root:genAllChildren()
local taskBtn = uiMap["battle_ui.top_node.task_btn"]
if self.battleController.battleType == GConst.BattleConst.BATTLE_TYPE.DAILY_CHALLENGE then
taskBtn:setActive(true)
taskBtn:addClickListener(function()
ModuleManager.DailyChallengeManager:showBattleTaskUI()
end)
else
taskBtn:setActive(false)
end
end
return BattleUI