private void WindowKeyDownEventHandler(object sender, KeyEventArgs e) { if (GlobalState.ExplosionPanelIsActive) { ExplosionPanel.SequenceNavigationKeyDownEventHandler(sender, e); } }
private void SaveAsExecuted(object sender, ExecutedRoutedEventArgs e) { if (GlobalState.IsPlaying) { ExplosionPanel.PlayPauseSequenceEventHandler(null, null); } var dlg = new Microsoft.Win32.SaveFileDialog { FileName = currentFileName, DefaultExt = ".xml", Filter = "Extensible Markup Language File|*.xml" }; if (dlg.ShowDialog() == true) { string filename = dlg.FileName; try { var fileData = new BoundMakerFile { Locations = GlobalState.Locations, Tiles = MapEditor.MapTerrain.GetTiles(), Sequences = GlobalState.Sequences }; XmlHandler.WriteXmlDocument(filename, fileData); currentFileName = dlg.SafeFileName; fullFilePath = dlg.FileName; fileExists = true; GlobalState.HasMadeChanges = false; RefreshTitle(); } catch { MessageBox.Show("Failed to save file. Sorry :("); } } }
private void SaveExecuted(object sender, ExecutedRoutedEventArgs e) { if (fileExists) { if (GlobalState.IsPlaying) { ExplosionPanel.PlayPauseSequenceEventHandler(null, null); } try { var fileData = new BoundMakerFile { Locations = GlobalState.Locations, Tiles = MapEditor.MapTerrain.GetTiles(), Sequences = GlobalState.Sequences }; XmlHandler.WriteXmlDocument(fullFilePath, fileData); fileExists = true; GlobalState.HasMadeChanges = false; RefreshTitle(); } catch { MessageBox.Show("Failed to save file. Try 'Save As'."); } } else { SaveAsExecuted(sender, e); } }
public MainWindow() { GlobalState.Locations = new List <MapLocation>(); GlobalState.Sequences = new List <BoundSequence>(); InitializeComponent(); foreach (MapTerrainTile tile in MapEditor.MapTerrain.GetTiles()) { tile.SetWindowInstance(this); } GlobalState.SelectedTile = Terrain.TileDirt; ExplosionPanel.CurrentSequence = new BoundSequence(GlobalState.Locations); GlobalState.Sequences.Add(ExplosionPanel.CurrentSequence); ExplosionPanel.SetWindowInstance(this); TerrainMode.IsChecked = true; RefreshTitle(); }
private void CodeToggleEventHandler(object sender, RoutedEventArgs e) { viewCode = !viewCode; if (viewCode) { if (GlobalState.IsPlaying) { ExplosionPanel.PlayPauseSequenceEventHandler(null, null); } MapWindow.Visibility = Visibility.Hidden; CodeWindow.Visibility = Visibility.Visible; ToggleCodeGenerationButton.Content = "Switch to Editor Mode"; } else { MapWindow.Visibility = Visibility.Visible; CodeWindow.Visibility = Visibility.Hidden; ToggleCodeGenerationButton.Content = "Switch to Code Generation Mode"; CodeWindow.TriggerOutput.Text = "Trigger output will go here."; } }
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(); } }
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; }