Ejemplo n.º 1
0
 private void NewExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     if (GlobalState.IsPlaying)
     {
         ExplosionPanel.PlayPauseSequenceEventHandler(null, null);
     }
     if (e != null && GlobalState.HasMadeChanges && MessageBox.Show($"Do you want save changes to {currentFileName}?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         if (fileExists)
         {
             SaveExecuted(sender, e);
         }
         else
         {
             SaveAsExecuted(sender, e);
         }
     }
     foreach (MapTerrainTile tile in MapEditor.MapTerrain.GetTiles())
     {
         tile.SetTerrain("null");
     }
     foreach (MapLocation loc in GlobalState.Locations)
     {
         MapEditor.MapCanvas.Children.Remove(loc);
     }
     GlobalState.Locations = new List <MapLocation>();
     GlobalState.Sequences = new List <BoundSequence>
     {
         new BoundSequence()
     };
     ExplosionPanel.CurrentSequence = GlobalState.Sequences[0];
     ExplosionPanel.UpdateNavigation();
     if (e != null)
     {
         currentFileName            = "Untitled.xml";
         fileExists                 = false;
         GlobalState.HasMadeChanges = false;
         RefreshTitle();
     }
 }
Ejemplo n.º 2
0
        private void OpenExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (GlobalState.IsPlaying)
            {
                ExplosionPanel.PlayPauseSequenceEventHandler(null, null);
            }

            if (GlobalState.HasMadeChanges && MessageBox.Show($"Do you want save changes to {currentFileName}?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                if (fileExists)
                {
                    SaveExecuted(sender, e);
                }
                else
                {
                    SaveAsExecuted(sender, e);
                }
            }
            var dialog = new Microsoft.Win32.OpenFileDialog
            {
                DefaultExt = ".xml",
                Filter     = "Extensible Markup Language File|*.xml"
            };
            bool?result = dialog.ShowDialog();

            if (result == true)
            {
                string               filename        = dialog.FileName;
                List <MapLocation>   backupLocations = GlobalState.Locations;
                List <BoundSequence> backupSequences = GlobalState.Sequences;
                try
                {
                    BoundMakerFile fileData = XmlHandler.ReadXmlDocument(filename);
                    NewExecuted(null, null);
                    GlobalState.Locations = fileData.Locations.ToList();
                    GlobalState.Sequences = fileData.Sequences.ToList();
                    foreach (MapTerrainTile newTile in fileData.Tiles)
                    {
                        MapEditor.MapTerrain.GetCell(Grid.GetRow(newTile), Grid.GetColumn(newTile)).SetTerrain(newTile.Terrain);
                    }
                    foreach (MapLocation m in GlobalState.Locations)
                    {
                        MapEditor.MapCanvas.Children.Add(m);
                        m.SetWindowInstance(this);
                    }
                    LocationPanel.SetLocationNames();
                    if (GlobalState.Sequences.Count == 0)
                    {
                        GlobalState.Sequences.Add(new BoundSequence());
                    }
                    ExplosionPanel.CurrentSequence = GlobalState.Sequences[0];
                    ExplosionPanel.UpdateNavigation();
                    if (GlobalState.TerrainPanelIsActive)
                    {
                        SetToTerrainMode(null, null);
                    }
                    else if (GlobalState.LocationPanelIsActive)
                    {
                        SetToLocationMode(null, null);
                    }
                    else if (GlobalState.ExplosionPanelIsActive)
                    {
                        SetToExplosionMode(null, null);
                    }
                    currentFileName            = dialog.SafeFileName;
                    fullFilePath               = dialog.FileName;
                    fileExists                 = true;
                    GlobalState.HasMadeChanges = false;
                    RefreshTitle();
                }
                catch
                {
                    GlobalState.Locations = backupLocations;
                    GlobalState.Sequences = backupSequences;
                    MessageBox.Show("Failed to read file. And I tried really hard, too :(");
                }
            }
            e.Handled = true;
        }