c1_lua/lua/app/ui/battle/cell/grid_cell.lua
2023-04-19 09:48:53 +08:00

117 lines
3.9 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())
self:showHighLight(false)
--- 测试代码
-- 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)
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 str = GConst.EMPTY_STRING
if show then
str = self.gridEntity:getAroundEliminationCount()
end
uiMap["grid_cell.touch_node.ani_node.count"]:setText(str)
end
function GridCell:resetTranform()
end
return GridCell