mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 23:22:55 +08:00
filter beatmaps by star range
This commit is contained in:
parent
7137c01352
commit
11dad7bf74
@ -77,6 +77,7 @@ namespace osu.Game.Tests.Visual
|
||||
testEmptyTraversal();
|
||||
testHiding();
|
||||
testSelectingFilteredRuleset();
|
||||
testFilterByStarRange();
|
||||
testCarouselRootIsRandom();
|
||||
}
|
||||
|
||||
@ -245,6 +246,54 @@ namespace osu.Game.Tests.Visual
|
||||
AddAssert("Selection is non-null", () => currentSelection != null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test filtering by restricting the desired star range
|
||||
/// </summary>
|
||||
private void testFilterByStarRange()
|
||||
{
|
||||
var manyStarDiffs = createTestBeatmapSet(set_count + 1);
|
||||
manyStarDiffs.Beatmaps.Clear();
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
manyStarDiffs.Beatmaps.Add(new BeatmapInfo
|
||||
{
|
||||
OnlineBeatmapID = manyStarDiffs.ID * 10 + i,
|
||||
Path = $"randomDiff{i}.osu",
|
||||
Version = $"Totally Normal {i}",
|
||||
StarDifficulty = i,
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
{
|
||||
OverallDifficulty = 5,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
AddStep("add set with many stars", () => carousel.UpdateBeatmapSet(manyStarDiffs));
|
||||
|
||||
AddStep("select added set", () => carousel.SelectBeatmap(manyStarDiffs.Beatmaps[0], false));
|
||||
|
||||
AddStep("Filter to 1-3 stars", () => carousel.Filter(new FilterCriteria { DisplayStarsMinimum = 1, DisplayStarsMaximum = 3 }, false));
|
||||
checkVisibleItemCount(diff: false, count: 1);
|
||||
checkVisibleItemCount(diff: true, count: 3);
|
||||
|
||||
AddStep("Filter to 3-3 stars", () => carousel.Filter(new FilterCriteria { DisplayStarsMinimum = 3, DisplayStarsMaximum = 3 }, false));
|
||||
checkVisibleItemCount(diff: false, count: 1);
|
||||
checkVisibleItemCount(diff: true, count: 1);
|
||||
|
||||
AddStep("Filter to 4-2 stars", () => carousel.Filter(new FilterCriteria { DisplayStarsMinimum = 4, DisplayStarsMaximum = 2 }, false));
|
||||
checkVisibleItemCount(diff: false, count: 0);
|
||||
checkVisibleItemCount(diff: true, count: 0);
|
||||
|
||||
AddStep("remove added set", () =>
|
||||
{
|
||||
carousel.RemoveBeatmapSet(manyStarDiffs);
|
||||
manyStarDiffs = null;
|
||||
});
|
||||
|
||||
AddStep("Un-filter", () => carousel.Filter(new FilterCriteria(), false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test random non-repeating algorithm
|
||||
/// </summary>
|
||||
|
@ -26,6 +26,12 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
|
||||
bool match = criteria.Ruleset == null || Beatmap.RulesetID == criteria.Ruleset.ID || Beatmap.RulesetID == 0 && criteria.Ruleset.ID > 0 && criteria.AllowConvertedBeatmaps;
|
||||
|
||||
if(criteria.DisplayStarsMinimum.HasValue)
|
||||
match &= Beatmap.StarDifficulty >= criteria.DisplayStarsMinimum;
|
||||
|
||||
if (criteria.DisplayStarsMaximum.HasValue)
|
||||
match &= Beatmap.StarDifficulty <= criteria.DisplayStarsMaximum;
|
||||
|
||||
if (!string.IsNullOrEmpty(criteria.SearchText))
|
||||
match &=
|
||||
Beatmap.Metadata.SearchableTerms.Any(term => term.IndexOf(criteria.SearchText, StringComparison.InvariantCultureIgnoreCase) >= 0) ||
|
||||
|
@ -32,14 +32,13 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
public SortMode Sort
|
||||
{
|
||||
get { return sort; }
|
||||
get => sort;
|
||||
set
|
||||
{
|
||||
if (sort != value)
|
||||
{
|
||||
sort = value;
|
||||
FilterChanged?.Invoke(CreateCriteria());
|
||||
}
|
||||
if (sort == value) return;
|
||||
|
||||
sort = value;
|
||||
FilterChanged?.Invoke(CreateCriteria());
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,14 +46,13 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
public GroupMode Group
|
||||
{
|
||||
get { return group; }
|
||||
get => group;
|
||||
set
|
||||
{
|
||||
if (group != value)
|
||||
{
|
||||
group = value;
|
||||
FilterChanged?.Invoke(CreateCriteria());
|
||||
}
|
||||
if (group == value) return;
|
||||
|
||||
group = value;
|
||||
FilterChanged?.Invoke(CreateCriteria());
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +62,9 @@ namespace osu.Game.Screens.Select
|
||||
Sort = sort,
|
||||
SearchText = searchTextBox.Text,
|
||||
AllowConvertedBeatmaps = showConverted,
|
||||
Ruleset = ruleset.Value
|
||||
Ruleset = ruleset.Value,
|
||||
DisplayStarsMinimum = minimumStars,
|
||||
DisplayStarsMaximum = maximumStars,
|
||||
};
|
||||
|
||||
public Action Exit;
|
||||
@ -168,7 +168,9 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
private readonly IBindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
||||
|
||||
private Bindable<bool> showConverted;
|
||||
private readonly Bindable<bool> showConverted = new Bindable<bool>();
|
||||
private readonly Bindable<double> minimumStars = new Bindable<double>();
|
||||
private readonly Bindable<double> maximumStars = new Bindable<double>();
|
||||
|
||||
public readonly Box Background;
|
||||
|
||||
@ -177,8 +179,14 @@ namespace osu.Game.Screens.Select
|
||||
{
|
||||
sortTabs.AccentColour = colours.GreenLight;
|
||||
|
||||
showConverted = config.GetBindable<bool>(OsuSetting.ShowConvertedBeatmaps);
|
||||
showConverted.ValueChanged += val => updateCriteria();
|
||||
config.BindWith(OsuSetting.ShowConvertedBeatmaps, showConverted);
|
||||
showConverted.ValueChanged += _ => updateCriteria();
|
||||
|
||||
config.BindWith(OsuSetting.DisplayStarsMinimum, minimumStars);
|
||||
minimumStars.ValueChanged += _ => updateCriteria();
|
||||
|
||||
config.BindWith(OsuSetting.DisplayStarsMaximum, maximumStars);
|
||||
maximumStars.ValueChanged += _ => updateCriteria();
|
||||
|
||||
ruleset.BindTo(parentRuleset);
|
||||
ruleset.BindValueChanged(_ => updateCriteria(), true);
|
||||
|
@ -13,5 +13,7 @@ namespace osu.Game.Screens.Select
|
||||
public string SearchText;
|
||||
public RulesetInfo Ruleset;
|
||||
public bool AllowConvertedBeatmaps;
|
||||
public double? DisplayStarsMinimum;
|
||||
public double? DisplayStarsMaximum;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user