diff --git a/DungeonShooting_Godot/prefab/ui/MapEditorTools.tscn b/DungeonShooting_Godot/prefab/ui/MapEditorTools.tscn index 1035eed..664092a 100644 --- a/DungeonShooting_Godot/prefab/ui/MapEditorTools.tscn +++ b/DungeonShooting_Godot/prefab/ui/MapEditorTools.tscn @@ -33,7 +33,7 @@ offset_top = -36.0 offset_right = 160.0 grow_vertical = 0 -color = Color(1, 1, 1, 0) +color = Color(1, 1, 1, 0.313726) script = ExtResource("2_6qfy3") [node name="E_HoverRoot" type="Control" parent="DoorToolRoot"] @@ -48,7 +48,7 @@ offset_top = -36.0 offset_right = 160.0 grow_vertical = 0 -color = Color(1, 1, 1, 0) +color = Color(1, 1, 1, 0.313726) script = ExtResource("2_6qfy3") [node name="S_HoverRoot" type="Control" parent="DoorToolRoot"] @@ -65,7 +65,7 @@ offset_top = -36.0 offset_right = 160.0 grow_vertical = 0 -color = Color(1, 1, 1, 0) +color = Color(1, 1, 1, 0.313726) script = ExtResource("2_6qfy3") [node name="W_HoverRoot" type="Control" parent="DoorToolRoot"] @@ -81,7 +81,7 @@ offset_top = -36.0 offset_right = 160.0 grow_vertical = 0 -color = Color(1, 1, 1, 0) +color = Color(1, 1, 1, 0.313726) script = ExtResource("2_6qfy3") [node name="HoverPreviewRoot" type="Control" parent="DoorToolRoot"] @@ -176,6 +176,12 @@ texture_pressed = ExtResource("2_rwvbg") texture_hover = ExtResource("2_rwvbg") +[node name="DoorTool" type="TextureButton" parent="HBoxContainer"] +layout_mode = 2 +texture_normal = ExtResource("2_rwvbg") +texture_pressed = ExtResource("2_rwvbg") +texture_hover = ExtResource("2_rwvbg") + [node name="CenterTool" type="TextureButton" parent="HBoxContainer"] layout_mode = 2 texture_normal = ExtResource("2_rwvbg") diff --git a/DungeonShooting_Godot/src/game/ui/mapEditor/TileView/EditorTileMap.cs b/DungeonShooting_Godot/src/game/ui/mapEditor/TileView/EditorTileMap.cs index 8dee7b6..0544fcd 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditor/TileView/EditorTileMap.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditor/TileView/EditorTileMap.cs @@ -12,7 +12,7 @@ public partial class EditorTileMap : TileMap { - public enum MouseLeftButtonType + public enum MouseButtonType { /// /// 无状态 @@ -27,9 +27,13 @@ /// Pen, /// - /// 区域模式 + /// 绘制区域模式 /// - Area + Area, + /// + /// 编辑门区域模式 + /// + Door, } /// @@ -67,8 +71,11 @@ /// public MapEditorToolsPanel MapEditorToolsPanel { get; set; } - //是否启用绘制图块 - private MouseLeftButtonType _mouseLeftButtonType = MouseLeftButtonType.None; + /// + /// 左键功能 + /// + public MouseButtonType MouseType { get; set; } = MouseButtonType.Area; + //鼠标坐标 private Vector2 _mousePosition; //鼠标所在的cell坐标 @@ -141,36 +148,49 @@ if (!MapEditorToolsPanel.S_HBoxContainer.Instance.IsPositionOver(GetGlobalMousePosition())) //不在Ui节点上 { //左键绘制 - if (_isLeftPressed && _mouseLeftButtonType == MouseLeftButtonType.Pen) + if (_isLeftPressed) { - if (Input.IsKeyPressed(Key.Shift)) //按住shift绘制矩形 + if (MouseType == MouseButtonType.Pen) //绘制单格 + { + if (_prevMouseCellPosition != _mouseCellPosition || !_changeFlag) //鼠标位置变过 + { + _changeFlag = true; + _prevMouseCellPosition = _mouseCellPosition; + //绘制自动图块 + SetSingleAutoCell(_mouseCellPosition); + } + } + else if (MouseType == MouseButtonType.Area) //绘制区域 { _drawFullRect = true; } - else if (_prevMouseCellPosition != _mouseCellPosition || !_changeFlag) //鼠标位置变过 + else if (MouseType == MouseButtonType.Drag) //拖拽 { - _changeFlag = true; - _prevMouseCellPosition = _mouseCellPosition; - //绘制自动图块 - SetSingleAutoCell(_mouseCellPosition); + SetMapPosition(GetGlobalMousePosition() + _moveOffset); } } - else if (_isRightPressed && _mouseLeftButtonType == MouseLeftButtonType.Pen) //右键擦除 + else if (_isRightPressed) //右键擦除 { - if (Input.IsKeyPressed(Key.Shift)) //按住shift擦除矩形 + if (MouseType == MouseButtonType.Pen) //绘制单格 + { + if (_prevMouseCellPosition != _mouseCellPosition || !_changeFlag) //鼠标位置变过 + { + _changeFlag = true; + _prevMouseCellPosition = _mouseCellPosition; + EraseSingleAutoCell(_mouseCellPosition); + } + } + else if (MouseType == MouseButtonType.Area) //绘制区域 { _drawFullRect = true; } - else if (_prevMouseCellPosition != _mouseCellPosition || !_changeFlag) //鼠标位置变过 + else if (MouseType == MouseButtonType.Drag) //拖拽 { - _changeFlag = true; - _prevMouseCellPosition = _mouseCellPosition; - EraseSingleAutoCell(_mouseCellPosition); + SetMapPosition(GetGlobalMousePosition() + _moveOffset); } } else if (_isMiddlePressed) //中键移动 { - //GD.Print("移动..."); SetMapPosition(GetGlobalMousePosition() + _moveOffset); } } @@ -182,7 +202,7 @@ if (_generateTimer <= 0) { //计算区域 - CalcTileRect(); + CalcTileRect(false); GD.Print("开始检测是否可以生成地形..."); if (CheckTerrain()) { @@ -230,7 +250,7 @@ } } - if (_mouseLeftButtonType == MouseLeftButtonType.Pen || _mouseLeftButtonType == MouseLeftButtonType.Area) + if (MouseType == MouseButtonType.Pen || MouseType == MouseButtonType.Area) { if (_drawFullRect) //绘制填充矩形 { @@ -266,6 +286,7 @@ { if (mouseButton.Pressed) //按下 { + _moveOffset = Position - GetGlobalMousePosition(); _mouseStartCellPosition = LocalToMap(GetLocalMousePosition()); } else @@ -284,6 +305,7 @@ { if (mouseButton.Pressed) //按下 { + _moveOffset = Position - GetGlobalMousePosition(); _mouseStartCellPosition = LocalToMap(GetLocalMousePosition()); } else @@ -395,12 +417,7 @@ //聚焦 //MapEditorPanel.CallDelay(0.1f, OnClickCenterTool); CallDeferred(nameof(OnClickCenterTool)); - - // var doorPos = (_roomPosition + new Vector2I(_roomSize.X - 1, 1)) * GameConfig.TileCellSize; - // MapEditorToolsPanel.CreateDoorTool( - // doorPos, DoorDirection.E, - // 0 * GameConfig.TileCellSize, 4 * GameConfig.TileCellSize - // ); + //加载门编辑区域 foreach (var doorAreaInfo in _doorConfigs) { @@ -557,12 +574,15 @@ ClearLayer(AutoMiddleLayer); } - //从新计算房间区域 - private void CalcTileRect() + //重新计算房间区域 + private void CalcTileRect(bool sendMessage) { var rect = GetUsedRect(); _roomPosition = rect.Position; - SetMapSize(rect.Size); + if (sendMessage) + { + SetMapSize(rect.Size); + } } //检测是否有不合规的图块, 返回true表示图块正常 @@ -580,13 +600,21 @@ var pos = new Vector2I(x + i, y + j); if (GetCellSourceId(AutoFloorLayer, pos) == -1) { - //先检测对角是否有地板 - var left = _autoCellLayerGrid.Get(pos.X - 1, pos.Y); - var right = _autoCellLayerGrid.Get(pos.X + 1, pos.Y); - var top = _autoCellLayerGrid.Get(pos.X, pos.Y + 1); - var down = _autoCellLayerGrid.Get(pos.X, pos.Y - 1); + //先检测对边是否有地板 + if ((_autoCellLayerGrid.Get(pos.X - 1, pos.Y) && _autoCellLayerGrid.Get(pos.X + 1, pos.Y)) //left & right + || (_autoCellLayerGrid.Get(pos.X, pos.Y + 1) && _autoCellLayerGrid.Get(pos.X, pos.Y - 1))) //top & down + { + _checkTerrainFlag = false; + _checkTerrainErrorPosition = pos; + return false; + } - if ((left && right) || (top && down)) + //再检测对角是否有地板 + var topLeft = _autoCellLayerGrid.Get(pos.X - 1, pos.Y + 1); //top-left + var downRight = _autoCellLayerGrid.Get(pos.X + 1, pos.Y - 1); //down-right + var downLeft = _autoCellLayerGrid.Get(pos.X - 1, pos.Y - 1); //down-left + var topRight = _autoCellLayerGrid.Get(pos.X + 1, pos.Y + 1); //top-right + if ((topLeft && downRight && !downLeft && !topRight) || (!topLeft && !downRight && downLeft && topRight)) { _checkTerrainFlag = false; _checkTerrainErrorPosition = pos; @@ -617,7 +645,7 @@ //绘制自动图块 SetCellsTerrainConnect(AutoFloorLayer, arr, _terrainSet, _terrain, false); //计算区域 - CalcTileRect(); + CalcTileRect(true); //将墙壁移动到指定层 MoveTerrainCell(); } @@ -712,7 +740,7 @@ /// public void OnSelectHandTool() { - + MouseType = MouseButtonType.Drag; } /// @@ -720,7 +748,7 @@ /// public void OnSelectPenTool() { - + MouseType = MouseButtonType.Pen; } /// @@ -728,7 +756,15 @@ /// public void OnSelectRectTool() { - + MouseType = MouseButtonType.Area; + } + + /// + /// 选择编辑门区域 + /// + public void OnSelectDoorTool() + { + MouseType = MouseButtonType.Door; } /// diff --git a/DungeonShooting_Godot/src/game/ui/mapEditor/TileView/EditorTileMapBar.cs b/DungeonShooting_Godot/src/game/ui/mapEditor/TileView/EditorTileMapBar.cs index e7dd3a2..a507e40 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditor/TileView/EditorTileMapBar.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditor/TileView/EditorTileMapBar.cs @@ -23,6 +23,7 @@ mapEditorToolsPanel.S_HandTool.Instance.Pressed += _editorTileMap.Instance.OnSelectHandTool; mapEditorToolsPanel.S_PenTool.Instance.Pressed += _editorTileMap.Instance.OnSelectPenTool; mapEditorToolsPanel.S_RectTool.Instance.Pressed += _editorTileMap.Instance.OnSelectRectTool; + mapEditorToolsPanel.S_DoorTool.Instance.Pressed += _editorTileMap.Instance.OnSelectDoorTool; mapEditorToolsPanel.S_CenterTool.Instance.Pressed += _editorTileMap.Instance.OnClickCenterTool; } @@ -33,6 +34,7 @@ mapEditorToolsPanel.S_HandTool.Instance.Pressed -= _editorTileMap.Instance.OnSelectHandTool; mapEditorToolsPanel.S_PenTool.Instance.Pressed -= _editorTileMap.Instance.OnSelectPenTool; mapEditorToolsPanel.S_RectTool.Instance.Pressed -= _editorTileMap.Instance.OnSelectRectTool; + mapEditorToolsPanel.S_DoorTool.Instance.Pressed -= _editorTileMap.Instance.OnSelectDoorTool; mapEditorToolsPanel.S_CenterTool.Instance.Pressed -= _editorTileMap.Instance.OnClickCenterTool; } diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs index c843b23..fa3ec60 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs @@ -1,5 +1,6 @@ using System; using Godot; +using UI.MapEditor; namespace UI.MapEditorTools; @@ -156,13 +157,13 @@ /// /// 设置门区域所占范围, 单位: 像素 /// - public void SetDoorAreaRange(int start, int size) + public void SetDoorAreaRange(int start, int end) { var startPosition = _startButton.Position; startPosition.X = start - _startButton.Size.X; _startButton.Position = startPosition; - SetDoorAreaSize(size); + SetDoorAreaSize(end - start); } /// @@ -287,7 +288,7 @@ { _canComment = true; _node.L_DoorArea.Instance.Color = _defaultColor; - SetDoorAreaRange(_startDragRange.X, _startDragRange.Y - _startDragRange.X); + SetDoorAreaRange(_startDragRange.X, _startDragRange.Y); } else { @@ -380,7 +381,7 @@ { _canComment = true; _node.L_DoorArea.Instance.Color = _defaultColor; - SetDoorAreaRange(_startDragRange.X, _startDragRange.Y - _startDragRange.X); + SetDoorAreaRange(_startDragRange.X, _startDragRange.Y); } else { @@ -423,11 +424,19 @@ private void OnMouseEntered() { + if (MapEditorToolsPanel.EditorMap.Instance.MouseType != EditorTileMap.MouseButtonType.Door) + { + return; + } _mouseHover = true; } private void OnMouseExited() { + if (MapEditorToolsPanel.EditorMap.Instance.MouseType != EditorTileMap.MouseButtonType.Door) + { + return; + } _mouseHover = false; } } \ 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 9cc1213..a648c3f 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragButton.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragButton.cs @@ -1,5 +1,6 @@ using System; using Godot; +using UI.MapEditor; namespace UI.MapEditorTools; @@ -64,6 +65,10 @@ private void OnButtonDown() { + if (_mapEditorToolsPanel.EditorMap.Instance.MouseType != EditorTileMap.MouseButtonType.Door) + { + return; + } if (_down) { return; @@ -80,6 +85,10 @@ private void OnButtonUp() { + if (_mapEditorToolsPanel.EditorMap.Instance.MouseType != EditorTileMap.MouseButtonType.Door) + { + return; + } if (!_down) { return; diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorHoverArea.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorHoverArea.cs index f0e2db6..9e505f2 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorHoverArea.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorHoverArea.cs @@ -1,4 +1,5 @@ using Godot; +using UI.MapEditor; using UI.MapEditorTools; public partial class DoorHoverArea : ColorRect @@ -85,6 +86,10 @@ private void OnMouseEnter() { + if (MapEditorToolsPanel.EditorMap.Instance.MouseType != EditorTileMap.MouseButtonType.Door) + { + return; + } if (MapEditorToolsPanel.ActiveHoverArea == null || !IsDrag) { _mouseHover = true; @@ -94,6 +99,10 @@ private void OnMouseExit() { + if (MapEditorToolsPanel.EditorMap.Instance.MouseType != EditorTileMap.MouseButtonType.Door) + { + return; + } if (MapEditorToolsPanel.ActiveHoverArea == null || !IsDrag) { _mouseHover = false; diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorTools.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorTools.cs index 2549a3d..dba79c1 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorTools.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorTools.cs @@ -385,6 +385,15 @@ } /// + /// 类型: , 路径: MapEditorTools.HBoxContainer.DoorTool + /// + public class DoorTool : UiNode + { + public DoorTool(MapEditorTools uiPanel, Godot.TextureButton node) : base(uiPanel, node) { } + public override DoorTool Clone() => new (UiPanel, (Godot.TextureButton)Instance.Duplicate()); + } + + /// /// 类型: , 路径: MapEditorTools.HBoxContainer.CenterTool /// public class CenterTool : UiNode @@ -438,6 +447,19 @@ private RectTool _L_RectTool; /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: MapEditorTools.DoorTool + /// + public DoorTool L_DoorTool + { + get + { + if (_L_DoorTool == null) _L_DoorTool = new DoorTool(UiPanel, Instance.GetNodeOrNull("DoorTool")); + return _L_DoorTool; + } + } + private DoorTool _L_DoorTool; + + /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: MapEditorTools.CenterTool /// public CenterTool L_CenterTool @@ -546,6 +568,11 @@ public RectTool S_RectTool => L_HBoxContainer.L_RectTool; /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: MapEditorTools.HBoxContainer.DoorTool + /// + public DoorTool S_DoorTool => L_HBoxContainer.L_DoorTool; + + /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: MapEditorTools.HBoxContainer.CenterTool /// public CenterTool S_CenterTool => L_HBoxContainer.L_CenterTool; diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs index 803edaf..dfa784d 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Godot; +using UI.MapEditor; namespace UI.MapEditorTools; @@ -40,9 +41,17 @@ public override void Process(float delta) { S_HoverPreviewRoot.Instance.Visible = ActiveHoverArea != null && !DoorHoverArea.IsDrag; + if (EditorMap.Instance.MouseType == EditorTileMap.MouseButtonType.Door) + { + S_DoorToolRoot.Instance.Modulate = new Color(1, 1, 1, 1); + } + else + { + S_DoorToolRoot.Instance.Modulate = new Color(1, 1, 1, 0.4f); + } } - public DoorHoverArea GetDoorHoverAreaByDirection(DoorDirection direction) + public DoorHoverArea GetDoorHoverArea(DoorDirection direction) { switch (direction) { @@ -53,6 +62,18 @@ } return null; } + + public Control GetDoorHoverAreaRoot(DoorDirection direction) + { + switch (direction) + { + case DoorDirection.E: return S_E_HoverRoot.Instance; + case DoorDirection.N: return S_N_HoverRoot.Instance; + case DoorDirection.W: return S_W_HoverRoot.Instance; + case DoorDirection.S: return S_S_HoverRoot.Instance; + } + return null; + } /// /// 设置活动的鼠标悬停的区域 @@ -76,11 +97,11 @@ /// 门区域数据 public DoorToolTemplate CreateDoorTool(DoorAreaInfo doorAreaInfo) { - var doorHoverArea = GetDoorHoverAreaByDirection(doorAreaInfo.Direction); + var doorHoverArea = GetDoorHoverArea(doorAreaInfo.Direction); var inst = CreateDoorToolInstance(doorHoverArea); inst.Instance.DoorAreaInfo = doorAreaInfo; - inst.Instance.SetDoorAreaPosition(doorHoverArea.GetParent().Position); - inst.Instance.SetDoorAreaRange(doorAreaInfo.Start, doorAreaInfo.End - doorAreaInfo.Start); + inst.Instance.SetDoorAreaPosition(GetDoorHoverAreaRoot(doorAreaInfo.Direction).Position); + inst.Instance.SetDoorAreaRange(doorAreaInfo.Start, doorAreaInfo.End); return inst; } @@ -95,8 +116,8 @@ Action onSubmit, Action onCancel) { var inst = CreateDoorToolInstance(doorHoverArea); - inst.Instance.SetDoorAreaPosition(doorHoverArea.GetParent().Position); - inst.Instance.SetDoorAreaRange(start, 0); + inst.Instance.SetDoorAreaPosition(GetDoorHoverAreaRoot(doorHoverArea.Direction).Position); + inst.Instance.SetDoorAreaRange(start, start); inst.Instance.MakeDragMode(onSubmit, () => { RemoveDoorTool(inst); @@ -138,15 +159,125 @@ { position *= GameConfig.TileCellSize; size *= GameConfig.TileCellSize; - S_N_HoverRoot.Instance.Position = position + GameConfig.TileCellSizeVector2I; - S_E_HoverRoot.Instance.Position = new Vector2(position.X + size.X - GameConfig.TileCellSize, position.Y + GameConfig.TileCellSize); - S_S_HoverRoot.Instance.Position = new Vector2(position.X + GameConfig.TileCellSize, position.Y + size.Y - GameConfig.TileCellSize); - S_W_HoverRoot.Instance.Position = position + GameConfig.TileCellSizeVector2I; + + var nPos1 = S_N_HoverRoot.Instance.Position; + var ePos1 = S_E_HoverRoot.Instance.Position; + var sPos1 = S_S_HoverRoot.Instance.Position; + var wPos1 = S_W_HoverRoot.Instance.Position; + var nPos2 = position + GameConfig.TileCellSizeVector2I; + var ePos2 = new Vector2(position.X + size.X - GameConfig.TileCellSize, position.Y + GameConfig.TileCellSize); + var sPos2 = new Vector2(position.X + GameConfig.TileCellSize, position.Y + size.Y - GameConfig.TileCellSize); + var wPos2 = position + GameConfig.TileCellSizeVector2I; + + var nSize2 = new Vector2(size.X - GameConfig.TileCellSize * 2, S_N_HoverArea.Instance.Size.Y); + var eSize2 = new Vector2(size.Y - GameConfig.TileCellSize * 2, S_E_HoverArea.Instance.Size.Y); + var sSize2 = new Vector2(size.X - GameConfig.TileCellSize * 2, S_S_HoverArea.Instance.Size.Y); + var wSize2 = new Vector2(size.Y - GameConfig.TileCellSize * 2, S_W_HoverArea.Instance.Size.Y); - S_N_HoverArea.Instance.Size = new Vector2(size.X - GameConfig.TileCellSize * 2, S_N_HoverArea.Instance.Size.Y); - S_E_HoverArea.Instance.Size = new Vector2(size.Y - GameConfig.TileCellSize * 2, S_E_HoverArea.Instance.Size.Y); - S_S_HoverArea.Instance.Size = new Vector2(size.X - GameConfig.TileCellSize * 2, S_S_HoverArea.Instance.Size.Y); - S_W_HoverArea.Instance.Size = new Vector2(size.Y - GameConfig.TileCellSize * 2, S_W_HoverArea.Instance.Size.Y); + S_N_HoverRoot.Instance.Position = nPos2; + S_E_HoverRoot.Instance.Position = ePos2; + S_S_HoverRoot.Instance.Position = sPos2; + S_W_HoverRoot.Instance.Position = wPos2; + + S_N_HoverArea.Instance.Size = nSize2; + S_E_HoverArea.Instance.Size = eSize2; + S_S_HoverArea.Instance.Size = sSize2; + S_W_HoverArea.Instance.Size = wSize2; + + //调整门区域 + for (var i = 0; i < _doorTools.Count; i++) + { + var doorTool = _doorTools[i]; + var direction = doorTool.Instance.Direction; + var areaRoot = GetDoorHoverAreaRoot(direction); + var doorAreaRange = doorTool.Instance.GetDoorAreaRange(); + doorTool.Instance.SetDoorAreaPosition(areaRoot.Position); + + if (direction == DoorDirection.N) + { + var hOffset = (int)(nPos2.X - nPos1.X); + doorAreaRange.X -= hOffset; + doorAreaRange.Y -= hOffset; + + if (doorAreaRange.X >= 0 && doorAreaRange.Y <= nSize2.X) //允许提交 + { + doorTool.Instance.SetDoorAreaRange(doorAreaRange.X, doorAreaRange.Y); + if (doorTool.Instance.DoorAreaInfo != null) + { + doorTool.Instance.DoorAreaInfo.Start = doorAreaRange.X; + doorTool.Instance.DoorAreaInfo.End = doorAreaRange.Y; + } + } + else //如果超出区域, 则删除 + { + RemoveDoorTool(doorTool); + i--; + } + } + else if (direction == DoorDirection.S) + { + var hOffset = (int)(sPos2.X - sPos1.X); + doorAreaRange.X -= hOffset; + doorAreaRange.Y -= hOffset; + + if (doorAreaRange.X >= 0 && doorAreaRange.Y <= sSize2.X) //允许提交 + { + doorTool.Instance.SetDoorAreaRange(doorAreaRange.X, doorAreaRange.Y); + if (doorTool.Instance.DoorAreaInfo != null) + { + doorTool.Instance.DoorAreaInfo.Start = doorAreaRange.X; + doorTool.Instance.DoorAreaInfo.End = doorAreaRange.Y; + } + } + else //如果超出区域, 则删除 + { + RemoveDoorTool(doorTool); + i--; + } + } + else if (direction == DoorDirection.E) + { + var vOffset = (int)(ePos2.Y - ePos1.Y); + doorAreaRange.X -= vOffset; + doorAreaRange.Y -= vOffset; + + if (doorAreaRange.X >= 0 && doorAreaRange.Y <= eSize2.X) //允许提交 + { + doorTool.Instance.SetDoorAreaRange(doorAreaRange.X, doorAreaRange.Y); + if (doorTool.Instance.DoorAreaInfo != null) + { + doorTool.Instance.DoorAreaInfo.Start = doorAreaRange.X; + doorTool.Instance.DoorAreaInfo.End = doorAreaRange.Y; + } + } + else //如果超出区域, 则删除 + { + RemoveDoorTool(doorTool); + i--; + } + } + else if (direction == DoorDirection.W) + { + var vOffset = (int)(wPos2.Y - wPos1.Y); + doorAreaRange.X -= vOffset; + doorAreaRange.Y -= vOffset; + + if (doorAreaRange.X >= 0 && doorAreaRange.Y <= wSize2.X) //允许提交 + { + doorTool.Instance.SetDoorAreaRange(doorAreaRange.X, doorAreaRange.Y); + if (doorTool.Instance.DoorAreaInfo != null) + { + doorTool.Instance.DoorAreaInfo.Start = doorAreaRange.X; + doorTool.Instance.DoorAreaInfo.End = doorAreaRange.Y; + } + } + else //如果超出区域, 则删除 + { + RemoveDoorTool(doorTool); + i--; + } + } + } } private DoorToolTemplate CreateDoorToolInstance(DoorHoverArea doorHoverArea)