void newTilesetToolStripMenuItem_Click(object sender, EventArgs e) { using (FormNewTileset frmNewTileset = new FormNewTileset()) { frmNewTileset.ShowDialog(); if (frmNewTileset.OKPressed) { TilesetData data = frmNewTileset.TilesetData; try { GDIImage image = (GDIImage)GDIBitmap.FromFile(data.TilesetImageName); tileSetImages.Add(image); Stream stream = new FileStream(data.TilesetImageName, FileMode.Open, FileAccess.Read); Texture2D texture = Texture2D.FromStream(GraphicsDevice, stream); Tileset tileset = new Tileset( texture, data.TilesWide, data.TilesHigh, data.TileWidthInPixels, data.TileHeightInPixels); tileSets.Add(tileset); tileSetData.Add(data); if (map != null) { map.AddTileset(tileset); } stream.Close(); stream.Dispose(); } catch (Exception ex) { MessageBox.Show("Error reading file.\n" + ex.Message, "Error reading image"); return; } lbTileset.Items.Add(data.TilesetName); if (lbTileset.SelectedItem == null) { lbTileset.SelectedIndex = 0; } mapLayerToolStripMenuItem.Enabled = true; } } }
private void LoudDefaultLayers() { MapLayerData mapLayerData1 = new MapLayerData("Water", mData.MapWidth, mData.MapHeight, 0, 0, 6); MapLayer layer = MapLayer.FromMapLayerData(mapLayerData1); clbLayers.Items.Add(mapLayerData1.MapLayerName, true); clbLayers.SelectedIndex = clbLayers.Items.Count - 1; layers.Add(layer); MapLayerData mapLayerData2 = new MapLayerData("Level 1", mData.MapWidth, mData.MapHeight, 1, -1, -1); layer = MapLayer.FromMapLayerData(mapLayerData2); clbLayers.Items.Add(mapLayerData2.MapLayerName, true); clbLayers.SelectedIndex = clbLayers.Items.Count - 1; layers.Add(layer); MapLayerData mapLayerData3 = new MapLayerData("Level 2", mData.MapWidth, mData.MapHeight, 2, -1, -1); layer = MapLayer.FromMapLayerData(mapLayerData3); clbLayers.Items.Add(mapLayerData3.MapLayerName, true); clbLayers.SelectedIndex = clbLayers.Items.Count - 1; layers.Add(layer); if (map == null) { map = new TileMapIso(tileSets[0], (MapLayer)layers[0]); for (int i = 1; i < tileSets.Count; i++) { map.AddTileset(tileSets[1]); } for (int i = 1; i < layers.Count; i++) { map.AddLayer(layers[1]); } } }
void newLayerToolStripMenuItem_Click(object sender, EventArgs e) { using (FormNewLayer frmNewLayer = new FormNewLayer(mData.MapWidth, mData.MapHeight)) { frmNewLayer.ShowDialog(); if (frmNewLayer.OKPressed) { MapLayerData data = frmNewLayer.MapLayerData; if (clbLayers.Items.Contains(data.MapLayerName)) { MessageBox.Show("Layer with name " + data.MapLayerName + " exists.", "Existing layer"); return; } MapLayer layer = MapLayer.FromMapLayerData(data); clbLayers.Items.Add(data.MapLayerName, true); clbLayers.SelectedIndex = clbLayers.Items.Count - 1; layers.Add(layer); if (map == null) { map = new TileMapIso(tileSets[0], (MapLayer)layers[0]); for (int i = 1; i < tileSets.Count; i++) { map.AddTileset(tileSets[1]); } for (int i = 1; i < layers.Count; i++) { map.AddLayer(layers[1]); } } } } }
void openMapToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofDialog = new OpenFileDialog(); ofDialog.Filter = "Level Files (*.xml)|*.xml"; ofDialog.CheckFileExists = true; ofDialog.CheckPathExists = true; DialogResult result = ofDialog.ShowDialog(); if (result != DialogResult.OK) { return; } string path = Path.GetDirectoryName(ofDialog.FileName); MapData mapData = null; try { mapData = XnaSerializer.Deserialize <MapData>(ofDialog.FileName); } catch (Exception exc) { MessageBox.Show(exc.Message, "Error reading level"); return; } tileSetImages.Clear(); tileSetData.Clear(); tileSets.Clear(); layers.Clear(); lbTileset.Items.Clear(); clbLayers.Items.Clear(); mData = new MapData(mapData.MapName, mapData.MapWidth, mapData.MapHeight); string directory = System.IO.Directory.GetCurrentDirectory(); int pos = directory.IndexOf("ZombocalypseRevised\\") + 20; directory = directory.Substring(0, pos).Trim() + "ZombocalypseRevised\\ZombocalypseRevisedContent\\"; foreach (TilesetData data in mapData.Tilesets) { Texture2D texture = null; tileSetData.Add(data); int posLoadLoc = data.TilesetImageName.IndexOf("TileSets\\"); int lenghtFull = data.TilesetImageName.Length - posLoadLoc; string fileDirectoryFull = directory + data.TilesetImageName.Substring(posLoadLoc, lenghtFull).Trim(); lbTileset.Items.Add(data.TilesetName); GDIImage image = (GDIImage)GDIBitmap.FromFile(fileDirectoryFull); tileSetImages.Add(image); using (Stream stream = new FileStream(fileDirectoryFull, FileMode.Open, FileAccess.Read)) { texture = Texture2D.FromStream(GraphicsDevice, stream); tileSets.Add( new Tileset( texture, data.TilesWide, data.TilesHigh, data.TileWidthInPixels, data.TileHeightInPixels)); } } foreach (MapLayerData data in mapData.Layers) { clbLayers.Items.Add(data.MapLayerName, true); layers.Add(MapLayer.FromMapLayerData(data)); } lbTileset.SelectedIndex = 0; clbLayers.SelectedIndex = 0; nudCurrentTile.Value = 0; map = new TileMapIso(tileSets[0], (MapLayer)layers[0]); for (int i = 1; i < tileSets.Count; i++) { map.AddTileset(tileSets[i]); } for (int i = 1; i < layers.Count; i++) { map.AddLayer(layers[i]); } tilesetToolStripMenuItem.Enabled = true; mapLayerToolStripMenuItem.Enabled = true; }