diff --git a/DungeonShooting_Godot/src/framework/common/NodeExtend.cs b/DungeonShooting_Godot/src/framework/common/NodeExtend.cs
index f9bea2d..8ef3c99 100644
--- a/DungeonShooting_Godot/src/framework/common/NodeExtend.cs
+++ b/DungeonShooting_Godot/src/framework/common/NodeExtend.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections;
using Godot;
///
@@ -49,4 +50,94 @@
{
GameApplication.Instance.World.GetRoomLayer(layer).AddChild(node);
}
+
+ ///
+ /// 延时指定时间调用一个回调函数
+ ///
+ public static void CallDelay(this ICoroutine coroutine, float delayTime, Action cb)
+ {
+ coroutine.StartCoroutine(_CallDelay(delayTime, cb));
+ }
+
+ ///
+ /// 延时指定时间调用一个回调函数
+ ///
+ public static void CallDelay(this ICoroutine coroutine, float delayTime, Action cb, T1 arg1)
+ {
+ coroutine.StartCoroutine(_CallDelay(delayTime, cb, arg1));
+ }
+
+ ///
+ /// 延时指定时间调用一个回调函数
+ ///
+ public static void CallDelay(this ICoroutine coroutine, float delayTime, Action cb, T1 arg1, T2 arg2)
+ {
+ coroutine.StartCoroutine(_CallDelay(delayTime, cb, arg1, arg2));
+ }
+
+ ///
+ /// 延时指定时间调用一个回调函数
+ ///
+ public static void CallDelay(this ICoroutine coroutine, float delayTime, Action cb, T1 arg1, T2 arg2, T3 arg3)
+ {
+ coroutine.StartCoroutine(_CallDelay(delayTime, cb, arg1, arg2, arg3));
+ }
+
+ //---------------------------
+
+ ///
+ /// 延时指定时间调用一个回调函数
+ ///
+ public static void CallDelayInNode(this Node node, float delayTime, Action cb)
+ {
+ GameApplication.Instance.StartCoroutine(_CallDelay(delayTime, cb));
+ }
+
+ ///
+ /// 延时指定时间调用一个回调函数
+ ///
+ public static void CallDelayInNode(this Node node, float delayTime, Action cb, T1 arg1)
+ {
+ GameApplication.Instance.StartCoroutine(_CallDelay(delayTime, cb, arg1));
+ }
+
+ ///
+ /// 延时指定时间调用一个回调函数
+ ///
+ public static void CallDelayInNode(this Node node, float delayTime, Action cb, T1 arg1, T2 arg2)
+ {
+ GameApplication.Instance.StartCoroutine(_CallDelay(delayTime, cb, arg1, arg2));
+ }
+
+ ///
+ /// 延时指定时间调用一个回调函数
+ ///
+ public static void CallDelayInNode(this Node node, float delayTime, Action cb, T1 arg1, T2 arg2, T3 arg3)
+ {
+ GameApplication.Instance.StartCoroutine(_CallDelay(delayTime, cb, arg1, arg2, arg3));
+ }
+
+ private static IEnumerator _CallDelay(float delayTime, Action cb)
+ {
+ yield return new WaitForSeconds(delayTime);
+ cb();
+ }
+
+ private static IEnumerator _CallDelay(float delayTime, Action cb, T1 arg1)
+ {
+ yield return new WaitForSeconds(delayTime);
+ cb(arg1);
+ }
+
+ private static IEnumerator _CallDelay(float delayTime, Action cb, T1 arg1, T2 arg2)
+ {
+ yield return new WaitForSeconds(delayTime);
+ cb(arg1, arg2);
+ }
+
+ private static IEnumerator _CallDelay(float delayTime, Action cb, T1 arg1, T2 arg2, T3 arg3)
+ {
+ yield return new WaitForSeconds(delayTime);
+ cb(arg1,arg2, arg3);
+ }
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/framework/common/Utils.cs b/DungeonShooting_Godot/src/framework/common/Utils.cs
index 2148b40..c1ce0a2 100644
--- a/DungeonShooting_Godot/src/framework/common/Utils.cs
+++ b/DungeonShooting_Godot/src/framework/common/Utils.cs
@@ -1,6 +1,3 @@
-using System;
-using System.Collections;
-using System.Linq;
using Godot;
///
@@ -163,61 +160,4 @@
return position.X >= globalPosition.X && position.X <= (globalPosition.X + size.X) &&
position.Y >= globalPosition.Y && position.Y <= (globalPosition.Y + size.Y);
}
-
-
- ///
- /// 延时指定时间调用一个回调函数
- ///
- public static void CallDelay(this ICoroutine coroutine, float delayTime, Action cb)
- {
- coroutine.StartCoroutine(_CallDelay(delayTime, cb));
- }
-
- ///
- /// 延时指定时间调用一个回调函数
- ///
- public static void CallDelay(this ICoroutine coroutine, float delayTime, Action cb, T1 arg1)
- {
- coroutine.StartCoroutine(_CallDelay(delayTime, cb, arg1));
- }
-
- ///
- /// 延时指定时间调用一个回调函数
- ///
- public static void CallDelay(this ICoroutine coroutine, float delayTime, Action cb, T1 arg1, T2 arg2)
- {
- coroutine.StartCoroutine(_CallDelay(delayTime, cb, arg1, arg2));
- }
-
- ///
- /// 延时指定时间调用一个回调函数
- ///
- public static void CallDelay(this ICoroutine coroutine, float delayTime, Action cb, T1 arg1, T2 arg2, T3 arg3)
- {
- coroutine.StartCoroutine(_CallDelay(delayTime, cb, arg1, arg2, arg3));
- }
-
- private static IEnumerator _CallDelay(float delayTime, Action cb)
- {
- yield return new WaitForSeconds(delayTime);
- cb();
- }
-
- private static IEnumerator _CallDelay(float delayTime, Action cb, T1 arg1)
- {
- yield return new WaitForSeconds(delayTime);
- cb(arg1);
- }
-
- private static IEnumerator _CallDelay(float delayTime, Action cb, T1 arg1, T2 arg2)
- {
- yield return new WaitForSeconds(delayTime);
- cb(arg1, arg2);
- }
-
- private static IEnumerator _CallDelay(float delayTime, Action cb, T1 arg1, T2 arg2, T3 arg3)
- {
- yield return new WaitForSeconds(delayTime);
- cb(arg1,arg2, arg3);
- }
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs
index ed838c0..f1268a5 100644
--- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs
+++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs
@@ -17,6 +17,9 @@
/// 朝向
///
public DoorDirection Direction { get; private set; }
+
+ private DoorDragButton _startButton;
+ private DoorDragButton _endButton;
private MapEditorTools.DoorToolTemplate _node;
private Vector2 _startTempPos;
@@ -40,8 +43,11 @@
{
_node = node;
_defaultColor = _node.L_DoorArea.Instance.Color;
- _node.L_StartBtn.Instance.DragEvent += OnStartAreaDrag;
- _node.L_EndBtn.Instance.DragEvent += OnEndAreaDrag;
+ _startButton = _node.L_StartBtn.Instance;
+ _endButton = _node.L_EndBtn.Instance;
+
+ _startButton.DragEvent += OnStartAreaDrag;
+ _endButton.DragEvent += OnEndAreaDrag;
SetDoorAreaSize(GameConfig.TileCellSize * 4);
SetDoorAreaDirection(DoorDirection.N);
@@ -56,10 +62,15 @@
_isDragMode = false;
if (_canComment) //可以提交
{
+ _isDragMode = false;
+ _onCancel = null;
+ _startButton.EmitSignal(BaseButton.SignalName.ButtonUp);
+ _endButton.EmitSignal(BaseButton.SignalName.ButtonUp);
if (_onSubmit != null)
{
var doorAreaRange = GetDoorAreaRange();
_onSubmit(doorAreaRange.X, doorAreaRange.Y);
+ _onSubmit = null;
}
}
else //不能提交
@@ -115,7 +126,7 @@
///
public Vector2I GetDoorAreaRange()
{
- return new Vector2I((int)(_node.L_StartBtn.Instance.Position.X + _node.L_StartBtn.Instance.Size.X), _areaSize);
+ return new Vector2I((int)(_startButton.Position.X + _startButton.Size.X), _areaSize);
}
///
@@ -123,9 +134,9 @@
///
public void SetDoorAreaRange(int start, int size)
{
- var startPosition = _node.L_StartBtn.Instance.Position;
- startPosition.X = start - _node.L_StartBtn.Instance.Size.X;
- _node.L_StartBtn.Instance.Position = startPosition;
+ var startPosition = _startButton.Position;
+ startPosition.X = start - _startButton.Size.X;
+ _startButton.Position = startPosition;
SetDoorAreaSize(size);
}
@@ -135,9 +146,9 @@
///
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;
+ var startPosition = _startButton.Position;
+ startPosition.X = start - _startButton.Size.X;
+ _startButton.Position = startPosition;
RefreshArea();
}
@@ -149,7 +160,7 @@
{
_areaSize = value;
RefreshArea();
- GD.Print("size: " + GetDoorAreaRange());
+ //GD.Print("size: " + GetDoorAreaRange());
}
//刷新区域位置
@@ -157,13 +168,13 @@
{
var colorRect = _node.L_DoorArea.Instance;
var position = colorRect.Position;
- position.X = _node.L_StartBtn.Instance.Position.X + _node.L_StartBtn.Instance.Size.X;
+ position.X = _startButton.Position.X + _startButton.Size.X;
colorRect.Position = position;
colorRect.Size = AreaSize;
- var position2 = _node.L_EndBtn.Instance.Position;
+ var position2 = _endButton.Position;
position2.X = position.X + AreaSize.X;
- _node.L_EndBtn.Instance.Position = position2;
+ _endButton.Position = position2;
}
//拖拽起始点
@@ -172,19 +183,40 @@
if (dragState == DragState.DragStart)
{
_canComment = true;
- _startTempPos = _node.L_StartBtn.Instance.Position;
+ _startTempPos = _startButton.Position;
_startDragRange = GetDoorAreaRange();
}
else if (dragState == DragState.DragMove)
{
+ if (_isDragMode)
+ {
+ offset.X -= GameConfig.TileCellSize;
+ }
+
var position = _startTempPos;
position.X = position.X += offset.X;
- var endPosition = _node.L_EndBtn.Instance.Position;
+ var endPosition = _endButton.Position;
+
+ //拖拽模式
+ if (_isDragMode)
+ {
+ if (position.X > endPosition.X) //该换方向了
+ {
+ _startButton.EmitSignal(BaseButton.SignalName.ButtonUp);
+ _endButton.EmitSignal(BaseButton.SignalName.ButtonDown);
+
+ if (Mathf.Abs(position.X - endPosition.X) >= GameConfig.TileCellSize * 4 && !_canComment)
+ {
+ _canComment = true;
+ _node.L_DoorArea.Instance.Color = _defaultColor;
+ }
+ return;
+ }
+ }
//计算区域大小
- var areaSize = (int)(endPosition.X - position.X - _node.L_StartBtn.Instance.Size.X);
-
- _node.L_StartBtn.Instance.Position = position;
+ var areaSize = (int)(endPosition.X - position.X - _startButton.Size.X);
+ _startButton.Position = position;
//刷新区域位置
SetDoorAreaSize(areaSize);
@@ -227,24 +259,40 @@
if (dragState == DragState.DragStart)
{
_canComment = true;
- _endTempPos = _node.L_EndBtn.Instance.Position;
+ _endTempPos = _endButton.Position;
_startDragRange = GetDoorAreaRange();
}
else if (dragState == DragState.DragMove)
{
var position = _endTempPos;
position.X = position.X += offset.X;
+ var startPosition = _startButton.Position;
+
+ //拖拽模式
+ if (_isDragMode)
+ {
+ if (position.X < startPosition.X) //该换方向了
+ {
+ _endButton.EmitSignal(BaseButton.SignalName.ButtonUp);
+ _startButton.EmitSignal(BaseButton.SignalName.ButtonDown);
+ if (Mathf.Abs(position.X - startPosition.X) >= GameConfig.TileCellSize * 4 && !_canComment)
+ {
+ _canComment = true;
+ _node.L_DoorArea.Instance.Color = _defaultColor;
+ }
+ return;
+ }
+ }
+
//区域大小
- var areaSize = (int)(position.X - _node.L_StartBtn.Instance.Position.X - _node.L_StartBtn.Instance.Size.X);
+ var areaSize = (int)(position.X - _startButton.Position.X - _startButton.Size.X);
//刷新区域位置
SetDoorAreaSize(areaSize);
//终点坐标必须要大于起始点坐标
- var startPosition = _node.L_StartBtn.Instance.Position;
if (position.X > startPosition.X)
{
-
//区域必须大于等于 4 格宽度
if (areaSize >= GameConfig.TileCellSize * 4)
{
@@ -256,7 +304,7 @@
return;
}
}
-
+
//错误的位置
if (_canComment)
{
@@ -287,6 +335,6 @@
_isDragMode = true;
_onSubmit = onSubmit;
_onCancel = onCancel;
- _node.L_EndBtn.Instance.EmitSignal(BaseButton.SignalName.ButtonDown);
+ _endButton.EmitSignal(BaseButton.SignalName.ButtonDown);
}
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragButton.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragButton.cs
index 3a54a10..9cc1213 100644
--- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragButton.cs
+++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragButton.cs
@@ -64,10 +64,14 @@
private void OnButtonDown()
{
+ if (_down)
+ {
+ return;
+ }
_down = true;
Modulate = new Color(0.7f, 0.7f, 0.7f, 1);
_startPos = GetGlobalMousePosition();
- _prevPos = Vector2.Zero;
+ _prevPos = new Vector2(-99999, -99999);
if (DragEvent != null)
{
DragEvent(DragState.DragStart, Vector2.Zero);
@@ -76,6 +80,10 @@
private void OnButtonUp()
{
+ if (!_down)
+ {
+ return;
+ }
_down = false;
Modulate = new Color(1, 1, 1, 1);
if (DragEvent != null)
diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorHoverArea.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorHoverArea.cs
index c366953..6025080 100644
--- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorHoverArea.cs
+++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorHoverArea.cs
@@ -63,7 +63,7 @@
//提交门区域
private void OnSubmitDoorArea(int start, int end)
{
-
+ GD.Print("提交区域: " + start + ", " + end);
}
private void OnMouseEnter()
diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs
index 269f884..4f6a3ea 100644
--- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs
@@ -82,13 +82,7 @@
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));
+ inst.Instance.MakeDragMode(onSubmit, () => RemoveDoorTool(inst));
}
///