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 static Task<LevelMapXMLData> LayoutToMapData(DBLayoutPanel layout) { Task<LevelMapXMLData> task = new Task<LevelMapXMLData>(() => { LevelMapXMLData mapData = CreateMapData(layout); return mapData; }); task.Start(); return 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; }
private void InitializeControls() { layout = new DBLayoutPanel(); tileImagesBox = new ComboBox() {}; tileColLabel = new Label(); tileRowLabel = new Label(); tileColTextBox = new TextBox(); tileRowTextBox = new TextBox(); tileImageLabel = new Label(); tileImageTextBox = new TextBox(); soundFxLabel = new Label(); soundFxTextBox = new TextBox(); loadFxButton = new Button(); tileSolidLabel = new Label(); tileSolidCheckBox = new CheckBox(); tileEmptyLabel = new Label(); tileEmptyCheckBox = new CheckBox(); groupBox1 = new GroupBox(); rotateTileButton = new Button(); txtCommand = new TextBox(); txtCommand.Visible = false; txtCommand.Focus(); }
private async void MapEditorForm_LoadAsync(object sender, EventArgs e) { if (!formLoaded) { Task<DBLayoutPanel> createEditorTask = Task.Run(() => { return CreateMap(); }); layout = await createEditorTask; InitializeLayout(); this.Controls.Add(layout); } }
private async void OpenMap() { string folder; string fileName; string fullPath; Cursor.Current = Cursors.WaitCursor; OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { folder = dlg.InitialDirectory; fileName = dlg.FileName; fullPath = Path.Combine(folder, fileName); LevelMapXMLData mapData = await Serializer.FromXml<LevelMapXMLData>(fullPath); this.Controls.Remove(layout); layout = null; cancelOpenMapBtn.Enabled = true; cancelOpenMapBtn.Visible = true; if (openMapCancelSource.Token.IsCancellationRequested) openMapCancelSource = new System.Threading.CancellationTokenSource(); layout = await GetMapFromXmlData(mapData); InitializeLayout(); this.Text = Path.GetFileNameWithoutExtension(fullPath); this.Controls.Add(layout); this.cancelOpenMapBtn.Visible = false; this.cancelOpenMapBtn.Enabled = false; Cursor.Current = Cursors.Arrow; } }
private async void AssignLayoutFromXmlData(LevelMapXMLData mapdata) { formLoaded = true; layout = await GetMapFromXmlData(mapdata); InitializeLayout(); }//used by 2nd constructor
private DBLayoutPanel CreateMap() { DBLayoutPanel layout = new DBLayoutPanel(); layout.RowCount = rows; layout.ColumnCount = columns; for(int row = 0; row < layout.RowCount; row++) for(int col = 0; col < layout.ColumnCount; col++) { Tile pBox = new Tile(); pBox.Row = row; pBox.Column = col; pBox.Solid = false; pBox.Empty = true; pBox.Width = tileWidth; pBox.Height = tileHieght; pBox.Margin = new System.Windows.Forms.Padding(0); pBox.BackColor = Color.DarkSlateGray; layout.Controls.Add(pBox); } return layout; }