Skip to content

Commit

Permalink
Stop exposing CarouselItem externally
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jan 10, 2025
1 parent c18df2c commit 4e87467
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions osu.Game/Screens/SelectV2/BeatmapCarouselV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ protected override Drawable GetDrawableForDisplay(CarouselItem item)
return drawable;
}

protected override CarouselItem CreateCarouselItemForModel(object model) => new BeatmapCarouselItem(model);

private void beatmapSetsChanged(object? beatmaps, NotifyCollectionChangedEventArgs changed)
{
// TODO: moving management of BeatmapInfo tracking to BeatmapStore might be something we want to consider.
Expand All @@ -70,15 +72,15 @@ private void beatmapSetsChanged(object? beatmaps, NotifyCollectionChangedEventAr
switch (changed.Action)
{
case NotifyCollectionChangedAction.Add:
Items.AddRange(newBeatmapSets!.SelectMany(s => s.Beatmaps).Select(b => new BeatmapCarouselItem(b)));
Items.AddRange(newBeatmapSets!.SelectMany(s => s.Beatmaps));
break;

case NotifyCollectionChangedAction.Remove:

foreach (var set in beatmapSetInfos!)
{
foreach (var beatmap in set.Beatmaps)
Items.RemoveAll(i => i.Model is BeatmapInfo bi && beatmap.Equals(bi));
Items.RemoveAll(i => i is BeatmapInfo bi && beatmap.Equals(bi));
}

break;
Expand Down
11 changes: 9 additions & 2 deletions osu.Game/Screens/SelectV2/Carousel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public abstract partial class Carousel : CompositeDrawable
/// <remarks>
/// Note that an <see cref="ICarouselFilter"/> may add new items which are displayed but not tracked in this list.
/// </remarks>
protected readonly BindableList<CarouselItem> Items = new BindableList<CarouselItem>();
protected readonly BindableList<object> Items = new BindableList<object>();

/// <summary>
/// The currently selected model.
Expand Down Expand Up @@ -143,6 +143,13 @@ protected Carousel()
/// <returns>The manifested drawable.</returns>
protected abstract Drawable GetDrawableForDisplay(CarouselItem item);

/// <summary>
/// Create an internal carousel representation for the provided model object.
/// </summary>
/// <param name="model">The model.</param>
/// <returns>A <see cref="CarouselItem"/> representing the model.</returns>
protected abstract CarouselItem CreateCarouselItemForModel(object model);

#region Filtering and display preparation

private Task filterTask = Task.CompletedTask;
Expand All @@ -161,7 +168,7 @@ private async Task performFilter()
}

Stopwatch stopwatch = Stopwatch.StartNew();
IEnumerable<CarouselItem> items = new List<CarouselItem>(Items);
IEnumerable<CarouselItem> items = new List<CarouselItem>(Items.Select(CreateCarouselItemForModel));

await Task.Run(async () =>
{
Expand Down

0 comments on commit 4e87467

Please sign in to comment.