Ensure visible items is greater than zero before trying to display a range

This commit is contained in:
Dean Herbert
2020-10-19 19:55:20 +09:00
parent 9106e97c37
commit d5940193a2

View File

@ -590,36 +590,39 @@ namespace osu.Game.Screens.Select
{ {
displayedRange = newDisplayRange; displayedRange = newDisplayRange;
var toDisplay = visibleItems.GetRange(displayedRange.first, displayedRange.last - displayedRange.first + 1); if (visibleItems.Count > 0)
foreach (var panel in ScrollableContent.Children)
{ {
if (toDisplay.Remove(panel.Item)) var toDisplay = visibleItems.GetRange(displayedRange.first, displayedRange.last - displayedRange.first + 1);
foreach (var panel in ScrollableContent.Children)
{ {
// panel already displayed. if (toDisplay.Remove(panel.Item))
continue; {
// panel already displayed.
continue;
}
// panel loaded as drawable but not required by visible range.
// remove but only if too far off-screen
if (panel.Y + panel.DrawHeight < visibleUpperBound - distance_offscreen_before_unload || panel.Y > visibleBottomBound + distance_offscreen_before_unload)
{
// may want a fade effect here (could be seen if a huge change happens, like a set with 20 difficulties becomes selected).
panel.ClearTransforms();
panel.Expire();
}
} }
// panel loaded as drawable but not required by visible range. // Add those items within the previously found index range that should be displayed.
// remove but only if too far off-screen foreach (var item in toDisplay)
if (panel.Y + panel.DrawHeight < visibleUpperBound - distance_offscreen_before_unload || panel.Y > visibleBottomBound + distance_offscreen_before_unload)
{ {
// may want a fade effect here (could be seen if a huge change happens, like a set with 20 difficulties becomes selected). var panel = setPool.Get(p => p.Item = item);
panel.ClearTransforms();
panel.Expire(); panel.Depth = item.CarouselYPosition;
panel.Y = item.CarouselYPosition;
ScrollableContent.Add(panel);
} }
} }
// Add those items within the previously found index range that should be displayed.
foreach (var item in toDisplay)
{
var panel = setPool.Get(p => p.Item = item);
panel.Depth = item.CarouselYPosition;
panel.Y = item.CarouselYPosition;
ScrollableContent.Add(panel);
}
} }
// Finally, if the filtered items have changed, animate drawables to their new locations. // Finally, if the filtered items have changed, animate drawables to their new locations.