Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / tileSetEditorCombination / leftTop / RectBrush.cs
@小李xl 小李xl on 18 Dec 2023 1 KB 导入组合图块, 开发中
  1. using Godot;
  2.  
  3. namespace UI.TileSetEditorCombination;
  4.  
  5. public partial class RectBrush : Node2D
  6. {
  7. /// <summary>
  8. /// 所在的根节点
  9. /// </summary>
  10. public Control Root { get; set; }
  11.  
  12. private bool _drawFlag = false;
  13. private int _x;
  14. private int _y;
  15. private int _w;
  16. private int _h;
  17. public override void _Process(double delta)
  18. {
  19. QueueRedraw();
  20. }
  21.  
  22. /// <summary>
  23. /// 停止绘制
  24. /// </summary>
  25. public void ClearDrawRect()
  26. {
  27. _drawFlag = false;
  28. }
  29.  
  30. /// <summary>
  31. /// 设置绘制的矩形区域
  32. /// </summary>
  33. public void SetDrawRect(int x, int y, int w, int h)
  34. {
  35. _drawFlag = true;
  36. _x = x;
  37. _y = y;
  38. _w = w;
  39. _h = h;
  40. }
  41.  
  42. /// <summary>
  43. /// 获取原点坐标, 单位: 像素
  44. /// </summary>
  45. public Vector2I GetOriginPosition()
  46. {
  47. return new Vector2I(_x, _y);
  48. }
  49.  
  50. /// <summary>
  51. /// 获取中心点坐标, 单位: 像素
  52. /// </summary>
  53. public Vector2I GetCenterPosition()
  54. {
  55. if (!_drawFlag)
  56. {
  57. return Vector2I.Zero;
  58. }
  59. return new Vector2I(_x + _w / 2, _y + _h / 2);
  60. }
  61.  
  62. /// <summary>
  63. /// 获取绘制的矩形大小, 单位: 像素
  64. /// </summary>
  65. public Vector2I GetRectSize()
  66. {
  67. if (!_drawFlag)
  68. {
  69. return Vector2I.Zero;
  70. }
  71.  
  72. return new Vector2I(_w, _h);
  73. }
  74.  
  75. public override void _Draw()
  76. {
  77. if (Root != null && _drawFlag)
  78. {
  79. DrawRect(new Rect2(_x, _y, _w, _h), new Color(1, 1, 0, 0.5f), false, 2f / Root.Scale.X);
  80. }
  81. }
  82. }