Avoid reconstructing beatmap difficulties that were recently displayed

This commit is contained in:
Dean Herbert 2020-10-13 16:04:37 +09:00
parent 1da49073ab
commit cecdf14f53

View File

@ -56,6 +56,7 @@ namespace osu.Game.Screens.Select.Carousel
base.FreeAfterUse(); base.FreeAfterUse();
Item = null; Item = null;
ClearTransforms(); ClearTransforms();
} }
@ -66,20 +67,14 @@ namespace osu.Game.Screens.Select.Carousel
if (beatmapOverlay != null) if (beatmapOverlay != null)
viewDetails = beatmapOverlay.FetchAndShowBeatmapSet; viewDetails = beatmapOverlay.FetchAndShowBeatmapSet;
Content.Add(beatmapContainer = new Container<DrawableCarouselItem>
{
X = 100,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
});
} }
protected override void UpdateItem() protected override void UpdateItem()
{ {
base.UpdateItem(); base.UpdateItem();
beatmapContainer.Clear(); Content.Clear();
beatmapContainer = null;
if (Item == null) if (Item == null)
return; return;
@ -160,10 +155,13 @@ namespace osu.Game.Screens.Select.Carousel
MovementContainer.MoveToX(0, 500, Easing.OutExpo); MovementContainer.MoveToX(0, 500, Easing.OutExpo);
foreach (var beatmap in beatmapContainer) if (beatmapContainer != null)
{ {
beatmap.MoveToY(0, 800, Easing.OutQuint); foreach (var beatmap in beatmapContainer)
beatmap.FadeOut(80).Expire(); {
beatmap.MoveToY(0, 800, Easing.OutQuint);
beatmap.FadeOut(80);
}
} }
} }
@ -173,33 +171,55 @@ namespace osu.Game.Screens.Select.Carousel
MovementContainer.MoveToX(-100, 500, Easing.OutExpo); MovementContainer.MoveToX(-100, 500, Easing.OutExpo);
// on selection we show our child beatmaps. if (beatmapContainer != null)
// for now this is a simple drawable construction each selection.
// can be improved in the future.
var carouselBeatmapSet = (CarouselBeatmapSet)Item;
// ToArray() in this line is required due to framework oversight: https://github.com/ppy/osu-framework/pull/3929
var visibleBeatmaps = carouselBeatmapSet.Children
.Where(c => c.Visible)
.Select(c => c.CreateDrawableRepresentation())
.ToArray();
LoadComponentsAsync(visibleBeatmaps, loaded =>
{ {
// make sure the pooled target hasn't changed. // if already loaded, we only need to re-animate.
if (carouselBeatmapSet != Item) animateBeatmaps();
return; }
else
{
// on selection we show our child beatmaps.
// for now this is a simple drawable construction each selection.
// can be improved in the future.
var carouselBeatmapSet = (CarouselBeatmapSet)Item;
beatmapContainer.ChildrenEnumerable = loaded; // ToArray() in this line is required due to framework oversight: https://github.com/ppy/osu-framework/pull/3929
var visibleBeatmaps = carouselBeatmapSet.Children
.Where(c => c.Visible)
.Select(c => c.CreateDrawableRepresentation())
.ToArray();
beatmapContainer = new Container<DrawableCarouselItem>
{
X = 100,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
ChildrenEnumerable = visibleBeatmaps
};
Logger.Log($"loading {visibleBeatmaps.Length} beatmaps for {Item}");
LoadComponentAsync(beatmapContainer, loaded =>
{
// make sure the pooled target hasn't changed.
if (carouselBeatmapSet != Item)
return;
Content.Child = loaded;
animateBeatmaps();
});
}
void animateBeatmaps()
{
float yPos = DrawableCarouselBeatmap.CAROUSEL_BEATMAP_SPACING; float yPos = DrawableCarouselBeatmap.CAROUSEL_BEATMAP_SPACING;
foreach (var item in loaded) foreach (var item in beatmapContainer.Children)
{ {
item.MoveToY(yPos, 800, Easing.OutQuint); item.MoveToY(yPos, 800, Easing.OutQuint);
yPos += item.Item.TotalHeight + DrawableCarouselBeatmap.CAROUSEL_BEATMAP_SPACING; yPos += item.Item.TotalHeight + DrawableCarouselBeatmap.CAROUSEL_BEATMAP_SPACING;
} }
}); }
} }
private const int maximum_difficulty_icons = 18; private const int maximum_difficulty_icons = 18;