Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
Added mod filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Aug 22, 2016
1 parent c6e1fb2 commit 0c58491
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 14 deletions.
63 changes: 56 additions & 7 deletions OsuHelper/ViewModels/RecommenderViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,10 +28,15 @@ public class RecommenderViewModel : ViewModelBase

private IEnumerable<BeatmapRecommendation> _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<BeatmapRecommendation> Recommendations
{
get { return _recommendations; }
Expand All @@ -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; }
Expand All @@ -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; }
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 27 additions & 7 deletions OsuHelper/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,39 @@



<UniformGrid Grid.Row="1"
Margin="5"
HorizontalAlignment="Right"
Columns="2">
<TextBlock Margin="2"
<Grid Grid.Row="1" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<WrapPanel Grid.Column="0"
HorizontalAlignment="Left"
VerticalAlignment="Center">
<CheckBox Margin="2"
Content="HR"
IsChecked="{Binding HrFilter}"
IsThreeState="True" />
<CheckBox Margin="2"
Content="DT"
IsChecked="{Binding DtFilter}"
IsThreeState="True" />
<CheckBox Margin="2"
Content="HD"
IsChecked="{Binding HdFilter}"
IsThreeState="True" />
</WrapPanel>
<TextBlock Grid.Column="1"
Margin="2"
VerticalAlignment="Center"
Text="{Binding RecommendationsCount,
StringFormat=Total: \{0\}}" />
<Button Margin="2"
<Button Grid.Column="2"
Margin="2"
VerticalAlignment="Center"
Command="{Binding UpdateCommand}"
Content="Update" />
</UniformGrid>
</Grid>

<ProgressBar Grid.Row="2"
Foreground="{DynamicResource SecondaryAccentForegroundBrush}"
Expand Down

0 comments on commit 0c58491

Please sign in to comment.