-- 填充障碍块工具 local ObstacleTool = class("ObstacleTool") local ToolSize = 0; function ObstacleTool:MouseDown(button , x , y) -- 按下ALT控制相机 if app.cs.getModifierKeys() == Keys.Alt then return end -- 转换坐标 local worldPos = app.cameraController:convertScreenToWorldPos(x, y); -- 将像素坐标转换成逻辑坐标 local logicalPos = app.editor.Map:getTilePosition(worldPos.x, worldPos.z); -- 左键按下添加障碍快 if (button == MouseButtons.Left) then for x = -ToolSize , ToolSize do for y = -ToolSize , ToolSize do app.editor.Map:addObstacle(logicalPos.x + x, logicalPos.y + y); end end end -- 右键按下删除障碍块 if (button == MouseButtons.Right) then for x = -ToolSize , ToolSize do for y = -ToolSize , ToolSize do app.editor.Map:removeObstacle(logicalPos.x + x, logicalPos.y + y); end end end -- 中间填充 if button == MouseButtons.Middle then local map = app.editor.Map; local function FillShape(x, y) if not map:isInMap(x , y) then return end if not map:isObstacle(x,y) then map:addObstacle(x, y); FillShape(x+1, y); FillShape(x-1, y); FillShape(x, y+1); FillShape(x, y-1); end end FillShape(logicalPos.x , logicalPos.y); end end function ObstacleTool:MouseMove(button, x , y) -- 按下ALT控制相机 if app.cs.getModifierKeys() == Keys.Alt then return end -- 转换坐标 local worldPos = app.cameraController:convertScreenToWorldPos(x, y); -- 将像素坐标转换成逻辑坐标 local logicalPos = app.editor.Map:getTilePosition(worldPos.x, worldPos.z); -- 左键按下添加障碍快 if (button == MouseButtons.Left) then for x = -ToolSize , ToolSize do for y = -ToolSize , ToolSize do app.editor.Map:addObstacle(logicalPos.x + x, logicalPos.y + y); end end end -- 右键按下删除障碍块 if (button == MouseButtons.Right) then for x = -ToolSize , ToolSize do for y = -ToolSize , ToolSize do app.editor.Map:removeObstacle(logicalPos.x + x, logicalPos.y + y); end end end end function ObstacleTool:DialogKey(Control, Alt, Shift, KeyCode) if KeyCode == Keys.Up then ToolSize = ToolSize + 1; elseif KeyCode == Keys.Down then ToolSize = ToolSize - 1; elseif KeyCode == Keys.Left then ToolSize = ToolSize - 10; elseif KeyCode == Keys.Right then ToolSize = ToolSize + 10; end if ToolSize > 100 then ToolSize = 100; elseif ToolSize < 0 then ToolSize = 0; end ToolSize = math.ceil(ToolSize); end function ObstacleTool:MouseUp(button, x, y) end return ObstacleTool;