diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn index e4b32fa..a3f6801 100644 --- a/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn +++ b/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn @@ -88,20 +88,6 @@ z_index = -1 centered = false -[node name="ColorRect" type="ColorRect" parent="VSplitContainer/PanelTop/MarginContainer/TopBg/TerrainRoot/CellRoot/RightCell"] -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_left = 3.0 -offset_top = 3.0 -offset_right = -4.0 -offset_bottom = -4.0 -grow_horizontal = 2 -grow_vertical = 2 -mouse_filter = 2 -color = Color(0, 0, 0, 0.6) - [node name="TerrainTexture1" type="TextureRect" parent="VSplitContainer/PanelTop/MarginContainer/TopBg/TerrainRoot"] self_modulate = Color(1, 1, 1, 0.27451) custom_minimum_size = Vector2(192, 64) @@ -223,7 +209,7 @@ selected = 0 popup/item_0/text = "47格(3*3)" popup/item_0/id = 0 -popup/item_1/text = "13格(2*2))" +popup/item_1/text = "13格(2*2)" popup/item_1/id = 1 [node name="PanelBottom" type="Panel" parent="VSplitContainer"] diff --git a/DungeonShooting_Godot/resource/map/tileSet/TileSet2/TileSet.json b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/TileSet.json index d1a041d..c76beae 100644 --- a/DungeonShooting_Godot/resource/map/tileSet/TileSet2/TileSet.json +++ b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/TileSet.json @@ -89,8 +89,13 @@ "24": [ 48, 0 + ], + "272": [ + 0, + 0 ] - } + }, + "TerrainType": 1 }, "Combination": [ { @@ -301,32 +306,8 @@ "Terrain": { "F": {}, "M": {}, - "T": { - "144": [ - 0, - 0 - ], - "48": [ - 16, - 0 - ], - "56": [ - 32, - 0 - ], - "24": [ - 48, - 0 - ], - "250": [ - 64, - 48 - ], - "442": [ - 112, - 48 - ] - } + "T": {}, + "TerrainType": 1 }, "Combination": [ { diff --git a/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetTerrainInfo.cs b/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetTerrainInfo.cs index 2e0bfa8..aac6b37 100644 --- a/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetTerrainInfo.cs +++ b/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetTerrainInfo.cs @@ -2,16 +2,16 @@ using System.Collections.Generic; using System.Text.Json.Serialization; using Godot; +using static TerrainPeering; /// /// 地形配置数据, 数据都为 int 数组, 下标0和1分别代表x和y, 单位: 像素 /// public class TileSetTerrainInfo : IClone { - public const byte TopLayerType = 1; + public const byte TerrainLayerType = 1; public const byte MiddleLayerType = 2; public const byte FloorLayerType = 3; - public const byte Terrain2x2Type = 4; //type = 3 /// @@ -25,15 +25,22 @@ [JsonInclude] public Dictionary M; /// - /// 顶部墙壁47格 (47块) type = 1 + /// 自动平铺地形 (47块/13块) type = 1 /// [JsonInclude] public Dictionary T; + /// + /// 地形类型, 0: 3x3地形, 1: 2x2地形 + /// + [JsonInclude] + public byte TerrainType; + public void InitData() { - T = new Dictionary(); - M = new Dictionary(); + TerrainType = 0; F = new Dictionary(); + M = new Dictionary(); + T = new Dictionary(); } public TileSetTerrainInfo Clone() @@ -52,16 +59,32 @@ { terrainInfo.F.Add(pair.Key, new []{ pair.Value[0], pair.Value[1] }); } + terrainInfo.TerrainType = TerrainType; return terrainInfo; } - + /// /// 返回这个TileSet地形是否可以正常使用了 /// /// public bool CanUse() { - return T != null && T.Count == 47 && M != null && M.Count == 4 && F != null && F.Count == 1; + if (TerrainType == 0) + { + if (T == null || T.Count != 47) + { + return false; + } + } + else + { + if (T == null || T.Count != 13) + { + return false; + } + } + + return M != null && M.Count == 4 && F != null && F.Count == 1; } /// @@ -79,19 +102,18 @@ /// 地形类型 public int TerrainCoordsToIndex(Vector2I bitCoords, byte type) { - if (type == 1) + if (type == TerrainLayerType) { - return bitCoords.Y * GameConfig.TerrainBitSize1.X + bitCoords.X; + return bitCoords.Y * GameConfig.TerrainBit3x3.X + bitCoords.X; } - else if (type == 2) + else if (type == MiddleLayerType) { - return bitCoords.Y * GameConfig.TerrainBitSize2.X + bitCoords.X; + return bitCoords.Y * GameConfig.TerrainBitMiddle.X + bitCoords.X; } - else if (type == 3) + else if (type == FloorLayerType) { - return bitCoords.Y * GameConfig.TerrainBitSize3.X + bitCoords.X; + return bitCoords.Y * GameConfig.TerrainBitFloor.X + bitCoords.X; } - return -1; } @@ -102,57 +124,82 @@ /// 地形类型 public int TerrainBitToIndex(uint bit, byte type) { - if (type == TopLayerType) //顶部墙壁 + if (type == TerrainLayerType) //顶部墙壁 { - switch (bit) + if (TerrainType == 0) //47格 { - case TerrainPeering.Center | TerrainPeering.Bottom: return 0; - case TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: return 1; - case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: return 2; - case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Bottom: return 3; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: return 4; - case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 5; - case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom: return 6; - case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: return 7; - case TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 8; - case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 9; - case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 10; - case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.LeftBottom | TerrainPeering.Bottom: return 11; - case TerrainPeering.Top | TerrainPeering.Center | TerrainPeering.Bottom: return 12; - case TerrainPeering.Top | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: return 13; - case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: return 14; - case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Bottom: return 15; - case TerrainPeering.Top | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 16; - case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 17; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 18; - case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.LeftBottom | TerrainPeering.Bottom: return 19; - case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 20; - case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom: return 21; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom: return 23; - case TerrainPeering.Top | TerrainPeering.Center: return 24; - case TerrainPeering.Top | TerrainPeering.Center | TerrainPeering.Right: return 25; - case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right: return 26; - case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center: return 27; - case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: return 28; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 29; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom: return 30; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Bottom: return 31; - case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 32; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 33; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 34; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.LeftBottom | TerrainPeering.Bottom: return 35; - case TerrainPeering.Center: return 36; - case TerrainPeering.Center | TerrainPeering.Right: return 37; - case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right: return 38; - case TerrainPeering.Left | TerrainPeering.Center: return 39; - case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom: return 40; - case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right: return 41; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right: return 42; - case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: return 43; - case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Center | TerrainPeering.Right: return 44; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right: return 45; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: return 46; - case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center: return 47; + switch (bit) + { + case Center | Bottom: return 0; + case Center | Right | Bottom: return 1; + case Left | Center | Right | Bottom: return 2; + case Left | Center | Bottom: return 3; + case LeftTop | Top | Left | Center | Right | Bottom: return 4; + case Left | Center | Right | Bottom | RightBottom: return 5; + case Left | Center | Right | LeftBottom | Bottom: return 6; + case Top | RightTop | Left | Center | Right | Bottom: return 7; + case Center | Right | Bottom | RightBottom: return 8; + case Top | Left | Center | Right | LeftBottom | Bottom | RightBottom: return 9; + case Left | Center | Right | LeftBottom | Bottom | RightBottom: return 10; + case Left | Center | LeftBottom | Bottom: return 11; + case Top | Center | Bottom: return 12; + case Top | Center | Right | Bottom: return 13; + case Top | Left | Center | Right | Bottom: return 14; + case Top | Left | Center | Bottom: return 15; + case Top | Center | Right | Bottom | RightBottom: return 16; + case Top | RightTop | Left | Center | Right | LeftBottom | Bottom | RightBottom: return 17; + case LeftTop | Top | Left | Center | Right | LeftBottom | Bottom | RightBottom: return 18; + case Top | Left | Center | LeftBottom | Bottom: return 19; + case Top | RightTop | Center | Right | Bottom | RightBottom: return 20; + case Top | RightTop | Left | Center | Right | LeftBottom | Bottom: return 21; + case LeftTop | Top | Left | Center | Right | LeftBottom | Bottom: return 23; + case Top | Center: return 24; + case Top | Center | Right: return 25; + case Top | Left | Center | Right: return 26; + case Top | Left | Center: return 27; + case Top | RightTop | Center | Right | Bottom: return 28; + case LeftTop | Top | RightTop | Left | Center | Right | Bottom | RightBottom: return 29; + case LeftTop | Top | RightTop | Left | Center | Right | LeftBottom | Bottom: return 30; + case LeftTop | Top | Left | Center | Bottom: return 31; + case Top | RightTop | Left | Center | Right | Bottom | RightBottom: return 32; + case LeftTop | Top | RightTop | Left | Center | Right | LeftBottom | Bottom | RightBottom: return 33; + case LeftTop | Top | Left | Center | Right | Bottom | RightBottom: return 34; + case LeftTop | Top | Left | Center | LeftBottom | Bottom: return 35; + case Center: return 36; + case Center | Right: return 37; + case Left | Center | Right: return 38; + case Left | Center: return 39; + case Top | Left | Center | Right | LeftBottom | Bottom: return 40; + case Top | RightTop | Left | Center | Right: return 41; + case LeftTop | Top | Left | Center | Right: return 42; + case Top | Left | Center | Right | Bottom | RightBottom: return 43; + case Top | RightTop | Center | Right: return 44; + case LeftTop | Top | RightTop | Left | Center | Right: return 45; + case LeftTop | Top | RightTop | Left | Center | Right | Bottom: return 46; + case LeftTop | Top | Left | Center: return 47; + } + } + else if (TerrainType == 1) //13格 + { + switch (bit) + { + //第一排 + case Center | RightBottom: return 0; + case Center | RightBottom | LeftBottom: return 1; + case Center | LeftBottom: return 2; + case Center | LeftTop | RightTop | LeftBottom: return 3; + case Center | LeftTop | RightTop | RightBottom: return 4; + //第二排 + case Center | RightTop | RightBottom: return 5; + case Center | LeftTop | LeftBottom | RightTop | RightBottom: return 6; + case Center | LeftTop | LeftBottom: return 7; + case Center | LeftTop | LeftBottom | RightBottom: return 8; + case Center | RightTop | LeftBottom | RightBottom: return 9; + //第三排 + case Center | RightTop: return 10; + case Center | LeftTop | RightBottom: return 11; + case Center | LeftTop: return 12; + } } } else if (type == MiddleLayerType) @@ -181,56 +228,82 @@ /// public uint IndexToTerrainBit(int index, byte type) { - if (type == TopLayerType) //顶部墙壁 + if (type == TerrainLayerType) //顶部墙壁 { - switch (index) + if (TerrainType == 0) //47格 { - case 0: return TerrainPeering.Center | TerrainPeering.Bottom; - case 1: return TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom; - case 2: return TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom; - case 3: return TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Bottom; - case 4: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom; - case 5: return TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom; - case 6: return TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom; - case 7: return TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom; - case 8: return TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom; - case 9: return TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom; - case 10: return TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom; - case 11: return TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.LeftBottom | TerrainPeering.Bottom; - case 12: return TerrainPeering.Top | TerrainPeering.Center | TerrainPeering.Bottom; - case 13: return TerrainPeering.Top | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom; - case 14: return TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom; - case 15: return TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Bottom; - case 16: return TerrainPeering.Top | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom; - case 17: return TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom; - case 18: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom; - case 19: return TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.LeftBottom | TerrainPeering.Bottom; - case 20: return TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom; case 21: return TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom; - case 23: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom; - case 24: return TerrainPeering.Top | TerrainPeering.Center; - case 25: return TerrainPeering.Top | TerrainPeering.Center | TerrainPeering.Right; - case 26: return TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right; - case 27: return TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center; - case 28: return TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom; - case 29: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom; - case 30: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom; - case 31: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Bottom; - case 32: return TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom; - case 33: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom; - case 34: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom; - case 35: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.LeftBottom | TerrainPeering.Bottom; - case 36: return TerrainPeering.Center; - case 37: return TerrainPeering.Center | TerrainPeering.Right; - case 38: return TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right; - case 39: return TerrainPeering.Left | TerrainPeering.Center; - case 40: return TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom; - case 41: return TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right; - case 42: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right; - case 43: return TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom; - case 44: return TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Center | TerrainPeering.Right; - case 45: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right; - case 46: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom; - case 47: return TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center; + switch (index) + { + case 0: return Center | Bottom; + case 1: return Center | Right | Bottom; + case 2: return Left | Center | Right | Bottom; + case 3: return Left | Center | Bottom; + case 4: return LeftTop | Top | Left | Center | Right | Bottom; + case 5: return Left | Center | Right | Bottom | RightBottom; + case 6: return Left | Center | Right | LeftBottom | Bottom; + case 7: return Top | RightTop | Left | Center | Right | Bottom; + case 8: return Center | Right | Bottom | RightBottom; + case 9: return Top | Left | Center | Right | LeftBottom | Bottom | RightBottom; + case 10: return Left | Center | Right | LeftBottom | Bottom | RightBottom; + case 11: return Left | Center | LeftBottom | Bottom; + case 12: return Top | Center | Bottom; + case 13: return Top | Center | Right | Bottom; + case 14: return Top | Left | Center | Right | Bottom; + case 15: return Top | Left | Center | Bottom; + case 16: return Top | Center | Right | Bottom | RightBottom; + case 17: return Top | RightTop | Left | Center | Right | LeftBottom | Bottom | RightBottom; + case 18: return LeftTop | Top | Left | Center | Right | LeftBottom | Bottom | RightBottom; + case 19: return Top | Left | Center | LeftBottom | Bottom; + case 20: return Top | RightTop | Center | Right | Bottom | RightBottom; + case 21: return Top | RightTop | Left | Center | Right | LeftBottom | Bottom; + case 23: return LeftTop | Top | Left | Center | Right | LeftBottom | Bottom; + case 24: return Top | Center; + case 25: return Top | Center | Right; + case 26: return Top | Left | Center | Right; + case 27: return Top | Left | Center; + case 28: return Top | RightTop | Center | Right | Bottom; + case 29: return LeftTop | Top | RightTop | Left | Center | Right | Bottom | RightBottom; + case 30: return LeftTop | Top | RightTop | Left | Center | Right | LeftBottom | Bottom; + case 31: return LeftTop | Top | Left | Center | Bottom; + case 32: return Top | RightTop | Left | Center | Right | Bottom | RightBottom; + case 33: return LeftTop | Top | RightTop | Left | Center | Right | LeftBottom | Bottom | RightBottom; + case 34: return LeftTop | Top | Left | Center | Right | Bottom | RightBottom; + case 35: return LeftTop | Top | Left | Center | LeftBottom | Bottom; + case 36: return Center; + case 37: return Center | Right; + case 38: return Left | Center | Right; + case 39: return Left | Center; + case 40: return Top | Left | Center | Right | LeftBottom | Bottom; + case 41: return Top | RightTop | Left | Center | Right; + case 42: return LeftTop | Top | Left | Center | Right; + case 43: return Top | Left | Center | Right | Bottom | RightBottom; + case 44: return Top | RightTop | Center | Right; + case 45: return LeftTop | Top | RightTop | Left | Center | Right; + case 46: return LeftTop | Top | RightTop | Left | Center | Right | Bottom; + case 47: return LeftTop | Top | Left | Center; + } + } + else if (TerrainType == 1) //13格 + { + switch (index) + { + //第一排 + case 0: return Center | RightBottom; + case 1: return Center | RightBottom | LeftBottom; + case 2: return Center | LeftBottom; + case 3: return Center | LeftTop | RightTop | LeftBottom; + case 4: return Center | LeftTop | RightTop | RightBottom; + //第二排 + case 5: return Center | RightTop | RightBottom; + case 6: return Center | LeftTop | LeftBottom | RightTop | RightBottom; + case 7: return Center | LeftTop | LeftBottom; + case 8: return Center | LeftTop | LeftBottom | RightBottom; + case 9: return Center | RightTop | LeftBottom | RightBottom; + //第三排 + case 10: return Center | RightTop; + case 11: return Center | LeftTop | RightBottom; + case 12: return Center | LeftTop; + } } } else if (type == MiddleLayerType) @@ -241,7 +314,7 @@ } } - return TerrainPeering.None; + return None; } /// @@ -249,15 +322,15 @@ /// public void SetTerrainCell(int index, byte type, int[] cellData) { - if (type == 1) //顶部墙壁 + if (type == TerrainLayerType) //顶部墙壁 { var terrainBit = IndexToTerrainBit(index, type); - if (terrainBit != TerrainPeering.None) + if (terrainBit != None) { T[terrainBit] = cellData; } } - else if (type == 2) //侧方墙壁 + else if (type == MiddleLayerType) //侧方墙壁 { switch (index) { @@ -267,7 +340,7 @@ case 3: M[3] = cellData; break; } } - else if (type == 3) //地板 + else if (type == FloorLayerType) //地板 { F[0] = cellData; } @@ -278,15 +351,15 @@ /// public void RemoveTerrainCell(int index, byte type) { - if (type == 1) //顶部墙壁 + if (type == TerrainLayerType) //顶部墙壁 { var terrainBit = IndexToTerrainBit(index, type); - if (terrainBit != TerrainPeering.None) + if (terrainBit != None) { T.Remove(terrainBit); } } - else if (type == 2) //侧方墙壁 + else if (type == MiddleLayerType) //侧方墙壁 { switch (index) { @@ -296,7 +369,7 @@ case 3: M.Remove(3); break; } } - else if (type == 3) //地板 + else if (type == FloorLayerType) //地板 { F.Remove(0); } @@ -307,10 +380,10 @@ /// public int[] GetTerrainCell(int index, byte type) { - if (type == 1) //顶部墙壁 + if (type == TerrainLayerType) //顶部墙壁 { var terrainBit = IndexToTerrainBit(index, type); - if (terrainBit != TerrainPeering.None) + if (terrainBit != None) { if (T.TryGetValue(terrainBit, out var cellData)) { @@ -318,7 +391,7 @@ } } } - else if (type == 2) //侧方墙壁 + else if (type == MiddleLayerType) //侧方墙壁 { switch (index) { @@ -344,7 +417,7 @@ break; } } - else if (type == 3) //地板 + else if (type == FloorLayerType) //地板 { if (F.TryGetValue(0, out var cellData)) return cellData; } diff --git a/DungeonShooting_Godot/src/game/GameConfig.cs b/DungeonShooting_Godot/src/game/GameConfig.cs index 1d1e741..a42e0fe 100644 --- a/DungeonShooting_Godot/src/game/GameConfig.cs +++ b/DungeonShooting_Godot/src/game/GameConfig.cs @@ -109,17 +109,17 @@ /// /// 地形掩码纹理大小, 顶部墙壁/47格地形 /// - public static readonly Vector2I TerrainBitSize1 = new Vector2I(12, 4); - /// - /// 地形掩码纹理大小, 侧方墙壁 - /// - public static readonly Vector2I TerrainBitSize2 = new Vector2I(4, 1); - /// - /// 地形掩码纹理大小, 地板 - /// - public static readonly Vector2I TerrainBitSize3 = new Vector2I(1, 1); + public static readonly Vector2I TerrainBit3x3 = new Vector2I(12, 4); /// /// 地形掩码纹理大小, 13格地形 /// - public static readonly Vector2I TerrainBitSize4 = new Vector2I(5, 3); + public static readonly Vector2I TerrainBit2x2 = new Vector2I(5, 3); + /// + /// 地形掩码纹理大小, 侧方墙壁 + /// + public static readonly Vector2I TerrainBitMiddle = new Vector2I(4, 1); + /// + /// 地形掩码纹理大小, 地板 + /// + public static readonly Vector2I TerrainBitFloor = new Vector2I(1, 1); } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/room/AutoTileConfig.cs b/DungeonShooting_Godot/src/game/room/AutoTileConfig.cs index 599edec..d7a21cc 100644 --- a/DungeonShooting_Godot/src/game/room/AutoTileConfig.cs +++ b/DungeonShooting_Godot/src/game/room/AutoTileConfig.cs @@ -187,185 +187,185 @@ { //第一列 case TerrainPeering.Center | TerrainPeering.Bottom: - Auto_000_010_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_000_010_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.Center | TerrainPeering.Bottom: - Auto_010_010_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_010_010_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.Center: - Auto_010_010_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_010_010_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; case TerrainPeering.Center: - Auto_000_010_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_000_010_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; //第二列 case TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: - Auto_000_011_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_000_011_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: - Auto_010_011_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_010_011_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.Center | TerrainPeering.Right: - Auto_010_011_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_010_011_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; case TerrainPeering.Center | TerrainPeering.Right: - Auto_000_011_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_000_011_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; //第三列 case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: - Auto_000_111_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_000_111_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: - Auto_010_111_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_010_111_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right: - Auto_010_111_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_010_111_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right: - Auto_000_111_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_000_111_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; //第四列 case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Bottom: - Auto_000_110_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_000_110_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Bottom: - Auto_010_110_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_010_110_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center: - Auto_010_110_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_010_110_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; case TerrainPeering.Left | TerrainPeering.Center: - Auto_000_110_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_000_110_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; //第五列 case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: - Auto_110_111_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_110_111_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_010_011_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_010_011_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: - Auto_011_011_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_011_011_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom: - Auto_010_111_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_010_111_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; //第六列 case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_000_111_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_000_111_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_011_111_111 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_011_111_111 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_111_111_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_111_111_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right: - Auto_011_111_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_011_111_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; //第七列 case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom: - Auto_000_111_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_000_111_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_110_111_111 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_110_111_111 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom: - Auto_111_111_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_111_111_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right: - Auto_110_111_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_110_111_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; //第八列 case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: - Auto_011_111_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_011_111_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.LeftBottom | TerrainPeering.Bottom: - Auto_010_110_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_010_110_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Bottom: - Auto_110_110_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_110_110_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_010_111_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_010_111_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; //第九列 case TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_000_011_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_000_011_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_011_011_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_011_011_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_011_111_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_011_111_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Center | TerrainPeering.Right: - Auto_011_011_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_011_011_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; //第十列 case TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_010_111_111 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_010_111_111 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_110_111_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_110_111_011 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_111_111_111 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_111_111_111 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right: - Auto_111_111_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_111_111_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; //第十一列 case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom | TerrainPeering.RightBottom: - Auto_000_111_111 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_000_111_111 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom: - Auto_011_111_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_011_111_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.RightTop | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.Bottom: - Auto_111_111_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_111_111_010 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; //第十二列 case TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.LeftBottom | TerrainPeering.Bottom: - Auto_000_110_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_000_110_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.Right | TerrainPeering.LeftBottom | TerrainPeering.Bottom: - Auto_110_111_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_110_111_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center | TerrainPeering.LeftBottom | TerrainPeering.Bottom: - Auto_110_110_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.TopMapLayer); + Auto_110_110_110 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.TopMapLayer); break; case TerrainPeering.LeftTop | TerrainPeering.Top | TerrainPeering.Left | TerrainPeering.Center: - Auto_110_110_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TopLayerType, GameConfig.MiddleMapLayer); + Auto_110_110_000 = new TileCellData(sourceId, pos, peeringValue, TileSetTerrainInfo.TerrainLayerType, GameConfig.MiddleMapLayer); break; default: diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs index 1176d9b..c210c6e 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs @@ -54,15 +54,6 @@ } /// - /// 类型: , 路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.CellRoot.RightCell.ColorRect - /// - public class ColorRect : UiNode - { - public ColorRect(TileSetEditorTerrainPanel uiPanel, Godot.ColorRect node) : base(uiPanel, node) { } - public override ColorRect Clone() => new (UiPanel, (Godot.ColorRect)Instance.Duplicate()); - } - - /// /// 类型: , 路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.CellRoot.RightCell /// public class RightCell : UiNode @@ -80,19 +71,6 @@ } private CellTexture _L_CellTexture; - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.CellRoot.ColorRect - /// - public ColorRect L_ColorRect - { - get - { - if (_L_ColorRect == null) _L_ColorRect = new ColorRect(UiPanel, Instance.GetNode("ColorRect")); - return _L_ColorRect; - } - } - private ColorRect _L_ColorRect; - public RightCell(TileSetEditorTerrainPanel uiPanel, Godot.Control node) : base(uiPanel, node) { } public override RightCell Clone() => new (UiPanel, (Godot.Control)Instance.Duplicate()); } @@ -707,11 +685,6 @@ public CellTexture S_CellTexture => L_VSplitContainer.L_PanelTop.L_MarginContainer.L_TopBg.L_TerrainRoot.L_CellRoot.L_RightCell.L_CellTexture; /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.CellRoot.RightCell.ColorRect - /// - public ColorRect S_ColorRect => L_VSplitContainer.L_PanelTop.L_MarginContainer.L_TopBg.L_TerrainRoot.L_CellRoot.L_RightCell.L_ColorRect; - - /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.CellRoot.RightCell /// public RightCell S_RightCell => L_VSplitContainer.L_PanelTop.L_MarginContainer.L_TopBg.L_TerrainRoot.L_CellRoot.L_RightCell; diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs index b35eb97..2d0e61d 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs @@ -15,11 +15,11 @@ /// public MaskCell DraggingCell { get; set; } - public UiGrid TopGrid1; - public UiGrid TopGrid2; - public UiGrid TopGrid3; - public UiGrid TopGrid4; - public UiGrid BottomGrid; + public UiGrid TerrainGrid3x3; + public UiGrid TerrainGrid2x2; + public UiGrid TerrainGridMiddle; + public UiGrid TerrainGridFloor; + public UiGrid MaskGrid; private bool _refreshGridConnect = false; @@ -35,14 +35,14 @@ //背景颜色改变 AddEventListener(EventEnum.OnSetTileSetBgColor, OnChangeTileSetBgColor); - BottomGrid = CreateUiGrid(S_BottomCell); - BottomGrid.SetCellOffset(Vector2I.Zero); - BottomGrid.GridContainer.MouseFilter = MouseFilterEnum.Ignore; + MaskGrid = CreateUiGrid(S_BottomCell); + MaskGrid.SetCellOffset(Vector2I.Zero); + MaskGrid.GridContainer.MouseFilter = MouseFilterEnum.Ignore; - TopGrid1 = InitTopGrid(S_TerrainRoot.L_TerrainTexture1.Instance, GameConfig.TerrainBitSize1, TileSetTerrainInfo.TopLayerType); - TopGrid2 = InitTopGrid(S_TerrainRoot.L_TerrainTexture2.Instance, GameConfig.TerrainBitSize2, TileSetTerrainInfo.MiddleLayerType); - TopGrid3 = InitTopGrid(S_TerrainRoot.L_TerrainTexture3.Instance, GameConfig.TerrainBitSize3, TileSetTerrainInfo.FloorLayerType); - TopGrid4 = InitTopGrid(S_TerrainRoot.L_TerrainTexture3.Instance, GameConfig.TerrainBitSize4, TileSetTerrainInfo.Terrain2x2Type); + TerrainGrid3x3 = InitTopGrid(S_TerrainRoot.L_TerrainTexture1.Instance, GameConfig.TerrainBit3x3, TileSetTerrainInfo.TerrainLayerType); + TerrainGrid2x2 = InitTopGrid(S_TerrainRoot.L_TerrainTexture4.Instance, GameConfig.TerrainBit2x2, TileSetTerrainInfo.TerrainLayerType); + TerrainGridMiddle = InitTopGrid(S_TerrainRoot.L_TerrainTexture2.Instance, GameConfig.TerrainBitMiddle, TileSetTerrainInfo.MiddleLayerType); + TerrainGridFloor = InitTopGrid(S_TerrainRoot.L_TerrainTexture3.Instance, GameConfig.TerrainBitFloor, TileSetTerrainInfo.FloorLayerType); OnSetTileTexture(EditorPanel.Texture); OnChangeTileSetBgColor(EditorPanel.BgColor); @@ -59,14 +59,14 @@ if (_refreshGridConnect) { - _refreshGridConnect = true; + _refreshGridConnect = false; var terrain = EditorPanel.TileSetSourceInfo.Terrain; - TopGrid1.ForEach(cell => RefreshConnectTerrainCell(terrain, cell)); + TerrainGrid3x3.ForEach(cell => RefreshConnectTerrainCell(terrain, cell)); if (EditorPanel.TileSetSourceIndex == 0) //必须选中Main Source { - TopGrid2.ForEach(cell => RefreshConnectTerrainCell(terrain, cell)); - TopGrid3.ForEach(cell => RefreshConnectTerrainCell(terrain, cell)); + TerrainGridMiddle.ForEach(cell => RefreshConnectTerrainCell(terrain, cell)); + TerrainGridFloor.ForEach(cell => RefreshConnectTerrainCell(terrain, cell)); } } } @@ -93,33 +93,37 @@ //改变选中的TileSet资源 private void OnSelectTileSetSource(object obj) { - //先清除所有绑定的Terrain - TopGrid1.ForEach(cell => ((TerrainCell)cell).ClearCell()); - TopGrid2.ForEach(cell => ((TerrainCell)cell).ClearCell()); - TopGrid3.ForEach(cell => ((TerrainCell)cell).ClearCell()); - TopGrid4.ForEach(cell => ((TerrainCell)cell).ClearCell()); + //清除所有绑定的Terrain + TerrainGrid3x3.ForEach(cell => ((TerrainCell)cell).ClearCell()); + TerrainGridMiddle.ForEach(cell => ((TerrainCell)cell).ClearCell()); + TerrainGridFloor.ForEach(cell => ((TerrainCell)cell).ClearCell()); + TerrainGrid2x2.ForEach(cell => ((TerrainCell)cell).ClearCell()); S_TopBg.Instance.SetHoverCell(null); S_BottomBg.Instance.SetHoverCell(null); - + var sourceIndex = EditorPanel.TileSetSourceIndex; if (sourceIndex == 0) //选中Main Source时就只能使用 47 Terrain { S_TerrainTexture2.Instance.Visible = true; S_TerrainTexture3.Instance.Visible = true; - TopGrid2.Visible = true; - TopGrid3.Visible = true; + TerrainGridMiddle.Visible = true; + TerrainGridFloor.Visible = true; S_TerrainTexture1.L_Label.Instance.Text = "顶部墙壁"; - S_TerrainTypeButton.Instance.Selected = 0; S_TerrainTypeButton.Instance.Visible = false; + S_TerrainTypeButton.Instance.Selected = 0; + S_TopBg.Instance.ChangeTerrainType(0, false); } else { S_TerrainTexture2.Instance.Visible = false; S_TerrainTexture3.Instance.Visible = false; - TopGrid2.Visible = false; - TopGrid3.Visible = false; + TerrainGridMiddle.Visible = false; + TerrainGridFloor.Visible = false; S_TerrainTexture1.L_Label.Instance.Text = "地形"; S_TerrainTypeButton.Instance.Visible = true; + var selectIndex = EditorPanel.TileSetSourceInfo.Terrain.TerrainType; + S_TerrainTypeButton.Instance.Selected = selectIndex; + S_TopBg.Instance.ChangeTerrainType(selectIndex, false); } //再加载Terrain @@ -128,17 +132,17 @@ var terrain = ((TileSetSourceInfo)obj).Terrain; if (sourceIndex == 0) //选中Main Source { - TopGrid1.ForEach(cell => SetTerrainCellData(terrain, cell)); - TopGrid2.ForEach(cell => SetTerrainCellData(terrain, cell)); - TopGrid3.ForEach(cell => SetTerrainCellData(terrain, cell)); + TerrainGrid3x3.ForEach(cell => SetTerrainCellData(terrain, cell)); + TerrainGridMiddle.ForEach(cell => SetTerrainCellData(terrain, cell)); + TerrainGridFloor.ForEach(cell => SetTerrainCellData(terrain, cell)); } else if (S_TerrainTypeButton.Instance.Selected == 0) //选中47个Terrain { - TopGrid1.ForEach(cell => SetTerrainCellData(terrain, cell)); + TerrainGrid3x3.ForEach(cell => SetTerrainCellData(terrain, cell)); } else //选中13格Terrain { - TopGrid4.ForEach(cell => SetTerrainCellData(terrain, cell)); + TerrainGrid2x2.ForEach(cell => SetTerrainCellData(terrain, cell)); } } } @@ -163,8 +167,8 @@ var terrainCell = (TerrainCell)cell; var x = data[0]; var y = data[1]; - var index = x / GameConfig.TileCellSize + y / GameConfig.TileCellSize * BottomGrid.GetColumns(); - var maskCell = (MaskCell)BottomGrid.GetCell(index); + var index = x / GameConfig.TileCellSize + y / GameConfig.TileCellSize * MaskGrid.GetColumns(); + var maskCell = (MaskCell)MaskGrid.GetCell(index); if (maskCell != null) { //绑定TerrainCell @@ -181,14 +185,14 @@ if (EditorPanel.TileSetSourceIndex == 0) //选中Main Source { var flag = true; - TopGrid1.ForEach((cell) => + TerrainGrid3x3.ForEach((cell) => { flag = !((TerrainCell)cell).OnDropCell(maskCell); return flag; }); if (flag) { - TopGrid2.ForEach((cell) => + TerrainGridMiddle.ForEach((cell) => { flag = !((TerrainCell)cell).OnDropCell(maskCell); return flag; @@ -196,7 +200,7 @@ } if (flag) { - TopGrid3.ForEach((cell) => + TerrainGridFloor.ForEach((cell) => { return ((TerrainCell)cell).OnDropCell(maskCell); }); @@ -204,14 +208,14 @@ } else if (S_TerrainTypeButton.Instance.Selected == 0) //选中47个Terrain { - TopGrid1.ForEach((cell) => + TerrainGrid3x3.ForEach((cell) => { return !((TerrainCell)cell).OnDropCell(maskCell); }); } else //选中13格Terrain { - TopGrid4.ForEach((cell) => + TerrainGrid2x2.ForEach((cell) => { return !((TerrainCell)cell).OnDropCell(maskCell); }); @@ -223,19 +227,19 @@ { S_BottomBg.Instance.OnChangeTileSetTexture(); - BottomGrid.RemoveAll(); + MaskGrid.RemoveAll(); var cellHorizontal = EditorPanel.CellHorizontal; if (cellHorizontal <= 0) { return; } var cellVertical = EditorPanel.CellVertical; - BottomGrid.SetColumns(cellHorizontal); + MaskGrid.SetColumns(cellHorizontal); for (var y = 0; y < cellVertical; y++) { for (var x = 0; x < cellHorizontal; x++) { - BottomGrid.Add(new Rect2I(x * GameConfig.TileCellSize, y * GameConfig.TileCellSize, GameConfig.TileCellSize, GameConfig.TileCellSize)); + MaskGrid.Add(new Rect2I(x * GameConfig.TileCellSize, y * GameConfig.TileCellSize, GameConfig.TileCellSize, GameConfig.TileCellSize)); } } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/MaskCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/MaskCell.cs index f37e719..099274d 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/MaskCell.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/MaskCell.cs @@ -60,10 +60,10 @@ { CellNode.Instance.DrawRect( new Rect2(Vector2.Zero, CellNode.Instance.Size), - new Color(0, 1, 0), false, 3f / _textureRect.Scale.X + new Color(0, 1, 0, 0.3f) ); } - else if (ConnectTerrainCell != null) + if (ConnectTerrainCell != null) { //选中时绘制轮廓 CellNode.Instance.DrawRect( diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TileEditArea.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TileEditArea.cs index ec451c0..4353e24 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TileEditArea.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TileEditArea.cs @@ -29,8 +29,8 @@ if (_panel.S_BottomBg.Instance.IsMouseInRect() && _panel.S_TileTexture.Instance.IsMouseInRect()) { var cellPosition = Utils.GetMouseCellPosition(_panel.S_TileTexture.Instance); - var index = cellPosition.X + cellPosition.Y * _panel.BottomGrid.GetColumns(); - var tempCell = (MaskCell)_panel.BottomGrid.GetCell(index); + var index = cellPosition.X + cellPosition.Y * _panel.MaskGrid.GetColumns(); + var tempCell = (MaskCell)_panel.MaskGrid.GetCell(index); if (tempCell.ConnectTerrainCell != null) { cell = tempCell; @@ -71,12 +71,12 @@ if (_panel.S_BottomBg.Instance.IsMouseInRect() && _panel.S_TileTexture.Instance.IsMouseInRect()) { var cellPosition = Utils.GetMouseCellPosition(_panel.S_TileTexture.Instance); - var index = cellPosition.X + cellPosition.Y * _panel.BottomGrid.GetColumns(); - var cell = (MaskCell)_panel.BottomGrid.GetCell(index); + var index = cellPosition.X + cellPosition.Y * _panel.MaskGrid.GetColumns(); + var cell = (MaskCell)_panel.MaskGrid.GetCell(index); if (cell.ConnectTerrainCell == null) //必须要没有使用的Cell { _panel.DraggingCell = cell; - _panel.BottomGrid.SelectIndex = index; + _panel.MaskGrid.SelectIndex = index; _dragMoveFlag = false; } } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCell.cs index 1f987e5..812d01a 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCell.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCell.cs @@ -24,13 +24,11 @@ /// public Vector2I TextureCell { get; private set; } - private Control _root; private TileSetEditorTerrainPanel _panel; public override void OnInit() { _panel = CellNode.UiPanel; - _root = _panel.S_TopBg.L_TerrainRoot.Instance; CellNode.Instance.GuiInput += OnGuiInput; CellNode.Instance.Draw += OnDraw; } @@ -65,7 +63,7 @@ ClearCell(); if (flag) { - SetTerrainBitData(null); + ClearTerrainBitData(); if (ConnectMaskCell != null) { ConnectMaskCell.SetConnectTerrainCell(null); @@ -97,6 +95,14 @@ IsPutDownTexture = false; } + /// + /// 清除存储的地形掩码数据 + /// + public void ClearTerrainBitData() + { + SetTerrainBitData(null); + } + private void OnDropData(MaskCell maskCell) { SetCell(maskCell.Data); @@ -131,7 +137,7 @@ { CellNode.Instance.DrawRect( new Rect2(Vector2.Zero, CellNode.Instance.Size), - new Color(0, 1, 0), false, 3f / _root.Scale.X + new Color(0, 1, 0, 0.2f) ); } } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TileEditTerrain.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TileEditTerrain.cs index 8152bd9..0d5df4b 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TileEditTerrain.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TileEditTerrain.cs @@ -23,7 +23,10 @@ //聚焦按钮点击 UiNode.L_FocusBtn.Instance.Pressed += OnFocusClick; //切换TerrainType按钮点击 - UiNode.L_TerrainTypeButton.Instance.ItemSelected += ChangeTerrainType; + UiNode.L_TerrainTypeButton.Instance.ItemSelected += (index) => + { + ChangeTerrainType(index, true); + }; } /// @@ -41,43 +44,51 @@ var _panel = UiNode.UiPanel; if (_panel.S_TopBg.Instance.IsMouseInRect()) { - if (_panel.S_TerrainTexture1.Instance.IsMouseInRect()) + if (_panel.EditorPanel.TileSetSourceIndex == 0) //选中Main Source { - var cellPosition = Utils.GetMouseCellPosition(_panel.S_TerrainTexture1.Instance); - var index = cellPosition.X + cellPosition.Y * _panel.TopGrid1.GetColumns(); - var tempCell = (TerrainCell)_panel.TopGrid1.GetCell(index); - if (tempCell.ConnectMaskCell != null) + cell = CalcMouseHoverCell(_panel.S_TerrainTexture1.Instance, _panel.TerrainGrid3x3); + if (cell == null) { - cell = tempCell; + CalcMouseHoverCell(_panel.S_TerrainTexture2.Instance, _panel.TerrainGridMiddle); + } + if (cell == null) + { + CalcMouseHoverCell(_panel.S_TerrainTexture3.Instance, _panel.TerrainGridFloor); } } - //必须选中Main Source - if (_panel.EditorPanel.TileSetSourceIndex == 0) + else if (_panel.S_TerrainTypeButton.Instance.Selected == 0) //选中47个Terrain { - if (_panel.S_TerrainTexture2.Instance.IsMouseInRect()) - { - var cellPosition = Utils.GetMouseCellPosition(_panel.S_TerrainTexture2.Instance); - var index = cellPosition.X + cellPosition.Y * _panel.TopGrid2.GetColumns(); - var tempCell = (TerrainCell)_panel.TopGrid2.GetCell(index); - if (tempCell.ConnectMaskCell != null) - { - cell = tempCell; - } - } - if (_panel.S_TerrainTexture3.Instance.IsMouseInRect()) - { - var cellPosition = Utils.GetMouseCellPosition(_panel.S_TerrainTexture3.Instance); - var index = cellPosition.X + cellPosition.Y * _panel.TopGrid3.GetColumns(); - var tempCell = (TerrainCell)_panel.TopGrid3.GetCell(index); - if (tempCell.ConnectMaskCell != null) - { - cell = tempCell; - } - } + cell = CalcMouseHoverCell(_panel.S_TerrainTexture1.Instance, _panel.TerrainGrid3x3); + } + else //选中13格Terrain + { + cell = CalcMouseHoverCell(_panel.S_TerrainTexture4.Instance, _panel.TerrainGrid2x2); } } SetHoverCell(cell); } + + /// + /// 计算鼠标悬停在的地形单元。 + /// + /// 矩形控件。 + /// 网格。 + /// 鼠标悬停在的地形单元,如果鼠标不在矩形控件内或单元无效则返回null。 + private TerrainCell CalcMouseHoverCell(Control rectControl, UiGrid grid) + { + if (rectControl.IsMouseInRect()) + { + var cellPosition = Utils.GetMouseCellPosition(rectControl); + var index = cellPosition.X + cellPosition.Y * grid.GetColumns(); + var tempCell = (TerrainCell)grid.GetCell(index); + if (tempCell != null && tempCell.ConnectMaskCell != null) + { + return tempCell; + } + } + + return null; + } /// /// 设置鼠标悬停Cell @@ -123,13 +134,13 @@ /// /// 切换Terrain类型 /// - public void ChangeTerrainType(long index) + public void ChangeTerrainType(long index, bool initiative) { if (_currentTerrainType == index) { return; } - if (UiNode.UiPanel.EditorPanel.TileSetSourceIndex == 0) //选中 Main Source 时不需要询问 + if (!initiative) { _currentTerrainType = (int)index; DoChangeTerrainType(index); @@ -140,7 +151,9 @@ if (v) { _currentTerrainType = (int)index; + UiNode.UiPanel.EditorPanel.TileSetSourceInfo.Terrain.TerrainType = (byte)_currentTerrainType; DoChangeTerrainType(index); + DoClearCell(); } else { @@ -152,8 +165,40 @@ private void DoChangeTerrainType(long index) { UiNode.L_TerrainRoot.L_TerrainTexture1.Instance.Visible = index == 0; - UiNode.UiPanel.TopGrid1.Visible = index == 0; + UiNode.UiPanel.TerrainGrid3x3.Visible = index == 0; UiNode.L_TerrainRoot.L_TerrainTexture4.Instance.Visible = index != 0; - UiNode.UiPanel.TopGrid4.Visible = index != 0; + UiNode.UiPanel.TerrainGrid2x2.Visible = index != 0; + } + + private void DoClearCell() + { + UiNode.UiPanel.TerrainGrid3x3.ForEach(cell => + { + var terrainCell = (TerrainCell)cell; + terrainCell.ClearTerrainBitData(); + terrainCell.ClearCell(); + }); + UiNode.UiPanel.TerrainGridMiddle.ForEach(cell => + { + var terrainCell = (TerrainCell)cell; + terrainCell.ClearTerrainBitData(); + terrainCell.ClearCell(); + }); + UiNode.UiPanel.TerrainGridFloor.ForEach(cell => + { + var terrainCell = (TerrainCell)cell; + terrainCell.ClearTerrainBitData(); + terrainCell.ClearCell(); + }); + UiNode.UiPanel.TerrainGrid2x2.ForEach(cell => + { + var terrainCell = (TerrainCell)cell; + terrainCell.ClearTerrainBitData(); + terrainCell.ClearCell(); + }); + UiNode.UiPanel.MaskGrid.ForEach(cell => + { + ((MaskCell)cell).SetConnectTerrainCell(null); + }); } } \ No newline at end of file