Esempio n. 1
0
        public void SelectDeck(Deck deck, bool setActive)
        {
            if (DeckList.Instance.ActiveDeck != null)
            {
                DeckPickerList.ClearFromCache(DeckList.Instance.ActiveDeck);
            }
            if (deck != null)
            {
                //set up notes
                DeckNotesEditor.SetDeck(deck);
                var flyoutHeader = deck.Name.Length >= 20 ? string.Join("", deck.Name.Take(17)) + "..." : deck.Name;
                FlyoutNotes.Header = flyoutHeader;

                //set up tags
                TagControlEdit.SetSelectedTags(DeckPickerList.SelectedDecks);
                MenuItemQuickSetTag.ItemsSource = TagControlEdit.Tags;
                MenuItemQuickSetTag.Items.Refresh();
                DeckPickerList.MenuItemQuickSetTag.ItemsSource = TagControlEdit.Tags;
                DeckPickerList.MenuItemQuickSetTag.Items.Refresh();


                //set and save last used deck for class
                if (setActive)
                {
                    while (DeckList.Instance.LastDeckClass.Any(ldc => ldc.Class == deck.Class))
                    {
                        var lastSelected = DeckList.Instance.LastDeckClass.FirstOrDefault(ldc => ldc.Class == deck.Class);
                        if (lastSelected != null)
                        {
                            DeckList.Instance.LastDeckClass.Remove(lastSelected);
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (Core.Initialized)
                    {
                        DeckList.Instance.LastDeckClass.Add(new DeckInfo {
                            Class = deck.Class, Name = deck.Name, Id = deck.DeckId
                        });
                        DeckList.Save();
                    }

                    Log.Info("Switched to deck: " + deck.Name);

                    int useNoDeckMenuItem = Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey(TrayIcon.UseNoDeckMenuItemName);
                    Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Checked = false;
                }
            }
            else
            {
                Core.Game.IsUsingPremade = false;

                if (DeckList.Instance.ActiveDeck != null)
                {
                    DeckList.Instance.ActiveDeck.IsSelectedInGui = false;
                }

                DeckList.Instance.ActiveDeck = null;
                if (setActive)
                {
                    DeckPickerList.DeselectDeck();
                }

                var useNoDeckMenuItem = Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey(TrayIcon.UseNoDeckMenuItemName);
                Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Checked = true;
            }

            if (setActive)
            {
                UseDeck(deck);
            }
            DeckPickerList.SelectDeck(deck);
            UpdateDeckList(deck);
            EnableMenuItems(deck != null);
            ManaCurveMyDecks.SetDeck(deck);
            UpdatePanelVersionComboBox(deck);
            if (setActive)
            {
                Core.Overlay.ListViewPlayer.Items.Refresh();
                Core.Windows.PlayerWindow.ListViewPlayer.Items.Refresh();
            }
            DeckManagerEvents.OnDeckSelected.Execute(deck);
        }
        public void SelectDeck(Deck deck, bool setActive)
        {
            if (DeckList.Instance.ActiveDeck != null)
            {
                DeckPickerList.ClearFromCache(DeckList.Instance.ActiveDeck);
            }
            if (deck != null)
            {
                //set up tags
                TagControlEdit.SetSelectedTags(DeckPickerList.SelectedDecks);
                DeckPickerList.MenuItemQuickSetTag.ItemsSource = TagControlEdit.Tags;
                DeckPickerList.MenuItemQuickSetTag.Items.Refresh();

                OnPropertyChanged(nameof(HsReplayButtonVisibility));

                //set and save last used deck for class
                if (setActive)
                {
                    while (DeckList.Instance.LastDeckClass.Any(ldc => ldc.Class == deck.Class))
                    {
                        var lastSelected = DeckList.Instance.LastDeckClass.FirstOrDefault(ldc => ldc.Class == deck.Class);
                        if (lastSelected != null)
                        {
                            DeckList.Instance.LastDeckClass.Remove(lastSelected);
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (Core.Initialized)
                    {
                        DeckList.Instance.LastDeckClass.Add(new DeckInfo {
                            Class = deck.Class, Name = deck.Name, Id = deck.DeckId
                        });
                        DeckList.Save();
                    }

                    Log.Info($"Switched to deck: {deck.Name} ({deck.SelectedVersion.ShortVersionString})");
                    Core.TrayIcon.MenuItemUseNoDeck.Checked = false;
                }

                if (FlyoutDeckScreenshot.IsOpen)
                {
                    DeckScreenshotFlyout.Deck = deck.GetSelectedDeckVersion();
                }
                if (FlyoutDeckExport.IsOpen)
                {
                    DeckExportFlyout.Deck = deck.GetSelectedDeckVersion();
                }

                if (FlyoutDeckHistory.IsOpen)
                {
                    if (deck.HasVersions)
                    {
                        DeckHistoryFlyout.Deck = deck;
                    }
                    else
                    {
                        FlyoutDeckHistory.IsOpen = false;
                    }
                }
            }
            else
            {
                Core.Game.IsUsingPremade = false;

                if (DeckList.Instance.ActiveDeck != null)
                {
                    DeckList.Instance.ActiveDeck.IsSelectedInGui = false;
                }

                DeckList.Instance.ActiveDeck = null;
                if (setActive)
                {
                    DeckPickerList.DeselectDeck();
                }

                Core.TrayIcon.MenuItemUseNoDeck.Checked = true;
            }

            if (setActive)
            {
                UseDeck(deck);
            }
            DeckPickerList.SelectDeck(deck);
            UpdateDeckList(deck);
            ManaCurveMyDecks.SetDeck(deck);
            UpdatePanelVersionComboBox(deck);
            GroupBoxHsReplayDeckInfo.Visibility = deck?.IsArenaDeck == true ? Collapsed : Visible;
            if (setActive)
            {
                Core.Overlay.ListViewPlayer.Items.Refresh();
                Core.Windows.PlayerWindow.ListViewPlayer.Items.Refresh();
            }
            DeckManagerEvents.OnDeckSelected.Execute(deck);
        }