private void NewDeckCommand(object sender, ExecutedRoutedEventArgs e) { e.Handled = true; if (Game == null) { if (Program.GamesRepository.Games.Count == 1) Game = Program.GamesRepository.Games[0]; else { MessageBox.Show("You have to select a game before you can use this command.", "Error", MessageBoxButton.OK); return; } } Deck = new Deck(Game); _deckFilename = null; }
private void NewClicked(object sender, RoutedEventArgs e) { if (_unsaved) { MessageBoxResult result = MessageBox.Show("This deck contains unsaved modifications. Save?", "Warning", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning); switch (result) { case MessageBoxResult.Yes: Save(); break; case MessageBoxResult.No: break; default: return; } } Game = (Data.Game) ((MenuItem) e.OriginalSource).DataContext; CommandManager.InvalidateRequerySuggested(); Deck = new Deck(Game); _deckFilename = null; }
protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); if (_unsaved) { MessageBoxResult result = MessageBox.Show("This deck contains unsaved modifications. Save?", "Warning", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning); switch (result) { case MessageBoxResult.Yes: Save(); break; case MessageBoxResult.No: break; default: e.Cancel = true; return; } } cardImage.Source = null; cardImage = null; Game = null; // Close DB if required }
private void LoadDeck(Data.Game game) { if (_unsaved) { MessageBoxResult result = MessageBox.Show("This deck contains unsaved modifications. Save?", "Warning", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning); switch (result) { case MessageBoxResult.Yes: Save(); break; case MessageBoxResult.No: break; default: return; } } // Show the dialog to choose the file var ofd = new OpenFileDialog { Filter = "Octgn deck files (*.o8d) | *.o8d", InitialDirectory = ((game != null) && Prefs.LastFolder == "") ? game.DefaultDecksPath : Prefs.LastFolder }; if (ofd.ShowDialog() != true) return; Prefs.LastFolder = Path.GetDirectoryName(ofd.FileName); // Try to load the file contents Deck newDeck; try { newDeck = Deck.Load(ofd.FileName, Program.GamesRepository); } catch (DeckException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } catch (Exception ex) { MessageBox.Show("Octgn couldn't load the deck.\r\nDetails:\r\n\r\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } Game = Program.GamesRepository.Games.First(g => g.Id == newDeck.GameId); Deck = newDeck; _deckFilename = ofd.FileName; CommandManager.InvalidateRequerySuggested(); }
public void SetLoadedGame(Game game) { Game = game; }