Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / tileSetEditorTerrain / up / TerrainBrush.cs
@小李xl 小李xl on 5 Jan 2024 1 KB 继续开发TileSet地形编辑器
  1. using System.Collections.Generic;
  2. using Godot;
  3.  
  4. namespace UI.TileSetEditorTerrain;
  5.  
  6. public partial class TerrainBrush : Control
  7. {
  8. public Control Root { get; set; }
  9. public List<Control> TerrainTextureList { get; } = new List<Control>();
  10.  
  11. public override void _Process(double delta)
  12. {
  13. QueueRedraw();
  14. }
  15.  
  16. public override void _Draw()
  17. {
  18. var scale = Root.Scale;
  19. //绘制区域
  20. foreach (var control in TerrainTextureList)
  21. {
  22. DrawRect(
  23. new Rect2(control.Position, control.Size.AsVector2I()), new Color(1, 1, 0, 0.5f), false,
  24. 2f / scale.X
  25. );
  26. }
  27.  
  28. //绘制鼠标悬停区域
  29. foreach (var control in TerrainTextureList)
  30. {
  31. if (control.IsMouseInRect())
  32. {
  33. var pos = Utils.GetMouseCellPosition(control) * GameConfig.TileCellSize;
  34. DrawRect(
  35. new Rect2(pos + control.Position,GameConfig.TileCellSizeVector2I),
  36. Colors.Green, false, 3f / scale.X
  37. );
  38. break;
  39. }
  40. }
  41. }
  42. }