Display certain sort criterias based on selected category and query

This commit is contained in:
Salman Ahmed 2022-09-15 03:58:32 +03:00
parent de7dd29d79
commit efebe55d22
3 changed files with 65 additions and 13 deletions

View File

@ -151,19 +151,20 @@ namespace osu.Game.Overlays.BeatmapListing
config.BindWith(OsuSetting.BeatmapListingCardSize, cardSize); config.BindWith(OsuSetting.BeatmapListingCardSize, cardSize);
var sortCriteria = sortControl.Current; searchControl.Query.BindValueChanged(_ =>
var sortDirection = sortControl.SortDirection;
searchControl.Query.BindValueChanged(query =>
{ {
sortCriteria.Value = string.IsNullOrEmpty(query.NewValue) ? SortCriteria.Ranked : SortCriteria.Relevance; resetSortControl();
sortDirection.Value = SortDirection.Descending;
queueUpdateSearch(true); queueUpdateSearch(true);
}); });
searchControl.Category.BindValueChanged(_ =>
{
resetSortControl();
queueUpdateSearch();
});
searchControl.General.CollectionChanged += (_, _) => queueUpdateSearch(); searchControl.General.CollectionChanged += (_, _) => queueUpdateSearch();
searchControl.Ruleset.BindValueChanged(_ => queueUpdateSearch()); searchControl.Ruleset.BindValueChanged(_ => queueUpdateSearch());
searchControl.Category.BindValueChanged(_ => queueUpdateSearch());
searchControl.Genre.BindValueChanged(_ => queueUpdateSearch()); searchControl.Genre.BindValueChanged(_ => queueUpdateSearch());
searchControl.Language.BindValueChanged(_ => queueUpdateSearch()); searchControl.Language.BindValueChanged(_ => queueUpdateSearch());
searchControl.Extra.CollectionChanged += (_, _) => queueUpdateSearch(); searchControl.Extra.CollectionChanged += (_, _) => queueUpdateSearch();
@ -171,8 +172,8 @@ namespace osu.Game.Overlays.BeatmapListing
searchControl.Played.BindValueChanged(_ => queueUpdateSearch()); searchControl.Played.BindValueChanged(_ => queueUpdateSearch());
searchControl.ExplicitContent.BindValueChanged(_ => queueUpdateSearch()); searchControl.ExplicitContent.BindValueChanged(_ => queueUpdateSearch());
sortCriteria.BindValueChanged(_ => queueUpdateSearch()); sortControl.Current.BindValueChanged(_ => queueUpdateSearch());
sortDirection.BindValueChanged(_ => queueUpdateSearch()); sortControl.SortDirection.BindValueChanged(_ => queueUpdateSearch());
apiUser = api.LocalUser.GetBoundCopy(); apiUser = api.LocalUser.GetBoundCopy();
apiUser.BindValueChanged(_ => queueUpdateSearch()); apiUser.BindValueChanged(_ => queueUpdateSearch());
@ -199,6 +200,8 @@ namespace osu.Game.Overlays.BeatmapListing
performRequest(); performRequest();
} }
private void resetSortControl() => sortControl.Reset(searchControl.Category.Value, !string.IsNullOrEmpty(searchControl.Query.Value));
private void queueUpdateSearch(bool queryTextChanged = false) private void queueUpdateSearch(bool queryTextChanged = false)
{ {
SearchStarted?.Invoke(); SearchStarted?.Invoke();

View File

@ -17,18 +17,65 @@ namespace osu.Game.Overlays.BeatmapListing
{ {
public readonly Bindable<SortDirection> SortDirection = new Bindable<SortDirection>(Overlays.SortDirection.Descending); public readonly Bindable<SortDirection> SortDirection = new Bindable<SortDirection>(Overlays.SortDirection.Descending);
public BeatmapListingSortTabControl() private SearchCategory? lastCategory;
private bool? lastHasQuery;
protected override void LoadComplete()
{ {
Current.Value = SortCriteria.Ranked; base.LoadComplete();
Reset(SearchCategory.Leaderboard, false);
}
public void Reset(SearchCategory category, bool hasQuery)
{
if (category != lastCategory || hasQuery != lastHasQuery)
{
TabControl.Clear();
TabControl.AddItem(SortCriteria.Title);
TabControl.AddItem(SortCriteria.Artist);
TabControl.AddItem(SortCriteria.Difficulty);
if (category == SearchCategory.Any || category > SearchCategory.Loved)
TabControl.AddItem(SortCriteria.Updated);
if (category < SearchCategory.Pending || category == SearchCategory.Mine)
TabControl.AddItem(SortCriteria.Ranked);
TabControl.AddItem(SortCriteria.Rating);
TabControl.AddItem(SortCriteria.Plays);
TabControl.AddItem(SortCriteria.Favourites);
if (hasQuery)
TabControl.AddItem(SortCriteria.Relevance);
if (category == SearchCategory.Pending)
TabControl.AddItem(SortCriteria.Nominations);
}
var nonQueryCriteria = category >= SearchCategory.Pending ? SortCriteria.Updated : SortCriteria.Ranked;
Current.Value = hasQuery ? SortCriteria.Relevance : nonQueryCriteria;
SortDirection.Value = Overlays.SortDirection.Descending;
// if the new criteria isn't different from the previous one,
// then re-adding tab items will not mark the current tab as selected.
// see: https://github.com/ppy/osu-framework/issues/5412
TabControl.Current.TriggerChange();
lastCategory = category;
lastHasQuery = hasQuery;
} }
protected override SortTabControl CreateControl() => new BeatmapSortTabControl protected override SortTabControl CreateControl() => new BeatmapSortTabControl
{ {
SortDirection = { BindTarget = SortDirection } SortDirection = { BindTarget = SortDirection },
}; };
private class BeatmapSortTabControl : SortTabControl private class BeatmapSortTabControl : SortTabControl
{ {
protected override bool AddEnumEntriesAutomatically => false;
public readonly Bindable<SortDirection> SortDirection = new Bindable<SortDirection>(); public readonly Bindable<SortDirection> SortDirection = new Bindable<SortDirection>();
protected override TabItem<SortCriteria> CreateTabItem(SortCriteria value) => new BeatmapSortTabItem(value) protected override TabItem<SortCriteria> CreateTabItem(SortCriteria value) => new BeatmapSortTabItem(value)

View File

@ -26,6 +26,8 @@ namespace osu.Game.Overlays
{ {
public class OverlaySortTabControl<T> : CompositeDrawable, IHasCurrentValue<T> public class OverlaySortTabControl<T> : CompositeDrawable, IHasCurrentValue<T>
{ {
public TabControl<T> TabControl { get; }
private readonly BindableWithCurrent<T> current = new BindableWithCurrent<T>(); private readonly BindableWithCurrent<T> current = new BindableWithCurrent<T>();
public Bindable<T> Current public Bindable<T> Current
@ -59,7 +61,7 @@ namespace osu.Game.Overlays
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold), Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
Text = SortStrings.Default Text = SortStrings.Default
}, },
CreateControl().With(c => TabControl = CreateControl().With(c =>
{ {
c.Anchor = Anchor.CentreLeft; c.Anchor = Anchor.CentreLeft;
c.Origin = Anchor.CentreLeft; c.Origin = Anchor.CentreLeft;