1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 12:42:54 +08:00

Merge pull request #4456 from peppy/fix-direct-queries

Fix osu!direct firing excess queries during initial search characters
This commit is contained in:
Dan Balasescu 2019-03-12 12:54:31 +09:00 committed by GitHub
commit 8897739a53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -134,9 +134,9 @@ namespace osu.Game.Overlays
Filter.Tabs.Current.Value = DirectSortCriteria.Ranked; Filter.Tabs.Current.Value = DirectSortCriteria.Ranked;
} }
}; };
((FilterControl)Filter).Ruleset.ValueChanged += _ => Scheduler.AddOnce(updateSearch); ((FilterControl)Filter).Ruleset.ValueChanged += _ => queueUpdateSearch();
Filter.DisplayStyleControl.DisplayStyle.ValueChanged += style => recreatePanels(style.NewValue); Filter.DisplayStyleControl.DisplayStyle.ValueChanged += style => recreatePanels(style.NewValue);
Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += _ => Scheduler.AddOnce(updateSearch); Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += _ => queueUpdateSearch();
Header.Tabs.Current.ValueChanged += tab => Header.Tabs.Current.ValueChanged += tab =>
{ {
@ -144,24 +144,11 @@ namespace osu.Game.Overlays
{ {
currentQuery.Value = 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); queueUpdateSearch();
} }
}; };
currentQuery.ValueChanged += text => currentQuery.ValueChanged += text => queueUpdateSearch(!string.IsNullOrEmpty(text.NewValue));
{
queryChangedDebounce?.Cancel();
if (string.IsNullOrEmpty(text.NewValue))
Scheduler.AddOnce(updateSearch);
else
{
BeatmapSets = null;
ResultAmounts = null;
queryChangedDebounce = Scheduler.AddDelayed(updateSearch, 500);
}
};
currentQuery.BindTo(Filter.Search.Current); currentQuery.BindTo(Filter.Search.Current);
@ -170,7 +157,7 @@ namespace osu.Game.Overlays
if (Header.Tabs.Current.Value != DirectTab.Search && tab.NewValue != (DirectSortCriteria)Header.Tabs.Current.Value) if (Header.Tabs.Current.Value != DirectTab.Search && tab.NewValue != (DirectSortCriteria)Header.Tabs.Current.Value)
Header.Tabs.Current.Value = DirectTab.Search; Header.Tabs.Current.Value = DirectTab.Search;
Scheduler.AddOnce(updateSearch); queueUpdateSearch();
}; };
updateResultCounts(); updateResultCounts();
@ -242,37 +229,42 @@ namespace osu.Game.Overlays
// Queries are allowed to be run only on the first pop-in // Queries are allowed to be run only on the first pop-in
if (getSetsRequest == null) if (getSetsRequest == null)
Scheduler.AddOnce(updateSearch); queueUpdateSearch();
} }
private SearchBeatmapSetsRequest getSetsRequest; private SearchBeatmapSetsRequest getSetsRequest;
private readonly Bindable<string> currentQuery = new Bindable<string>(); private readonly Bindable<string> currentQuery = new Bindable<string>(string.Empty);
private ScheduledDelegate queryChangedDebounce; private ScheduledDelegate queryChangedDebounce;
private PreviewTrackManager previewTrackManager; private PreviewTrackManager previewTrackManager;
private void queueUpdateSearch(bool queryTextChanged = false)
{
BeatmapSets = null;
ResultAmounts = null;
getSetsRequest?.Cancel();
queryChangedDebounce?.Cancel();
queryChangedDebounce = Scheduler.AddDelayed(updateSearch, queryTextChanged ? 500 : 100);
}
private void updateSearch() private void updateSearch()
{ {
queryChangedDebounce?.Cancel();
if (!IsLoaded) if (!IsLoaded)
return; return;
if (State == Visibility.Hidden) if (State == Visibility.Hidden)
return; return;
BeatmapSets = null;
ResultAmounts = null;
getSetsRequest?.Cancel();
if (api == null) if (api == null)
return; return;
previewTrackManager.StopAnyPlaying(this); previewTrackManager.StopAnyPlaying(this);
getSetsRequest = new SearchBeatmapSetsRequest(currentQuery.Value ?? string.Empty, getSetsRequest = new SearchBeatmapSetsRequest(
currentQuery.Value,
((FilterControl)Filter).Ruleset.Value, ((FilterControl)Filter).Ruleset.Value,
Filter.DisplayStyleControl.Dropdown.Current.Value, Filter.DisplayStyleControl.Dropdown.Current.Value,
Filter.Tabs.Current.Value); //todo: sort direction (?) Filter.Tabs.Current.Value); //todo: sort direction (?)