public static bool?ShowDialog(Window owner, IPokeBox pokeBox, bool silentEdit = false)
        {
            EditBoxWindow window = new EditBoxWindow(pokeBox, silentEdit);

            window.Owner = owner;
            return(window.ShowDialog());
        }
 private void UpdateBoxNames()
 {
     foreach (ListViewItem listViewItem in boxes)
     {
         IPokeBox box = listViewItem.Tag as IPokeBox;
         ((Label)((StackPanel)listViewItem.Content).Children[1]).Content = box.Name;
     }
 }
        private void MakeBox(int index, ListViewItem listViewItem)
        {
            IPokeBox   pokeBox    = pokePC[index];
            StackPanel stackPanel = new StackPanel();

            stackPanel.Orientation = Orientation.Horizontal;

            double scale   = 0.3;
            int    xOffset = 2;
            int    yOffset = 2;
            Grid   boxGrid = new Grid();

            boxGrid.Width  = xOffset * 2 + 156 * scale;
            boxGrid.Height = yOffset * 2 + 141 * scale;
            Image wallpaperImage = new Image();

            wallpaperImage.Source = pokeBox.WallpaperImage;
            wallpaperImage.Width  = 156 * scale;
            wallpaperImage.Height = 141 * scale;
            wallpaperImage.Margin = new Thickness(xOffset, yOffset, 0, 0);
            boxGrid.Children.Add(wallpaperImage);
            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 6; x++)
                {
                    IPokemon pokemon = pokeBox[x + y * 6];
                    if (pokemon != null)
                    {
                        // Dont bother with the shadow mask. It's not a big deal here
                        Image boxImage = new Image();
                        boxImage.Width  = 32 * scale;
                        boxImage.Height = 32 * scale;
                        boxImage.Margin = new Thickness(xOffset + (2 + x * 24) * scale, yOffset + (13 + y * 24) * scale, 0, 0);
                        boxImage.Source = pokemon.BoxSprite;
                        boxImage.HorizontalAlignment = HorizontalAlignment.Left;
                        boxImage.VerticalAlignment   = VerticalAlignment.Top;
                        boxGrid.Children.Add(boxImage);
                    }
                }
            }
            stackPanel.Children.Add(boxGrid);


            Label name = new Label();

            name.Content           = pokeBox.Name;
            name.Margin            = new Thickness(3, 0, 0, 0);
            name.FontWeight        = FontWeights.Bold;
            name.VerticalAlignment = VerticalAlignment.Center;
            stackPanel.Children.Add(name);

            listViewItem.ContextMenu         = contextMenu;
            listViewItem.ContextMenuOpening += OnContextMenuOpening;
            listViewItem.Content             = stackPanel;
            listViewItem.Tag = pokeBox;
        }
        private void OnBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int newSelection = listViewBoxes.SelectedIndex;

            if (newSelection != -1)
            {
                selectedIndex = newSelection;
                selectedBox   = boxes[selectedIndex].Tag as IPokeBox;
                pokeBoxControl.LoadBox(selectedBox, PokeManager.GetIndexOfGame(selectedBox.PokePC.GameSave));
            }
        }
        public EditBoxWindow(IPokeBox pokeBox, bool silentEdit)
        {
            InitializeComponent();
            if (pokeBox is BoxPokeBox)
            {
                this.newName = ((BoxPokeBox)pokeBox).RealName;
                this.pokeBox = ((BoxPokeBox)pokeBox).PrimaryBox;
            }
            else
            {
                this.newName = pokeBox.Name;
                this.pokeBox = pokeBox;
            }
            this.buttonQuotes1.Content = "“";
            this.buttonQuotes2.Content = "”";
            this.silentEdit            = silentEdit;

            string[] wallpaperNames = null;
            if (pokeBox.GameType == GameTypes.Ruby || pokeBox.GameType == GameTypes.Sapphire)
            {
                wallpaperNames = RSNames;
            }
            else if (pokeBox.GameType == GameTypes.Emerald)
            {
                wallpaperNames = EmeraldNames;
            }
            else if (pokeBox.GameType == GameTypes.FireRed || pokeBox.GameType == GameTypes.LeafGreen)
            {
                wallpaperNames = FRLGNames;
            }
            else if (pokeBox.GameType == GameTypes.PokemonBox)
            {
                wallpaperNames = BoxNames;
            }
            else if (pokeBox.GameType == GameTypes.Colosseum)
            {
                wallpaperNames = ColosseumNames;
            }
            else if (pokeBox.GameType == GameTypes.XD)
            {
                wallpaperNames = XDNames;
            }
            else if (pokeBox.GameType == GameTypes.Any)
            {
                wallpaperNames = ManagerNames;
            }

            this.newWallpaper = Math.Min((byte)(wallpaperNames.Length - 1), (byte)pokeBox.Wallpaper);
            foreach (string wallpaperName in wallpaperNames)
            {
                comboBoxWallpaper.Items.Add(wallpaperName);
            }

            if (pokeBox is ManagerPokeBox)
            {
                newUsingCustomWallpaper   = ManagerPokeBox.UsingCustomWallpaper;
                newWallpaperName          = ManagerPokeBox.WallpaperName;
                customWallpaperStartIndex = comboBoxWallpaper.Items.Count;
                if (!ManagerPokeBox.UsingCustomWallpaper)
                {
                    ManagerPokeBoxWallpapers outResult;
                    if (Enum.TryParse <ManagerPokeBoxWallpapers>(ManagerPokeBox.WallpaperName, true, out outResult))
                    {
                        this.comboBoxWallpaper.SelectedIndex = (byte)outResult;
                    }
                    else
                    {
                        this.comboBoxWallpaper.SelectedIndex = (byte)ManagerPokeBoxWallpapers.SimpleRS;
                    }
                }
                for (int i = 0; i < PokemonDatabase.NumCustomWallpapers; i++)
                {
                    string wallpaperName = PokemonDatabase.GetCustomWallpaperNameAt(i);
                    comboBoxWallpaper.Items.Add(wallpaperName);
                    if (ManagerPokeBox.UsingCustomWallpaper && ManagerPokeBox.WallpaperName.ToLower() == wallpaperName.ToLower())
                    {
                        this.comboBoxWallpaper.SelectedIndex = customWallpaperStartIndex + i;
                    }
                }
            }
            else
            {
                this.comboBoxWallpaper.SelectedIndex = newWallpaper;
            }

            if (pokeBox.GameType == GameTypes.Colosseum || pokeBox.GameType == GameTypes.XD)
            {
                comboBoxWallpaper.IsEnabled = false;
            }

            // FREEEEDOOMMMMM
            if (pokeBox.GameType == GameTypes.Any)
            {
                this.textBoxName.MaxLength = 20;
            }
            else if (pokeBox.PokePC.GameSave.IsJapanese)
            {
                this.buttonDots.Visibility         = Visibility.Hidden;
                this.buttonQuotes1.Visibility      = Visibility.Hidden;
                this.buttonQuotes2.Visibility      = Visibility.Hidden;
                this.buttonSingleQuote1.Visibility = Visibility.Hidden;
                this.buttonSingleQuote2.Visibility = Visibility.Hidden;
                //this.textBoxName.MaxLength = 5;
            }


            this.textBoxName.Text = newName;
            this.textBoxName.Focus();
            textBoxName.SelectAll();
        }