private void OnAddClicked(object sender, RoutedEventArgs e)
 {
     if (!IsGBAGame || GBAGameSave.SecretBaseManager.SharedSecretBases.Count < 19)
     {
         var location = SecretBaseLocationChooser.Show(Window.GetWindow(this), 0, IsGBAGame ? GBAGameSave.SecretBaseManager : null);
         if (location.HasValue && location.Value != 0)
         {
             SharedSecretBase newSecretBase = new SharedSecretBase(location.Value, null);
             if (IsGBAGame)
             {
                 bool result = SecretBaseEditTrainerWindow.Show(Window.GetWindow(this), newSecretBase, false);
                 if (result)
                 {
                     newSecretBase = GBAGameSave.SecretBaseManager.AddSecretBase(newSecretBase);
                     AddListViewItems();
                     listViewSecretBases.SelectedIndex = 2 + GBAGameSave.SecretBaseManager.SharedSecretBases.IndexOf(newSecretBase);
                     listViewSecretBases.ScrollIntoView(listViewSecretBases.SelectedItem);
                     ((Control)listViewSecretBases.SelectedItem).Focus();
                 }
             }
             else
             {
                 newSecretBase = PokeManager.AddSecretBase(newSecretBase);
                 AddListViewItems();
                 listViewSecretBases.SelectedIndex = PokeManager.SecretBases.IndexOf(newSecretBase);
                 listViewSecretBases.ScrollIntoView(listViewSecretBases.SelectedItem);
                 ((Control)listViewSecretBases.SelectedItem).Focus();
             }
         }
     }
     else
     {
         TriggerMessageBox.Show(Window.GetWindow(this), "This game already has the maximum amount of 19 shared Secret Bases", "Can't Import");
     }
 }
Exemple #2
0
        public static bool Show(Window owner, SharedSecretBase secretBase, bool allowNoTeam, bool creating = false)
        {
            SecretBaseEditTrainerWindow window = new SecretBaseEditTrainerWindow(secretBase, allowNoTeam, creating);

            window.Owner = owner;
            var result = window.ShowDialog();

            return(result.HasValue ? result.Value : false);
        }
        private void OnEditTrainerClicked(object sender, RoutedEventArgs e)
        {
            bool result = SecretBaseEditTrainerWindow.Show(Window.GetWindow(this), (SharedSecretBase)secretBase, !IsGBAGame);

            if (result)
            {
                UpdateListViewItems();
                OnSecretBaseSelected(null, null);
            }
        }
        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);
                    }
                }
            }
        }
        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");
            }
        }
 public static bool Show(Window owner, SharedSecretBase secretBase, bool allowNoTeam, bool creating = false)
 {
     SecretBaseEditTrainerWindow window = new SecretBaseEditTrainerWindow(secretBase, allowNoTeam, creating);
     window.Owner = owner;
     var result = window.ShowDialog();
     return (result.HasValue ? result.Value : false);
 }