You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 regels
2.4 KiB

  1. -- 填充障碍块工具
  2. local ObstacleTool = class("ObstacleTool")
  3. local ToolSize = 0;
  4. function ObstacleTool:MouseDown(button , x , y)
  5. -- 按下ALT控制相机
  6. if app.cs.getModifierKeys() == Keys.Alt then return end
  7. -- 转换坐标
  8. local worldPos = app.cameraController:convertScreenToWorldPos(x, y);
  9. -- 将像素坐标转换成逻辑坐标
  10. local logicalPos = app.editor.Map:getTilePosition(worldPos.x, worldPos.z);
  11. -- 左键按下添加障碍快
  12. if (button == MouseButtons.Left) then
  13. for x = -ToolSize , ToolSize do
  14. for y = -ToolSize , ToolSize do
  15. app.editor.Map:addObstacle(logicalPos.x + x, logicalPos.y + y);
  16. end
  17. end
  18. end
  19. -- 右键按下删除障碍块
  20. if (button == MouseButtons.Right) then
  21. for x = -ToolSize , ToolSize do
  22. for y = -ToolSize , ToolSize do
  23. app.editor.Map:removeObstacle(logicalPos.x + x, logicalPos.y + y);
  24. end
  25. end
  26. end
  27. -- 中间填充
  28. if button == MouseButtons.Middle then
  29. local map = app.editor.Map;
  30. local function FillShape(x, y)
  31. if not map:isInMap(x , y) then
  32. return
  33. end
  34. if not map:isObstacle(x,y) then
  35. map:addObstacle(x, y);
  36. FillShape(x+1, y);
  37. FillShape(x-1, y);
  38. FillShape(x, y+1);
  39. FillShape(x, y-1);
  40. end
  41. end
  42. FillShape(logicalPos.x , logicalPos.y);
  43. end
  44. end
  45. function ObstacleTool:MouseMove(button, x , y)
  46. -- 按下ALT控制相机
  47. if app.cs.getModifierKeys() == Keys.Alt then return end
  48. -- 转换坐标
  49. local worldPos = app.cameraController:convertScreenToWorldPos(x, y);
  50. -- 将像素坐标转换成逻辑坐标
  51. local logicalPos = app.editor.Map:getTilePosition(worldPos.x, worldPos.z);
  52. -- 左键按下添加障碍快
  53. if (button == MouseButtons.Left) then
  54. for x = -ToolSize , ToolSize do
  55. for y = -ToolSize , ToolSize do
  56. app.editor.Map:addObstacle(logicalPos.x + x, logicalPos.y + y);
  57. end
  58. end
  59. end
  60. -- 右键按下删除障碍块
  61. if (button == MouseButtons.Right) then
  62. for x = -ToolSize , ToolSize do
  63. for y = -ToolSize , ToolSize do
  64. app.editor.Map:removeObstacle(logicalPos.x + x, logicalPos.y + y);
  65. end
  66. end
  67. end
  68. end
  69. function ObstacleTool:DialogKey(Control, Alt, Shift, KeyCode)
  70. if KeyCode == Keys.Up then
  71. ToolSize = ToolSize + 1;
  72. elseif KeyCode == Keys.Down then
  73. ToolSize = ToolSize - 1;
  74. elseif KeyCode == Keys.Left then
  75. ToolSize = ToolSize - 10;
  76. elseif KeyCode == Keys.Right then
  77. ToolSize = ToolSize + 10;
  78. end
  79. if ToolSize > 100 then
  80. ToolSize = 100;
  81. elseif ToolSize < 0 then
  82. ToolSize = 0;
  83. end
  84. ToolSize = math.ceil(ToolSize);
  85. end
  86. function ObstacleTool:MouseUp(button, x, y)
  87. end
  88. return ObstacleTool;