mirror of
https://github.com/ppy/osu
synced 2025-03-25 04:18:03 +00:00
Use a bindable for the current query.
Aso debounce and don't require hitting enter.
This commit is contained in:
parent
4e1a998f9d
commit
8045e0566f
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
@ -124,18 +125,29 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
if (tab != DirectTab.Search)
|
if (tab != DirectTab.Search)
|
||||||
{
|
{
|
||||||
Filter.Search.Text = lastQuery = string.Empty;
|
currentQuery.Value = string.Empty;
|
||||||
Filter.Tabs.Current.Value = (DirectSortCriteria)Header.Tabs.Current.Value;
|
Filter.Tabs.Current.Value = (DirectSortCriteria)Header.Tabs.Current.Value;
|
||||||
Scheduler.AddOnce(updateSearch);
|
Scheduler.AddOnce(updateSearch);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Filter.Search.OnCommit = (sender, text) =>
|
currentQuery.ValueChanged += v =>
|
||||||
{
|
{
|
||||||
lastQuery = Filter.Search.Text;
|
queryChangedDebounce?.Cancel();
|
||||||
updateSets();
|
|
||||||
|
if (string.IsNullOrEmpty(v))
|
||||||
|
Scheduler.AddOnce(updateSearch);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BeatmapSets = null;
|
||||||
|
ResultAmounts = null;
|
||||||
|
|
||||||
|
queryChangedDebounce = Scheduler.AddDelayed(updateSearch, 500);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
currentQuery.BindTo(Filter.Search.Current);
|
||||||
|
|
||||||
Filter.Tabs.Current.ValueChanged += sortCriteria =>
|
Filter.Tabs.Current.ValueChanged += sortCriteria =>
|
||||||
{
|
{
|
||||||
if (Header.Tabs.Current.Value != DirectTab.Search && sortCriteria != (DirectSortCriteria)Header.Tabs.Current.Value)
|
if (Header.Tabs.Current.Value != DirectTab.Search && sortCriteria != (DirectSortCriteria)Header.Tabs.Current.Value)
|
||||||
@ -157,7 +169,7 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private void updateResultCounts()
|
private void updateResultCounts()
|
||||||
{
|
{
|
||||||
resultCountsContainer.FadeTo(ResultAmounts == null ? 0f : 1f, 200, EasingTypes.Out);
|
resultCountsContainer.FadeTo(ResultAmounts == null ? 0f : 1f, 200, EasingTypes.OutQuint);
|
||||||
if (ResultAmounts == null) return;
|
if (ResultAmounts == null) return;
|
||||||
|
|
||||||
resultCountsText.Text = pluralize("Artist", ResultAmounts.Artists) + ", " +
|
resultCountsText.Text = pluralize("Artist", ResultAmounts.Artists) + ", " +
|
||||||
@ -177,9 +189,15 @@ namespace osu.Game.Overlays
|
|||||||
}
|
}
|
||||||
|
|
||||||
private GetBeatmapSetsRequest getSetsRequest;
|
private GetBeatmapSetsRequest getSetsRequest;
|
||||||
private string lastQuery = string.Empty;
|
|
||||||
|
private readonly Bindable<string> currentQuery = new Bindable<string>();
|
||||||
|
|
||||||
|
private ScheduledDelegate queryChangedDebounce;
|
||||||
|
|
||||||
private void updateSearch()
|
private void updateSearch()
|
||||||
{
|
{
|
||||||
|
queryChangedDebounce?.Cancel();
|
||||||
|
|
||||||
if (!IsLoaded) return;
|
if (!IsLoaded) return;
|
||||||
|
|
||||||
BeatmapSets = null;
|
BeatmapSets = null;
|
||||||
@ -211,10 +229,9 @@ namespace osu.Game.Overlays
|
|||||||
tags.AddRange(s.Metadata.Tags.Split(' '));
|
tags.AddRange(s.Metadata.Tags.Split(' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultAmounts = new ResultCounts(distinctCount(artists),
|
ResultAmounts = new ResultCounts(distinctCount(artists), distinctCount(songs), distinctCount(tags));
|
||||||
distinctCount(songs),
|
|
||||||
distinctCount(tags));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
api.Queue(getSetsRequest);
|
api.Queue(getSetsRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user