diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room1/Room1_preinstall.json b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room1/Room1_preinstall.json
index 16ba545..a69d795 100644
--- a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room1/Room1_preinstall.json
+++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room1/Room1_preinstall.json
@@ -1 +1 @@
-[{"Name":"test1","Weight":100,"Remark":"","WaveList":[[{"Position":{"X":4,"Y":-3},"Size":{"X":0,"Y":0},"DelayTime":0,"MarkList":[{"Id":"weapon0001","Weight":100,"Attr":{"CurrAmmon":"0","ResidueAmmo":"0"}}]},{"Position":{"X":4,"Y":4},"Size":{"X":0,"Y":0},"DelayTime":0,"MarkList":[{"Id":"weapon0001","Weight":100,"Attr":{"CurrAmmon":"0","ResidueAmmo":"0"}}]}]]}]
\ No newline at end of file
+[{"Name":"test1","Weight":100,"Remark":"","WaveList":[[{"Position":{"X":85,"Y":32},"Size":{"X":50,"Y":50},"DelayTime":0,"MarkList":[{"Id":"weapon0001","Weight":100,"Attr":{"CurrAmmon":"0","ResidueAmmo":"0"}}]},{"Position":{"X":-26,"Y":-45},"Size":{"X":60,"Y":30},"DelayTime":0,"MarkList":[{"Id":"weapon0002","Weight":100,"Attr":{"CurrAmmon":"0","ResidueAmmo":"0"}}]},{"Position":{"X":0,"Y":0},"Size":{"X":15,"Y":15},"DelayTime":0,"MarkList":[{"Id":"weapon0007","Weight":100,"Attr":{"CurrAmmon":"0","ResidueAmmo":"0"}}]}]]}]
\ 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 c1ce0a2..99fe1a7 100644
--- a/DungeonShooting_Godot/src/framework/common/Utils.cs
+++ b/DungeonShooting_Godot/src/framework/common/Utils.cs
@@ -160,4 +160,13 @@
return position.X >= globalPosition.X && position.X <= (globalPosition.X + size.X) &&
position.Y >= globalPosition.Y && position.Y <= (globalPosition.Y + size.Y);
}
+
+ ///
+ /// 判断点是否在区域内
+ ///
+ public static bool IsPositionInRect(Vector2 pos, Rect2 rect2)
+ {
+ return pos.X >= rect2.Position.X && pos.X <= rect2.Position.X + rect2.Size.X &&
+ pos.Y >= rect2.Position.Y && pos.Y <= rect2.Position.Y + rect2.Size.Y;
+ }
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/framework/ui/UiNode.cs b/DungeonShooting_Godot/src/framework/ui/UiNode.cs
index 2e58eb0..6ed13ca 100644
--- a/DungeonShooting_Godot/src/framework/ui/UiNode.cs
+++ b/DungeonShooting_Godot/src/framework/ui/UiNode.cs
@@ -37,6 +37,7 @@
}
}
+ //已知问题: 通过 OpenNestedUi() 打开子Ui, 然后再克隆当前节点, 被克隆出来的节点的子Ui不会被调用生命周期函数, 也就是没有被记录
public UiBase OpenNestedUi(string uiName, UiBase prevUi = null)
{
var packedScene = ResourceManager.Load("res://" + GameConfig.UiPrefabDir + uiName + ".tscn");
diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs
index 25df7cc..c5461e6 100644
--- a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs
@@ -308,6 +308,12 @@
//隐藏工具
S_DynamicTool.Reparent(this);
S_DynamicTool.Instance.Visible = false;
+ //派发移除标记事件
+ var list = selectPreinstall.WaveList[index];
+ foreach (var markInfo in list)
+ {
+ EventManager.EmitEvent(EventEnum.OnDeleteMark, markInfo);
+ }
//移除数据
selectPreinstall.WaveList.RemoveAt(index);
_grid.RemoveByIndex(index);
diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs
index 4a281d1..727c2ef 100644
--- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs
@@ -86,6 +86,7 @@
_eventFactory = EventManager.CreateEventFactory();
_eventFactory.AddEventListener(EventEnum.OnCreateMark, OnCreateMarkTool);
_eventFactory.AddEventListener(EventEnum.OnSelectMark, OnSelectMarkTool);
+ _eventFactory.AddEventListener(EventEnum.OnDeleteMark, OnDeleteMarkTool);
_eventFactory.AddEventListener(EventEnum.OnSelectPreinstall, RefreshMark);
}
@@ -158,7 +159,7 @@
{
if (arg is MarkInfo markInfo)
{
- if (markInfo != ActiveMark.MarkInfo)
+ if (ActiveMark == null || markInfo != ActiveMark.MarkInfo)
{
if (_currMarkToolsMap.TryGetValue(markInfo, out var markTemplate))
{
@@ -167,6 +168,23 @@
}
}
}
+
+ //删除标记
+ private void OnDeleteMarkTool(object arg)
+ {
+ if (arg is MarkInfo markInfo)
+ {
+ if (_currMarkToolsMap.TryGetValue(markInfo, out var markTemplate))
+ {
+ if (ActiveMark == markTemplate.Instance)
+ {
+ SetActiveMark(null);
+ }
+ markTemplate.QueueFree();
+ _currMarkToolsMap.Remove(markInfo);
+ }
+ }
+ }
///
/// 获取门区域对象
diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkAreaTool.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkAreaTool.cs
new file mode 100644
index 0000000..8343a4e
--- /dev/null
+++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkAreaTool.cs
@@ -0,0 +1,148 @@
+using System.Drawing;
+using Godot;
+using Color = Godot.Color;
+
+namespace UI.MapEditorTools;
+
+public partial class MarkAreaTool : Node2D
+{
+ ///
+ /// 宽度
+ ///
+ public int Width { get; private set; }
+ ///
+ /// 高度
+ ///
+ public int Height { get; private set; }
+
+ private static Color _sideColor = new Color(0, 0, 0, 0);
+ private static Color _sideHoverColor = new Color(0, 0, 0, 0.3f);
+ private static Color _cornerColor = new Color(1, 1, 1, 1);
+ private static Color _cornerHoverColor = new Color(0.65f, 0.65f, 0.65f, 1);
+
+ private bool _mouseInL = false;
+ private bool _mouseInR = false;
+ private bool _mouseInT = false;
+ private bool _mouseInB = false;
+ private bool _mouseInLT = false;
+ private bool _mouseInRT = false;
+ private bool _mouseInLB = false;
+ private bool _mouseInRB = false;
+
+ public void SetSize(int width, int height)
+ {
+ Width = width;
+ Height = height;
+ }
+
+ public override void _Process(double delta)
+ {
+ if (!Visible)
+ {
+ return;
+ }
+
+ _mouseInL = false;
+ _mouseInR = false;
+ _mouseInT = false;
+ _mouseInB = false;
+ _mouseInLT = false;
+ _mouseInRT = false;
+ _mouseInLB = false;
+ _mouseInRB = false;
+
+ var mousePosition = GetLocalMousePosition();
+ //判断鼠标是否在点上
+ if (Utils.IsPositionInRect(mousePosition, GetLeftTopRect()))
+ {
+ _mouseInLT = true;
+ }
+ else if (Utils.IsPositionInRect(mousePosition, GetRightTopRect()))
+ {
+ _mouseInRT = true;
+ }
+ else if (Utils.IsPositionInRect(mousePosition, GetLeftBottomRect()))
+ {
+ _mouseInLB = true;
+ }
+ else if (Utils.IsPositionInRect(mousePosition, GetRightBottomRect()))
+ {
+ _mouseInRB = true;
+ }
+ else if (Utils.IsPositionInRect(mousePosition, GetLeftRect()))
+ {
+ _mouseInL = true;
+ }
+ else if (Utils.IsPositionInRect(mousePosition, GetRightRect()))
+ {
+ _mouseInR = true;
+ }
+ else if (Utils.IsPositionInRect(mousePosition, GetTopRect()))
+ {
+ _mouseInT = true;
+ }
+ else if (Utils.IsPositionInRect(mousePosition, GetBottomRect()))
+ {
+ _mouseInB = true;
+ }
+
+ if (Visible)
+ {
+ QueueRedraw();
+ }
+ }
+
+ public override void _Draw()
+ {
+ //绘制边框
+ DrawRect(GetTopRect(), _mouseInT ? _sideHoverColor : _sideColor);
+ DrawRect(GetBottomRect(), _mouseInB ? _sideHoverColor : _sideColor);
+ DrawRect(GetLeftRect(), _mouseInL ? _sideHoverColor : _sideColor);
+ DrawRect(GetRightRect(), _mouseInR ? _sideHoverColor : _sideColor);
+ //绘制角
+ DrawRect(GetLeftTopRect(), _mouseInLT ? _cornerHoverColor : _cornerColor);
+ DrawRect(GetLeftBottomRect(), _mouseInLB ? _cornerHoverColor : _cornerColor);
+ DrawRect(GetRightTopRect(), _mouseInRT ? _cornerHoverColor : _cornerColor);
+ DrawRect(GetRightBottomRect(), _mouseInRB ? _cornerHoverColor : _cornerColor);
+ }
+
+ private Rect2 GetTopRect()
+ {
+ return new Rect2(-Width / 2f + 0.5f, -Height / 2f - 0.5f, Width - 1, 1);
+ }
+
+ private Rect2 GetBottomRect()
+ {
+ return new Rect2(-Width / 2f + 0.5f, Height / 2f - 0.5f, Width - 1, 1);
+ }
+
+ private Rect2 GetLeftRect()
+ {
+ return new Rect2(-Width / 2f - 0.5f, -Height / 2f + 0.5f, 1, Height - 1);
+ }
+
+ private Rect2 GetRightRect()
+ {
+ return new Rect2(Width / 2f - 0.5f, -Height / 2f + 0.5f, 1, Height - 1);
+ }
+
+ private Rect2 GetLeftTopRect()
+ {
+ return new Rect2(-Width / 2f - 1.5f, -Height / 2f - 1.5f, 3, 3);
+ }
+
+ private Rect2 GetLeftBottomRect()
+ {
+ return new Rect2(-Width / 2f - 1.5f, Height / 2f - 1.5f, 3, 3);
+ }
+
+ private Rect2 GetRightTopRect()
+ {
+ return new Rect2(Width / 2f - 1.5f, -Height / 2f - 1.5f, 3, 3);
+ }
+
+ private Rect2 GetRightBottomRect()
+ {
+ return new Rect2(Width / 2f - 1.5f, Height / 2f - 1.5f, 3, 3);
+ }
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkTool.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkTool.cs
index 0553ed3..40f4837 100644
--- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkTool.cs
+++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkTool.cs
@@ -16,12 +16,18 @@
private MapEditorTools.MarkTemplate _toolNode;
private bool _isDown;
private Vector2 _offset;
+ private MarkAreaTool _markAreaToolUp;
public void SetUiNode(IUiNode uiNode)
{
_toolNode = (MapEditorTools.MarkTemplate)uiNode;
_toolNode.Instance.MouseEntered += OnMouseEntered;
_toolNode.Instance.MouseExited += OnMouseExited;
+
+ _markAreaToolUp = new MarkAreaTool();
+ _markAreaToolUp.Position = Size / 2;
+ _markAreaToolUp.Visible = false;
+ AddChild(_markAreaToolUp);
}
public override void _Process(double delta)
@@ -68,12 +74,18 @@
QueueRedraw();
}
+
+ RefreshAreaTool();
}
+ ///
+ /// 初始化数据
+ ///
public void InitData(MarkInfo markInfo)
{
MarkInfo = markInfo;
Position = markInfo.Position.AsVector2() - (Size / 2).Ceil();
+ RefreshAreaTool();
}
private void OnMouseEntered()
@@ -88,10 +100,24 @@
public override void _Draw()
{
- if (MarkInfo != null && MarkInfo.Size.X != 0 && MarkInfo.Size.Y != 0)
+ if (MarkInfo != null && MarkInfo.Size.X > 0 && MarkInfo.Size.Y > 0)
{
var size = MarkInfo.Size.AsVector2();
DrawRect(new Rect2(-size / 2 + Size / 2, size.X, size.Y), new Color(1, 1, 1, 0.3f), false, 1);
}
}
+
+ //刷新区域标记工具数据
+ private void RefreshAreaTool()
+ {
+ if (_toolNode.UiPanel.ActiveMark == this && MarkInfo.Size.X > 0 && MarkInfo.Size.Y > 0)
+ {
+ _markAreaToolUp.Visible = true;
+ _markAreaToolUp.SetSize((int)MarkInfo.Size.X, (int)MarkInfo.Size.Y);
+ }
+ else
+ {
+ _markAreaToolUp.Visible = false;
+ }
+ }
}
\ No newline at end of file