Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the method of finding a drawable representation of items to be…
Browse files Browse the repository at this point in the history
… on-demand
peppy committed Jan 22, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 4230a57 commit f0c56ca
Showing 2 changed files with 22 additions and 11 deletions.
11 changes: 6 additions & 5 deletions osu.Game/Screens/SelectV2/BeatmapCarousel.cs
Original file line number Diff line number Diff line change
@@ -70,9 +70,9 @@ protected override void HandleItemDeselected(List<CarouselItem> allItems, Carous
}
}

protected override void HandleItemSelected(List<CarouselItem> allItems, CarouselItem item, Drawable? drawableItem)
protected override void HandleItemSelected(List<CarouselItem> allItems, CarouselItem item)
{
base.HandleItemSelected(allItems, item, drawableItem);
base.HandleItemSelected(allItems, item);

// Selecting a set isn't valid – let's re-select the first difficulty.
if (item.Model is BeatmapSetInfo setInfo)
@@ -92,11 +92,12 @@ protected override void HandleItemSelected(List<CarouselItem> allItems, Carousel
UpdateYPositions(allItems, VisibleHalfHeight, SpacingBetweenPanels);
}

protected override void HandleItemActivated(CarouselItem item, Drawable? drawableItem)
protected override void HandleItemActivated(CarouselItem item)
{
base.HandleItemActivated(item, drawableItem);
base.HandleItemActivated(item);

if (drawableItem is BeatmapCarouselPanel drawable)
// TODO: maybe this should be handled by the panel itself?
if (GetMaterialisedDrawableForItem(item) is BeatmapCarouselPanel drawable)
drawable.FlashFromActivation();
}

22 changes: 16 additions & 6 deletions osu.Game/Screens/SelectV2/Carousel.cs
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ public void ActivateSelection()
return;
}

HandleItemActivated(currentSelectionCarouselItem, scroll.Panels.SingleOrDefault(p => ((ICarouselPanel)p).Item == currentSelectionCarouselItem));
HandleItemActivated(currentSelectionCarouselItem);
}

#endregion
@@ -171,6 +171,17 @@ public void ActivateSelection()
/// <returns>A <see cref="CarouselItem"/> representing the model.</returns>
protected abstract CarouselItem CreateCarouselItemForModel(T model);

/// <summary>
/// Given a <see cref="CarouselItem"/>, find a drawable representation if it is currently displayed in the carousel.
/// </summary>
/// <remarks>
/// This will only return a drawable if it is "on-screen".
/// </remarks>
/// <param name="item">The item to find a related drawable representation.</param>
/// <returns>The drawable representation if it exists.</returns>
protected Drawable? GetMaterialisedDrawableForItem(CarouselItem item) =>
scroll.Panels.SingleOrDefault(p => ((ICarouselPanel)p).Item == currentSelectionCarouselItem);

/// <summary>
/// Called when an item is "activated".
/// </summary>
@@ -180,22 +191,21 @@ public void ActivateSelection()
/// - Start gameplay on a beatmap difficulty.
/// </remarks>
/// <param name="item">The carousel item which was activated.</param>
/// <param name="drawableItem">The drawable representation of the item, if manifested.</param>
protected virtual void HandleItemActivated(CarouselItem item, Drawable? drawableItem)
protected virtual void HandleItemActivated(CarouselItem item)
{
}

/// <summary>
/// Called when an item is "deselected".
/// </summary>
protected virtual void HandleItemDeselected(List<CarouselItem> carouselItems, CarouselItem carouselItem)
protected virtual void HandleItemDeselected(List<CarouselItem> allItems, CarouselItem item)
{
}

/// <summary>
/// Called when an item is "selected".
/// </summary>
protected virtual void HandleItemSelected(List<CarouselItem> allItems, CarouselItem item, Drawable? drawableItem)
protected virtual void HandleItemSelected(List<CarouselItem> allItems, CarouselItem item)
{
}

@@ -458,7 +468,7 @@ private void updateSelection()
if (currentSelectionCarouselItem != null)
HandleItemDeselected(displayedCarouselItems, currentSelectionCarouselItem);
currentSelectionCarouselItem = item;
HandleItemSelected(displayedCarouselItems, item, scroll.Panels.SingleOrDefault(p => ((ICarouselPanel)p).Item == currentSelectionCarouselItem));
HandleItemSelected(displayedCarouselItems, item);
}
}
}

0 comments on commit f0c56ca

Please sign in to comment.