PaintableGrid.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. using UnityEngine.Tilemaps;
  6. namespace UnityEditor.Tilemaps
  7. {
  8. internal abstract class PaintableGrid : ScriptableObject
  9. {
  10. private const int k_MaxMouseCellDelta = 500;
  11. public enum MarqueeType { None = 0, Pick, Box, Select }
  12. private int m_PermanentControlID;
  13. public abstract void Repaint();
  14. protected abstract void RegisterUndo();
  15. protected abstract void Paint(Vector3Int position);
  16. protected abstract void Erase(Vector3Int position);
  17. protected abstract void BoxFill(BoundsInt position);
  18. protected abstract void BoxErase(BoundsInt position);
  19. protected abstract void FloodFill(Vector3Int position);
  20. protected abstract void PickBrush(BoundsInt position, Vector3Int pickStart);
  21. protected abstract void Select(BoundsInt position);
  22. protected abstract void Move(BoundsInt from, BoundsInt to);
  23. protected abstract void MoveStart(BoundsInt position);
  24. protected abstract void MoveEnd(BoundsInt position);
  25. protected abstract bool ValidateFloodFillPosition(Vector3Int position);
  26. protected abstract Vector2Int ScreenToGrid(Vector2 screenPosition);
  27. protected abstract bool PickingIsDefaultTool();
  28. protected abstract bool CanPickOutsideEditMode();
  29. protected abstract Grid.CellLayout CellLayout();
  30. protected abstract void ClearGridSelection();
  31. protected virtual void OnBrushPickStarted() {}
  32. protected virtual void OnBrushPickDragged(BoundsInt position) {}
  33. protected virtual void OnBrushPickCancelled() {}
  34. protected virtual void OnEditStart() {}
  35. protected virtual void OnEditEnd() {}
  36. internal static PaintableGrid s_LastActivePaintableGrid;
  37. private Vector2Int m_PreviousMouseGridPosition;
  38. private Vector2Int m_MouseGridPosition;
  39. private bool m_MouseGridPositionChanged;
  40. private bool m_PositionChangeRepaintDone;
  41. protected Vector2Int? m_PreviousMove;
  42. protected Vector2Int? m_MarqueeStart;
  43. private MarqueeType m_MarqueeType = MarqueeType.None;
  44. private bool m_IsExecuting;
  45. private Type m_TypeBeforeExecution;
  46. private int m_ZPosition;
  47. public Vector2Int mouseGridPosition { get { return m_MouseGridPosition; } }
  48. public bool isPicking { get { return m_MarqueeType == MarqueeType.Pick; } }
  49. public bool isBoxing { get { return m_MarqueeType == MarqueeType.Box; } }
  50. public GridLayout.CellLayout cellLayout { get { return CellLayout(); } }
  51. public int zPosition { get { return m_ZPosition; } set { m_ZPosition = value; } }
  52. protected bool executing
  53. {
  54. get { return m_IsExecuting; }
  55. set
  56. {
  57. var isExecuting = value && isHotControl;
  58. if (isExecuting != m_IsExecuting)
  59. {
  60. if (isExecuting)
  61. OnEditStart();
  62. else
  63. OnEditEnd();
  64. }
  65. m_IsExecuting = isExecuting;
  66. }
  67. }
  68. protected bool isHotControl { get { return GUIUtility.hotControl == m_PermanentControlID; } }
  69. protected bool mouseGridPositionChanged { get { return m_MouseGridPositionChanged; } }
  70. protected bool inEditMode { get { return PaintableGrid.InGridEditMode(); } }
  71. protected virtual void OnEnable()
  72. {
  73. m_PermanentControlID = GUIUtility.GetPermanentControlID();
  74. }
  75. protected virtual void OnDisable()
  76. {
  77. }
  78. public virtual void OnGUI()
  79. {
  80. if (CanPickOutsideEditMode() || inEditMode)
  81. HandleBrushPicking();
  82. if (inEditMode)
  83. {
  84. HandleBrushPaintAndErase();
  85. HandleSelectTool();
  86. HandleMoveTool();
  87. HandleEditModeChange();
  88. HandleFloodFill();
  89. HandleBoxTool();
  90. }
  91. else if (isHotControl && !IsPickingEvent(Event.current))
  92. {
  93. // Release hot control if it still has it while not in picking or grid edit mode
  94. GUIUtility.hotControl = 0;
  95. }
  96. if (mouseGridPositionChanged && !m_PositionChangeRepaintDone)
  97. {
  98. Repaint();
  99. m_PositionChangeRepaintDone = true;
  100. }
  101. }
  102. protected void ResetPreviousMousePositionToCurrentPosition()
  103. {
  104. m_PreviousMouseGridPosition = m_MouseGridPosition;
  105. }
  106. protected void UpdateMouseGridPosition(bool forceUpdate = false)
  107. {
  108. if (Event.current.type == EventType.MouseDrag
  109. || Event.current.type == EventType.MouseMove
  110. // Case 1075857: Mouse Down when window is not in focus needs to update mouse grid position
  111. || Event.current.type == EventType.MouseDown
  112. || Event.current.type == EventType.DragUpdated
  113. || forceUpdate)
  114. {
  115. Vector2Int newGridPosition = ScreenToGrid(Event.current.mousePosition);
  116. if (newGridPosition != m_MouseGridPosition)
  117. {
  118. var delta = newGridPosition - m_MouseGridPosition;
  119. // Case 1024422: Limit mouse cell delta changes for Grid/Tilemap input handling due to camera changes when switching modes/axis views
  120. if (Mathf.Abs(delta.x) > k_MaxMouseCellDelta)
  121. newGridPosition.x = m_MouseGridPosition.x + Math.Sign(delta.x) * k_MaxMouseCellDelta;
  122. if (Mathf.Abs(delta.y) > k_MaxMouseCellDelta)
  123. newGridPosition.y = m_MouseGridPosition.y + Math.Sign(delta.y) * k_MaxMouseCellDelta;
  124. ResetPreviousMousePositionToCurrentPosition();
  125. m_MouseGridPosition = newGridPosition;
  126. MouseGridPositionChanged();
  127. }
  128. else if (!forceUpdate)
  129. {
  130. m_MouseGridPositionChanged = false;
  131. }
  132. }
  133. }
  134. private void MouseGridPositionChanged()
  135. {
  136. m_MouseGridPositionChanged = true;
  137. m_PositionChangeRepaintDone = false;
  138. }
  139. private void HandleEditModeChange()
  140. {
  141. // Handles changes in EditMode while tool is expected to be in the same mode
  142. if (isPicking && !TilemapEditorTool.IsActive(typeof(PickingTool)))
  143. {
  144. m_MarqueeStart = null;
  145. m_MarqueeType = MarqueeType.None;
  146. if (isHotControl)
  147. {
  148. GUI.changed = true;
  149. GUIUtility.hotControl = 0;
  150. }
  151. }
  152. if (isBoxing && !TilemapEditorTool.IsActive(typeof(BoxTool)))
  153. {
  154. m_MarqueeStart = null;
  155. m_MarqueeType = MarqueeType.None;
  156. if (isHotControl)
  157. {
  158. GUI.changed = true;
  159. GUIUtility.hotControl = 0;
  160. }
  161. }
  162. if (!TilemapEditorTool.IsActive(typeof(SelectTool)) && !TilemapEditorTool.IsActive(typeof(MoveTool)))
  163. {
  164. ClearGridSelection();
  165. }
  166. }
  167. private void HandleBrushPicking()
  168. {
  169. Event evt = Event.current;
  170. if (evt.type == EventType.MouseDown && IsPickingEvent(evt) && !isHotControl)
  171. {
  172. m_TypeBeforeExecution = typeof(PaintTool);
  173. if (inEditMode && !TilemapEditorTool.IsActive(typeof(PickingTool)))
  174. {
  175. m_TypeBeforeExecution = UnityEditor.EditorTools.ToolManager.activeToolType;
  176. TilemapEditorTool.SetActiveEditorTool(typeof(PickingTool));
  177. }
  178. m_MarqueeStart = mouseGridPosition;
  179. m_MarqueeType = MarqueeType.Pick;
  180. s_LastActivePaintableGrid = this;
  181. Event.current.Use();
  182. GUI.changed = true;
  183. GUIUtility.hotControl = m_PermanentControlID;
  184. OnBrushPickStarted();
  185. }
  186. if (evt.type == EventType.MouseDrag && isHotControl && m_MarqueeStart.HasValue && m_MarqueeType == MarqueeType.Pick && IsPickingEvent(evt))
  187. {
  188. RectInt rect = GridEditorUtility.GetMarqueeRect(m_MarqueeStart.Value, mouseGridPosition);
  189. OnBrushPickDragged(new BoundsInt(new Vector3Int(rect.xMin, rect.yMin, zPosition), new Vector3Int(rect.size.x, rect.size.y, 1)));
  190. Event.current.Use();
  191. GUI.changed = true;
  192. }
  193. if (evt.rawType == EventType.MouseUp && isHotControl && m_MarqueeStart.HasValue && m_MarqueeType == MarqueeType.Pick && IsPickingEvent(evt))
  194. {
  195. // Check if event only occurred in the PaintableGrid window as evt.type will filter for this
  196. if (evt.type == EventType.MouseUp && m_MarqueeType == MarqueeType.Pick)
  197. {
  198. RectInt rect = GridEditorUtility.GetMarqueeRect(m_MarqueeStart.Value, mouseGridPosition);
  199. Vector2Int pivot = GetMarqueePivot(m_MarqueeStart.Value, mouseGridPosition);
  200. PickBrush(new BoundsInt(new Vector3Int(rect.xMin, rect.yMin, zPosition), new Vector3Int(rect.size.x, rect.size.y, 1)), new Vector3Int(pivot.x, pivot.y, 0));
  201. if (inEditMode && UnityEditor.EditorTools.ToolManager.activeToolType != m_TypeBeforeExecution)
  202. {
  203. if (PickingIsDefaultTool()
  204. && (m_TypeBeforeExecution == typeof(EraseTool)
  205. || m_TypeBeforeExecution == typeof(MoveTool)))
  206. {
  207. // If Picking is default, change to a Paint Tool to facilitate editing if previous tool does not allow for painting
  208. TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
  209. }
  210. else
  211. {
  212. TilemapEditorTool.SetActiveEditorTool(m_TypeBeforeExecution);
  213. }
  214. }
  215. GridPaletteBrushes.ActiveGridBrushAssetChanged();
  216. s_LastActivePaintableGrid = this;
  217. Event.current.Use();
  218. GUI.changed = true;
  219. }
  220. else
  221. // Event occurred outside of PaintableGrid window, cancel the pick event
  222. {
  223. OnBrushPickCancelled();
  224. }
  225. m_MarqueeType = MarqueeType.None;
  226. m_MarqueeStart = null;
  227. GUIUtility.hotControl = 0;
  228. InspectorWindow.RepaintAllInspectors();
  229. }
  230. }
  231. private bool IsPickingEvent(Event evt)
  232. {
  233. return ((evt.control && !TilemapEditorTool.IsActive(typeof(MoveTool)))
  234. || TilemapEditorTool.IsActive(typeof(PickingTool))
  235. || !TilemapEditorTool.IsActive(typeof(SelectTool)) && PickingIsDefaultTool())
  236. && evt.button == 0 && !evt.alt;
  237. }
  238. private void HandleSelectTool()
  239. {
  240. Event evt = Event.current;
  241. if (evt.type == EventType.MouseDown && evt.button == 0 && !evt.alt && (TilemapEditorTool.IsActive(typeof(SelectTool)) || (TilemapEditorTool.IsActive(typeof(MoveTool)) && evt.control)))
  242. {
  243. if (TilemapEditorTool.IsActive(typeof(MoveTool)) && evt.control)
  244. TilemapEditorTool.SetActiveEditorTool(typeof(SelectTool));
  245. m_PreviousMove = null;
  246. m_MarqueeStart = mouseGridPosition;
  247. m_MarqueeType = MarqueeType.Select;
  248. s_LastActivePaintableGrid = this;
  249. GUIUtility.hotControl = m_PermanentControlID;
  250. Event.current.Use();
  251. }
  252. if (evt.rawType == EventType.MouseUp && evt.button == 0 && !evt.alt && m_MarqueeStart.HasValue && isHotControl && TilemapEditorTool.IsActive(typeof(SelectTool)))
  253. {
  254. // Check if event only occurred in the PaintableGrid window as evt.type will filter for this
  255. if (evt.type == EventType.MouseUp && m_MarqueeType == MarqueeType.Select)
  256. {
  257. RectInt rect = GridEditorUtility.GetMarqueeRect(m_MarqueeStart.Value, mouseGridPosition);
  258. Select(new BoundsInt(new Vector3Int(rect.xMin, rect.yMin, zPosition), new Vector3Int(rect.size.x, rect.size.y, 1)));
  259. Event.current.Use();
  260. }
  261. if (evt.control)
  262. TilemapEditorTool.SetActiveEditorTool(typeof(MoveTool));
  263. m_MarqueeStart = null;
  264. m_MarqueeType = MarqueeType.None;
  265. InspectorWindow.RepaintAllInspectors();
  266. GUIUtility.hotControl = 0;
  267. }
  268. if (evt.type == EventType.KeyDown && evt.keyCode == KeyCode.Escape && !m_MarqueeStart.HasValue && !m_PreviousMove.HasValue)
  269. {
  270. ClearGridSelection();
  271. Event.current.Use();
  272. }
  273. }
  274. private void HandleMoveTool()
  275. {
  276. Event evt = Event.current;
  277. if (evt.type == EventType.MouseDown && evt.button == 0 && !evt.alt && TilemapEditorTool.IsActive(typeof(MoveTool)))
  278. {
  279. RegisterUndo();
  280. Vector3Int mouse3D = new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, GridSelection.position.zMin);
  281. if (GridSelection.active && GridSelection.position.Contains(mouse3D))
  282. {
  283. GUIUtility.hotControl = m_PermanentControlID;
  284. executing = true;
  285. m_MarqueeStart = null;
  286. m_MarqueeType = MarqueeType.None;
  287. m_PreviousMove = mouseGridPosition;
  288. MoveStart(GridSelection.position);
  289. s_LastActivePaintableGrid = this;
  290. }
  291. Event.current.Use();
  292. }
  293. if (evt.type == EventType.MouseDrag && evt.button == 0 && TilemapEditorTool.IsActive(typeof(MoveTool)) && isHotControl)
  294. {
  295. if (m_MouseGridPositionChanged && m_PreviousMove.HasValue)
  296. {
  297. executing = true;
  298. BoundsInt previousRect = GridSelection.position;
  299. BoundsInt previousBounds = new BoundsInt(new Vector3Int(previousRect.xMin, previousRect.yMin, GridSelection.position.zMin), new Vector3Int(previousRect.size.x, previousRect.size.y, 1));
  300. Vector2Int direction = mouseGridPosition - m_PreviousMove.Value;
  301. BoundsInt pos = GridSelection.position;
  302. pos.position = new Vector3Int(pos.x + direction.x, pos.y + direction.y, pos.z);
  303. GridSelection.position = pos;
  304. Move(previousBounds, pos);
  305. m_PreviousMove = mouseGridPosition;
  306. Event.current.Use();
  307. }
  308. }
  309. if (evt.type == EventType.MouseUp && evt.button == 0 && m_PreviousMove.HasValue && TilemapEditorTool.IsActive(typeof(MoveTool)) && isHotControl)
  310. {
  311. m_PreviousMove = null;
  312. MoveEnd(GridSelection.position);
  313. executing = false;
  314. GUIUtility.hotControl = 0;
  315. Event.current.Use();
  316. }
  317. }
  318. private void HandleBrushPaintAndErase()
  319. {
  320. Event evt = Event.current;
  321. if (!IsPaintingEvent(evt) && !IsErasingEvent(evt))
  322. return;
  323. switch (evt.type)
  324. {
  325. case EventType.MouseDown:
  326. RegisterUndo();
  327. GUIUtility.hotControl = m_PermanentControlID;
  328. executing = true;
  329. m_TypeBeforeExecution = EditorTools.ToolManager.activeToolType;
  330. if (IsErasingEvent(evt))
  331. {
  332. if (!TilemapEditorTool.IsActive(typeof(EraseTool)))
  333. TilemapEditorTool.SetActiveEditorTool(typeof(EraseTool));
  334. Erase(new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, zPosition));
  335. }
  336. else
  337. {
  338. if (!TilemapEditorTool.IsActive(typeof(PaintTool)))
  339. TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
  340. Paint(new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, zPosition));
  341. }
  342. Event.current.Use();
  343. GUI.changed = true;
  344. break;
  345. case EventType.MouseDrag:
  346. executing = true;
  347. if (isHotControl && mouseGridPositionChanged)
  348. {
  349. List<Vector2Int> points = GridEditorUtility.GetPointsOnLine(m_PreviousMouseGridPosition, mouseGridPosition).ToList();
  350. if (points[0] == mouseGridPosition)
  351. points.Reverse();
  352. if (!evt.shift && !TilemapEditorTool.IsActive(typeof(PaintTool)) && m_TypeBeforeExecution == typeof(PaintTool))
  353. TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
  354. else if (evt.shift && TilemapEditorTool.IsActive(typeof(PaintTool)))
  355. TilemapEditorTool.SetActiveEditorTool(typeof(EraseTool));
  356. for (int i = 1; i < points.Count; i++)
  357. {
  358. if (IsErasingEvent(evt))
  359. {
  360. Erase(new Vector3Int(points[i].x, points[i].y, zPosition));
  361. }
  362. else
  363. {
  364. Paint(new Vector3Int(points[i].x, points[i].y, zPosition));
  365. }
  366. }
  367. Event.current.Use();
  368. GUI.changed = true;
  369. }
  370. break;
  371. case EventType.MouseUp:
  372. executing = false;
  373. if (isHotControl)
  374. {
  375. if (!TilemapEditorTool.IsActive(typeof(PaintTool)) && m_TypeBeforeExecution == typeof(PaintTool))
  376. {
  377. TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
  378. }
  379. Event.current.Use();
  380. GUI.changed = true;
  381. GUIUtility.hotControl = 0;
  382. }
  383. break;
  384. }
  385. }
  386. private bool IsPaintingEvent(Event evt)
  387. {
  388. return (evt.button == 0 && !evt.control && !evt.alt && TilemapEditorTool.IsActive(typeof(PaintTool)));
  389. }
  390. private bool IsErasingEvent(Event evt)
  391. {
  392. return (evt.button == 0 && !evt.control && !evt.alt
  393. && ((evt.shift && !TilemapEditorTool.IsActive(typeof(BoxTool))
  394. && !TilemapEditorTool.IsActive(typeof(FillTool))
  395. && !TilemapEditorTool.IsActive(typeof(SelectTool))
  396. && !TilemapEditorTool.IsActive(typeof(MoveTool)))
  397. || TilemapEditorTool.IsActive(typeof(EraseTool))));
  398. }
  399. private void HandleFloodFill()
  400. {
  401. if (TilemapEditorTool.IsActive(typeof(FillTool)) && GridPaintingState.gridBrush != null && ValidateFloodFillPosition(new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, 0)))
  402. {
  403. Event evt = Event.current;
  404. if (evt.type == EventType.MouseDown && evt.button == 0 && !evt.alt)
  405. {
  406. GUIUtility.hotControl = m_PermanentControlID;
  407. GUI.changed = true;
  408. executing = true;
  409. Event.current.Use();
  410. }
  411. if (evt.type == EventType.MouseUp && evt.button == 0 && isHotControl)
  412. {
  413. RegisterUndo();
  414. FloodFill(new Vector3Int(mouseGridPosition.x, mouseGridPosition.y, zPosition));
  415. executing = false;
  416. GUI.changed = true;
  417. Event.current.Use();
  418. GUIUtility.hotControl = 0;
  419. }
  420. }
  421. }
  422. private void HandleBoxTool()
  423. {
  424. Event evt = Event.current;
  425. if (evt.type == EventType.MouseDown && evt.button == 0 && !evt.alt && TilemapEditorTool.IsActive(typeof(BoxTool)))
  426. {
  427. m_MarqueeStart = mouseGridPosition;
  428. m_MarqueeType = MarqueeType.Box;
  429. Event.current.Use();
  430. GUI.changed = true;
  431. executing = true;
  432. GUIUtility.hotControl = m_PermanentControlID;
  433. }
  434. if (evt.type == EventType.MouseDrag && evt.button == 0 && TilemapEditorTool.IsActive(typeof(BoxTool)))
  435. {
  436. if (isHotControl && m_MarqueeStart.HasValue)
  437. {
  438. Event.current.Use();
  439. executing = true;
  440. GUI.changed = true;
  441. }
  442. }
  443. if (evt.type == EventType.MouseUp && evt.button == 0 && TilemapEditorTool.IsActive(typeof(BoxTool)))
  444. {
  445. if (isHotControl && m_MarqueeStart.HasValue)
  446. {
  447. RegisterUndo();
  448. RectInt rect = GridEditorUtility.GetMarqueeRect(m_MarqueeStart.Value, mouseGridPosition);
  449. if (evt.shift)
  450. BoxErase(new BoundsInt(rect.x, rect.y, zPosition, rect.size.x, rect.size.y, 1));
  451. else
  452. BoxFill(new BoundsInt(rect.x, rect.y, zPosition, rect.size.x, rect.size.y, 1));
  453. Event.current.Use();
  454. executing = false;
  455. GUI.changed = true;
  456. GUIUtility.hotControl = 0;
  457. }
  458. m_MarqueeStart = null;
  459. m_MarqueeType = MarqueeType.None;
  460. }
  461. }
  462. private Vector2Int GetMarqueePivot(Vector2Int start, Vector2Int end)
  463. {
  464. Vector2Int pivot = new Vector2Int(
  465. Math.Max(end.x - start.x, 0),
  466. Math.Max(end.y - start.y, 0)
  467. );
  468. return pivot;
  469. }
  470. public void ChangeZPosition(int change)
  471. {
  472. m_ZPosition += change;
  473. MouseGridPositionChanged();
  474. Repaint();
  475. }
  476. public void ResetZPosition()
  477. {
  478. if (m_ZPosition == 0)
  479. return;
  480. m_ZPosition = 0;
  481. MouseGridPositionChanged();
  482. Repaint();
  483. }
  484. public static bool InGridEditMode()
  485. {
  486. return UnityEditor.EditorTools.ToolManager.activeToolType != null
  487. && UnityEditor.EditorTools.ToolManager.activeToolType.IsSubclassOf(typeof(TilemapEditorTool));
  488. }
  489. // TODO: Someday EditMode or its future incarnation will be public and we can get rid of this
  490. // TODO: Temporarily use ActiveTool's type to determine brush tool
  491. public static GridBrushBase.Tool EditTypeToBrushTool(Type activeToolType)
  492. {
  493. if (activeToolType == typeof(BoxTool))
  494. return GridBrushBase.Tool.Box;
  495. if (activeToolType == typeof(EraseTool))
  496. return GridBrushBase.Tool.Erase;
  497. if (activeToolType == typeof(FillTool))
  498. return GridBrushBase.Tool.FloodFill;
  499. if (activeToolType == typeof(PaintTool))
  500. return GridBrushBase.Tool.Paint;
  501. if (activeToolType == typeof(PickingTool))
  502. return GridBrushBase.Tool.Pick;
  503. if (activeToolType == typeof(SelectTool))
  504. return GridBrushBase.Tool.Select;
  505. if (activeToolType == typeof(MoveTool))
  506. return GridBrushBase.Tool.Move;
  507. return GridBrushBase.Tool.Paint;
  508. }
  509. }
  510. }