1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

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);
var sortCriteria = sortControl.Current;
var sortDirection = sortControl.SortDirection;
searchControl.Query.BindValueChanged(query =>
searchControl.Query.BindValueChanged(_ =>
{
sortCriteria.Value = string.IsNullOrEmpty(query.NewValue) ? SortCriteria.Ranked : SortCriteria.Relevance;
sortDirection.Value = SortDirection.Descending;
resetSortControl();
queueUpdateSearch(true);
});
searchControl.Category.BindValueChanged(_ =>
{
resetSortControl();
queueUpdateSearch();
});
searchControl.General.CollectionChanged += (_, _) => queueUpdateSearch();
searchControl.Ruleset.BindValueChanged(_ => queueUpdateSearch());
searchControl.Category.BindValueChanged(_ => queueUpdateSearch());
searchControl.Genre.BindValueChanged(_ => queueUpdateSearch());
searchControl.Language.BindValueChanged(_ => queueUpdateSearch());
searchControl.Extra.CollectionChanged += (_, _) => queueUpdateSearch();
@ -171,8 +172,8 @@ namespace osu.Game.Overlays.BeatmapListing
searchControl.Played.BindValueChanged(_ => queueUpdateSearch());
searchControl.ExplicitContent.BindValueChanged(_ => queueUpdateSearch());
sortCriteria.BindValueChanged(_ => queueUpdateSearch());
sortDirection.BindValueChanged(_ => queueUpdateSearch());
sortControl.Current.BindValueChanged(_ => queueUpdateSearch());
sortControl.SortDirection.BindValueChanged(_ => queueUpdateSearch());
apiUser = api.LocalUser.GetBoundCopy();
apiUser.BindValueChanged(_ => queueUpdateSearch());
@ -199,6 +200,8 @@ namespace osu.Game.Overlays.BeatmapListing
performRequest();
}
private void resetSortControl() => sortControl.Reset(searchControl.Category.Value, !string.IsNullOrEmpty(searchControl.Query.Value));
private void queueUpdateSearch(bool queryTextChanged = false)
{
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 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
{
SortDirection = { BindTarget = SortDirection }
SortDirection = { BindTarget = SortDirection },
};
private class BeatmapSortTabControl : SortTabControl
{
protected override bool AddEnumEntriesAutomatically => false;
public readonly Bindable<SortDirection> SortDirection = new Bindable<SortDirection>();
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 TabControl<T> TabControl { get; }
private readonly BindableWithCurrent<T> current = new BindableWithCurrent<T>();
public Bindable<T> Current
@ -59,7 +61,7 @@ namespace osu.Game.Overlays
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
Text = SortStrings.Default
},
CreateControl().With(c =>
TabControl = CreateControl().With(c =>
{
c.Anchor = Anchor.CentreLeft;
c.Origin = Anchor.CentreLeft;