138 lines
4.3 KiB
Lua
138 lines
4.3 KiB
Lua
local BattleUI = class("BattleUI", BaseUI)
|
||
local GRID_CELL = "app/ui/battle/cell/grid_cell"
|
||
local GRID_CELL_PATH = "assets/prefabs/ui/battle/cell/grid_cell.prefab"
|
||
|
||
local DEFAULT_X = 10000
|
||
|
||
function BattleUI:getPrefabPath()
|
||
return "assets/prefabs/ui/battle/battle_ui.prefab"
|
||
end
|
||
|
||
function BattleUI:onLoadRootComplete()
|
||
self:_display()
|
||
end
|
||
|
||
function BattleUI:_display()
|
||
local uiMap = self.root:genAllChildren()
|
||
self:initGridCell()
|
||
end
|
||
|
||
function BattleUI:_addListeners()
|
||
|
||
end
|
||
|
||
function BattleUI:initGridCell()
|
||
if self.gridCells and self.gridInitOver then
|
||
self:onInitGridCellOver()
|
||
return
|
||
end
|
||
|
||
local uiMap = self.root:genAllChildren()
|
||
local parent = uiMap["battle_ui.bg_2.board_node"]
|
||
|
||
self.gridCells = {}
|
||
self.cellLoadRemianCount = GConst.BattleConst.ROW_COUNT * GConst.BattleConst.COLUMN_COUNT
|
||
for r = 1, GConst.BattleConst.ROW_COUNT do
|
||
for c = 1, GConst.BattleConst.COLUMN_COUNT do
|
||
CellManager:loadCellAsync(GRID_CELL_PATH, GRID_CELL, parent, function(cell)
|
||
local posId = ModuleManager.BattleManager:getPosId(r, c)
|
||
self.gridCells[posId] = cell
|
||
local gameObject = cell:getGameObject()
|
||
gameObject.name = "grid_cell_" .. posId
|
||
cell:getBaseObject():setAnchoredPositionX(DEFAULT_X) -- 初始化时放到屏幕外
|
||
|
||
self.cellLoadRemianCount = self.cellLoadRemianCount - 1
|
||
if self.cellLoadRemianCount <= 0 then
|
||
self.gridInitOver = true
|
||
self:onInitGridCellOver()
|
||
end
|
||
end)
|
||
end
|
||
end
|
||
end
|
||
|
||
function BattleUI:onInitGridCellOver()
|
||
for posId, cell in pairs(self.gridCells) do
|
||
local entity = DataManager.BattleData:getGridEntity(posId)
|
||
if entity then
|
||
cell:refresh(entity, function(eventType)
|
||
if self.battleController then
|
||
self.battleController:onTouchEvent(eventType, entity:getPosId())
|
||
end
|
||
end)
|
||
local pos = entity:getPos()
|
||
cell:getBaseObject():setAnchoredPosition(pos.x, pos.y)
|
||
entity:setCell(cell)
|
||
end
|
||
end
|
||
end
|
||
|
||
function BattleUI:setController(controller)
|
||
self.battleController = controller
|
||
end
|
||
|
||
function BattleUI:showBoardMask(elementType)
|
||
if not self.gridCells then
|
||
return
|
||
end
|
||
local entities = DataManager.BattleData:getGridEnties()
|
||
for posId, entity in pairs(entities) do
|
||
if entity and entity:getCell() then
|
||
entity:getCell():refresh(entity, function(eventType)
|
||
if self.battleController then
|
||
self.battleController:onTouchEvent(eventType, entity:getPosId())
|
||
end
|
||
end, elementType)
|
||
end
|
||
end
|
||
end
|
||
|
||
function BattleUI:eliminationAni(cellList, callback)
|
||
if not cellList then
|
||
if callback then
|
||
callback()
|
||
end
|
||
return
|
||
end
|
||
|
||
for _, cell in ipairs(cellList) do
|
||
if cell then
|
||
cell:getBaseObject():setAnchoredPositionX(DEFAULT_X)
|
||
end
|
||
end
|
||
|
||
if callback then
|
||
self:performWithDelayGlobal(function()
|
||
callback()
|
||
end, 1)
|
||
end
|
||
end
|
||
|
||
function BattleUI:fallGrid(listInfo)
|
||
for _, info in pairs(listInfo) do
|
||
local entity = info.entity
|
||
local pathInfoList = info.pathInfoList
|
||
local cell = entity:getCell()
|
||
local posId = entity:getPosId()
|
||
if cell then
|
||
local gameObject = cell:getGameObject()
|
||
gameObject.name = "grid_cell_" .. posId
|
||
if cell.fallSeq then
|
||
cell.fallSeq:Kill()
|
||
cell.fallSeq = nil
|
||
end
|
||
local baseObject = cell:getBaseObject()
|
||
cell.fallSeq = baseObject:createBindTweenSequence()
|
||
-- cell.fallSeq:Append(baseObject:getTransform():DOLocalPath(pathInfoList, 2))
|
||
for index, pos in ipairs(pathInfoList) do
|
||
if index == 1 then -- 初始位置,直接0秒直接设置
|
||
cell.fallSeq:Append(baseObject:getTransform():DOAnchorPos(pos, 0)) -- 暂时使用这种 等待改进dopath
|
||
else
|
||
cell.fallSeq:Append(baseObject:getTransform():DOAnchorPos(pos, 1)) -- 暂时使用这种 等待改进dopath
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
return BattleUI |