c1_lua/lua/app/ui/battle/cell/grid_cell.lua
xiekaidong ccddeb8aa3 修复
2023-04-20 18:50:19 +08:00

175 lines
6.1 KiB
Lua

local GridCell = class("GridCell", BaseCell)
function GridCell:refresh(gridEntity, curElement)
self.gridEntity = gridEntity
local uiMap = self:getUIMap()
local downBg = uiMap["grid_cell.touch_node.ani_node.down_bg"]
local elementType = gridEntity:getElementType()
local elementIcon = uiMap["grid_cell.touch_node.ani_node.middle_bg"]
if self.lastElementType ~= elementType then
self.lastElementType = elementType
local atlas, icon = ModuleManager.BattleManager:getElementIcon(elementType)
elementIcon:setSprite(atlas, icon)
end
elementIcon:setVisible(true)
local showMask = false
if curElement and (curElement ~= elementType or not gridEntity:canLink()) then
showMask = true
end
self.curElement = curElement
uiMap["grid_cell.touch_node.ani_node.obstacle"]:setVisible(gridEntity:isObstacleType())
if self.lastGridType ~= gridEntity:getGridType() then
self.lastGridType = gridEntity:getGridType()
local atlas, icon = ModuleManager.BattleManager:getGridTypeIcon(self.lastGridType)
uiMap["grid_cell.touch_node.ani_node.up_bg"]:setSprite(atlas, icon)
end
local skillIcon = uiMap["grid_cell.touch_node.ani_node.skill_icon"]
local skillId = gridEntity:getSkillId()
if skillId then
elementIcon:setVisible(false)
skillIcon:setVisible(true)
local sprite
local skillEntity = DataManager.BattleData:getSkillEntityBySkillId(skillId)
if skillEntity then
sprite = skillEntity:getBattleIcon()
else
local cfg = ModuleManager.BattleManager.SKILL_CFG[skillId]
if cfg then
sprite = tostring(cfg.battle_icon)
end
end
if sprite and self.lastSkillSprite ~= sprite then
self.lastSkillSprite = sprite
skillIcon:setSprite(GConst.ATLAS_PATH.ICON_SKILL, self.lastSkillSprite)
end
elementType = gridEntity:getElementType(skillEntity)
if not elementType then
showMask = false
end
else
skillIcon:setVisible(false)
end
uiMap["grid_cell.touch_node.ani_node.mask"]:setVisible(showMask)
self:showCircle(gridEntity:getNeedElimination())
if self.gridEntity:getIsIdle() then
self.lastShowHlElementType = nil
self:hideAni()
end
self:showHighLight(self.lastShowHlElementType ~= nil, self.lastShowHlElementType)
--- 测试代码
-- uiMap["grid_cell.touch_node.ani_node.count"]:setText(gridEntity:getAroundEliminationCount())
end
function GridCell:addTouchListener(func)
local uiMap = self:getUIMap()
uiMap["grid_cell.touch_node"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_ELIMINATION_TOUCH_EVENT):AddTouchEventListener(func)
end
function GridCell:showCircle(show)
local uiMap = self:getUIMap()
uiMap["grid_cell.touch_node.ani_node.circle"]:setVisible(show == true)
end
function GridCell:showHighLight(show, mainElementType, parentUI)
if not self.gridEntity then
return
end
local uiMap = self:getUIMap()
local downBg = uiMap["grid_cell.touch_node.ani_node.down_bg"]
local skillId = self.gridEntity:getSkillId()
downBg:setVisible(skillId ~= nil)
if skillId then
local skillEntity = DataManager.BattleData:getSkillEntityBySkillId(skillId)
local ignoreElementType = skillEntity:getIgnoreElementType()
local skillBg
if ignoreElementType and not mainElementType then
skillBg = GConst.BattleConst.SKILL_ELEMENT_BG_2.ANY
else
mainElementType = mainElementType or skillEntity:getPosition()
skillBg = GConst.BattleConst.SKILL_ELEMENT_BG_2[mainElementType]
end
if self.lastSkillBg ~= skillBg then
self.lastSkillBg = skillBg
downBg:setSprite(GConst.ATLAS_PATH.BATTLE, self.lastSkillBg)
end
end
local elementType = mainElementType or self.gridEntity:getElementType()
--- 测试代码
local str = GConst.EMPTY_STRING
if show then
str = self.gridEntity:getAroundEliminationCount()
end
uiMap["grid_cell.touch_node.ani_node.count"]:setText(str)
if not self.outLineSfxObjs then
self.outLineSfxObjs = {}
for elementType, name in pairs(GConst.BattleConst.OUTLINE_SFX) do
self.outLineSfxObjs[elementType] = uiMap["grid_cell.touch_node.ani_node.effect_node." .. name]
end
end
local find = false
for type, obj in pairs(self.outLineSfxObjs) do
if show and type == elementType then
find = true
if self.lastShowHlElementType ~= elementType then
self.lastShowHlElementType = elementType
obj:setActive(true)
end
else
obj:setActive(false)
end
end
if not find then
self.lastShowHlElementType = nil
end
end
function GridCell:resetTranform()
local uiMap = self:getUIMap()
uiMap["grid_cell.touch_node"]:setAnchoredPosition(0, 0)
uiMap["grid_cell.touch_node"]:setLocalScale(1, 1, 1)
end
function GridCell:showAni()
local uiMap = self:getUIMap()
if not self.aniComp then
self.aniComp = uiMap["grid_cell.touch_node"]:getComponent(GConst.TYPEOF_UNITY_CLASS.ANIMATOR)
end
-- CS.UnityEngine.Animator.StringToHash("idle") 结果是-601574123
self.aniComp.enabled = true
self.aniComp:Play(-601574123, -1, 0)
end
function GridCell:hideAni()
local uiMap = self:getUIMap()
if not self.aniComp then
self.aniComp = uiMap["grid_cell.touch_node"]:getComponent(GConst.TYPEOF_UNITY_CLASS.ANIMATOR)
end
self.aniComp.enabled = false
self:resetTranform()
end
function GridCell:setOrder(uiOder)
local uiMap = self:getUIMap()
for i = 1, 5 do
local obj = uiMap["grid_cell.touch_node.ani_node.effect_node.sfx_piece_qizi_b0" .. i]
obj:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_EFFECT_HELPER):SetSortingOrder(uiOder, GConst.UI_EFFECT_ORDER.LEVEL1)
end
-- uiMap["grid_cell.touch_node.ani_node.effect_node.sfx_piece_line_b01"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_EFFECT_HELPER):SetSortingOrder(uiOder, GConst.UI_EFFECT_ORDER.LEVEL1)
end
return GridCell