Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / tileSetEditorTerrain / right / TerrainCellDropHandler.cs
@小李xl 小李xl on 23 Dec 2023 1 KB 编辑TileSet地形, 制作中
  1. using Godot;
  2.  
  3. namespace UI.TileSetEditorTerrain;
  4.  
  5. public partial class TerrainCellDropHandler : Control
  6. {
  7. /// <summary>
  8. /// 是否放置了图块
  9. /// </summary>
  10. public bool IsPutDownTexture { get; set; }
  11. private TerrainCell _cell;
  12. private TileSetEditorTerrainPanel _panel;
  13. public void Init(TerrainCell cell)
  14. {
  15. _cell = cell;
  16. _panel = cell.CellNode.UiPanel;
  17. }
  18. public override bool _CanDropData(Vector2 atPosition, Variant data)
  19. {
  20. return data.VariantType == Variant.Type.Rect2I;
  21. }
  22. public override void _DropData(Vector2 atPosition, Variant data)
  23. {
  24. var rect = data.AsRect2I();
  25. var sprite2D = _cell.CellNode.L_CellTexture.Instance;
  26. sprite2D.Texture = _panel.EditorPanel.Texture;
  27. sprite2D.RegionEnabled = true;
  28. sprite2D.RegionRect = rect;
  29. IsPutDownTexture = true;
  30. }
  31.  
  32. public override void _GuiInput(InputEvent @event)
  33. {
  34. //右键擦除图块
  35. if (@event is InputEventMouseButton mouseEvent && mouseEvent.ButtonIndex == MouseButton.Right && mouseEvent.Pressed)
  36. {
  37. AcceptEvent();
  38. _cell.CellNode.L_CellTexture.Instance.Texture = null;
  39. IsPutDownTexture = false;
  40. }
  41. }
  42. }