public void UpdateArchivedClassVisibility()
        {
            if (DeckList.Instance.Decks.Any(d => d.Archived))
            {
                if (!_classItems.Contains(_archivedClassItem))
                {
                    _classItems.Add(_archivedClassItem);
                    ArchivedClassVisible = true;

                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ArchivedClassVisible"));
                }
            }
            else
            {
                var removed = _classItems.Remove(_archivedClassItem);

                if (removed)
                {
                    ArchivedClassVisible = false;

                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ArchivedClassVisible"));
                }

                SelectedClasses.Remove(HeroClassAll.Archived);
                if (SelectedClasses.Count == 0)
                {
                    SelectClass(HeroClassAll.All);
                }
            }
        }
Exemplo n.º 2
0
        public void UpdateArchivedClassVisibility()
        {
            _anyArchived = DeckList.Instance.Decks.Any(d => d.Archived);

            if (_anyArchived)
            {
                if (!_classItems.Contains(_archivedClassItem))
                {
                    _classItems.Add(_archivedClassItem);

                    if (PropertyChanged != null)
                    {
                        PropertyChanged(this, new PropertyChangedEventArgs("MinWindowHeight"));
                    }
                }
            }
            else
            {
                var removed = _classItems.Remove(_archivedClassItem);

                if (removed && PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("MinWindowHeight"));
                }

                SelectedClasses.Remove(HeroClassAll.Archived);
                if (SelectedClasses.Count == 0)
                {
                    SelectClass(HeroClassAll.All);
                }
            }
        }
Exemplo n.º 3
0
        private void DeselectPickerClassItem(DeckPickerClassItem dpci)
        {
            var heroClass = dpci.DataContext as HeroClassAll?;

            if (heroClass != null && SelectedClasses.Remove(heroClass.Value))
            {
                dpci.OnDelselected();
            }
        }
Exemplo n.º 4
0
        private void DeselectPickerClassItem(DeckPickerClassItem dpci)
        {
#pragma warning disable IDE0019
            var heroClass = dpci.DataContext as HeroClassAll?;
            if (heroClass != null && SelectedClasses.Remove(heroClass.Value))
            {
                dpci.OnDelselected();
            }
#pragma warning restore IDE0019
        }
Exemplo n.º 5
0
        public void UpdateArchivedClassVisibility()
        {
            if (DeckList.Instance.Decks.Any(d => d.Archived))
            {
                if (!_classItems.Contains(_archivedClassItem))
                {
                    _classItems.Add(_archivedClassItem);
                    ArchivedClassVisible = true;
                }
            }
            else
            {
                if (_classItems.Remove(_archivedClassItem))
                {
                    ArchivedClassVisible = false;
                }

                SelectedClasses.Remove(HeroClassAll.Archived);
                if (SelectedClasses.Count == 0)
                {
                    SelectClass(HeroClassAll.All);
                }
            }
        }
Exemplo n.º 6
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();
            }
        }