private void MenuItem_SaveAs_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Level data (*.xml)|*.xml"; if (saveFileDialog.ShowDialog() == true) { // Saved to the selected path _path = saveFileDialog.FileName; LevelXML.SaveXML(_path, _layerTiles, _level); } _Level_Menu.Visibility = Visibility.Collapsed; }
private void MenuItem_Save_Click(object sender, RoutedEventArgs e) { // If attempting to save but the current level is new, use Save As if (_path == "") { MenuItem_SaveAs_Click(null, null); } else // otherwise overwrite the file { LevelXML.SaveXML(_path, _layerTiles, _level); } _Level_Menu.Visibility = Visibility.Collapsed; }
private void MenuItem_Open_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Level data (*.xml)|*.xml|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { _path = openFileDialog.FileName; // Use the XML loader to get the tile information and general game properties stored. LevelEditor.LoadLevelInfo loadLevelInfo = LevelXML.LoadXML(_path); if (loadLevelInfo.success == true) { // Assign the new information _level.mapHeight = loadLevelInfo.level.mapHeight; _level.mapWidth = loadLevelInfo.level.mapWidth; _level.tileWidth = loadLevelInfo.level.tileWidth; _level.generalGameProperties = loadLevelInfo.level.generalGameProperties; // Reinitialise the level Initialise(loadLevelInfo.level.tileSheetPath); // Draw all of the tiles for (int i = 0; i < loadLevelInfo.tiles.Length; i++) { DrawTile(loadLevelInfo.tiles[i]); } } else { System.Windows.MessageBox.Show("Error: Failed to load level."); } } _Level_Menu.Visibility = Visibility.Collapsed; }