1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 19:22:56 +08:00

Fix panel animation and depth

This commit is contained in:
Dean Herbert 2017-12-17 02:33:01 +09:00
parent 29a8ade59f
commit e2710a309c

View File

@ -305,11 +305,9 @@ namespace osu.Game.Screens.Select
perform(); perform();
} }
public void ScrollToSelected(bool animated = true) private float? scrollTarget;
{
float selectedY = computeYPositions(animated); public void ScrollToSelected(bool animated = true) => Schedule(() => { if (scrollTarget != null) ScrollTo(scrollTarget.Value, animated); });
ScrollTo(selectedY, animated);
}
private CarouselBeatmapSet createCarouselSet(BeatmapSetInfo beatmapSet) private CarouselBeatmapSet createCarouselSet(BeatmapSetInfo beatmapSet)
{ {
@ -351,39 +349,56 @@ namespace osu.Game.Screens.Select
/// Computes the target Y positions for every item in the carousel. /// Computes the target Y positions for every item in the carousel.
/// </summary> /// </summary>
/// <returns>The Y position of the currently selected item.</returns> /// <returns>The Y position of the currently selected item.</returns>
private float computeYPositions(bool animated = true) private void computeYPositions(bool animated = true)
{ {
yPositions.Clear(); yPositions.Clear();
float currentY = DrawHeight / 2; float currentY = DrawHeight / 2;
float selectedY = currentY; DrawableCarouselBeatmapSet lastSet = null;
float lastSetY = 0; scrollTarget = null;
var selected = selectedBeatmap;
foreach (DrawableCarouselItem d in Items) foreach (DrawableCarouselItem d in Items)
{ {
switch (d) if (d.IsPresent)
{ {
case DrawableCarouselBeatmapSet set: switch (d)
set.MoveToX(set.Item.State == CarouselItemState.Selected ? -100 : 0, 500, Easing.OutExpo); {
lastSetY = set.Position.Y; case DrawableCarouselBeatmapSet set:
break; lastSet = set;
case DrawableCarouselBeatmap beatmap:
beatmap.MoveToX(beatmap.Item.State == CarouselItemState.Selected ? -50 : 0, 500, Easing.OutExpo);
if (beatmap.Item == selected) set.MoveToX(set.Item.State == CarouselItemState.Selected ? -100 : 0, 500, Easing.OutExpo);
selectedY = currentY + beatmap.DrawHeight / 2 - DrawHeight / 2; set.MoveToY(currentY, animated ? 750 : 0, Easing.OutExpo);
break;
case DrawableCarouselBeatmap beatmap:
if (beatmap.Item.State.Value == CarouselItemState.Selected)
scrollTarget = currentY + beatmap.DrawHeight / 2 - DrawHeight / 2;
// on first display we want to begin hidden under our group's header. void performMove(float y, float? startY = null)
if (animated && !beatmap.IsPresent) {
beatmap.MoveToY(lastSetY); if (startY != null) beatmap.MoveTo(new Vector2(0, startY.Value));
break; beatmap.MoveToX(beatmap.Item.State == CarouselItemState.Selected ? -50 : 0, 500, Easing.OutExpo);
beatmap.MoveToY(y, animated ? 750 : 0, Easing.OutExpo);
}
Debug.Assert(lastSet != null);
float? setY = null;
if (!d.IsLoaded || beatmap.Alpha == 0) // can't use IsPresent due to DrawableCarouselItem override.
setY = lastSet.Y + lastSet.DrawHeight + 5;
if (d.IsLoaded)
performMove(currentY, setY);
else
{
float y = currentY;
d.OnLoadComplete = _ => performMove(y, setY);
}
break;
}
} }
yPositions.Add(currentY); yPositions.Add(currentY);
d.MoveToY(currentY, animated ? 750 : 0, Easing.OutExpo);
if (d.Item.Visible) if (d.Item.Visible)
currentY += d.DrawHeight + 5; currentY += d.DrawHeight + 5;
@ -393,8 +408,6 @@ namespace osu.Game.Screens.Select
scrollableContent.Height = currentY; scrollableContent.Height = currentY;
yPositionsCache.Validate(); yPositionsCache.Validate();
return selectedY;
} }
private void select(CarouselItem item) private void select(CarouselItem item)
@ -477,7 +490,7 @@ namespace osu.Game.Screens.Select
// Makes sure headers are always _below_ items, // Makes sure headers are always _below_ items,
// and depth flows downward. // and depth flows downward.
item.Depth = i + (item is DrawableCarouselBeatmapSet ? Items.Count : 0); item.Depth = i + (item is DrawableCarouselBeatmapSet ? -Items.Count : 0);
switch (item.LoadState) switch (item.LoadState)
{ {