diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapTile/TerrainCell.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapTile/TerrainCell.cs index 4158ebf..7de0b47 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorMapTile/TerrainCell.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapTile/TerrainCell.cs @@ -1,4 +1,7 @@ -namespace UI.MapEditorMapTile; +using Godot; +using static TerrainPeering; + +namespace UI.MapEditorMapTile; /// /// 地形选项, Data 为 TileSetTerrainInfo 的 index @@ -9,9 +12,14 @@ /// 选中的地形配置数据 /// public TileSetTerrainInfo TileSetTerrainInfo; + + private Image _image; + private ImageTexture _texture; public override void OnInit() { + _texture = new ImageTexture(); + CellNode.L_TerrainPreview.Instance.Texture = _texture; CellNode.L_Select.Instance.Visible = false; CellNode.L_ErrorIcon.Instance.Visible = false; } @@ -22,14 +30,49 @@ CellNode.L_TerrainName.Instance.Text = TileSetTerrainInfo.Name; //是否可以使用 - if (TileSetTerrainInfo.Ready) + CellNode.L_ErrorIcon.Instance.Visible = !TileSetTerrainInfo.Ready; + + if (_image != null) { - CellNode.L_ErrorIcon.Instance.Visible = false; - + _image.Dispose(); } - else + + //创建预览图 + _image = Image.Create( + 3 * GameConfig.TileCellSize, + 3 * GameConfig.TileCellSize, + false, Image.Format.Rgba8 + ); + if (TileSetTerrainInfo.TerrainType == 0) //3x3 { - CellNode.L_ErrorIcon.Instance.Visible = true; + + } + else //2x2 + { + var src = CellNode.UiPanel.TileSetSourceInfo.GetSourceImage(); + int[] temp; + if (TileSetTerrainInfo.T.TryGetValue(Center | RightBottom, out temp)) + { + var pos = TileSetTerrainInfo.GetPosition(temp); + _image.BlitRect(src, new Rect2I(pos * GameConfig.TileCellSize, GameConfig.TileCellSizeVector2I), new Vector2I(0, 0)); + } + } + + _texture.SetImage(_image); + } + + public override void OnDestroy() + { + if (_texture != null) + { + _texture.Dispose(); + _texture = null; + } + + if (_image != null) + { + _image.Dispose(); + _image = null; } }