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 a69d795..9ee2b94 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":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 +[{"Name":"test1","Weight":100,"Remark":"","WaveList":[[{"Position":{"X":1,"Y":-53},"Size":{"X":20,"Y":10},"DelayTime":0,"MarkList":[{"Id":"weapon0001","Weight":100,"Attr":{"CurrAmmon":"0","ResidueAmmo":"0"}}]},{"Position":{"X":1,"Y":-36},"Size":{"X":21,"Y":20},"DelayTime":0,"MarkList":[{"Id":"weapon0001","Weight":100,"Attr":{"CurrAmmon":"0","ResidueAmmo":"0"}}]},{"Position":{"X":5,"Y":15},"Size":{"X":50,"Y":20},"DelayTime":0,"MarkList":[{"Id":"weapon0002","Weight":100,"Attr":{"CurrAmmon":"0","ResidueAmmo":"0"}}]}]]}] \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/ui/mapEditor/tileView/EditorTileMap.cs b/DungeonShooting_Godot/src/game/ui/mapEditor/tileView/EditorTileMap.cs index 1359cb6..cc44030 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditor/tileView/EditorTileMap.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditor/tileView/EditorTileMap.cs @@ -159,6 +159,11 @@ } } + /// <summary> + /// 选中的标记 + /// </summary> + public MarkTool SelectMark => MapEditorToolsPanel.ActiveMark; + //变动过的数据 //地图位置, 单位: 格 diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorMarkCell.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorMarkCell.cs index e9cb203..d5849cf 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorMarkCell.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorMarkCell.cs @@ -1,24 +1,23 @@ -using System.Collections.Generic; -using Config; +using Config; namespace UI.MapEditorMapMark; -public class EditorMarkCell : UiCell<MapEditorMapMark.MarkItem, MarkInfo> +public class EditorMarkCell : UiCell<MapEditorMapMark.MarkItem, MapEditorMapMarkPanel.MarkCellData> { public override void OnInit() { CellNode.L_MarkButton.Instance.Pressed += OnClick; } - public override void OnSetData(MarkInfo data) + public override void OnSetData(MapEditorMapMarkPanel.MarkCellData data) { var text = ""; - if (data.MarkList != null) + if (data.MarkInfo.MarkList != null) { var str = ""; - for (var i = 0; i < data.MarkList.Count; i++) + for (var i = 0; i < data.MarkInfo.MarkList.Count; i++) { - var markInfoItem = data.MarkList[i]; + var markInfoItem = data.MarkInfo.MarkList[i]; if (i > 0) { str += ","; @@ -33,7 +32,7 @@ text += "空"; } - text += "\n" + data.DelayTime + "秒"; + text += "\n" + data.MarkInfo.DelayTime + "秒"; CellNode.L_MarkButton.Instance.Text = text; } diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorWaveCell.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorWaveCell.cs index 1299cb6..a345772 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorWaveCell.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorWaveCell.cs @@ -6,7 +6,7 @@ public class EditorWaveCell : UiCell<MapEditorMapMark.WaveItem, List<MarkInfo>> { - public UiGrid<MapEditorMapMark.MarkItem, MarkInfo> MarkGrid; + public UiGrid<MapEditorMapMark.MarkItem, MapEditorMapMarkPanel.MarkCellData> MarkGrid; public override void OnInit() { @@ -16,7 +16,7 @@ CellNode.L_MarginContainer.L_AddMarkButton.Instance.Pressed += OnAddMark; CellNode.L_MarkContainer.L_MarkItem.Instance.SetHorizontalExpand(true); - MarkGrid = new UiGrid<MapEditorMapMark.MarkItem, MarkInfo>(CellNode.L_MarkContainer.L_MarkItem, typeof(EditorMarkCell)); + MarkGrid = new UiGrid<MapEditorMapMark.MarkItem, MapEditorMapMarkPanel.MarkCellData>(CellNode.L_MarkContainer.L_MarkItem, typeof(EditorMarkCell)); MarkGrid.SetColumns(1); MarkGrid.SetHorizontalExpand(true); MarkGrid.SetCellOffset(new Vector2I(0, 5)); @@ -24,7 +24,12 @@ public override void OnSetData(List<MarkInfo> data) { - MarkGrid.SetDataList(data.ToArray()); + var array = new MapEditorMapMarkPanel.MarkCellData[data.Count]; + for (var i = 0; i < data.Count; i++) + { + array[i] = new MapEditorMapMarkPanel.MarkCellData(Grid, data[i]); + } + MarkGrid.SetDataList(array); } public override void OnRefreshIndex() @@ -49,7 +54,7 @@ { var preinstall = CellNode.UiPanel.GetSelectPreinstall(); preinstall.WaveList[Index].Add(markInfo); - MarkGrid.Add(markInfo); + MarkGrid.Add(new MapEditorMapMarkPanel.MarkCellData(Grid, markInfo)); //添加标记工具 EventManager.EmitEvent(EventEnum.OnCreateMark, markInfo); } diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs index c5461e6..6d350c4 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs @@ -12,6 +12,18 @@ Wave, Mark } + + public class MarkCellData + { + public UiGrid<WaveItem, List<MarkInfo>> ParentGrid; + public MarkInfo MarkInfo; + + public MarkCellData(UiGrid<WaveItem, List<MarkInfo>> parentGrid, MarkInfo markInfo) + { + ParentGrid = parentGrid; + MarkInfo = markInfo; + } + } /// <summary> /// 选中的cell选项 @@ -73,7 +85,7 @@ //选中标记回调 private void OnSelectMark(object arg) { - if (arg is MarkInfo markInfo && (SelectCell is not EditorMarkCell || (SelectCell is EditorMarkCell markCell && markCell.Data != markInfo))) + if (arg is MarkInfo markInfo && (SelectCell is not EditorMarkCell || (SelectCell is EditorMarkCell markCell && markCell.Data.MarkInfo != markInfo))) { var selectPreinstall = GetSelectPreinstall(); if (selectPreinstall != null) @@ -319,14 +331,6 @@ _grid.RemoveByIndex(index); EditorTileMap.SelectWaveIndex = -1; } - - /// <summary> - /// 添加标记 - /// </summary> - public void OnAddMark() - { - - } /// <summary> /// 编辑标记数据 @@ -342,5 +346,29 @@ public void OnDeleteMark() { + if (SelectCell is EditorMarkCell markCell) + { + var index = EditorTileMap.SelectWaveIndex; + if (index < 0) + { + return; + } + + var selectPreinstall = GetSelectPreinstall(); + if (selectPreinstall == null) + { + return; + } + + var waveCell = (EditorWaveCell)_grid.GetCell(index); + //隐藏工具 + S_DynamicTool.Reparent(this); + S_DynamicTool.Instance.Visible = false; + var markInfo = waveCell.Data[index]; + //派发移除标记事件 + EventManager.EmitEvent(EventEnum.OnDeleteMark, markInfo); + waveCell.MarkGrid.RemoveByIndex(index); + waveCell.Data.RemoveAt(index); + } } } diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkAreaTool.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkAreaTool.cs index d446319..047e2cb 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkAreaTool.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkAreaTool.cs @@ -20,6 +20,8 @@ private bool _mouseInRT = false; private bool _mouseInLB = false; private bool _mouseInRB = false; + //是否绘制角 + private bool _showCornerBlock = false; private MarkInfo _markInfo; private MarkTool _markTool; @@ -33,6 +35,7 @@ private Vector2 _prevMousePosition; private Vector2 _startPosition; private float _startWidth; + private float _startHeight; public void InitData(MapEditorTools.ToolRoot toolRoot, MarkTool markTool) { @@ -48,6 +51,8 @@ return; } + _showCornerBlock = _markInfo.Size.X >= 4 && _markInfo.Size.Y >= 4; + var globalMousePosition = GetGlobalMousePosition(); if (IsDrag) //按下拖拽按钮 { if (!Input.IsMouseButtonPressed(MouseButton.Left)) //松开拖拽 @@ -56,19 +61,70 @@ } else //拖拽中 { - var pos = GetGlobalMousePosition(); + var pos = globalMousePosition; if (pos != _prevMousePosition) { + if (_mouseInL) { - var offset = GetGlobalMousePosition() - _startMousePosition; - offset = offset / _toolRoot.Instance.Scale; - var newWidth = Mathf.Max(1, (int)(_startWidth - offset.X)); + var offset = globalMousePosition - _startMousePosition; + offset = offset / _toolRoot.Instance.Scale * 2f; + var newWidth = Mathf.Max(2, (int)(_startWidth - offset.X)); _markInfo.Size = new SerializeVector2(newWidth, _markInfo.Size.Y); - var end = (int)(_startPosition.X + _startWidth / 2f); - var newX = (int)(end - newWidth / 2f); - _markTool.Position = new Vector2(newX, _markTool.Position.Y); - GD.Print("newWidth: " + newWidth); + } + else if (_mouseInR) + { + var offset = _startMousePosition - globalMousePosition; + offset = offset / _toolRoot.Instance.Scale * 2f; + var newWidth = Mathf.Max(2, (int)(_startWidth - offset.X)); + _markInfo.Size = new SerializeVector2(newWidth, _markInfo.Size.Y); + } + else if (_mouseInT) + { + var offset = globalMousePosition - _startMousePosition; + offset = offset / _toolRoot.Instance.Scale * 2f; + var newHeight = Mathf.Max(2, (int)(_startHeight - offset.Y)); + _markInfo.Size = new SerializeVector2(_markInfo.Size.X, newHeight); + } + else if (_mouseInB) + { + var offset = _startMousePosition - globalMousePosition; + offset = offset / _toolRoot.Instance.Scale * 2f; + var newHeight = Mathf.Max(2, (int)(_startHeight - offset.Y)); + _markInfo.Size = new SerializeVector2(_markInfo.Size.X, newHeight); + } + //---------------------------------------------------------------------------------- + else if (_mouseInLT) + { + var offset = globalMousePosition - _startMousePosition; + offset = offset / _toolRoot.Instance.Scale * 2f; + var newWidth = Mathf.Max(2, (int)(_startWidth - offset.X)); + var newHeight = Mathf.Max(2, (int)(_startHeight - offset.Y)); + _markInfo.Size = new SerializeVector2(newWidth, newHeight); + } + else if (_mouseInLB) + { + var offsetX = (globalMousePosition.X - _startMousePosition.X) / _toolRoot.Instance.Scale.X * 2f; + var offsetY = (_startMousePosition.Y - globalMousePosition.Y) / _toolRoot.Instance.Scale.Y * 2f; + var newWidth = Mathf.Max(2, (int)(_startWidth - offsetX)); + var newHeight = Mathf.Max(2, (int)(_startHeight - offsetY)); + _markInfo.Size = new SerializeVector2(newWidth, newHeight); + } + else if (_mouseInRT) + { + var offsetX = (_startMousePosition.X - globalMousePosition.X) / _toolRoot.Instance.Scale.X * 2f; + var offsetY = (globalMousePosition.Y - _startMousePosition.Y) / _toolRoot.Instance.Scale.Y * 2f; + var newWidth = Mathf.Max(2, (int)(_startWidth - offsetX)); + var newHeight = Mathf.Max(2, (int)(_startHeight - offsetY)); + _markInfo.Size = new SerializeVector2(newWidth, newHeight); + } + else if (_mouseInRB) + { + var offset = _startMousePosition - globalMousePosition; + offset = offset / _toolRoot.Instance.Scale * 2f; + var newWidth = Mathf.Max(2, (int)(_startWidth - offset.X)); + var newHeight = Mathf.Max(2, (int)(_startHeight - offset.Y)); + _markInfo.Size = new SerializeVector2(newWidth, newHeight); } _prevMousePosition = pos; } @@ -88,22 +144,22 @@ var flag = false; var mousePosition = GetLocalMousePosition(); //判断鼠标是否在点上 - if (Utils.IsPositionInRect(mousePosition, GetLeftTopRect())) + if (_showCornerBlock && Utils.IsPositionInRect(mousePosition, GetLeftTopRect())) { _mouseInLT = true; flag = true; } - else if (Utils.IsPositionInRect(mousePosition, GetRightTopRect())) + else if (_showCornerBlock && Utils.IsPositionInRect(mousePosition, GetRightTopRect())) { _mouseInRT = true; flag = true; } - else if (Utils.IsPositionInRect(mousePosition, GetLeftBottomRect())) + else if (_showCornerBlock && Utils.IsPositionInRect(mousePosition, GetLeftBottomRect())) { _mouseInLB = true; flag = true; } - else if (Utils.IsPositionInRect(mousePosition, GetRightBottomRect())) + else if (_showCornerBlock && Utils.IsPositionInRect(mousePosition, GetRightBottomRect())) { _mouseInRB = true; flag = true; @@ -134,10 +190,11 @@ if (Input.IsMouseButtonPressed(MouseButton.Left)) { IsDrag = true; - _startMousePosition = GetGlobalMousePosition(); + _startMousePosition = globalMousePosition; _prevMousePosition = _startMousePosition; _startPosition = _markTool.Position; _startWidth = _markInfo.Size.X; + _startHeight = _markInfo.Size.Y; } } } @@ -155,11 +212,14 @@ 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); + if (_showCornerBlock) + { + //绘制角 + DrawRect(GetLeftTopRect(), _mouseInLT ? _cornerHoverColor : _cornerColor); + DrawRect(GetLeftBottomRect(), _mouseInLB ? _cornerHoverColor : _cornerColor); + DrawRect(GetRightTopRect(), _mouseInRT ? _cornerHoverColor : _cornerColor); + DrawRect(GetRightBottomRect(), _mouseInRB ? _cornerHoverColor : _cornerColor); + } } private Rect2 GetTopRect() diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkTool.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkTool.cs index fedda46..fb894b4 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkTool.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MarkTool.cs @@ -22,7 +22,7 @@ private bool _isDown; private Vector2 _offset; private MarkAreaTool _markAreaToolUp; - + public void SetUiNode(IUiNode uiNode) { _toolNode = (MapEditorTools.MarkTemplate)uiNode; @@ -53,7 +53,9 @@ else if (!_isDown) { //按下鼠标 - if (!_markAreaToolUp.IsDrag && Input.IsMouseButtonPressed(MouseButton.Left)) + var activeMark = _toolNode.UiPanel.ActiveMark; + if ((activeMark == null || (!activeMark.IsDrag && !activeMark._markAreaToolUp.IsDrag)) + && !_markAreaToolUp.IsDrag && Input.IsMouseButtonPressed(MouseButton.Left)) { _isDown = true; if (_toolNode.UiPanel.ActiveMark != this)