Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / mapEditorTools / DoorHoverArea.cs
@小李xl 小李xl on 27 Jul 2023 2 KB 创建拖拽区域
  1. using Godot;
  2. using UI.MapEditorTools;
  3.  
  4. public partial class DoorHoverArea : ColorRect
  5. {
  6. /// <summary>
  7. /// 所属 Ui 对象
  8. /// </summary>
  9. public MapEditorToolsPanel MapEditorToolsPanel { get; private set; }
  10.  
  11. /// <summary>
  12. /// 房间门的朝向
  13. /// </summary>
  14. public DoorDirection Direction { get; private set; }
  15. /// <summary>
  16. /// 是否拖拽中
  17. /// </summary>
  18. public bool IsDrag { get; private set; }
  19.  
  20. private bool _mouseHover;
  21. private Control _parent;
  22. public override void _Ready()
  23. {
  24. _parent = GetParent<Control>();
  25. MouseEntered += OnMouseEnter;
  26. MouseExited += OnMouseExit;
  27. }
  28.  
  29. public void Init(MapEditorToolsPanel panel, DoorDirection direction)
  30. {
  31. MapEditorToolsPanel = panel;
  32. Direction = direction;
  33. }
  34.  
  35. public override void _Process(double delta)
  36. {
  37. if (_mouseHover && MapEditorToolsPanel.ActiveHoverArea == this)
  38. {
  39. var start = Utils.Adsorption(_parent.GetLocalMousePosition().X, GameConfig.TileCellSize);
  40. MapEditorToolsPanel.S_HoverPreviewRoot.Instance.Position = new Vector2(start, 0);
  41. if (!IsDrag)
  42. {
  43. if (Input.IsMouseButtonPressed(MouseButton.Left))
  44. {
  45. GD.Print("开始...");
  46. IsDrag = true;
  47. MapEditorToolsPanel.CreateDragDoorTool(_parent.Position, Direction, start, OnSubmitDoorArea);
  48. }
  49. }
  50. else
  51. {
  52. if (!Input.IsMouseButtonPressed(MouseButton.Left))
  53. {
  54. GD.Print("结束...");
  55. IsDrag = false;
  56. }
  57. }
  58. }
  59. }
  60.  
  61. //提交门区域
  62. private void OnSubmitDoorArea(int start, int end)
  63. {
  64. }
  65. private void OnMouseEnter()
  66. {
  67. if (MapEditorToolsPanel.ActiveHoverArea == null || !MapEditorToolsPanel.ActiveHoverArea.IsDrag)
  68. {
  69. _mouseHover = true;
  70. MapEditorToolsPanel.SetActiveHoverArea(this);
  71. }
  72. }
  73. private void OnMouseExit()
  74. {
  75. if (MapEditorToolsPanel.ActiveHoverArea == null || !MapEditorToolsPanel.ActiveHoverArea.IsDrag)
  76. {
  77. _mouseHover = false;
  78. if (MapEditorToolsPanel.ActiveHoverArea == this)
  79. {
  80. MapEditorToolsPanel.SetActiveHoverArea(null);
  81. }
  82. }
  83. }
  84. }