From 9c4c713aa01699c0a246fa86ed9ce69b7b7c396c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sat, 10 Dec 2016 11:30:22 +0100 Subject: [PATCH] Fix panels that are moving off-screen having an incorrect X coordinate applied. --- osu.Game/Screens/Select/CarouselContainer.cs | 52 ++++++++++++-------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/osu.Game/Screens/Select/CarouselContainer.cs b/osu.Game/Screens/Select/CarouselContainer.cs index 069c8d8d37..2c59639ce7 100644 --- a/osu.Game/Screens/Select/CarouselContainer.cs +++ b/osu.Game/Screens/Select/CarouselContainer.cs @@ -190,18 +190,45 @@ namespace osu.Game.Screens.Select return 125 + x; } + /// + /// Update a panel's x position and multiplicative alpha based on its y position and + /// the current scroll position. + /// + /// The panel to be updated. + /// Half the draw height of the carousel container. + private void updatePanel(Panel p, float halfHeight) + { + float panelDrawY = p.Position.Y - Current + p.DrawHeight / 2; + float dist = Math.Abs(1f - panelDrawY / halfHeight); + + // Setting the origin position serves as an additive position on top of potential + // local transformation we may want to apply (e.g. when a panel gets selected, we + // may want to smoothly transform it leftwards.) + p.OriginPosition = new Vector2(-offsetX(dist, halfHeight), 0); + + // We are applying a multiplicative alpha (which is internally done by nesting an + // additional container and setting that container's alpha) such that we can + // layer transformations on top, with a similar reasoning to the previous comment. + p.SetMultiplicativeAlpha(MathHelper.Clamp(1.75f - 1.5f * dist, 0, 1)); + } + protected override void Update() { base.Update(); + // Determine which items stopped being on screen for future removal from the lifetimelist. float drawHeight = DrawHeight; + float halfHeight = drawHeight / 2; - Lifetime.AliveItems.ForEach(delegate (Panel p) + foreach (Panel p in Lifetime.AliveItems) { float panelPosY = p.Position.Y; p.IsOnScreen = panelPosY >= Current - p.DrawHeight && panelPosY <= Current + drawHeight; - }); + updatePanel(p, halfHeight); + } + // Determine range of indices for items that are now definitely on screen to be added + // to the lifetimelist in the future. int firstIndex = yPositions.BinarySearch(Current - Panel.MAX_HEIGHT); if (firstIndex < 0) firstIndex = ~firstIndex; int lastIndex = yPositions.BinarySearch(Current + drawHeight); @@ -210,26 +237,11 @@ namespace osu.Game.Screens.Select Lifetime.StartIndex = firstIndex; Lifetime.EndIndex = lastIndex; - float halfHeight = drawHeight / 2; - for (int i = firstIndex; i < lastIndex; ++i) { - var panel = Lifetime[i]; - - panel.IsOnScreen = true; - - float panelDrawY = panel.Position.Y - Current + panel.DrawHeight / 2; - float dist = Math.Abs(1f - panelDrawY / halfHeight); - - // Setting the origin position serves as an additive position on top of potential - // local transformation we may want to apply (e.g. when a panel gets selected, we - // may want to smoothly transform it leftwards.) - panel.OriginPosition = new Vector2(-offsetX(dist, halfHeight), 0); - - // We are applying a multiplicative alpha (which is internally done by nesting an - // additional container and setting that container's alpha) such that we can - // layer transformations on top, with a similar reasoning to the previous comment. - panel.SetMultiplicativeAlpha(MathHelper.Clamp(1.75f - 1.5f * dist, 0, 1)); + Panel p = Lifetime[i]; + p.IsOnScreen = true; + updatePanel(p, halfHeight); } } }