private static LevelMapXMLData CreateMapData(DBLayoutPanel layout) { int index = 0; TileXMLData[] tiles = new TileXMLData[layout.Controls.Count]; for (int row = 0; row < layout.RowCount; row++) for (int col = 0; col < layout.ColumnCount; col++) { Tile c = layout.GetControlFromPosition(col, row) as Tile; if (c.Color == null) c.Color = new Color(255, 255, 255); tiles[index] = new TileXMLData { Coordinates = new Vector2((col * c.Width), (row * c.Height)), Dimensions = new Vector2(c.Width, c.Height), TexturePath = "Tiles\\" + TrimExtension(c.TexturePath), SoundEffectPath = c.SoundFxPath, Color = c.Color, Solid = c.Solid, Empty = c.Empty }; index++; } LevelMapXMLData mapData = new LevelMapXMLData(); mapData.TileMapData = tiles; mapData.TilesAcross = layout.ColumnCount; mapData.TilesDown = layout.RowCount; return mapData; }
public MapEditorForm(LevelMapXMLData mapData) { InitializeControls(); PositionControls(); SubscribeToControlEvents(); LoadTileImages(); openMapCancelSource = new System.Threading.CancellationTokenSource(); AssignLayoutFromXmlData(mapData); InitializeComponent(); }
public static async Task<DBLayoutPanel> MapDataToLayout(LevelMapXMLData mapData) { Task<DBLayoutPanel> task = new Task<DBLayoutPanel>(() => { return CreateDBTablelayout(mapData); }); task.Start(); return await task; }
private static DBLayoutPanel CreateDBTablelayout(LevelMapXMLData mapData) { int rows = mapData.TilesDown; int cols = mapData.TilesAcross; int index = 0; DBLayoutPanel layout = new DBLayoutPanel(); layout.RowCount = rows; layout.ColumnCount = cols; for (int row = 0; row < layout.RowCount; row++) for (int col = 0; col < layout.ColumnCount; col++) { layout.Controls.Add(new Tile(mapData.TileMapData[index]) { Row = row, Column = col }, col, row); index++; } return layout; }
public MazeMap(LevelMapXMLData mapData) : base(mapData) { foreach (Tile t in Map) t.Color = Color.White; }
private async void AssignLayoutFromXmlData(LevelMapXMLData mapdata) { formLoaded = true; layout = await GetMapFromXmlData(mapdata); InitializeLayout(); }//used by 2nd constructor
private Task<DBLayoutPanel> GetMapFromXmlData(LevelMapXMLData mapData) { Task<DBLayoutPanel> openMapTask = Task<TableLayoutPanel>.Run(() => { DBLayoutPanel newLayout = LayoutConverter.MapDataToLayout(mapData).Result; return newLayout; }); return openMapTask; }