diff --git "a/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/Test.png" "b/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/Test.png" new file mode 100644 index 0000000..cb64efb --- /dev/null +++ "b/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/Test.png" Binary files differ diff --git "a/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/Test.png.import" "b/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/Test.png.import" new file mode 100644 index 0000000..23f5a74 --- /dev/null +++ "b/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/Test.png.import" @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dc08xp6er034l" +path="res://.godot/imported/Test.png-ad28b6f84a52b6d4955cef560a7a8c19.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://resource/map/tileSet/测试数据/Test.png" +dest_files=["res://.godot/imported/Test.png-ad28b6f84a52b6d4955cef560a7a8c19.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git "a/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/Test2.png.import" "b/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/Test2.png.import" index 62cda6b..06fa9e3 100644 --- "a/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/Test2.png.import" +++ "b/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/Test2.png.import" @@ -2,7 +2,7 @@ importer="texture" type="CompressedTexture2D" -uid="uid://pgdhntg56f77" +uid="uid://cjogonyo581on" path="res://.godot/imported/Test2.png-4f1e41d474574169a7bc738f71691230.ctex" metadata={ "vram_texture": false diff --git "a/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/TileSet.json" "b/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/TileSet.json" index e2b6879..ede5c66 100644 --- "a/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/TileSet.json" +++ "b/DungeonShooting_Godot/resource/map/tileSet/\346\265\213\350\257\225\346\225\260\346\215\256/TileSet.json" @@ -3,7 +3,7 @@ "Sources": [ { "Name": "Test", - "SourcePath": "D:\\GodotProject\\DungeonShooting\\DungeonShooting_Godot\\resource\\tileSprite\\map2\\Dungeon Tileset.png", + "SourcePath": "resource/map/tileSet/\u6D4B\u8BD5\u6570\u636E/Test.png", "Terrain": { "_f": [ 0, @@ -16,10 +16,7 @@ "_vc": null, "_vr": null, "_vs": null, - "_000_010_010": [ - 0, - 0 - ], + "_000_010_010": null, "_010_010_010": null, "_010_010_000": null, "_000_010_000": null, @@ -65,10 +62,7 @@ "_000_110_110": null, "_110_111_110": null, "_110_110_110": null, - "_110_110_000": [ - 176, - 48 - ] + "_110_110_000": null }, "Combination": [ { @@ -363,12 +357,21 @@ }, { "Name": "Test2", - "SourcePath": "D:\\GodotProject\\DungeonShooting\\DungeonShooting_Godot\\resource\\tileSprite\\map2\\Dungeon Tileset \u002B Spikes.png", + "SourcePath": "resource/map/tileSet/\u6D4B\u8BD5\u6570\u636E/Test2.png", "Terrain": { "_f": null, - "_vl": null, - "_vc": null, - "_vr": null, + "_vl": [ + 80, + 16 + ], + "_vc": [ + 96, + 16 + ], + "_vr": [ + 112, + 16 + ], "_vs": null, "_000_010_010": null, "_010_010_010": null, @@ -391,7 +394,10 @@ "_011_011_010": null, "_010_111_110": null, "_000_111_011": null, - "_011_111_111": null, + "_011_111_111": [ + 176, + 64 + ], "_111_111_011": null, "_011_111_000": null, "_000_111_110": null, @@ -405,7 +411,10 @@ "_000_011_011": null, "_011_011_011": null, "_011_111_011": null, - "_011_011_000": null, + "_011_011_000": [ + 144, + 16 + ], "_010_111_111": null, "_110_111_011": null, "_111_111_111": null, @@ -418,7 +427,376 @@ "_110_110_110": null, "_110_110_000": null }, - "Combination": [] + "Combination": [ + { + "Id": "638401565284022672", + "Name": "\u7EC4\u5408", + "Cells": [ + { + "X": 160, + "Y": 144 + }, + { + "X": 144, + "Y": 144 + }, + { + "X": 128, + "Y": 144 + }, + { + "X": 112, + "Y": 144 + }, + { + "X": 96, + "Y": 144 + }, + { + "X": 80, + "Y": 144 + }, + { + "X": 64, + "Y": 144 + }, + { + "X": 48, + "Y": 144 + }, + { + "X": 32, + "Y": 144 + }, + { + "X": 32, + "Y": 128 + }, + { + "X": 48, + "Y": 128 + }, + { + "X": 64, + "Y": 128 + }, + { + "X": 80, + "Y": 128 + }, + { + "X": 96, + "Y": 128 + }, + { + "X": 112, + "Y": 128 + }, + { + "X": 128, + "Y": 128 + }, + { + "X": 144, + "Y": 128 + }, + { + "X": 160, + "Y": 128 + }, + { + "X": 160, + "Y": 112 + }, + { + "X": 144, + "Y": 112 + }, + { + "X": 128, + "Y": 112 + }, + { + "X": 112, + "Y": 112 + }, + { + "X": 96, + "Y": 112 + }, + { + "X": 80, + "Y": 112 + }, + { + "X": 64, + "Y": 112 + }, + { + "X": 48, + "Y": 112 + }, + { + "X": 32, + "Y": 112 + }, + { + "X": 32, + "Y": 96 + }, + { + "X": 48, + "Y": 96 + }, + { + "X": 64, + "Y": 96 + }, + { + "X": 80, + "Y": 96 + }, + { + "X": 96, + "Y": 96 + }, + { + "X": 112, + "Y": 96 + }, + { + "X": 128, + "Y": 96 + }, + { + "X": 144, + "Y": 96 + }, + { + "X": 144, + "Y": 80 + }, + { + "X": 160, + "Y": 80 + }, + { + "X": 160, + "Y": 96 + }, + { + "X": 128, + "Y": 80 + }, + { + "X": 112, + "Y": 80 + }, + { + "X": 96, + "Y": 80 + }, + { + "X": 80, + "Y": 80 + }, + { + "X": 64, + "Y": 80 + }, + { + "X": 48, + "Y": 80 + }, + { + "X": 32, + "Y": 80 + } + ], + "Positions": [ + { + "X": 128, + "Y": 64 + }, + { + "X": 112, + "Y": 64 + }, + { + "X": 96, + "Y": 64 + }, + { + "X": 80, + "Y": 64 + }, + { + "X": 64, + "Y": 64 + }, + { + "X": 48, + "Y": 64 + }, + { + "X": 32, + "Y": 64 + }, + { + "X": 16, + "Y": 64 + }, + { + "X": 0, + "Y": 64 + }, + { + "X": 0, + "Y": 48 + }, + { + "X": 16, + "Y": 48 + }, + { + "X": 32, + "Y": 48 + }, + { + "X": 48, + "Y": 48 + }, + { + "X": 64, + "Y": 48 + }, + { + "X": 80, + "Y": 48 + }, + { + "X": 96, + "Y": 48 + }, + { + "X": 112, + "Y": 48 + }, + { + "X": 128, + "Y": 48 + }, + { + "X": 128, + "Y": 32 + }, + { + "X": 112, + "Y": 32 + }, + { + "X": 96, + "Y": 32 + }, + { + "X": 80, + "Y": 32 + }, + { + "X": 64, + "Y": 32 + }, + { + "X": 48, + "Y": 32 + }, + { + "X": 32, + "Y": 32 + }, + { + "X": 16, + "Y": 32 + }, + { + "X": 0, + "Y": 32 + }, + { + "X": 0, + "Y": 16 + }, + { + "X": 16, + "Y": 16 + }, + { + "X": 32, + "Y": 16 + }, + { + "X": 48, + "Y": 16 + }, + { + "X": 64, + "Y": 16 + }, + { + "X": 80, + "Y": 16 + }, + { + "X": 96, + "Y": 16 + }, + { + "X": 112, + "Y": 16 + }, + { + "X": 112, + "Y": 0 + }, + { + "X": 128, + "Y": 0 + }, + { + "X": 128, + "Y": 16 + }, + { + "X": 96, + "Y": 0 + }, + { + "X": 80, + "Y": 0 + }, + { + "X": 64, + "Y": 0 + }, + { + "X": 48, + "Y": 0 + }, + { + "X": 32, + "Y": 0 + }, + { + "X": 16, + "Y": 0 + }, + { + "X": 0, + "Y": 0 + } + ] + } + ] } ] } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetSourceInfo.cs b/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetSourceInfo.cs index 66cd5c3..88ece13 100644 --- a/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetSourceInfo.cs +++ b/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetSourceInfo.cs @@ -90,7 +90,6 @@ tileSetSourceInfo.Combination.Add(combination.Clone()); } tileSetSourceInfo.SourcePath = SourcePath; - tileSetSourceInfo._sourceImage = _sourceImage; return tileSetSourceInfo; } diff --git a/DungeonShooting_Godot/src/game/event/EventEnum.cs b/DungeonShooting_Godot/src/game/event/EventEnum.cs index 65e4a6a..30ca385 100644 --- a/DungeonShooting_Godot/src/game/event/EventEnum.cs +++ b/DungeonShooting_Godot/src/game/event/EventEnum.cs @@ -169,7 +169,7 @@ /// OnDeleteTileSetSource, /// - /// 设置TileSet纹理, 参数, 可能为 null + /// 设置TileSet纹理, 参数 /// OnSetTileTexture, /// diff --git a/DungeonShooting_Godot/src/game/manager/EditorTileSetManager.cs b/DungeonShooting_Godot/src/game/manager/EditorTileSetManager.cs index 0241586..b03a3d9 100644 --- a/DungeonShooting_Godot/src/game/manager/EditorTileSetManager.cs +++ b/DungeonShooting_Godot/src/game/manager/EditorTileSetManager.cs @@ -119,6 +119,98 @@ } } + /// + /// 获取指定索引的地形掩码存储的数据 + /// + public static int[] GetTileSetTerrainBit(TileSetTerrainInfo terrain, int index, byte type) + { + if (type == 1) //顶部墙壁 + { + switch (index) + { + //第一排 + case 0: return terrain._000_010_010; + case 1: return terrain._000_011_010; + case 2: return terrain._000_111_010; + case 3: return terrain._000_110_010; + + case 4: return terrain._110_111_010; + case 5: return terrain._000_111_011; + case 6: return terrain._000_111_110; + case 7: return terrain._011_111_010; + + case 8: return terrain._000_011_011; + case 9: return terrain._010_111_111; + case 10: return terrain._000_111_111; + case 11: return terrain._000_110_110; + + //第二排 + case 12: return terrain._010_010_010; + case 13: return terrain._010_011_010; + case 14: return terrain._010_111_010; + case 15: return terrain._010_110_010; + + case 16: return terrain._010_011_011; + case 17: return terrain._011_111_111; + case 18: return terrain._110_111_111; + case 19: return terrain._010_110_110; + + case 20: return terrain._011_011_011; + case 21: return terrain._011_111_110; + case 22: break; + case 23: return terrain._110_111_110; + + //第三排 + case 24: return terrain._010_010_000; + case 25: return terrain._010_011_000; + case 26: return terrain._010_111_000; + case 27: return terrain._010_110_000; + + case 28: return terrain._011_011_010; + case 29: return terrain._111_111_011; + case 30: return terrain._111_111_110; + case 31: return terrain._110_110_010; + + case 32: return terrain._011_111_011; + case 33: return terrain._111_111_111; + case 34: return terrain._110_111_011; + case 35: return terrain._110_110_110; + + //第四排 + case 36: return terrain._000_010_000; + case 37: return terrain._000_011_000; + case 38: return terrain._000_111_000; + case 39: return terrain._000_110_000; + + case 40: return terrain._010_111_110; + case 41: return terrain._011_111_000; + case 42: return terrain._110_111_000; + case 43: return terrain._010_111_011; + + case 44: return terrain._011_011_000; + case 45: return terrain._111_111_000; + case 46: return terrain._111_111_010; + case 47: return terrain._110_110_000; + } + } + else if (type == 2) //侧方墙壁 + { + switch (index) + { + case 0: return terrain._vs; + case 1: return terrain._vl; + case 2: return terrain._vc; + case 3: return terrain._vr; + } + } + else if (type == 3) //地板 + { + return terrain._f; + } + + return null; + } + //保存图块集 private static void OnTileSetSave(object o) { @@ -127,7 +219,27 @@ var dir = CustomMapPath + tileSetInfo.Name; if (Directory.Exists(dir)) { - Directory.Delete(dir, true); + //删除多余文件 + if (tileSetInfo.Sources == null) + { + Directory.Delete(dir, true); + } + else + { + var directoryInfo = new DirectoryInfo(dir); + var fileInfos = directoryInfo.GetFiles(); + foreach (var fileInfo in fileInfos) + { + if (fileInfo.Name.EndsWith(".png")) + { + var name = fileInfo.Name.Substring(0, fileInfo.Name.Length - 4); + if (tileSetInfo.Sources.FindIndex(info => info.Name == name) < 0) + { + fileInfo.Delete(); + } + } + } + } } Directory.CreateDirectory(dir); diff --git a/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs b/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs index 471b802..44af508 100644 --- a/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs +++ b/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs @@ -141,6 +141,7 @@ { var window = CreateWindowInstance(parentUi); window.SetWindowTitle(title); + window.SetWindowSize(new Vector2I(450, 230)); var body = window.OpenBody(UiManager.UiNames.EditorInput); window.CloseEvent += () => { diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs index fe2f6f2..a970df2 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs @@ -54,9 +54,13 @@ /// public UiGrid TabGrid { get; private set; } + private Image _emptyImage; + public override void OnCreateUi() { + _emptyImage = Image.Create(1, 1, false, Image.Format.Rgba8); Texture = new ImageTexture(); + Texture.SetImage(_emptyImage); S_Back.Instance.Visible = PrevUi != null; S_Back.Instance.Pressed += OnBackClick; @@ -93,7 +97,8 @@ { Texture.Dispose(); } - + + _emptyImage.Dispose(); TextureImage = null; if (TileSetInfo != null) @@ -134,6 +139,9 @@ { InitTexture = false; TextureImage = null; + Texture.SetImage(_emptyImage); + CellHorizontal = 0; + CellVertical = 0; } else { @@ -200,6 +208,7 @@ var findIndex = TileSetInfo.Sources.FindIndex(info => info.Name == name); if (findIndex >= 0) { + TileSetInfo.Sources[findIndex].Dispose(); TileSetInfo.Sources.RemoveAt(findIndex); } @@ -264,6 +273,7 @@ SetTextureData(null); } + //派发选择资源事件 EventManager.EmitEvent(EventEnum.OnSelectTileSetSource, TileSetSourceInfo); } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/TileSetEditorCombinationPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/TileSetEditorCombinationPanel.cs index 4cdefd3..80f450e 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/TileSetEditorCombinationPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/TileSetEditorCombinationPanel.cs @@ -14,12 +14,14 @@ { EditorPanel = (TileSetEditorPanel)ParentUi; + //改变选中资源事件 + AddEventListener(EventEnum.OnSelectTileSetSource, OnSelectTileSetSource); //改变纹理事件 AddEventListener(EventEnum.OnSetTileTexture, OnSetTileTexture); //改变背景颜色事件 AddEventListener(EventEnum.OnSetTileSetBgColor, OnSetTileSetBgColor); } - + public override void OnShowUi() { if (EditorPanel.Texture == null) @@ -35,12 +37,38 @@ { } + + //改变选中资源事件 + private void OnSelectTileSetSource(object obj) + { + //取消选中组合 + S_LeftBottomBg.Instance.ClearSelectCell(); + //清除绘制的组合 + S_LeftTopBg.Instance.ClearAllCell(); + //清除gird中的组合 + var grid = S_RightBg.Instance.Grid; + grid.RemoveAll(); + if (obj != null) + { + //grid加载组合 + var sourceInfo = (TileSetSourceInfo)obj; + foreach (var combinationInfo in sourceInfo.Combination) + { + var src = EditorPanel.TextureImage; + var previewImage = ImportCombinationData.GetPreviewTexture(src, combinationInfo.Cells, combinationInfo.Positions); + grid.Add(new ImportCombinationData(ImageTexture.CreateFromImage(previewImage), combinationInfo)); + } + } + } //改变TileSet纹理 private void OnSetTileTexture(object arg) { S_LeftBottomBg.Instance.OnChangeTileSetTexture(); - S_RightBg.Instance.OnChangeTileSetTexture(); + if (EditorPanel.InitTexture) + { + S_RightBg.Instance.OnChangeTileSetTexture(); + } } //改变TileSet背景颜色 diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs index 097d005..3691683 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs @@ -43,7 +43,7 @@ { if (Input.IsActionJustPressed(InputAction.MouseLeft)) //刚按下, 清除之前的选中 { - OnClearCell(); + ClearSelectCell(); } OnSelectCell(cellPosition); } @@ -108,7 +108,7 @@ /// /// 移除所有选中的Cell图块 /// - private void OnClearCell() + public void ClearSelectCell() { _useMask.Clear(); var count = _maskGrid.Count; diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs index 55a0c9f..7b3bc32 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs @@ -41,7 +41,7 @@ UiNode.UiPanel.AddEventListener(EventEnum.OnClearCombinationCell, OnClearCombinationCell); //删除按钮点击事件 - UiNode.L_DeleteBtn.Instance.Pressed += OnDeleteClick; + UiNode.L_DeleteBtn.Instance.Pressed += ClearAllCell; //聚焦按钮点击事件 UiNode.L_FocusBtn.Instance.Pressed += OnFocusClick; //导入组合按钮点击事件 @@ -127,8 +127,10 @@ } } - //删除所有图块 - private void OnDeleteClick() + /// + /// 删除已经绘制的图块 + /// + public void ClearAllCell() { foreach (var keyValuePair in _canvas) { @@ -150,7 +152,12 @@ private void OnImportClick() { var size = UiNode.L_CombinationRoot.L_RectBrush.Instance.GetRectSize(); - if (size == Vector2.Zero) + if (UiNode.UiPanel.EditorPanel.TextureImage == null) + { + EditorWindowManager.ShowTips("警告", "未选择纹理资源!"); + return; + } + else if (size == Vector2.Zero) { EditorWindowManager.ShowTips("警告", "请先绘制组合图块!"); return; diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs index 95bbe07..93bf1d7 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs @@ -4,24 +4,27 @@ public partial class TileSelected : VBoxContainer, IUiNodeScript { + /// + /// 存放所有组合数据 + /// + public UiGrid Grid { get; private set; } + private TileSetEditorCombination.RightBg _rightBg; - //存放所有组合数据 - private UiGrid _grid; public void SetUiNode(IUiNode uiNode) { _rightBg = (TileSetEditorCombination.RightBg)uiNode; - _grid = new UiGrid(_rightBg.L_ScrollContainer.L_CellButton, typeof(TileCell)); - _grid.SetCellOffset(new Vector2I(5, 5)); - _grid.SetAutoColumns(true); - _grid.SetHorizontalExpand(true); + Grid = new UiGrid(_rightBg.L_ScrollContainer.L_CellButton, typeof(TileCell)); + Grid.SetCellOffset(new Vector2I(5, 5)); + Grid.SetAutoColumns(true); + Grid.SetHorizontalExpand(true); _rightBg.UiPanel.AddEventListener(EventEnum.OnImportCombination, OnImportCombination); _rightBg.UiPanel.AddEventListener(EventEnum.OnRemoveCombination, OnRemoveCombination); _rightBg.UiPanel.AddEventListener(EventEnum.OnUpdateCombination, OnUpdateCombination); } - + /// /// 导入组合图块 /// @@ -30,8 +33,8 @@ if (obj is ImportCombinationData data) { _rightBg.UiPanel.EditorPanel.TileSetSourceInfo.Combination.Add(data.CombinationInfo); - _grid.Add(data); - _grid.Sort(); + Grid.Add(data); + Grid.Sort(); } } @@ -42,11 +45,11 @@ { if (obj is ImportCombinationData data) { - var uiCell = _grid.Find(c => c.Data.CombinationInfo.Id == data.CombinationInfo.Id); + var uiCell = Grid.Find(c => c.Data.CombinationInfo.Id == data.CombinationInfo.Id); _rightBg.UiPanel.EditorPanel.TileSetSourceInfo.Combination.Remove(data.CombinationInfo); if (uiCell != null) { - _grid.RemoveByIndex(uiCell.Index); + Grid.RemoveByIndex(uiCell.Index); } } } @@ -58,7 +61,7 @@ { if (obj is ImportCombinationData data) { - var uiCell = _grid.Find(c => c.Data.CombinationInfo.Id == data.CombinationInfo.Id); + var uiCell = Grid.Find(c => c.Data.CombinationInfo.Id == data.CombinationInfo.Id); if (uiCell != null) { uiCell.SetData(data); @@ -68,7 +71,7 @@ public void OnDestroy() { - _grid.Destroy(); + Grid.Destroy(); } @@ -79,7 +82,7 @@ { //_grid.RemoveAll(); //刷新预览图 - _grid.ForEach(cell => + Grid.ForEach(cell => { cell.Data.UpdatePreviewTexture(_rightBg.UiPanel.EditorPanel.TextureImage); }); diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs index c2e3fe4..ce0f1e5 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs @@ -46,18 +46,16 @@ private void OnSetTileTexture(object arg) { //判断是否已经初始化好纹理了 - if (_tileSetEditor.InitTexture) - { - S_ImportPreviewBg.Instance.Visible = true; - S_ReimportButton.Instance.Visible = true; - S_ImportColorPicker.Instance.Visible = true; - S_FocusBtn.Instance.Visible = true; - - //隐藏导入文本和icon - S_ImportLabel.Instance.Visible = false; - S_ImportIcon.Instance.Visible = false; - S_ImportButton.Instance.Visible = false; - } + //_tileSetEditor.InitTexture + S_ImportPreviewBg.Instance.Visible = _tileSetEditor.InitTexture; + S_ReimportButton.Instance.Visible = _tileSetEditor.InitTexture; + S_ImportColorPicker.Instance.Visible = _tileSetEditor.InitTexture; + S_FocusBtn.Instance.Visible = _tileSetEditor.InitTexture; + + //隐藏导入文本和icon + S_ImportLabel.Instance.Visible = !_tileSetEditor.InitTexture; + S_ImportIcon.Instance.Visible = !_tileSetEditor.InitTexture; + S_ImportButton.Instance.Visible = !_tileSetEditor.InitTexture; } //背景颜色改变 @@ -175,15 +173,16 @@ /// 纹理路径 private void SetImportTexture(string file) { - if (_tileSetEditor.TileSetSourceInfo == null) + var tileSetSourceInfo = _tileSetEditor.TileSetSourceInfo; + if (tileSetSourceInfo == null) { return; } Debug.Log("导入文件: " + file); var image = Image.LoadFromFile(file); - _tileSetEditor.TileSetSourceInfo.SourcePath = file; - _tileSetEditor.TileSetSourceInfo.SetSourceImage(image); + tileSetSourceInfo.SourcePath = GameConfig.RoomTileSetDir + _tileSetEditor.TileSetInfo.Name + "/" + tileSetSourceInfo.Name + ".png"; + tileSetSourceInfo.SetSourceImage(image); _tileSetEditor.SetTextureData(image); } } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs index e06d614..1b87644 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs @@ -24,6 +24,8 @@ { EditorPanel = (TileSetEditorPanel)ParentUi; + //改变选中的TileSet资源 + AddEventListener(EventEnum.OnSelectTileSetSource, OnSelectTileSetSource); //改变纹理事件 AddEventListener(EventEnum.OnSetTileTexture, OnSetTileTexture); //背景颜色改变 @@ -69,6 +71,45 @@ return grid; } + //改变选中的TileSet资源 + private void OnSelectTileSetSource(object obj) + { + //先清除所有绑定的Terrain + _topGrid1.ForEach(cell => cell.CellNode.Instance.ClearCell()); + _topGrid2.ForEach(cell => cell.CellNode.Instance.ClearCell()); + _topGrid3.ForEach(cell => cell.CellNode.Instance.ClearCell()); + + //再加载Terrain + if (obj != null) + { + var terrain = ((TileSetSourceInfo)obj).Terrain; + _topGrid1.ForEach(cell => + { + var ints = EditorTileSetManager.GetTileSetTerrainBit(terrain, cell.Index, cell.Data); + if (ints != null) + { + cell.CellNode.Instance.SetCell(new Rect2I(ints[0], ints[1], GameConfig.TileCellSize, GameConfig.TileCellSize)); + } + }); + _topGrid2.ForEach(cell => + { + var ints = EditorTileSetManager.GetTileSetTerrainBit(terrain, cell.Index, cell.Data); + if (ints != null) + { + cell.CellNode.Instance.SetCell(new Rect2I(ints[0], ints[1], GameConfig.TileCellSize, GameConfig.TileCellSize)); + } + }); + _topGrid3.ForEach(cell => + { + var ints = EditorTileSetManager.GetTileSetTerrainBit(terrain, cell.Index, cell.Data); + if (ints != null) + { + cell.CellNode.Instance.SetCell(new Rect2I(ints[0], ints[1], GameConfig.TileCellSize, GameConfig.TileCellSize)); + } + }); + } + } + //改变TileSet纹理 private void OnSetTileTexture(object arg) { diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCellDropHandler.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCellDropHandler.cs index b6d18f5..28a8d9f 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCellDropHandler.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCellDropHandler.cs @@ -31,12 +31,7 @@ public override void _DropData(Vector2 atPosition, Variant data) { var rect = data.AsRect2I(); - TextureCell = rect.Position; - var sprite2D = _cell.CellNode.L_CellTexture.Instance; - sprite2D.Texture = _panel.EditorPanel.Texture; - sprite2D.RegionEnabled = true; - sprite2D.RegionRect = rect; - IsPutDownTexture = true; + SetCell(rect); SetTerrainBitData(new []{ TextureCell.X, TextureCell.Y }); } @@ -46,12 +41,33 @@ if (@event is InputEventMouseButton mouseEvent && mouseEvent.ButtonIndex == MouseButton.Right && mouseEvent.Pressed) { AcceptEvent(); - _cell.CellNode.L_CellTexture.Instance.Texture = null; - IsPutDownTexture = false; + ClearCell(); SetTerrainBitData(null); } } + /// + /// 设置选择的Cell + /// + public void SetCell(Rect2I rect) + { + TextureCell = rect.Position; + var sprite2D = _cell.CellNode.L_CellTexture.Instance; + sprite2D.Texture = _panel.EditorPanel.Texture; + sprite2D.RegionEnabled = true; + sprite2D.RegionRect = rect; + IsPutDownTexture = true; + } + + /// + /// 清除选中的cell + /// + public void ClearCell() + { + _cell.CellNode.L_CellTexture.Instance.Texture = null; + IsPutDownTexture = false; + } + private void SetTerrainBitData(int[] cellData) { EditorTileSetManager.SetTileSetTerrainBit(_panel.EditorPanel.TileSetSourceInfo.Terrain, _cell.Index, _cell.Data, cellData);