From 0c58491c27890808d35cc4a0fc12b332e2b91529 Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Mon, 22 Aug 2016 03:09:56 +0300 Subject: [PATCH] Added mod filters --- OsuHelper/ViewModels/RecommenderViewModel.cs | 63 +++++++++++++++++--- OsuHelper/Views/MainWindow.xaml | 34 ++++++++--- 2 files changed, 83 insertions(+), 14 deletions(-) diff --git a/OsuHelper/ViewModels/RecommenderViewModel.cs b/OsuHelper/ViewModels/RecommenderViewModel.cs index 89e4361..ae63c70 100644 --- a/OsuHelper/ViewModels/RecommenderViewModel.cs +++ b/OsuHelper/ViewModels/RecommenderViewModel.cs @@ -8,8 +8,10 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.Linq; +using System.Windows.Data; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.CommandWpf; using NegativeLayer.Extensions; @@ -26,10 +28,15 @@ public class RecommenderViewModel : ViewModelBase private IEnumerable _recommendations; private int _recommendationsCount; - private bool _canUpdate = true; private BeatmapRecommendation _selectedRecommendation; + private bool? _hrFilter; + private bool? _dtFilter; + private bool? _hdFilter; + private bool _canUpdate = true; private double _progress; + private ICollectionView CollectionView => CollectionViewSource.GetDefaultView(Recommendations); + public IEnumerable Recommendations { get { return _recommendations; } @@ -48,6 +55,42 @@ public int RecommendationsCount set { Set(ref _recommendationsCount, value); } } + public BeatmapRecommendation SelectedRecommendation + { + get { return _selectedRecommendation; } + set { Set(ref _selectedRecommendation, value); } + } + + public bool? HrFilter + { + get { return _hrFilter; } + set + { + Set(ref _hrFilter, value); + UpdateFilter(); + } + } + + public bool? DtFilter + { + get { return _dtFilter; } + set + { + Set(ref _dtFilter, value); + UpdateFilter(); + } + } + + public bool? HdFilter + { + get { return _hdFilter; } + set + { + Set(ref _hdFilter, value); + UpdateFilter(); + } + } + public bool CanUpdate { get { return _canUpdate; } @@ -61,12 +104,6 @@ public bool CanUpdate public bool IsBusy => !CanUpdate; - public BeatmapRecommendation SelectedRecommendation - { - get { return _selectedRecommendation; } - set { Set(ref _selectedRecommendation, value); } - } - public double Progress { get { return _progress; } @@ -122,6 +159,18 @@ private void BloodcatDownloadBeatmap(Beatmap bm) Process.Start($"http://bloodcat.com/osu/s/{bm.MapSetID}"); } + private void UpdateFilter() + { + CollectionView.Filter = o => + { + var rec = (BeatmapRecommendation) o; + bool hrCheck = !HrFilter.HasValue || HrFilter.Value == rec.Mods.HasFlag(EnabledMods.HardRock); + bool dtCheck = !DtFilter.HasValue || DtFilter.Value == rec.Mods.HasFlag(EnabledMods.DoubleTime); + bool hdCheck = !HdFilter.HasValue || HdFilter.Value == rec.Mods.HasFlag(EnabledMods.Hidden); + return hrCheck && dtCheck && hdCheck; + }; + } + private async void Update() { CanUpdate = false; diff --git a/OsuHelper/Views/MainWindow.xaml b/OsuHelper/Views/MainWindow.xaml index 3dcf7e9..74b14b9 100644 --- a/OsuHelper/Views/MainWindow.xaml +++ b/OsuHelper/Views/MainWindow.xaml @@ -160,19 +160,39 @@ - - + + + + + + + + + + + -