public void Monitor(ICollectionView view, IEnumerable <Entry> entries)
        {
            foreach (var filter in AllFilters)
            {
                filter.PropertyChanged += (o, e) =>
                {
                    view.Refresh();
                    OnPropertyChanged(nameof(EngineerFilters));
                    OnPropertyChanged(nameof(GradeFilters));
                    OnPropertyChanged(nameof(TypeFilters));
                    OnPropertyChanged(nameof(CraftableFilters));
                    OnPropertyChanged(nameof(IgnoredFavoriteFilters));
                };
            }

            foreach (var item in entries)
            {
                item.PropertyChanged += (o, e) => Application.Current.Dispatcher.Invoke(view.Refresh);
            }

            view.Filter = o =>
            {
                var blueprint = (Blueprint)o;

                var ret = GradeFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint)) &&
                          EngineerFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint)) &&
                          TypeFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint)) &&
                          IgnoredFavoriteFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint)) &&
                          CraftableFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint));

                return(ret);
            };
        }
        public void Monitor(CollectionViewSource source, IEnumerable <Entry> entries)
        {
            foreach (var filter in AllFilters.Concat(IngredientFilters))
            {
                filter.PropertyChanged += (o, e) =>
                {
                    source.View.Refresh();
                    OnPropertyChanged(nameof(EngineerFilters));
                    OnPropertyChanged(nameof(GradeFilters));
                    OnPropertyChanged(nameof(TypeFilters));
                    OnPropertyChanged(nameof(CraftableFilters));
                    OnPropertyChanged(nameof(IgnoredFavoriteFilters));
                };
            }

            foreach (var item in entries)
            {
                item.PropertyChanged += (o, e) =>
                {
                    var extended = e as PropertyChangedExtendedEventArgs <int>;

                    if (e.PropertyName == "Count" || extended?.OldValue * extended?.NewValue == 0)
                    {
                        Application.Current.Dispatcher.Invoke(source.View.Refresh);
                    }
                };
            }

            foreach (var blueprint in (IEnumerable <Blueprint>)source.Source)
            {
                blueprint.PropertyChanged += (o, e) =>
                {
                    if (e.PropertyName == "Favorite" || e.PropertyName == "Ignored")
                    {
                        source.View.Refresh();
                    }
                };
            }

            source.Filter += (o, e) =>
            {
                var blueprint                = (Blueprint)e.Item;
                var checkedIngredients       = IngredientFilters.Where(f => f.Checked).ToList();
                var satisfyIngredientFilters = !checkedIngredients.Any() || checkedIngredients.Any(i => blueprint.Ingredients.Any(b => b.Entry == i.Entry));

                var ret = satisfyIngredientFilters &&
                          GradeFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint)) &&
                          EngineerFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint)) &&
                          TypeFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint)) &&
                          IgnoredFavoriteFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint)) &&
                          CraftableFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint));

                e.Accepted = ret;
            };
        }
Exemple #3
0
        public void Monitor(CollectionViewSource source, IEnumerable <Entry> entries, ObservableCollection <Entry> highlightedEntryData)
        {
            PropertyChanged += (o, e) =>
            {
                if (e.PropertyName == nameof(SearchText))
                {
                    source.View.Refresh();
                }
            };

            foreach (var filter in AllFilters)
            {
                filter.PropertyChanged += (o, e) =>
                {
                    source.View.Refresh();
                    OnPropertyChanged(nameof(EngineerFilters));
                    OnPropertyChanged(nameof(GradeFilters));
                    OnPropertyChanged(nameof(TypeFilters));
                    OnPropertyChanged(nameof(CraftableFilters));
                    OnPropertyChanged(nameof(IgnoredFavoriteFilters));
                };
            }

            highlightedEntryData.CollectionChanged += (o, e) =>
            {
                source.View.Refresh();
            };

            foreach (var item in entries)
            {
                item.PropertyChanged += (o, e) =>
                {
                    var extended = e as PropertyChangedExtendedEventArgs <int>;

                    if (e.PropertyName == "Count" || extended?.OldValue * extended?.NewValue == 0)
                    {
                        Application.Current.Dispatcher.Invoke(source.View.Refresh);
                    }
                };
            }

            foreach (var blueprint in (IEnumerable <Blueprint>)source.Source)
            {
                blueprint.PropertyChanged += (o, e) =>
                {
                    if (e.PropertyName == "Favorite" || e.PropertyName == "Ignored")
                    {
                        source.View.Refresh();
                    }
                };
            }

            source.Filter += (o, e) =>
            {
                var blueprint = (Blueprint)e.Item;

                var satisfySearchText = string.IsNullOrWhiteSpace(trimmedSearchText) ||
                                        trimmedSearchText.Split(' ').All(t =>
                                                                         blueprint.SearchableContent.IndexOf(t.Trim(),
                                                                                                             StringComparison.Ordinal) >= 0);

                var satisfyHighlightedFilters = !highlightedEntryData.Any() ||
                                                highlightedEntryData.Intersect(
                    blueprint.Ingredients.Select(i => i.Entry)).Any();

                var ret = satisfySearchText &&
                          satisfyHighlightedFilters &&
                          GradeFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint)) &&
                          EngineerFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint)) &&
                          TypeFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint)) &&
                          IgnoredFavoriteFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint)) &&
                          CraftableFilters.Where(f => f.Checked).Any(f => f.AppliesTo(blueprint));

                e.Accepted = ret;
            };
        }