Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / tileSetEditorTerrain / up / TerrainBrush.cs
@小李xl 小李xl on 11 Jan 2024 1 KB 制作2x2地形
  1. using System.Collections.Generic;
  2. using Godot;
  3.  
  4. namespace UI.TileSetEditorTerrain;
  5.  
  6. public partial class TerrainBrush : Control, IUiNodeScript
  7. {
  8. public Control Root { get; set; }
  9. public List<Control> TerrainTextureList { get; } = new List<Control>();
  10.  
  11. private TileSetEditorTerrain.Brush _uiNode;
  12.  
  13. public void SetUiNode(IUiNode uiNode)
  14. {
  15. _uiNode = (TileSetEditorTerrain.Brush) uiNode;
  16. }
  17.  
  18. public void OnDestroy()
  19. {
  20. }
  21.  
  22. public override void _Process(double delta)
  23. {
  24. QueueRedraw();
  25. }
  26.  
  27. public override void _Draw()
  28. {
  29. var scale = Root.Scale;
  30.  
  31. //绘制区域
  32. for (var i = 0; i < TerrainTextureList.Count; i++)
  33. {
  34. var control = TerrainTextureList[i];
  35. if (control.Visible)
  36. {
  37. DrawRect(
  38. new Rect2(control.Position, control.Size.AsVector2I()), new Color(1, 1, 0, 0.5f), false,
  39. 2f / scale.X
  40. );
  41. }
  42. }
  43. //绘制鼠标悬停区域
  44. for (var i = 0; i < TerrainTextureList.Count; i++)
  45. {
  46. var control = TerrainTextureList[i];
  47. if (control.Visible && control.IsMouseInRect())
  48. {
  49. var pos = Utils.GetMouseCellPosition(control) * GameConfig.TileCellSize;
  50. DrawRect(
  51. new Rect2(pos + control.Position, GameConfig.TileCellSizeVector2I),
  52. Colors.Green, false, 3f / scale.X
  53. );
  54. break;
  55. }
  56. }
  57. }
  58. }