public void SelectDeckAndAppropriateView(Deck deck)
        {
            if (Config.Instance.SelectedDeckType != DeckType.All)
            {
                if (deck.IsArenaDeck && Config.Instance.SelectedDeckType != DeckType.Arena)
                {
                    SelectDeckType(DeckType.Arena);
                }
                else if (!deck.IsArenaDeck && Config.Instance.SelectedDeckType != DeckType.Constructed)
                {
                    SelectDeckType(DeckType.Constructed);
                }
            }

            if (deck.Archived && !SelectedClasses.Contains(HeroClassAll.Archived))
            {
                SelectClass(HeroClassAll.Archived);
            }
            else if (!SelectedClasses.Contains(HeroClassAll.All))
            {
                HeroClassAll deckClass;
                if (Enum.TryParse(deck.Class, out deckClass))
                {
                    if (!SelectedClasses.Contains(deckClass))
                    {
                        SelectClass(deckClass);
                    }
                }
            }

            UpdateDecks(false);
            SelectDeck(deck);
        }
예제 #2
0
 public void SelectClass(HeroClassAll heroClass)
 {
     if (!SelectedClasses.Contains(heroClass))
     {
         var dpci = PickerClassItemFromEnum(ListViewClasses, heroClass);
         ListViewClasses.SelectedItems.Add(dpci);
     }
 }
예제 #3
0
        private void SelectPickerClassItem(DeckPickerClassItem dpci)
        {
            var heroClass = dpci.DataContext as HeroClassAll?;

            if (heroClass != null && !SelectedClasses.Contains(heroClass.Value))
            {
                SelectedClasses.Add(heroClass.Value);
                dpci.OnSelected();
            }
        }
예제 #4
0
        private void SelectPickerClassItem(DeckPickerClassItem dpci)
        {
#pragma warning disable IDE0019
            var heroClass = dpci.DataContext as HeroClassAll?;
            if (heroClass != null && !SelectedClasses.Contains(heroClass.Value))
            {
                SelectedClasses.Add(heroClass.Value);
                dpci.OnSelected();
            }
#pragma warning restore IDE0019
        }
        public void SelectDeckAndAppropriateView(Deck deck)
        {
            if (deck == null)
            {
                return;
            }
            ClearFromCache(deck);
            if (Config.Instance.SelectedDeckType != DeckType.All)
            {
                if (deck.IsArenaDeck && Config.Instance.SelectedDeckType != DeckType.Arena)
                {
                    SelectDeckType(DeckType.Arena);
                }
                else if (!deck.IsArenaDeck && Config.Instance.SelectedDeckType != DeckType.Constructed)
                {
                    SelectDeckType(DeckType.Constructed);
                }
            }

            if (deck.Archived && !SelectedClasses.Contains(HeroClassAll.Archived))
            {
                SelectClass(HeroClassAll.Archived);
            }
            else if (!SelectedClasses.Contains(HeroClassAll.All))
            {
                HeroClassAll deckClass;
                if (Enum.TryParse(deck.Class, out deckClass))
                {
                    if (!SelectedClasses.Contains(deckClass))
                    {
                        SelectClass(deckClass);
                    }
                }
            }

            UpdateDecks(false);
            SelectDeck(deck);
            var dpi = _displayedDecks.FirstOrDefault(x => Equals(x.Deck, deck));

            if (dpi != null)
            {
                ListViewDecks.ScrollIntoView(dpi);
            }
        }
예제 #6
0
        public void SelectDeckAndAppropriateView(Deck deck)
        {
            if (deck == null)
            {
                return;
            }
            ClearFromCache(deck);
            if (Config.Instance.SelectedDeckPickerDeckType != DeckType.All)
            {
                if (deck.IsArenaDeck && Config.Instance.SelectedDeckPickerDeckType != DeckType.Arena)
                {
                    SelectDeckType(DeckType.Arena);
                }
                else if (!deck.IsArenaDeck)
                {
                    if (deck.StandardViable && Config.Instance.SelectedDeckPickerDeckType != DeckType.Standard)
                    {
                        SelectDeckType(DeckType.Standard);
                    }
                    else if (!deck.StandardViable && Config.Instance.SelectedDeckPickerDeckType != DeckType.Wild)
                    {
                        SelectDeckType(DeckType.Wild);
                    }
                }
            }
            if (deck.Archived && !SelectedClasses.Contains(HeroClassAll.Archived))
            {
                SelectClass(HeroClassAll.Archived);
            }
            else if (!SelectedClasses.Contains(HeroClassAll.All))
            {
                HeroClassAll deckClass;
                if (Enum.TryParse(deck.Class, out deckClass))
                {
                    if (!SelectedClasses.Contains(deckClass))
                    {
                        SelectClass(deckClass);
                    }
                }
            }

            if (!DeckMatchesSelectedTags(deck))
            {
                if (Config.Instance.TagOperation == TagFilerOperation.Or)
                {
                    var missingTags = deck.Tags.Where(tag => !Config.Instance.SelectedTags.Contains(tag)).ToList();
                    if (missingTags.Any())
                    {
                        Config.Instance.SelectedTags.AddRange(missingTags);
                        Log.Info("Added missing tags so the deck shows up: " + missingTags.Aggregate((c, n) => c + ", " + n));
                    }
                    else
                    {
                        Config.Instance.SelectedTags.Add("None");
                        Log.Info("Added missing tags so the deck shows up: None");
                    }
                }
                else
                {
                    Config.Instance.SelectedTags = new List <string> {
                        "All"
                    };
                    Log.Info("Set tags to ALL so the deck shows up");
                }
                Config.Save();
                Core.MainWindow.SortFilterDecksFlyout.SetSelectedTags(Config.Instance.SelectedTags);
            }

            UpdateDecks(false);
            SelectDeck(deck);
            var dpi = _displayedDecks.FirstOrDefault(x => Equals(x.Deck, deck));

            if (dpi != null)
            {
                ListViewDecks.ScrollIntoView(dpi);
            }
        }
예제 #7
0
        private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_reselectingClasses)
            {
                return;
            }

            var removedPickerClassItems = e.RemovedItems.OfType <DeckPickerClassItem>();
            var addedPickerClassItems   = e.AddedItems.OfType <DeckPickerClassItem>().ToList();
            var addedClasses            = PickerClassItemsAsEnum(addedPickerClassItems).ToList();

            if (addedClasses.Contains(HeroClassAll.All))
            {
                _reselectingClasses = true;
                var senderList = ((ListView)sender);
                senderList.UnselectAll();
                foreach (var item in senderList.Items)
                {
                    var dpci = item as DeckPickerClassItem;
                    if (dpci != null)
                    {
                        var hca = (HeroClassAll)dpci.DataContext;

                        switch (hca)
                        {
                        case HeroClassAll.All:
                            senderList.SelectedItems.Add(item);
                            SelectPickerClassItem(dpci);
                            break;

                        case HeroClassAll.Archived:
                            if (!SelectedClasses.Contains(HeroClassAll.Archived))
                            {
                                if (addedClasses.Contains(HeroClassAll.Archived))
                                {
                                    senderList.SelectedItems.Add(item);
                                    SelectPickerClassItem(dpci);
                                }
                            }
                            else
                            {
                                if (PickerClassItemsAsEnum(removedPickerClassItems).Contains(HeroClassAll.Archived))
                                {
                                    DeselectPickerClassItem(dpci);
                                }
                                else
                                {
                                    senderList.SelectedItems.Add(item);
                                }
                            }
                            break;

                        default:
                            DeselectPickerClassItem(dpci);
                            break;
                        }
                    }
                }
                _reselectingClasses = false;
            }
            else
            {
                DeckPickerClassItem removedAllClassItem = null;
                foreach (var dpci in removedPickerClassItems)
                {
                    var heroClass = dpci.DataContext as HeroClassAll?;
                    switch (heroClass)
                    {
                    case null:
                        continue;

                    case HeroClassAll.All:
                        // We remove this from SelectedClasses now but we don't raise it's OnDeselected event yet,
                        // instead store a reference to it in case we want to quietly add this back to the
                        // SelectedClasses list later
                        SelectedClasses.Remove(heroClass.Value);
                        removedAllClassItem = dpci;
                        break;

                    default:
                        DeselectPickerClassItem(dpci);
                        break;
                    }
                }

                var allIsSelected = SelectedClasses.Contains(HeroClassAll.All);
                foreach (var dpci in addedPickerClassItems)
                {
                    var heroClass = dpci.DataContext as HeroClassAll?;
                    if (heroClass == null)
                    {
                        continue;
                    }

                    if (allIsSelected && heroClass != HeroClassAll.Archived)
                    {
                        _reselectingClasses = true;
                        ((ListView)sender).SelectedItems.Remove(dpci);
                        _reselectingClasses = false;
                        continue;
                    }

                    SelectPickerClassItem(dpci);
                }

                if (SelectedClasses.Count == 0 && !_clearingClasses)
                {
                    var senderList = (ListView)sender;
                    if (removedAllClassItem == null)
                    {
                        var dpciAll = PickerClassItemFromEnum(senderList, HeroClassAll.All);

                        // Select 'All', raising its OnSelected event
                        _reselectingClasses = true;
                        senderList.SelectedItems.Add(dpciAll);
                        SelectPickerClassItem(dpciAll);
                        _reselectingClasses = false;
                    }
                    else
                    {
                        // If there are no selected classes, and we earlier removed 'All', quietly add it back
                        _reselectingClasses = true;
                        senderList.SelectedItems.Add(removedAllClassItem);
                        SelectedClasses.Add(HeroClassAll.All);
                        _reselectingClasses = false;

                        // And make sure we do not raise its OnDeselected event if we were going to
                        removedAllClassItem = null;
                    }
                }

                // If we removed the 'All' class earlier, raise the DeckPickerClassItem's OnDeselected event now
                removedAllClassItem?.OnDelselected();
            }

            if (Core.MainWindow.IsLoaded)
            {
                UpdateDecks();
            }
        }