Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / editorTileImage / RectBrush.cs
@小李xl 小李xl on 21 Jan 2024 1 KB TileSet导入纹理设置
  1. using Godot;
  2.  
  3. namespace UI.EditorTileImage;
  4.  
  5. public partial class RectBrush : Control, IUiNodeScript
  6. {
  7. private Control _parent;
  8. private EditorTileImage.Brush UiNode;
  9. public void SetUiNode(IUiNode uiNode)
  10. {
  11. UiNode = (EditorTileImage.Brush)uiNode;
  12. _parent = GetParent<Control>();
  13. }
  14.  
  15. public void OnDestroy()
  16. {
  17. }
  18. public override void _Process(double delta)
  19. {
  20. if (UiNode.UiPanel.UseImage != null)
  21. {
  22. QueueRedraw();
  23. }
  24. }
  25.  
  26. public override void _Draw()
  27. {
  28. var panel = UiNode.UiPanel;
  29. if (panel.UseImage != null)
  30. {
  31. var sx = _parent.Scale.X;
  32. var size = panel.ImageSize;
  33. var lineWidth = 2f / sx;
  34. var lineWidthHalf = new Vector2(lineWidth / 2f, lineWidth / 2f);
  35. DrawRect(new Rect2(Vector2.Zero, size), Colors.Yellow, false, lineWidth);
  36.  
  37. var start = new Vector2(panel.StartXValue, panel.StartYValue);
  38. for (int i = 0; i < panel.HCountValue; i++)
  39. {
  40. for (int j = 0; j < panel.VCountValue; j++)
  41. {
  42. var offset = new Vector2(i * (panel.OffsetXValue + GameConfig.TileCellSize), j * (panel.OffsetYValue + GameConfig.TileCellSize));
  43. DrawRect(
  44. new Rect2(
  45. start + offset + lineWidthHalf,
  46. new Vector2(GameConfig.TileCellSize, GameConfig.TileCellSize) - new Vector2(lineWidth, lineWidth)
  47. ),
  48. new Color(0, 1, 0, 0.5f), false, lineWidth
  49. );
  50. }
  51. }
  52. }
  53. }
  54. }