コード例 #1
0
        public static bool Show(Exception exception)
        {
            ErrorMessageBox messageBox = new ErrorMessageBox(exception);
            var             result     = messageBox.ShowDialog();

            return(result.HasValue && result.Value);
        }
コード例 #2
0
 private void OnChangeGameType(object sender, RoutedEventArgs e)
 {
     if ((selectedGameSave.GameSave.GameType == GameTypes.Ruby || selectedGameSave.GameSave.GameType == GameTypes.Sapphire ||
          selectedGameSave.GameSave.GameType == GameTypes.FireRed || selectedGameSave.GameType == GameTypes.LeafGreen ||
          selectedGameSave.GameSave.GameType == GameTypes.Emerald) && selectedGameSave.GameSave is GBAGameSave)
     {
         var results = SelectGameTypeFullWindow.ShowDialog(this, selectedGameSave.IsJapanese);
         if (results != null)
         {
             GameTypes        gameType     = results.GameType;
             MessageBoxResult result       = MessageBoxResult.Yes;
             bool             reloadNeeded = false;
             if (((selectedGameSave.GameSave.GameType == GameTypes.Ruby || selectedGameSave.GameSave.GameType == GameTypes.Sapphire) && (gameType != GameTypes.Ruby && gameType != GameTypes.Sapphire)) ||
                 ((selectedGameSave.GameSave.GameType == GameTypes.FireRed || selectedGameSave.GameSave.GameType == GameTypes.LeafGreen) && (gameType != GameTypes.FireRed && gameType != GameTypes.LeafGreen)) ||
                 (selectedGameSave.GameSave.GameType == GameTypes.Emerald && gameType != GameTypes.Emerald))
             {
                 result = TriggerMessageBox.Show(this, "In order to change the game type to this the save must be reloaded. Are you sure you want to reload this save? Any unsaved changes will be lost.", "Reload Needed", MessageBoxButton.YesNo);
                 if (result == MessageBoxResult.Yes)
                 {
                     reloadNeeded = true;
                 }
             }
             if (result == MessageBoxResult.Yes)
             {
                 selectedGameSave.GameType            = gameType;
                 selectedGameSave.IsJapanese          = results.IsJapanese;
                 selectedGameSave.GameSave.IsJapanese = results.IsJapanese;
                 ((GBAGameSave)selectedGameSave.GameSave).GameType = gameType;
                 FillListViewItem(selectedGameSave, gameSaves[selectedIndex]);
                 if (reloadNeeded)
                 {
                     try {
                         PokeManager.ReloadGameSave(selectedGameSave);
                     }
                     catch (Exception ex) {
                         result = TriggerMessageBox.Show(this, "Error loading save after changing game type, this may not be the correct game type for it. Would you like to see the error?", "Load Error", MessageBoxButton.YesNo);
                         if (result == MessageBoxResult.Yes)
                         {
                             ErrorMessageBox.Show(ex);
                         }
                     }
                 }
             }
         }
     }
     else
     {
         // No need
         TriggerMessageBox.Show(this, "Only one game type applies to this save");
     }
 }
コード例 #3
0
        private void OnExportClicked(object sender, RoutedEventArgs e)
        {
            SharedSecretBase finalSecretBase;

            if (secretBase.IsPlayerSecretBase)
            {
                finalSecretBase = new SharedSecretBase((PlayerSecretBase)secretBase, null);
            }
            else
            {
                finalSecretBase = new SharedSecretBase((SharedSecretBase)secretBase, null);
            }
            if (IsGBAGame && secretBase.IsPlayerSecretBase)
            {
                MessageBoxResult result2 = TriggerMessageBox.Show(Window.GetWindow(this), "Would you like to edit your Secret Base's trainer before exporting?", "Edit Trainer", MessageBoxButton.YesNo);
                if (result2 == MessageBoxResult.Yes)
                {
                    finalSecretBase = new SharedSecretBase((PlayerSecretBase)secretBase, null);

                    SecretBaseEditTrainerWindow.Show(Window.GetWindow(this), finalSecretBase, true);
                }
            }
            SaveFileDialog fileDialog = new SaveFileDialog();

            fileDialog.Title        = "Export Secret Base";
            fileDialog.AddExtension = true;
            fileDialog.DefaultExt   = ".scrtb";
            fileDialog.FileName     = finalSecretBase.TrainerName + "'s Base";
            fileDialog.Filter       = "Secret Base Files (*.scrtb)|*.scrtb|All Files (*.*)|*.*";
            var result = fileDialog.ShowDialog(Window.GetWindow(this));

            if (result.HasValue && result.Value)
            {
                string filePath = fileDialog.FileName;
                filePath = System.IO.Path.GetFullPath(filePath);

                try {
                    File.WriteAllBytes(filePath, finalSecretBase.GetFinalData());
                }
                catch (Exception ex) {
                    MessageBoxResult result2 = TriggerMessageBox.Show(Window.GetWindow(this), "Error saving Secret Base file. Would you like to see the error?", "Export Error", MessageBoxButton.YesNo);
                    if (result2 == MessageBoxResult.Yes)
                    {
                        ErrorMessageBox.Show(ex);
                    }
                }
            }
        }
コード例 #4
0
        private void OnAddSaveClicked(object sender, RoutedEventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Title  = "Add Generation III Save";
            fileDialog.Filter = "GBA and GameCube Saves (*.sav, *.gci)|*.sav;*.gci|GBA Saves (*.sav)|*.sav|GameCube Saves (*.gci)|*.gci|All Files (*.*)|*.*";
            var result = fileDialog.ShowDialog(this);

            if (result.HasValue && result.Value)
            {
                string filePath = fileDialog.FileName;

                filePath = System.IO.Path.GetFullPath(filePath);
                foreach (ListViewItem item in gameSaves)
                {
                    GameSaveFileInfo save = item.Tag as GameSaveFileInfo;
                    if (filePath.ToLower() == System.IO.Path.GetFullPath(save.FilePath).ToLower())
                    {
                        TriggerMessageBox.Show(this, "This game save already exists", "Already Exists");
                        return;
                    }
                }

                try {
                    FileInfo         fileInfo = new FileInfo(filePath);
                    GameSaveFileInfo gameSaveFile;
                    GameTypes        gameType   = GameTypes.Any;
                    bool             isJapanese = false;
                    if (fileInfo.Length == 131072 || fileInfo.Length == 65536 || fileInfo.Length == 139264)
                    {
                        var results = SelectGameTypeFullWindow.ShowDialog(this, false);
                        if (results != null)
                        {
                            gameType   = results.GameType;
                            isJapanese = results.IsJapanese;
                        }
                    }
                    gameSaveFile = PokeManager.MakeNewGameSaveFileInfo(filePath, gameType, isJapanese);

                    ListViewItem listViewItem = new ListViewItem();
                    FillListViewItem(gameSaveFile, listViewItem);
                    gameSaves.Add(listViewItem);

                    listViewGameSaves.SelectedIndex = listViewGameSaves.Items.Count - 1;
                    // Hackish thing to make sure the list view is always scrolled at the bottom when adding a new box
                    //http://stackoverflow.com/questions/211971/scroll-wpf-listview-to-specific-line

                    /*VirtualizingStackPanel vsp =
                     * (VirtualizingStackPanel)typeof(ItemsControl).InvokeMember("_itemsHost",
                     *      BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic, null,
                     *      listViewGameSaves, null);
                     * double scrollHeight = vsp.ScrollOwner.ScrollableHeight;
                     * vsp.SetVerticalOffset(vsp.ScrollOwner.ScrollableHeight * 2);*/

                    listViewGameSaves.ScrollIntoView(listViewGameSaves.SelectedItem);
                    ((Control)listViewGameSaves.SelectedItem).Focus();
                }
                catch (Exception ex) {
                    MessageBoxResult result2 = TriggerMessageBox.Show(this, "Error loading game save file. Would you like to see the error?", "Read Error", MessageBoxButton.YesNo);
                    if (result2 == MessageBoxResult.Yes)
                    {
                        ErrorMessageBox.Show(ex);
                    }
                }
            }
        }
コード例 #5
0
        private void OnImportClicked(object sender, RoutedEventArgs e)
        {
            if (!IsGBAGame || GBAGameSave.SecretBaseManager.SharedSecretBases.Count < 19)
            {
                OpenFileDialog fileDialog = new OpenFileDialog();
                fileDialog.Title  = "Import Secret Base";
                fileDialog.Filter = "Secret Base Files (*.scrtb)|*.scrtb|All Files (*.*)|*.*";
                var result = fileDialog.ShowDialog(Window.GetWindow(this));
                if (result.HasValue && result.Value)
                {
                    string filePath = fileDialog.FileName;
                    filePath = System.IO.Path.GetFullPath(filePath);

                    try {
                        FileInfo fileInfo = new FileInfo(filePath);
                        if (fileInfo.Length != 160)
                        {
                            TriggerMessageBox.Show(Window.GetWindow(this), "Cannot import Secret Base. A Secret Base file must be 160 bytes in size", "Import Error");
                        }
                        else
                        {
                            SharedSecretBase newSecretBase = new SharedSecretBase(File.ReadAllBytes(filePath), null);
                            foreach (PlacedDecoration decoration in newSecretBase.PlacedDecorations)
                            {
                                if (decoration.DecorationData == null)
                                {
                                    throw new Exception("Invalid Decoration ID in Secret Base. ID=" + decoration.ID);
                                }
                            }
                            if (IsGBAGame)
                            {
                                bool added = false;
                                if (GBAGameSave.SecretBaseManager.IsLocationInUse(newSecretBase.LocationID))
                                {
                                    MessageBoxResult result2 = TriggerMessageBox.Show(Window.GetWindow(this), "Cannot import this Secret Base because its location is already in use. Would you like to select a new location?", "Location in Use", MessageBoxButton.YesNo);
                                    if (result2 == MessageBoxResult.Yes)
                                    {
                                        byte?location = SecretBaseLocationChooser.Show(Window.GetWindow(this), newSecretBase.LocationID, GBAGameSave.SecretBaseManager, true);
                                        if (location.HasValue && location.Value != 0 && !GBAGameSave.SecretBaseManager.IsLocationInUse(location.Value))
                                        {
                                            newSecretBase.SetNewLocation(location.Value);
                                            added = true;
                                        }
                                    }
                                }
                                else
                                {
                                    added = true;
                                }
                                if (added && newSecretBase.PokemonTeam.Count == 0)
                                {
                                    MessageBoxResult result3 = TriggerMessageBox.Show(Window.GetWindow(this), "This Secret Base has no Pokemon in its Team. You will need to add at least one Pokémon in order to import this Secret Base. Would you like to continue?", "No Team", MessageBoxButton.YesNo);
                                    if (result3 == MessageBoxResult.Yes)
                                    {
                                        added = SecretBaseEditTrainerWindow.Show(Window.GetWindow(this), newSecretBase, false);
                                    }
                                }
                                if (added)
                                {
                                    newSecretBase = GBAGameSave.SecretBaseManager.AddSecretBase(newSecretBase);
                                    AddListViewItems();
                                    listViewSecretBases.SelectedIndex = 2 + GBAGameSave.SecretBaseManager.SharedSecretBases.IndexOf(newSecretBase);
                                    listViewSecretBases.ScrollIntoView(listViewSecretBases.SelectedItem);
                                    ((Control)listViewSecretBases.SelectedItem).Focus();

                                    /*for (int i = 0; i < GBAGameSave.SecretBaseManager.SharedSecretBases.Count; i++) {
                                     *      if (GBAGameSave.SecretBaseManager.SharedSecretBases[i] == newSecretBase) {
                                     *              listViewSecretBases.SelectedIndex = i + 2;
                                     *              break;
                                     *      }
                                     * }*/
                                }
                            }
                            else
                            {
                                newSecretBase = PokeManager.AddSecretBase(newSecretBase);
                                AddListViewItems();
                                listViewSecretBases.SelectedIndex = PokeManager.SecretBases.IndexOf(newSecretBase);
                                listViewSecretBases.ScrollIntoView(listViewSecretBases.SelectedItem);
                                ((Control)listViewSecretBases.SelectedItem).Focus();

                                /*for (int i = 0; i < PokeManager.SecretBases.Count; i++) {
                                 *      if (PokeManager.SecretBases[i] == newSecretBase) {
                                 *               = i;
                                 *              break;
                                 *      }
                                 * }*/
                            }
                        }
                    }
                    catch (Exception ex) {
                        MessageBoxResult result2 = TriggerMessageBox.Show(Window.GetWindow(this), "Error reading Secret Base file. Would you like to see the error?", "Import Error", MessageBoxButton.YesNo);
                        if (result2 == MessageBoxResult.Yes)
                        {
                            ErrorMessageBox.Show(ex);
                        }
                    }
                }
            }
            else
            {
                TriggerMessageBox.Show(Window.GetWindow(this), "This game already has the maximum amount of 19 shared Secret Bases", "Can't Import");
            }
        }