diff --git a/DungeonShooting_Godot/prefab/ui/MapEditorTools.tscn b/DungeonShooting_Godot/prefab/ui/MapEditorTools.tscn index d4d4e18..1035eed 100644 --- a/DungeonShooting_Godot/prefab/ui/MapEditorTools.tscn +++ b/DungeonShooting_Godot/prefab/ui/MapEditorTools.tscn @@ -61,6 +61,7 @@ anchors_preset = 2 anchor_top = 1.0 anchor_bottom = 1.0 +offset_left = -9.12665e-05 offset_top = -36.0 offset_right = 160.0 grow_vertical = 0 @@ -83,20 +84,21 @@ color = Color(1, 1, 1, 0) script = ExtResource("2_6qfy3") -[node name="HoverPrevRoot" type="Control" parent="DoorToolRoot"] +[node name="HoverPreviewRoot" type="Control" parent="DoorToolRoot"] +visible = false anchors_preset = 0 mouse_filter = 2 -[node name="HoverPrev" type="TextureRect" parent="DoorToolRoot/HoverPrevRoot"] +[node name="HoverPreview" type="TextureRect" parent="DoorToolRoot/HoverPreviewRoot"] layout_mode = 1 anchors_preset = 7 anchor_left = 0.5 anchor_top = 1.0 anchor_right = 0.5 anchor_bottom = 1.0 -offset_left = -1.5 +offset_left = -2.0 offset_top = -36.0 -offset_right = 1.5 +offset_right = 2.0 grow_horizontal = 2 grow_vertical = 0 mouse_filter = 2 @@ -123,7 +125,7 @@ anchor_top = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 -offset_left = -3.0 +offset_left = -4.0 offset_top = -36.0 grow_horizontal = 0 grow_vertical = 0 @@ -139,7 +141,7 @@ anchor_bottom = 1.0 offset_left = 64.0 offset_top = -36.0 -offset_right = 67.0 +offset_right = 68.0 grow_vertical = 0 texture_normal = ExtResource("3_trbb5") stretch_mode = 0 diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs index d393db6..ed838c0 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs @@ -1,4 +1,5 @@ -using Godot; +using System; +using Godot; namespace UI.MapEditorTools; @@ -28,6 +29,12 @@ private bool _canComment = true; //开始拖拽时的区域 private Vector2I _startDragRange; + //是否是拖拽模式 + private bool _isDragMode = false; + //拖拽模式提交回调 + private Action _onSubmit; + //拖拽模式取消时回调 + private Action _onCancel; public void SetDoorDragAreaNode(MapEditorTools.DoorToolTemplate node) { @@ -40,6 +47,32 @@ SetDoorAreaDirection(DoorDirection.N); } + public override void _Process(double delta) + { + if (_isDragMode) + { + if (!Input.IsMouseButtonPressed(MouseButton.Left)) //松开了右键 + { + _isDragMode = false; + if (_canComment) //可以提交 + { + if (_onSubmit != null) + { + var doorAreaRange = GetDoorAreaRange(); + _onSubmit(doorAreaRange.X, doorAreaRange.Y); + } + } + else //不能提交 + { + if (_onCancel != null) + { + _onCancel(); + } + } + } + } + } + /// /// 设置门区域的位置, 单位: 像素 /// @@ -98,6 +131,18 @@ } /// + /// 设置区域起始坐标 + /// + public void SetDoorAreaStart(int start) + { + var startPosition = _node.L_StartBtn.Instance.Position; + startPosition.X = start - _node.L_StartBtn.Instance.Size.X; + _node.L_StartBtn.Instance.Position = startPosition; + + RefreshArea(); + } + + /// /// 设置区域大小, 单位: 像素 /// public void SetDoorAreaSize(int value) @@ -230,4 +275,18 @@ } } } + + /// + /// 将该区域变为拖拽模式, 用于创建门区域 + /// + /// 成功提交时回调, 参数1为起始点, 参数2为大小 + /// 取消时调用 + public void MakeDragMode(Action onSubmit, Action onCancel) + { + _canComment = false; + _isDragMode = true; + _onSubmit = onSubmit; + _onCancel = onCancel; + _node.L_EndBtn.Instance.EmitSignal(BaseButton.SignalName.ButtonDown); + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorHoverArea.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorHoverArea.cs index c2c017c..c366953 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorHoverArea.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorHoverArea.cs @@ -12,13 +12,13 @@ /// 房间门的朝向 /// public DoorDirection Direction { get; private set; } + /// + /// 是否拖拽中 + /// + public bool IsDrag { get; private set; } private bool _mouseHover; - private bool _isDrag; private Control _parent; - - private MapEditorTools.DoorToolTemplate _dragArea; - private MapEditorTools.HoverPrevRoot _cloneRoot; public override void _Ready() { @@ -35,37 +35,40 @@ public override void _Process(double delta) { - if (_mouseHover && MapEditorToolsPanel.ActiveHoverArea == this) { - var globalPosition = _parent.GlobalPosition; var start = Utils.Adsorption(_parent.GetLocalMousePosition().X, GameConfig.TileCellSize); - //MapEditorToolsPanel.S_HoverPrevRoot.Instance.Visible = true; - //MapEditorToolsPanel.S_HoverPrevRoot.Instance.GlobalPosition = new Vector2(); + MapEditorToolsPanel.S_HoverPreviewRoot.Instance.Position = new Vector2(start, 0); - if (!_isDrag) + if (!IsDrag) { if (Input.IsMouseButtonPressed(MouseButton.Left)) { - _isDrag = true; - _dragArea = MapEditorToolsPanel.CreateDoorTool(globalPosition, Direction, start, 4 * GameConfig.TileCellSize); + GD.Print("开始..."); + IsDrag = true; + MapEditorToolsPanel.CreateDragDoorTool(_parent.Position, Direction, start, OnSubmitDoorArea); } } else { if (!Input.IsMouseButtonPressed(MouseButton.Left)) { - _isDrag = false; - MapEditorToolsPanel.RemoveDoorTool(_dragArea); - _dragArea = null; + GD.Print("结束..."); + IsDrag = false; } } } } + //提交门区域 + private void OnSubmitDoorArea(int start, int end) + { + + } + private void OnMouseEnter() { - if (MapEditorToolsPanel.ActiveHoverArea == null || !MapEditorToolsPanel.ActiveHoverArea._isDrag) + if (MapEditorToolsPanel.ActiveHoverArea == null || !MapEditorToolsPanel.ActiveHoverArea.IsDrag) { _mouseHover = true; MapEditorToolsPanel.SetActiveHoverArea(this); @@ -74,10 +77,13 @@ private void OnMouseExit() { - if (MapEditorToolsPanel.ActiveHoverArea == null || !MapEditorToolsPanel.ActiveHoverArea._isDrag) + if (MapEditorToolsPanel.ActiveHoverArea == null || !MapEditorToolsPanel.ActiveHoverArea.IsDrag) { _mouseHover = false; - MapEditorToolsPanel.S_HoverPrevRoot.Instance.Visible = false; + if (MapEditorToolsPanel.ActiveHoverArea == this) + { + MapEditorToolsPanel.SetActiveHoverArea(null); + } } } } diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorTools.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorTools.cs index 8d6ccc4..2549a3d 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorTools.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorTools.cs @@ -165,34 +165,34 @@ } /// - /// 类型: , 路径: MapEditorTools.DoorToolRoot.HoverPrevRoot.HoverPrev + /// 类型: , 路径: MapEditorTools.DoorToolRoot.HoverPreviewRoot.HoverPreview /// - public class HoverPrev : UiNode + public class HoverPreview : UiNode { - public HoverPrev(MapEditorTools uiPanel, Godot.TextureRect node) : base(uiPanel, node) { } - public override HoverPrev Clone() => new (UiPanel, (Godot.TextureRect)Instance.Duplicate()); + public HoverPreview(MapEditorTools uiPanel, Godot.TextureRect node) : base(uiPanel, node) { } + public override HoverPreview Clone() => new (UiPanel, (Godot.TextureRect)Instance.Duplicate()); } /// - /// 类型: , 路径: MapEditorTools.DoorToolRoot.HoverPrevRoot + /// 类型: , 路径: MapEditorTools.DoorToolRoot.HoverPreviewRoot /// - public class HoverPrevRoot : UiNode + public class HoverPreviewRoot : UiNode { /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: MapEditorTools.DoorToolRoot.HoverPrev + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: MapEditorTools.DoorToolRoot.HoverPreview /// - public HoverPrev L_HoverPrev + public HoverPreview L_HoverPreview { get { - if (_L_HoverPrev == null) _L_HoverPrev = new HoverPrev(UiPanel, Instance.GetNodeOrNull("HoverPrev")); - return _L_HoverPrev; + if (_L_HoverPreview == null) _L_HoverPreview = new HoverPreview(UiPanel, Instance.GetNodeOrNull("HoverPreview")); + return _L_HoverPreview; } } - private HoverPrev _L_HoverPrev; + private HoverPreview _L_HoverPreview; - public HoverPrevRoot(MapEditorTools uiPanel, Godot.Control node) : base(uiPanel, node) { } - public override HoverPrevRoot Clone() => new (UiPanel, (Godot.Control)Instance.Duplicate()); + public HoverPreviewRoot(MapEditorTools uiPanel, Godot.Control node) : base(uiPanel, node) { } + public override HoverPreviewRoot Clone() => new (UiPanel, (Godot.Control)Instance.Duplicate()); } /// @@ -328,17 +328,17 @@ private W_HoverRoot _L_W_HoverRoot; /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: MapEditorTools.HoverPrevRoot + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: MapEditorTools.HoverPreviewRoot /// - public HoverPrevRoot L_HoverPrevRoot + public HoverPreviewRoot L_HoverPreviewRoot { get { - if (_L_HoverPrevRoot == null) _L_HoverPrevRoot = new HoverPrevRoot(UiPanel, Instance.GetNodeOrNull("HoverPrevRoot")); - return _L_HoverPrevRoot; + if (_L_HoverPreviewRoot == null) _L_HoverPreviewRoot = new HoverPreviewRoot(UiPanel, Instance.GetNodeOrNull("HoverPreviewRoot")); + return _L_HoverPreviewRoot; } } - private HoverPrevRoot _L_HoverPrevRoot; + private HoverPreviewRoot _L_HoverPreviewRoot; /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: MapEditorTools.DoorToolTemplate @@ -496,14 +496,14 @@ public W_HoverRoot S_W_HoverRoot => L_DoorToolRoot.L_W_HoverRoot; /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: MapEditorTools.DoorToolRoot.HoverPrevRoot.HoverPrev + /// 场景中唯一名称的节点, 节点类型: , 节点路径: MapEditorTools.DoorToolRoot.HoverPreviewRoot.HoverPreview /// - public HoverPrev S_HoverPrev => L_DoorToolRoot.L_HoverPrevRoot.L_HoverPrev; + public HoverPreview S_HoverPreview => L_DoorToolRoot.L_HoverPreviewRoot.L_HoverPreview; /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: MapEditorTools.DoorToolRoot.HoverPrevRoot + /// 场景中唯一名称的节点, 节点类型: , 节点路径: MapEditorTools.DoorToolRoot.HoverPreviewRoot /// - public HoverPrevRoot S_HoverPrevRoot => L_DoorToolRoot.L_HoverPrevRoot; + public HoverPreviewRoot S_HoverPreviewRoot => L_DoorToolRoot.L_HoverPreviewRoot; /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: MapEditorTools.DoorToolRoot.DoorToolTemplate.DoorArea diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs index 1def4ae..269f884 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using Godot; @@ -31,17 +32,25 @@ S_DoorToolTemplate.Instance.QueueFree(); } + public override void Process(float delta) + { + S_HoverPreviewRoot.Instance.Visible = ActiveHoverArea != null && !ActiveHoverArea.IsDrag; + } + /// /// 设置活动的鼠标悬停的区域 /// public void SetActiveHoverArea(DoorHoverArea hoverArea) { ActiveHoverArea = hoverArea; - // if (hoverArea != null) - // { - // S_HoverPrevRoot.Instance.Reparent(hoverArea.GetParent(), false); - // S_HoverPrevRoot.Instance.Visible = false; - // } + if (hoverArea != null) + { + S_HoverPreviewRoot.Instance.Reparent(hoverArea.GetParent(), false); + } + else + { + S_HoverPreviewRoot.Instance.Reparent(S_DoorToolRoot.Instance, false); + } } /// @@ -61,6 +70,28 @@ } /// + /// 创建拖拽状态下的门区域工具, 用于创建门区域 + /// + /// 原点坐标, 单位: 像素 + /// 方向 + /// 起始位置, 单位: 像素 + /// 成功提交时回调, 参数1为起始点, 参数2为大小 + public void CreateDragDoorTool(Vector2 position, DoorDirection direction, int start, Action onSubmit) + { + var inst = CreateDoorToolInstance(); + inst.Instance.SetDoorAreaPosition(position); + inst.Instance.SetDoorAreaDirection(direction); + inst.Instance.SetDoorAreaRange(start, 0); + inst.Instance.MakeDragMode( + (s, e) => + { + RemoveDoorTool(inst); + onSubmit(s, e); + }, + () => RemoveDoorTool(inst)); + } + + /// /// 移除门区域设置工具 /// public void RemoveDoorTool(DoorToolTemplate toolInstance)