Use existing ScoreRank for rank filter

This commit is contained in:
Andrei Zavatski 2020-10-28 23:35:08 +03:00
parent 4f6081c7f3
commit 5c2c5f2000
6 changed files with 68 additions and 34 deletions

View File

@ -8,6 +8,7 @@
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing;
using osu.Game.Rulesets;
using osu.Game.Scoring;
namespace osu.Game.Online.API.Requests
{
@ -27,7 +28,7 @@ public class SearchBeatmapSetsRequest : APIRequest<SearchBeatmapSetsResponse>
public SearchPlayed Played { get; }
public IReadOnlyCollection<SearchRank> Ranks { get; }
public IReadOnlyCollection<ScoreRank> Ranks { get; }
private readonly string query;
private readonly RulesetInfo ruleset;
@ -45,7 +46,7 @@ public SearchBeatmapSetsRequest(
SearchGenre genre = SearchGenre.Any,
SearchLanguage language = SearchLanguage.Any,
IReadOnlyCollection<SearchExtra> extra = null,
IReadOnlyCollection<SearchRank> ranks = null,
IReadOnlyCollection<ScoreRank> ranks = null,
SearchPlayed played = SearchPlayed.Any)
{
this.query = string.IsNullOrEmpty(query) ? string.Empty : System.Uri.EscapeDataString(query);

View File

@ -13,6 +13,7 @@
using osu.Game.Graphics.UserInterface;
using osuTK.Graphics;
using osu.Game.Rulesets;
using osu.Game.Scoring;
namespace osu.Game.Overlays.BeatmapListing
{
@ -30,7 +31,7 @@ public class BeatmapListingSearchControl : CompositeDrawable
public BindableList<SearchExtra> Extra => extraFilter.Current;
public BindableList<SearchRank> Ranks => ranksFilter.Current;
public BindableList<ScoreRank> Ranks => ranksFilter.Current;
public Bindable<SearchPlayed> Played => playedFilter.Current;
@ -55,7 +56,7 @@ public BeatmapSetInfo BeatmapSet
private readonly BeatmapSearchFilterRow<SearchGenre> genreFilter;
private readonly BeatmapSearchFilterRow<SearchLanguage> languageFilter;
private readonly BeatmapSearchMultipleSelectionFilterRow<SearchExtra> extraFilter;
private readonly BeatmapSearchMultipleSelectionFilterRow<SearchRank> ranksFilter;
private readonly BeatmapSearchScoreFilterRow ranksFilter;
private readonly BeatmapSearchFilterRow<SearchPlayed> playedFilter;
private readonly Box background;
@ -115,7 +116,7 @@ public BeatmapListingSearchControl()
genreFilter = new BeatmapSearchFilterRow<SearchGenre>(@"Genre"),
languageFilter = new BeatmapSearchFilterRow<SearchLanguage>(@"Language"),
extraFilter = new BeatmapSearchMultipleSelectionFilterRow<SearchExtra>(@"Extra"),
ranksFilter = new BeatmapSearchMultipleSelectionFilterRow<SearchRank>(@"Rank Achieved"),
ranksFilter = new BeatmapSearchScoreFilterRow(),
playedFilter = new BeatmapSearchFilterRow<SearchPlayed>(@"Played")
}
}

View File

@ -24,9 +24,11 @@ public BeatmapSearchMultipleSelectionFilterRow(string headerName)
Current.BindTo(filter.Current);
}
protected override Drawable CreateFilter() => filter = new MultipleSelectionFilter();
protected override Drawable CreateFilter() => filter = CreateMultipleSelectionFilter();
private class MultipleSelectionFilter : FillFlowContainer<MultipleSelectionFilterTabItem>
protected virtual MultipleSelectionFilter CreateMultipleSelectionFilter() => new MultipleSelectionFilter();
protected class MultipleSelectionFilter : FillFlowContainer<MultipleSelectionFilterTabItem>
{
public readonly BindableList<T> Current = new BindableList<T>();
@ -38,12 +40,16 @@ public MultipleSelectionFilter()
Height = 15;
Spacing = new Vector2(10, 0);
((T[])Enum.GetValues(typeof(T))).ForEach(i => Add(new MultipleSelectionFilterTabItem(i)));
GetValues().ForEach(i => Add(CreateTabItem(i)));
foreach (var item in Children)
item.Active.BindValueChanged(active => updateBindable(item.Value, active.NewValue));
}
protected virtual T[] GetValues() => (T[])Enum.GetValues(typeof(T));
protected virtual MultipleSelectionFilterTabItem CreateTabItem(T value) => new MultipleSelectionFilterTabItem(value);
private void updateBindable(T value, bool active)
{
if (active)
@ -53,7 +59,7 @@ private void updateBindable(T value, bool active)
}
}
private class MultipleSelectionFilterTabItem : FilterTabItem<T>
protected class MultipleSelectionFilterTabItem : FilterTabItem<T>
{
public MultipleSelectionFilterTabItem(T value)
: base(value)

View File

@ -0,0 +1,48 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Game.Scoring;
namespace osu.Game.Overlays.BeatmapListing
{
public class BeatmapSearchScoreFilterRow : BeatmapSearchMultipleSelectionFilterRow<ScoreRank>
{
public BeatmapSearchScoreFilterRow()
: base(@"Rank Achieved")
{
}
protected override MultipleSelectionFilter CreateMultipleSelectionFilter() => new RankFilter();
private class RankFilter : MultipleSelectionFilter
{
protected override MultipleSelectionFilterTabItem CreateTabItem(ScoreRank value) => new RankItem(value);
protected override ScoreRank[] GetValues() => base.GetValues().Reverse().ToArray();
}
private class RankItem : MultipleSelectionFilterTabItem
{
public RankItem(ScoreRank value)
: base(value)
{
}
protected override string CreateText(ScoreRank value)
{
switch (value)
{
case ScoreRank.XH:
return @"Silver SS";
case ScoreRank.SH:
return @"Silver S";
default:
return base.CreateText(value);
}
}
}
}
}

View File

@ -32,7 +32,7 @@ public FilterTabItem(T value)
text = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 13, weight: FontWeight.Regular),
Text = (value as Enum)?.GetDescription() ?? value.ToString()
Text = CreateText(value)
},
new HoverClickSounds()
});
@ -63,6 +63,8 @@ protected override void OnHoverLost(HoverLostEvent e)
protected override void OnDeactivated() => updateState();
protected virtual string CreateText(T value) => (value as Enum)?.GetDescription() ?? value.ToString();
private void updateState()
{
text.FadeColour(IsHovered ? colourProvider.Light1 : getStateColour(), 200, Easing.OutQuint);

View File

@ -1,24 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.ComponentModel;
namespace osu.Game.Overlays.BeatmapListing
{
public enum SearchRank
{
[Description(@"Silver SS")]
XH,
[Description(@"SS")]
X,
[Description(@"Silver S")]
SH,
S,
A,
B,
C,
D
}
}