1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 12:45:09 +08:00

Allow running initial filter criteria asynchronously

This reverts a portion of https://github.com/ppy/osu/pull/9539.

The rearrangement in `SongSelect` is required to get the initial filter
into `BeatmapCarousel` (and avoid the `FilterChanged` event firing,
causing a delayed/scheduled filter application).
This commit is contained in:
Dean Herbert 2024-08-28 18:22:05 +09:00
parent 5ed0c6e91a
commit 336abadbd1
No known key found for this signature in database
4 changed files with 30 additions and 21 deletions

View File

@ -1389,6 +1389,11 @@ namespace osu.Game.Tests.Visual.SongSelect
private partial class TestBeatmapCarousel : BeatmapCarousel
{
public TestBeatmapCarousel()
: base(new FilterCriteria())
{
}
public bool PendingFilterTask => PendingFilter != null;
public IEnumerable<DrawableCarouselItem> Items

View File

@ -246,7 +246,7 @@ namespace osu.Game.Tests.Visual.SongSelect
private BeatmapCarousel createCarousel()
{
return carousel = new BeatmapCarousel
return carousel = new BeatmapCarousel(new FilterCriteria())
{
RelativeSizeAxes = Axes.Both,
BeatmapSets = new List<BeatmapSetInfo>

View File

@ -170,13 +170,12 @@ namespace osu.Game.Screens.Select
}
root = newRoot;
root.Filter(activeCriteria);
Scroll.Clear(false);
itemsCache.Invalidate();
ScrollToSelected();
applyActiveCriteria(false);
// Restore selection
if (selectedBeatmapBefore != null && newRoot.BeatmapSetsByID.TryGetValue(selectedBeatmapBefore.BeatmapSet!.ID, out var newSelectionCandidates))
{
@ -215,7 +214,7 @@ namespace osu.Game.Screens.Select
private int visibleSetsCount;
public BeatmapCarousel()
public BeatmapCarousel(FilterCriteria initialCriterial)
{
root = new CarouselRoot(this);
InternalChild = new Container
@ -237,6 +236,8 @@ namespace osu.Game.Screens.Select
noResultsPlaceholder = new NoResultsPlaceholder()
}
};
activeCriteria = initialCriterial;
}
[BackgroundDependencyLoader]
@ -662,7 +663,7 @@ namespace osu.Game.Screens.Select
item.State.Value = CarouselItemState.Selected;
}
private FilterCriteria activeCriteria = new FilterCriteria();
private FilterCriteria activeCriteria;
protected ScheduledDelegate? PendingFilter;

View File

@ -162,20 +162,6 @@ namespace osu.Game.Screens.Select
ApplyToBackground(applyBlurToBackground);
});
LoadComponentAsync(Carousel = new BeatmapCarousel
{
AllowSelection = false, // delay any selection until our bindables are ready to make a good choice.
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both,
BleedTop = FilterControl.HEIGHT,
BleedBottom = Select.Footer.HEIGHT,
SelectionChanged = updateSelectedBeatmap,
BeatmapSetsChanged = carouselBeatmapsLoaded,
FilterApplied = () => Scheduler.AddOnce(updateVisibleBeatmapCount),
GetRecommendedBeatmap = s => recommender?.GetRecommendedBeatmap(s),
}, c => carouselContainer.Child = c);
// initial value transfer is required for FilterControl (it uses our re-cached bindables in its async load for the initial filter).
transferRulesetValue();
@ -227,7 +213,6 @@ namespace osu.Game.Screens.Select
{
RelativeSizeAxes = Axes.X,
Height = FilterControl.HEIGHT,
FilterChanged = ApplyFilterToCarousel,
},
new GridContainer // used for max width implementation
{
@ -328,6 +313,23 @@ namespace osu.Game.Screens.Select
modSpeedHotkeyHandler = new ModSpeedHotkeyHandler(),
});
// Important to load this after the filter control is loaded (so we have initial filter criteria prepared).
LoadComponentAsync(Carousel = new BeatmapCarousel(FilterControl.CreateCriteria())
{
AllowSelection = false, // delay any selection until our bindables are ready to make a good choice.
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both,
BleedTop = FilterControl.HEIGHT,
BleedBottom = Select.Footer.HEIGHT,
SelectionChanged = updateSelectedBeatmap,
BeatmapSetsChanged = carouselBeatmapsLoaded,
FilterApplied = () => Scheduler.AddOnce(updateVisibleBeatmapCount),
GetRecommendedBeatmap = s => recommender?.GetRecommendedBeatmap(s),
}, c => carouselContainer.Child = c);
FilterControl.FilterChanged = ApplyFilterToCarousel;
if (ShowSongSelectFooter)
{
AddRangeInternal(new Drawable[]
@ -992,7 +994,8 @@ namespace osu.Game.Screens.Select
// if we have a pending filter operation, we want to run it now.
// it could change selection (ie. if the ruleset has been changed).
Carousel.FlushPendingFilterOperations();
if (IsLoaded)
Carousel.FlushPendingFilterOperations();
return true;
}