Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / common / ui / EditorMaskBrush.cs
@小李xl 小李xl on 23 Dec 2023 1 KB 编辑TileSet地形, 制作中
  1. using Godot;
  2. using UI.TileSetEditor;
  3.  
  4. /// <summary>
  5. /// 地图编辑器通用遮罩笔刷
  6. /// </summary>
  7. public partial class EditorMaskBrush : Control
  8. {
  9. /// <summary>
  10. /// 绑定的地图纹理节点
  11. /// </summary>
  12. public TextureRect TileTexture { get; private set; }
  13. /// <summary>
  14. /// 绑定的 TileSetEditorPanel Ui
  15. /// </summary>
  16. public TileSetEditorPanel TileSetEditorPanel { get; private set; }
  17.  
  18. /// <summary>
  19. /// 初始化笔刷数绑定的节点
  20. /// </summary>
  21. public void Init(TextureRect tileTexture, TileSetEditorPanel tileSetEditorPanel)
  22. {
  23. TileTexture = tileTexture;
  24. TileSetEditorPanel = tileSetEditorPanel;
  25. }
  26. public override void _Process(double delta)
  27. {
  28. QueueRedraw();
  29. }
  30.  
  31. public override void _Draw()
  32. {
  33. if (TileTexture == null)
  34. {
  35. return;
  36. }
  37. //绘制texture区域
  38. if (TileTexture.Texture != null)
  39. {
  40. DrawRect(
  41. new Rect2(Vector2.Zero, TileSetEditorPanel.CellHorizontal * GameConfig.TileCellSize, TileSetEditorPanel.CellVertical * GameConfig.TileCellSize),
  42. new Color(1, 1, 0, 0.5f), false,
  43. 2f / TileTexture.Scale.X
  44. );
  45. }
  46.  
  47. //绘制鼠标悬停区域
  48. if (TileTexture.IsMouseInRect())
  49. {
  50. var pos = Utils.GetMouseCellPosition(TileTexture) * GameConfig.TileCellSize;
  51. DrawRect(
  52. new Rect2(pos,GameConfig.TileCellSizeVector2I),
  53. Colors.Green, false, 3f / TileTexture.Scale.X
  54. );
  55. }
  56. }
  57. }