diff --git a/DungeonShooting_Godot/prefab/ui/EditorForm.tscn b/DungeonShooting_Godot/prefab/ui/EditorForm.tscn index 295dd77..7dd42cf 100644 --- a/DungeonShooting_Godot/prefab/ui/EditorForm.tscn +++ b/DungeonShooting_Godot/prefab/ui/EditorForm.tscn @@ -7,6 +7,8 @@ anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 script = ExtResource("1_oq0ff") [node name="MarginContainer" type="MarginContainer" parent="."] diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn index a436e21..d2cce9d 100644 --- a/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn +++ b/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn @@ -300,11 +300,12 @@ offset_bottom = 1.0 mouse_filter = 2 -[node name="BottomCell" type="Control" parent="VSplitContainer/PanelBottom/BottomBg/TileTexture/CellRoot"] -anchors_preset = 0 +[node name="BottomCell" type="ColorRect" parent="VSplitContainer/PanelBottom/BottomBg/TileTexture/CellRoot"] +layout_mode = 0 offset_right = 16.0 offset_bottom = 16.0 mouse_filter = 2 +color = Color(0, 0, 0, 0.588235) [node name="MaskBrush" type="Control" parent="VSplitContainer/PanelBottom/BottomBg/TileTexture"] layout_mode = 1 diff --git a/DungeonShooting_Godot/resource/map/tileSet/TileSet2/TileSet.json b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/TileSet.json index 2ba5a4c..bcc13b5 100644 --- a/DungeonShooting_Godot/resource/map/tileSet/TileSet2/TileSet.json +++ b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/TileSet.json @@ -96,26 +96,6 @@ "TerrainType": 0 }, { - "Name": "Test", - "F": {}, - "M": {}, - "T": { - "16": [ - 0, - 128 - ], - "48": [ - 16, - 128 - ], - "56": [ - 32, - 128 - ] - }, - "TerrainType": 0 - }, - { "Name": "Test2", "F": {}, "M": {}, @@ -139,6 +119,10 @@ "276": [ 16, 48 + ], + "81": [ + 0, + 128 ] }, "TerrainType": 1 @@ -159,6 +143,18 @@ "276": [ 16, 80 + ], + "81": [ + 48, + 48 + ], + "340": [ + 208, + 32 + ], + "337": [ + 176, + 32 ] }, "TerrainType": 1 diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs index d87f6ff..9630fa4 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs @@ -648,12 +648,12 @@ } /// - /// 类型: , 路径: TileSetEditorTerrain.VSplitContainer.PanelBottom.BottomBg.TileTexture.CellRoot.BottomCell + /// 类型: , 路径: TileSetEditorTerrain.VSplitContainer.PanelBottom.BottomBg.TileTexture.CellRoot.BottomCell /// - public class BottomCell : UiNode + public class BottomCell : UiNode { - public BottomCell(TileSetEditorTerrainPanel uiPanel, Godot.Control node) : base(uiPanel, node) { } - public override BottomCell Clone() => new (UiPanel, (Godot.Control)Instance.Duplicate()); + public BottomCell(TileSetEditorTerrainPanel uiPanel, Godot.ColorRect node) : base(uiPanel, node) { } + public override BottomCell Clone() => new (UiPanel, (Godot.ColorRect)Instance.Duplicate()); } /// @@ -662,13 +662,13 @@ public class CellRoot_1 : UiNode { /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelBottom.BottomBg.TileTexture.BottomCell + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelBottom.BottomBg.TileTexture.BottomCell /// public BottomCell L_BottomCell { get { - if (_L_BottomCell == null) _L_BottomCell = new BottomCell(UiPanel, Instance.GetNode("BottomCell")); + if (_L_BottomCell == null) _L_BottomCell = new BottomCell(UiPanel, Instance.GetNode("BottomCell")); return _L_BottomCell; } } @@ -956,7 +956,7 @@ public PanelTop S_PanelTop => L_VSplitContainer.L_PanelTop; /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelBottom.BottomBg.TileTexture.CellRoot.BottomCell + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelBottom.BottomBg.TileTexture.CellRoot.BottomCell /// public BottomCell S_BottomCell => L_VSplitContainer.L_PanelBottom.L_BottomBg.L_TileTexture.L_CellRoot.L_BottomCell; diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs index 5354e15..14d40f0 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs @@ -100,24 +100,24 @@ { _refreshGridConnect = false; - // var terrainList = EditorPanel.TileSetSourceInfo.Terrain; - // for (var i = 0; i < terrainList.Count; i++) - // { - // var terrain = terrainList[i]; - // if (terrain.TerrainType == 0) //选中47格Terrain - // { - // TerrainGrid3x3.ForEach(cell => RefreshConnectTerrainCell(i, terrain, cell)); - // if (EditorPanel.TileSetSourceIndex == 0 && CurrTerrainIndex == 0) //选中Main Source - // { - // TerrainGridMiddle.ForEach(cell => RefreshConnectTerrainCell(i, terrain, cell)); - // TerrainGridFloor.ForEach(cell => RefreshConnectTerrainCell(i, terrain, cell)); - // } - // } - // else //选中13格Terrain - // { - // TerrainGrid2x2.ForEach(cell => RefreshConnectTerrainCell(i, terrain, cell)); - // } - // } + var terrainList = EditorPanel.TileSetSourceInfo.Terrain; + for (var i = 0; i < terrainList.Count; i++) + { + var terrain = terrainList[i]; + if (terrain.TerrainType == 0) //选中47格Terrain + { + TerrainGrid3x3.ForEach(cell => RefreshTerrainCellUseFlag(terrain, cell)); + if (EditorPanel.TileSetSourceIndex == 0 && CurrTerrainIndex == 0) //选中Main Source + { + TerrainGridMiddle.ForEach(cell => RefreshTerrainCellUseFlag(terrain, cell)); + TerrainGridFloor.ForEach(cell => RefreshTerrainCellUseFlag(terrain, cell)); + } + } + else //选中13格Terrain + { + TerrainGrid2x2.ForEach(cell => RefreshTerrainCellUseFlag(terrain, cell)); + } + } } } @@ -168,7 +168,7 @@ } } - private void RefreshConnectTerrainCell(int terrainIndex, TileSetTerrainInfo terrain, UiCell cell) + private void RefreshConnectTerrainCell(TileSetTerrainInfo terrain, UiCell cell) { var data = terrain.GetTerrainCell(cell.Index, cell.Data); if (data != null) @@ -181,7 +181,23 @@ if (maskCell != null) { //绑定TerrainCell - maskCell.SetConnectTerrainCell(terrainCell, terrainIndex); + maskCell.SetConnectTerrainCell(terrainCell); + } + } + } + + private void RefreshTerrainCellUseFlag(TileSetTerrainInfo terrain, UiCell cell) + { + var data = terrain.GetTerrainCell(cell.Index, cell.Data); + if (data != null) + { + var x = data[0]; + var y = data[1]; + var index = x / GameConfig.TileCellSize + y / GameConfig.TileCellSize * MaskGrid.GetColumns(); + var maskCell = (MaskCell)MaskGrid.GetCell(index); + if (maskCell != null) + { + maskCell.SetUseFlag(true); } } } @@ -279,7 +295,7 @@ MaskGrid.ForEach(cell => { - ((MaskCell)cell).SetConnectTerrainCell(null, -1); + ((MaskCell)cell).SetConnectTerrainCell(null); }); var terrain = CurrTerrain; @@ -287,35 +303,32 @@ { if (terrain.TerrainType == 0) //选中47个Terrain { - TerrainGrid3x3.ForEach(cell => SetTerrainCellData(terrain, cell)); + TerrainGrid3x3.ForEach(cell => + { + SetTerrainCellData(terrain, cell); + RefreshConnectTerrainCell(terrain, cell); + }); if (EditorPanel.TileSetSourceIndex == 0 && CurrTerrainIndex == 0) //选中Main Source { - TerrainGridMiddle.ForEach(cell => SetTerrainCellData(terrain, cell)); - TerrainGridFloor.ForEach(cell => SetTerrainCellData(terrain, cell)); + TerrainGridMiddle.ForEach(cell => + { + SetTerrainCellData(terrain, cell); + RefreshConnectTerrainCell(terrain, cell); + }); + TerrainGridFloor.ForEach(cell => + { + SetTerrainCellData(terrain, cell); + RefreshConnectTerrainCell(terrain, cell); + }); } } else //选中13格Terrain { - TerrainGrid2x2.ForEach(cell => SetTerrainCellData(terrain, cell)); - } - - var terrainList = EditorPanel.TileSetSourceInfo.Terrain; - for (var i = 0; i < terrainList.Count; i++) - { - var terrainInfo = terrainList[i]; - if (terrainInfo.TerrainType == 0) //选中47格Terrain + TerrainGrid2x2.ForEach(cell => { - TerrainGrid3x3.ForEach(cell => RefreshConnectTerrainCell(i, terrainInfo, cell)); - if (EditorPanel.TileSetSourceIndex == 0 && CurrTerrainIndex == 0) //选中Main Source - { - TerrainGridMiddle.ForEach(cell => RefreshConnectTerrainCell(i, terrainInfo, cell)); - TerrainGridFloor.ForEach(cell => RefreshConnectTerrainCell(i, terrainInfo, cell)); - } - } - else //选中13格Terrain - { - TerrainGrid2x2.ForEach(cell => RefreshConnectTerrainCell(i, terrainInfo, cell)); - } + SetTerrainCellData(terrain, cell); + RefreshConnectTerrainCell(terrain, cell); + }); } } @@ -402,7 +415,8 @@ terrainCell.ClearCell(); if (terrainCell.ConnectMaskCell != null) { - terrainCell.ConnectMaskCell.SetConnectTerrainCell(null, -1); + terrainCell.ConnectMaskCell.SetUseFlag(false); + terrainCell.ConnectMaskCell.SetConnectTerrainCell(null); } }); } @@ -414,7 +428,8 @@ terrainCell.ClearCell(); if (terrainCell.ConnectMaskCell != null) { - terrainCell.ConnectMaskCell.SetConnectTerrainCell(null, -1); + terrainCell.ConnectMaskCell.SetUseFlag(false); + terrainCell.ConnectMaskCell.SetConnectTerrainCell(null); } }); } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/MaskCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/MaskCell.cs index 9db8882..8f0554c 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/MaskCell.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/MaskCell.cs @@ -10,9 +10,9 @@ public TerrainCell ConnectTerrainCell { get; private set; } /// - /// 已经赋值并连接的Terrain所以 + /// 是否使用 /// - public int ConnectTerrainIndex { get; private set; } + public bool UseFlag { get; private set; } /// /// 鼠标是否悬停 @@ -21,9 +21,11 @@ private TextureRect _textureRect; private TileSetEditorTerrainPanel _panel; + private float _startA; public override void OnInit() { + _startA = CellNode.Instance.Color.A; _panel = CellNode.UiPanel; _textureRect = _panel.S_BottomBg.L_TileTexture.Instance; CellNode.Instance.Draw += Draw; @@ -31,7 +33,8 @@ public override void OnDisable() { - SetConnectTerrainCell(null, -1); + SetUseFlag(false); + SetConnectTerrainCell(null); } public override void Process(float delta) @@ -42,7 +45,7 @@ /// /// 设置连接的Cell /// - public void SetConnectTerrainCell(TerrainCell terrainCell, int terrainIndex) + public void SetConnectTerrainCell(TerrainCell terrainCell) { if (terrainCell == null) { @@ -57,26 +60,42 @@ ConnectTerrainCell = terrainCell; terrainCell.ConnectMaskCell = this; } - - ConnectTerrainIndex = terrainIndex; + } + + /// + /// 设置是否使用 + /// + public void SetUseFlag(bool flag) + { + UseFlag = flag; + CellNode.Instance.Color = new Color(0, 0, 0, flag ? 0 : _startA); } private void Draw() { - if (Hover || (ConnectTerrainCell != null && ConnectTerrainCell.Hover && CellNode.UiPanel.CurrTerrainIndex == ConnectTerrainIndex)) + if (Hover || (ConnectTerrainCell != null && ConnectTerrainCell.Hover)) { CellNode.Instance.DrawRect( new Rect2(Vector2.Zero, CellNode.Instance.Size), new Color(0, 1, 0, 0.3f) ); } - if (ConnectTerrainCell != null) + + //选中时绘制轮廓 + if (ConnectTerrainCell != null) //存在连接的Cell { - var color = CellNode.UiPanel.CurrTerrainIndex == ConnectTerrainIndex ? new Color(0, 1, 0) : new Color(1, 1, 1); - //选中时绘制轮廓 + var width = 2f / _textureRect.Scale.X; CellNode.Instance.DrawRect( - new Rect2(Vector2.Zero, CellNode.Instance.Size), - color, false, 2f / _textureRect.Scale.X + new Rect2(Vector2.Zero + new Vector2(width / 2f, width / 2f), CellNode.Instance.Size - new Vector2(width, width)), + new Color(0, 1, 0, 0.6f), false, width + ); + } + else if (UseFlag) + { + var width = 2f / _textureRect.Scale.X; + CellNode.Instance.DrawRect( + new Rect2(Vector2.Zero + new Vector2(width / 2f, width / 2f), CellNode.Instance.Size - new Vector2(width, width)), + new Color(1, 1, 1, 0.6f), false, width ); } } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TileEditArea.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TileEditArea.cs index 3ad6e7f..6f5cd7e 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TileEditArea.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TileEditArea.cs @@ -31,7 +31,7 @@ var cellPosition = Utils.GetMouseCellPosition(_panel.S_TileTexture.Instance); var index = cellPosition.X + cellPosition.Y * _panel.MaskGrid.GetColumns(); var tempCell = (MaskCell)_panel.MaskGrid.GetCell(index); - if (tempCell != null && tempCell.ConnectTerrainCell != null && tempCell.ConnectTerrainIndex == _panel.CurrTerrainIndex) + if (tempCell != null && tempCell.ConnectTerrainCell != null) { cell = tempCell; } @@ -73,7 +73,7 @@ var cellPosition = Utils.GetMouseCellPosition(_panel.S_TileTexture.Instance); var index = cellPosition.X + cellPosition.Y * _panel.MaskGrid.GetColumns(); var cell = (MaskCell)_panel.MaskGrid.GetCell(index); - if (cell != null && cell.ConnectTerrainCell == null) //必须要没有使用的Cell + if (cell != null && !cell.UseFlag) //必须要没有使用的Cell { _panel.DraggingCell = cell; _panel.MaskGrid.SelectIndex = index; diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCell.cs index 19bb987..14e6329 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCell.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCell.cs @@ -66,7 +66,8 @@ ClearTerrainBitData(); if (ConnectMaskCell != null) { - ConnectMaskCell.SetConnectTerrainCell(null, -1); + ConnectMaskCell.SetUseFlag(false); + ConnectMaskCell.SetConnectTerrainCell(null); } } } @@ -111,9 +112,11 @@ { if (ConnectMaskCell != null) { - ConnectMaskCell.SetConnectTerrainCell(null, -1); + ConnectMaskCell.SetUseFlag(false); + ConnectMaskCell.SetConnectTerrainCell(null); } - maskCell.SetConnectTerrainCell(this, CellNode.UiPanel.CurrTerrainIndex); + maskCell.SetConnectTerrainCell(this); + maskCell.SetUseFlag(true); } } @@ -133,7 +136,7 @@ private void OnDraw() { - if (ConnectMaskCell != null && (Hover || (ConnectMaskCell.Hover && CellNode.UiPanel.CurrTerrainIndex == ConnectMaskCell.ConnectTerrainIndex))) + if (ConnectMaskCell != null && (Hover || ConnectMaskCell.Hover)) { CellNode.Instance.DrawRect( new Rect2(Vector2.Zero, CellNode.Instance.Size),