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

Always debounce external Filter requests (except for tests)

The only exception to the rule here was "when screen isn't active apply
without debounce" but I'm not sure we want this. It would cause a
stutter on returning to song select and I'm not even sure this is a
common scenario.

I'd rather remove it and see if someone finds an actual case where this
is an issue.
This commit is contained in:
Dean Herbert 2024-08-28 18:56:09 +09:00
parent 336abadbd1
commit dd4a1104e4
No known key found for this signature in database
4 changed files with 55 additions and 59 deletions

View File

@ -52,11 +52,11 @@ namespace osu.Game.Tests.Visual.SongSelect
{
createCarousel(new List<BeatmapSetInfo>());
AddStep("filter to ruleset 0", () => carousel.Filter(new FilterCriteria
AddStep("filter to ruleset 0", () => carousel.FilterImmediately(new FilterCriteria
{
Ruleset = rulesets.AvailableRulesets.ElementAt(0),
AllowConvertedBeatmaps = true,
}, false));
}));
AddStep("add mixed ruleset beatmapset", () =>
{
@ -78,11 +78,11 @@ namespace osu.Game.Tests.Visual.SongSelect
&& visibleBeatmapPanels.Count(p => ((CarouselBeatmap)p.Item)!.BeatmapInfo.Ruleset.OnlineID == 0) == 1;
});
AddStep("filter to ruleset 1", () => carousel.Filter(new FilterCriteria
AddStep("filter to ruleset 1", () => carousel.FilterImmediately(new FilterCriteria
{
Ruleset = rulesets.AvailableRulesets.ElementAt(1),
AllowConvertedBeatmaps = true,
}, false));
}));
AddUntilStep("wait for filtered difficulties", () =>
{
@ -93,11 +93,11 @@ namespace osu.Game.Tests.Visual.SongSelect
&& visibleBeatmapPanels.Count(p => ((CarouselBeatmap)p.Item)!.BeatmapInfo.Ruleset.OnlineID == 1) == 1;
});
AddStep("filter to ruleset 2", () => carousel.Filter(new FilterCriteria
AddStep("filter to ruleset 2", () => carousel.FilterImmediately(new FilterCriteria
{
Ruleset = rulesets.AvailableRulesets.ElementAt(2),
AllowConvertedBeatmaps = true,
}, false));
}));
AddUntilStep("wait for filtered difficulties", () =>
{
@ -344,7 +344,7 @@ namespace osu.Game.Tests.Visual.SongSelect
// basic filtering
setSelected(1, 1);
AddStep("Filter", () => carousel.Filter(new FilterCriteria { SearchText = carousel.BeatmapSets.ElementAt(2).Metadata.Title }, false));
AddStep("Filter", () => carousel.FilterImmediately(new FilterCriteria { SearchText = carousel.BeatmapSets.ElementAt(2).Metadata.Title }));
checkVisibleItemCount(diff: false, count: 1);
checkVisibleItemCount(diff: true, count: 3);
waitForSelection(3, 1);
@ -360,13 +360,13 @@ namespace osu.Game.Tests.Visual.SongSelect
// test filtering some difficulties (and keeping current beatmap set selected).
setSelected(1, 2);
AddStep("Filter some difficulties", () => carousel.Filter(new FilterCriteria { SearchText = "Normal" }, false));
AddStep("Filter some difficulties", () => carousel.FilterImmediately(new FilterCriteria { SearchText = "Normal" }));
waitForSelection(1, 1);
AddStep("Un-filter", () => carousel.Filter(new FilterCriteria(), false));
AddStep("Un-filter", () => carousel.FilterImmediately(new FilterCriteria()));
waitForSelection(1, 1);
AddStep("Filter all", () => carousel.Filter(new FilterCriteria { SearchText = "Dingo" }, false));
AddStep("Filter all", () => carousel.FilterImmediately(new FilterCriteria { SearchText = "Dingo" }));
checkVisibleItemCount(false, 0);
checkVisibleItemCount(true, 0);
@ -378,7 +378,7 @@ namespace osu.Game.Tests.Visual.SongSelect
advanceSelection(false);
AddAssert("Selection is null", () => currentSelection == null);
AddStep("Un-filter", () => carousel.Filter(new FilterCriteria(), false));
AddStep("Un-filter", () => carousel.FilterImmediately(new FilterCriteria()));
AddAssert("Selection is non-null", () => currentSelection != null);
@ -399,7 +399,7 @@ namespace osu.Game.Tests.Visual.SongSelect
setSelected(1, 3);
AddStep("Apply a range filter", () => carousel.Filter(new FilterCriteria
AddStep("Apply a range filter", () => carousel.FilterImmediately(new FilterCriteria
{
SearchText = searchText,
StarDifficulty = new FilterCriteria.OptionalRange<double>
@ -408,7 +408,7 @@ namespace osu.Game.Tests.Visual.SongSelect
Max = 5.5,
IsLowerInclusive = true
}
}, false));
}));
// should reselect the buffered selection.
waitForSelection(3, 2);
@ -445,13 +445,13 @@ namespace osu.Game.Tests.Visual.SongSelect
AddAssert("ensure repeat", () => selectedSets.Contains(carousel.SelectedBeatmapSet));
AddStep("Add set with 100 difficulties", () => carousel.UpdateBeatmapSet(TestResources.CreateTestBeatmapSetInfo(100, rulesets.AvailableRulesets.ToArray())));
AddStep("Filter Extra", () => carousel.Filter(new FilterCriteria { SearchText = "Extra 10" }, false));
AddStep("Filter Extra", () => carousel.FilterImmediately(new FilterCriteria { SearchText = "Extra 10" }));
checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable();
AddStep("Un-filter", () => carousel.Filter(new FilterCriteria(), false));
AddStep("Un-filter", () => carousel.FilterImmediately(new FilterCriteria()));
}
[Test]
@ -527,7 +527,7 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(setCount: local_set_count, diffCount: local_diff_count);
AddStep("Sort by difficulty", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty }, false));
AddStep("Sort by difficulty", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Difficulty }));
checkVisibleItemCount(false, local_set_count * local_diff_count);
@ -566,7 +566,7 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(sets, () => new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(0) });
AddStep("Set non-empty mode filter", () =>
carousel.Filter(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(1) }, false));
carousel.FilterImmediately(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(1) }));
AddAssert("Something is selected", () => carousel.SelectedBeatmapInfo != null);
}
@ -601,7 +601,7 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(sets);
AddStep("Sort by date submitted", () => carousel.Filter(new FilterCriteria { Sort = SortMode.DateSubmitted }, false));
AddStep("Sort by date submitted", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.DateSubmitted }));
checkVisibleItemCount(diff: false, count: 10);
checkVisibleItemCount(diff: true, count: 5);
@ -610,11 +610,11 @@ namespace osu.Game.Tests.Visual.SongSelect
AddAssert("rest are at start", () => carousel.Items.OfType<DrawableCarouselBeatmapSet>().TakeWhile(i => i.Item is CarouselBeatmapSet s && s.BeatmapSet.DateSubmitted != null).Count(),
() => Is.EqualTo(6));
AddStep("Sort by date submitted and string", () => carousel.Filter(new FilterCriteria
AddStep("Sort by date submitted and string", () => carousel.FilterImmediately(new FilterCriteria
{
Sort = SortMode.DateSubmitted,
SearchText = zzz_string
}, false));
}));
checkVisibleItemCount(diff: false, count: 5);
checkVisibleItemCount(diff: true, count: 5);
@ -658,10 +658,10 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(sets);
AddStep("Sort by author", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Author }, false));
AddStep("Sort by author", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Author }));
AddAssert($"Check {zzz_uppercase} is last", () => carousel.BeatmapSets.Last().Metadata.Author.Username == zzz_uppercase);
AddAssert($"Check {zzz_lowercase} is second last", () => carousel.BeatmapSets.SkipLast(1).Last().Metadata.Author.Username == zzz_lowercase);
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false));
AddStep("Sort by artist", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Artist }));
AddAssert($"Check {zzz_uppercase} is last", () => carousel.BeatmapSets.Last().Metadata.Artist == zzz_uppercase);
AddAssert($"Check {zzz_lowercase} is second last", () => carousel.BeatmapSets.SkipLast(1).Last().Metadata.Artist == zzz_lowercase);
}
@ -703,7 +703,7 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(sets);
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false));
AddStep("Sort by artist", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Artist }));
AddAssert("Check last item", () =>
{
var lastItem = carousel.BeatmapSets.Last();
@ -746,10 +746,10 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(sets);
AddStep("Sort by title", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Title }, false));
AddStep("Sort by title", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Title }));
AddAssert("Items remain in descending added order", () => carousel.BeatmapSets.Select(s => s.DateAdded), () => Is.Ordered.Descending);
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false));
AddStep("Sort by artist", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Artist }));
AddAssert("Items remain in descending added order", () => carousel.BeatmapSets.Select(s => s.DateAdded), () => Is.Ordered.Descending);
}
@ -786,7 +786,7 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(sets);
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false));
AddStep("Sort by artist", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Artist }));
AddAssert("Items in descending added order", () => carousel.BeatmapSets.Select(s => s.DateAdded), () => Is.Ordered.Descending);
AddStep("Save order", () => originalOrder = carousel.BeatmapSets.Select(s => s.ID).ToArray());
@ -796,7 +796,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddAssert("Order didn't change", () => carousel.BeatmapSets.Select(s => s.ID), () => Is.EqualTo(originalOrder));
AddStep("Sort by title", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Title }, false));
AddStep("Sort by title", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Title }));
AddAssert("Order didn't change", () => carousel.BeatmapSets.Select(s => s.ID), () => Is.EqualTo(originalOrder));
}
@ -833,7 +833,7 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(sets);
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false));
AddStep("Sort by artist", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Artist }));
AddAssert("Items in descending added order", () => carousel.BeatmapSets.Select(s => s.DateAdded), () => Is.Ordered.Descending);
AddStep("Save order", () => originalOrder = carousel.BeatmapSets.Select(s => s.ID).ToArray());
@ -858,7 +858,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddAssert("Order didn't change", () => carousel.BeatmapSets.Select(s => s.ID), () => Is.EqualTo(originalOrder));
AddStep("Sort by title", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Title }, false));
AddStep("Sort by title", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Title }));
AddAssert("Order didn't change", () => carousel.BeatmapSets.Select(s => s.ID), () => Is.EqualTo(originalOrder));
}
@ -885,12 +885,12 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(sets);
AddStep("Sort by difficulty", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty }, false));
AddStep("Sort by difficulty", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Difficulty }));
checkVisibleItemCount(false, local_set_count * local_diff_count);
checkVisibleItemCount(true, 1);
AddStep("Filter to normal", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty, SearchText = "Normal" }, false));
AddStep("Filter to normal", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Difficulty, SearchText = "Normal" }));
checkVisibleItemCount(false, local_set_count);
checkVisibleItemCount(true, 1);
@ -901,7 +901,7 @@ namespace osu.Game.Tests.Visual.SongSelect
.Count(p => ((CarouselBeatmapSet)p.Item)!.Beatmaps.Single().BeatmapInfo.DifficultyName.StartsWith("Normal", StringComparison.Ordinal)) == local_set_count;
});
AddStep("Filter to insane", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty, SearchText = "Insane" }, false));
AddStep("Filter to insane", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Difficulty, SearchText = "Insane" }));
checkVisibleItemCount(false, local_set_count);
checkVisibleItemCount(true, 1);
@ -1022,7 +1022,7 @@ namespace osu.Game.Tests.Visual.SongSelect
carousel.UpdateBeatmapSet(testMixed);
});
AddStep("filter to ruleset 0", () =>
carousel.Filter(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(0) }, false));
carousel.FilterImmediately(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(0) }));
AddStep("select filtered map skipping filtered", () => carousel.SelectBeatmap(testMixed.Beatmaps[1], false));
AddAssert("unfiltered beatmap not selected", () => carousel.SelectedBeatmapInfo?.Ruleset.OnlineID == 0);
@ -1068,12 +1068,12 @@ namespace osu.Game.Tests.Visual.SongSelect
{
AddStep("Toggle non-matching filter", () =>
{
carousel.Filter(new FilterCriteria { SearchText = Guid.NewGuid().ToString() }, false);
carousel.FilterImmediately(new FilterCriteria { SearchText = Guid.NewGuid().ToString() });
});
AddStep("Restore no filter", () =>
{
carousel.Filter(new FilterCriteria(), false);
carousel.FilterImmediately(new FilterCriteria());
eagerSelectedIDs.Add(carousel.SelectedBeatmapSet!.ID);
});
}
@ -1097,7 +1097,7 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(manySets);
AddStep("Sort by difficulty", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty }, false));
AddStep("Sort by difficulty", () => carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Difficulty }));
advanceSelection(direction: 1, diff: false);
@ -1105,12 +1105,12 @@ namespace osu.Game.Tests.Visual.SongSelect
{
AddStep("Toggle non-matching filter", () =>
{
carousel.Filter(new FilterCriteria { SearchText = Guid.NewGuid().ToString() }, false);
carousel.FilterImmediately(new FilterCriteria { SearchText = Guid.NewGuid().ToString() });
});
AddStep("Restore no filter", () =>
{
carousel.Filter(new FilterCriteria(), false);
carousel.FilterImmediately(new FilterCriteria());
eagerSelectedIDs.Add(carousel.SelectedBeatmapSet!.ID);
});
}
@ -1185,7 +1185,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep($"Set ruleset to {rulesetInfo.ShortName}", () =>
{
carousel.Filter(new FilterCriteria { Ruleset = rulesetInfo, Sort = SortMode.Title }, false);
carousel.FilterImmediately(new FilterCriteria { Ruleset = rulesetInfo, Sort = SortMode.Title });
});
waitForSelection(i + 1, 1);
}
@ -1223,12 +1223,12 @@ namespace osu.Game.Tests.Visual.SongSelect
setSelected(i, 1);
AddStep("Set ruleset to taiko", () =>
{
carousel.Filter(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(1), Sort = SortMode.Title }, false);
carousel.FilterImmediately(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(1), Sort = SortMode.Title });
});
waitForSelection(i - 1, 1);
AddStep("Remove ruleset filter", () =>
{
carousel.Filter(new FilterCriteria { Sort = SortMode.Title }, false);
carousel.FilterImmediately(new FilterCriteria { Sort = SortMode.Title });
});
}
@ -1415,6 +1415,12 @@ namespace osu.Game.Tests.Visual.SongSelect
}
}
}
public void FilterImmediately(FilterCriteria newCriteria)
{
Filter(newCriteria);
FlushPendingFilterOperations();
}
}
}
}

View File

@ -1397,8 +1397,6 @@ namespace osu.Game.Tests.Visual.SongSelect
{
public Action? StartRequested;
public new Bindable<RulesetInfo> Ruleset => base.Ruleset;
public new FilterControl FilterControl => base.FilterControl;
public WorkingBeatmap CurrentBeatmap => Beatmap.Value;
@ -1408,18 +1406,18 @@ namespace osu.Game.Tests.Visual.SongSelect
public new void PresentScore(ScoreInfo score) => base.PresentScore(score);
public int FilterCount;
protected override bool OnStart()
{
StartRequested?.Invoke();
return base.OnStart();
}
public int FilterCount;
protected override void ApplyFilterToCarousel(FilterCriteria criteria)
[BackgroundDependencyLoader]
private void load()
{
FilterCount++;
base.ApplyFilterToCarousel(criteria);
FilterControl.FilterChanged += _ => FilterCount++;
}
}
}

View File

@ -700,12 +700,12 @@ namespace osu.Game.Screens.Select
}
}
public void Filter(FilterCriteria? newCriteria, bool debounce = true)
public void Filter(FilterCriteria? newCriteria)
{
if (newCriteria != null)
activeCriteria = newCriteria;
applyActiveCriteria(debounce);
applyActiveCriteria(true);
}
private bool beatmapsSplitOut;

View File

@ -328,7 +328,7 @@ namespace osu.Game.Screens.Select
GetRecommendedBeatmap = s => recommender?.GetRecommendedBeatmap(s),
}, c => carouselContainer.Child = c);
FilterControl.FilterChanged = ApplyFilterToCarousel;
FilterControl.FilterChanged = Carousel.Filter;
if (ShowSongSelectFooter)
{
@ -403,14 +403,6 @@ namespace osu.Game.Screens.Select
protected virtual ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay();
protected virtual void ApplyFilterToCarousel(FilterCriteria criteria)
{
// if not the current screen, we want to get carousel in a good presentation state before displaying (resume or enter).
bool shouldDebounce = this.IsCurrentScreen();
Carousel.Filter(criteria, shouldDebounce);
}
private DependencyContainer dependencies = null!;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)