void saveTilesetToolStripMenuItem_Click(object sender, EventArgs e) { if (tileSetData.Count == 0) { return; } SaveFileDialog sfDialog = new SaveFileDialog(); sfDialog.Filter = "Tileset Data (*.tdat)|*.tdat"; sfDialog.CheckPathExists = true; sfDialog.OverwritePrompt = true; sfDialog.ValidateNames = true; DialogResult result = sfDialog.ShowDialog(); if (result != DialogResult.OK) { return; } try { XnaSerializer.Serialize <TilesetData>( sfDialog.FileName, tileSetData[lbTileset.SelectedIndex]); } catch (Exception exc) { MessageBox.Show(exc.Message, "Error saving tileset"); } }
void saveLayerToolStripMenuItem_Click(object sender, EventArgs e) { if (layers.Count == 0) { return; } if (layers[clbLayers.SelectedIndex] is MapLayer) { SaveFileDialog sfDialog = new SaveFileDialog(); sfDialog.Filter = "Map Layer Data (*.mldt)|*.mldt"; sfDialog.CheckPathExists = true; sfDialog.OverwritePrompt = true; sfDialog.ValidateNames = true; DialogResult result = sfDialog.ShowDialog(); if (result != DialogResult.OK) { return; } MapLayerData data = new MapLayerData( clbLayers.SelectedItem.ToString(), ((MapLayer)layers[clbLayers.SelectedIndex]).Width, ((MapLayer)layers[clbLayers.SelectedIndex]).Height); for (int y = 0; y < ((MapLayer)layers[clbLayers.SelectedIndex]).Height; y++) { for (int x = 0; x < ((MapLayer)layers[clbLayers.SelectedIndex]).Width; x++) { data.SetTile( x, y, ((MapLayer)layers[clbLayers.SelectedIndex]).GetTile(x, y).TileIndex, ((MapLayer)layers[clbLayers.SelectedIndex]).GetTile(x, y).Tileset); } } try { XnaSerializer.Serialize <MapLayerData>(sfDialog.FileName, data); } catch (Exception exc) { MessageBox.Show(exc.Message, "Error saving map layer data"); } } }
void saveLevelToolStripMenuItem_Click(object sender, EventArgs e) { if (map == null) { return; } List <MapLayerData> mapLayerData = new List <MapLayerData>(); for (int i = 0; i < clbLayers.Items.Count; i++) { if (layers[i] is MapLayer) { MapLayerData data = new MapLayerData( clbLayers.Items[i].ToString(), ((MapLayer)layers[i]).Width, ((MapLayer)layers[i]).Height); for (int y = 0; y < ((MapLayer)layers[i]).Height; y++) { for (int x = 0; x < ((MapLayer)layers[i]).Width; x++) { data.SetTile(x, y, ((MapLayer)layers[i]).GetTile(x, y).TileIndex, ((MapLayer)layers[i]).GetTile(x, y).Tileset); } } mapLayerData.Add(data); } } MapData mapData = new MapData(levelData.MapName, tileSetData, mapLayerData); FolderBrowserDialog fbDialog = new FolderBrowserDialog(); fbDialog.Description = "Select Game Folder"; fbDialog.SelectedPath = Application.StartupPath; DialogResult result = fbDialog.ShowDialog(); if (result == DialogResult.OK) { if (!File.Exists(fbDialog.SelectedPath + @"\Game.xml")) { MessageBox.Show("Game not found", "Error"); return; } string LevelPath = Path.Combine(fbDialog.SelectedPath, @"Levels\"); string MapPath = Path.Combine(LevelPath, @"Maps\"); if (!Directory.Exists(LevelPath)) { Directory.CreateDirectory(LevelPath); } if (!Directory.Exists(MapPath)) { Directory.CreateDirectory(MapPath); } XnaSerializer.Serialize <LevelData>(LevelPath + levelData.LevelName + ".xml", levelData); XnaSerializer.Serialize <MapData>(MapPath + mapData.MapName + ".xml", mapData); } }
void saveLevelToolStripMenuItem_Click(object sender, EventArgs e) { if (map == null) { return; } List <MapLayerData> mapLayerData = new List <MapLayerData>(); for (int i = 0; i < clbLayers.Items.Count; i++) { if (layers[i] is MapLayer) { MapLayerData data = new MapLayerData( clbLayers.Items[i].ToString(), ((MapLayer)layers[i]).Width, ((MapLayer)layers[i]).Height); for (int y = 0; y < ((MapLayer)layers[i]).Height; y++) { for (int x = 0; x < ((MapLayer)layers[i]).Width; x++) { data.SetTile( x, y, ((MapLayer)layers[i]).GetTile(x, y).TileIndex, ((MapLayer)layers[i]).GetTile(x, y).Tileset); } } mapLayerData.Add(data); } } MapData mapData = new MapData(levelData.MapName, tileSetData, animatedSetData, mapLayerData, collisionLayer, animatedLayer); CharacterLayerData charData = new CharacterLayerData(); foreach (var c in FormMain.characters.Characters) { CharacterData character; if (c.Value is NonPlayerCharacter) { character = new NonPlayerCharacterData(); ((NonPlayerCharacterData)character).Quests = ((NonPlayerCharacter)c.Value).Quests; ((NonPlayerCharacterData)character).CurrentConversation = ((NonPlayerCharacter)c.Value).CurrentConversation; ((NonPlayerCharacterData)character).CurrentQuest = ((NonPlayerCharacter)c.Value).CurrentQuest; } else { character = new CharacterData(); } character.Name = c.Value.Entity.EntityName; character.Gender = c.Value.Entity.Gender; character.TextureName = c.Value.Sprite.Texture.Name; character.Head = new GameItemData(); character.Torso = new GameItemData(); character.Feet = new GameItemData(); character.Hands = new GameItemData(); character.MainHand = new GameItemData(); character.OffHand = new GameItemData(); character.EntityData = new EntityData( c.Value.Entity.EntityName, c.Value.Entity.Level, c.Value.Entity.Strength, c.Value.Entity.Dexterity, c.Value.Entity.Cunning, c.Value.Entity.Willpower, c.Value.Entity.Magic, c.Value.Entity.Constitution, c.Value.Entity.Health.MaximumValue, c.Value.Entity.Stamina.MaximumValue, c.Value.Entity.Mana.MaximumValue); charData.Characters.Add(c.Key, character); } FolderBrowserDialog fbDialog = new FolderBrowserDialog { Description = "Select Game Folder", SelectedPath = Application.StartupPath }; DialogResult result = fbDialog.ShowDialog(); if (result == DialogResult.OK) { if (!File.Exists(fbDialog.SelectedPath + @"\Game.xml")) { MessageBox.Show("Game not found", "Error"); return; } string LevelPath = Path.Combine(fbDialog.SelectedPath, @"Levels\"); string MapPath = Path.Combine(LevelPath, @"Maps\"); string CharPath = Path.Combine(LevelPath, @"Chars\"); if (!Directory.Exists(LevelPath)) { Directory.CreateDirectory(LevelPath); } if (!Directory.Exists(MapPath)) { Directory.CreateDirectory(MapPath); } if (!Directory.Exists(CharPath)) { Directory.CreateDirectory(CharPath); } XnaSerializer.Serialize <LevelData>( LevelPath + levelData.LevelName + ".xml", levelData); XnaSerializer.Serialize <MapData>( MapPath + mapData.MapName + ".xml", mapData); XnaSerializer.Serialize <CharacterLayerData>( CharPath + levelData.LevelName + ".xml", charData); } }