diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn index a2e0da3..598c689 100644 --- a/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn +++ b/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn @@ -17,7 +17,6 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_6jjk7") -Layer = null [node name="HSplitContainer" type="HSplitContainer" parent="."] layout_mode = 1 @@ -64,6 +63,18 @@ scale = Vector2(2, 2) mouse_filter = 2 +[node name="CellRoot" type="Control" parent="HSplitContainer/LeftBottom/MarginContainer/LeftBg/TileTexture"] +anchors_preset = 0 +offset_right = 1.0 +offset_bottom = 1.0 +mouse_filter = 2 + +[node name="Cell" type="TextureButton" parent="HSplitContainer/LeftBottom/MarginContainer/LeftBg/TileTexture/CellRoot"] +layout_mode = 0 +offset_right = 16.0 +offset_bottom = 16.0 +mouse_filter = 1 + [node name="MaskBrush" type="Control" parent="HSplitContainer/LeftBottom/MarginContainer/LeftBg/TileTexture"] layout_mode = 1 anchors_preset = 15 diff --git a/DungeonShooting_Godot/src/framework/ui/UiBase.cs b/DungeonShooting_Godot/src/framework/ui/UiBase.cs index f30270f..21c4c6b 100644 --- a/DungeonShooting_Godot/src/framework/ui/UiBase.cs +++ b/DungeonShooting_Godot/src/framework/ui/UiBase.cs @@ -71,6 +71,8 @@ private HashSet _nodeScripts; //存放事件集合的对象 private EventFactory _eventFactory; + //存放的IUiGrid对象 + private List _uiGrids; public UiBase(string uiName) { @@ -214,6 +216,15 @@ { OnDestroyUiEvent(); } + + if (_uiGrids != null) + { + foreach (var uiGrid in _uiGrids) + { + uiGrid.Destroy(); + } + _uiGrids.Clear(); + } //子Ui调用销毁 if (_nestedUiSet != null) @@ -269,6 +280,24 @@ _eventFactory.RemoveAllEventListener(); } } + + /// + /// 创建一个UiGrid对象, 该Ui对象会在Ui销毁时自动销毁 + /// + /// 模板对象 + /// 模板对象类型 + /// 存放的数据类型 + /// Cell处理类 + public UiGrid CreateUiGrid(TNode template) where TNode : IUiCellNode where TCell : UiCell + { + var uiGrid = new UiGrid(template, typeof(TCell)); + if (_uiGrids == null) + { + _uiGrids = new List(); + } + _uiGrids.Add(uiGrid); + return uiGrid; + } public sealed override void _Process(double delta) { diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs index 24d8abe..c05951f 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs @@ -32,6 +32,37 @@ } /// + /// 类型: , 路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.CellRoot.Cell + /// + public class Cell : UiNode + { + public Cell(TileSetEditorTerrainPanel uiPanel, Godot.TextureButton node) : base(uiPanel, node) { } + public override Cell Clone() => new (UiPanel, (Godot.TextureButton)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.CellRoot + /// + public class CellRoot : UiNode + { + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.Cell + /// + public Cell L_Cell + { + get + { + if (_L_Cell == null) _L_Cell = new Cell(UiPanel, Instance.GetNode("Cell")); + return _L_Cell; + } + } + private Cell _L_Cell; + + public CellRoot(TileSetEditorTerrainPanel uiPanel, Godot.Control node) : base(uiPanel, node) { } + public override CellRoot Clone() => new (UiPanel, (Godot.Control)Instance.Duplicate()); + } + + /// /// 类型: , 路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.MaskBrush /// public class MaskBrush : UiNode @@ -46,6 +77,19 @@ public class TileTexture : UiNode { /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.CellRoot + /// + public CellRoot L_CellRoot + { + get + { + if (_L_CellRoot == null) _L_CellRoot = new CellRoot(UiPanel, Instance.GetNode("CellRoot")); + return _L_CellRoot; + } + } + private CellRoot _L_CellRoot; + + /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.MaskBrush /// public MaskBrush L_MaskBrush @@ -372,6 +416,16 @@ /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.CellRoot.Cell + /// + public Cell S_Cell => L_HSplitContainer.L_LeftBottom.L_MarginContainer.L_LeftBg.L_TileTexture.L_CellRoot.L_Cell; + + /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.CellRoot + /// + public CellRoot S_CellRoot => L_HSplitContainer.L_LeftBottom.L_MarginContainer.L_LeftBg.L_TileTexture.L_CellRoot; + + /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.MaskBrush /// public MaskBrush S_MaskBrush => L_HSplitContainer.L_LeftBottom.L_MarginContainer.L_LeftBg.L_TileTexture.L_MaskBrush; diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs index c99123c..fe453a5 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs @@ -9,6 +9,8 @@ /// 父Ui /// public TileSetEditorPanel EditorPanel; + + private UiGrid _grid; public override void OnCreateUi() { @@ -16,6 +18,10 @@ //改变纹理事件 AddEventListener(EventEnum.OnSetTileTexture, OnSetTileTexture); + + _grid = CreateUiGrid(S_Cell); + _grid.SetCellOffset(Vector2I.Zero); + OnSetTileTexture(EditorPanel.Texture); } public override void OnDestroyUi() @@ -27,5 +33,21 @@ private void OnSetTileTexture(object arg) { S_LeftBg.Instance.OnChangeTileSetTexture(); + + _grid.RemoveAll(); + var cellHorizontal = EditorPanel.CellHorizontal; + if (cellHorizontal <= 0) + { + return; + } + var cellVertical = EditorPanel.CellVertical; + _grid.SetColumns(cellHorizontal); + for (var i = 0; i < cellVertical; i++) + { + for (var j = 0; j < cellHorizontal; j++) + { + _grid.Add(default); + } + } } } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/left/MaskCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/left/MaskCell.cs new file mode 100644 index 0000000..dd2cc04 --- /dev/null +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/left/MaskCell.cs @@ -0,0 +1,38 @@ +using Godot; + +namespace UI.TileSetEditorTerrain; + +public class MaskCell : UiCell +{ + public override void OnInit() + { + CellNode.Instance.Draw += OnDraw; + CellNode.Instance.AddDragListener(OnDrag); + } + + public override void Process(float delta) + { + CellNode.Instance.QueueRedraw(); + } + + private void OnDrag(DragState state, Vector2 delta) + { + if (state == DragState.DragStart) + { + Grid.SelectIndex = Index; + } + Debug.Log($"state: {state}, delta: {delta}"); + } + + private void OnDraw() + { + if (Grid.SelectIndex == Index) + { + //选中时绘制轮廓 + CellNode.Instance.DrawRect( + new Rect2(Vector2.Zero, CellNode.Instance.Size), + new Color(0, 1, 1), false, 2f / CellNode.UiPanel.S_LeftBg.L_TileTexture.Instance.Scale.X + ); + } + } +} \ No newline at end of file