From 9bf23bc4adc90661486bdc73dc094b8e9f3f9ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 22 Nov 2016 21:40:47 +0100 Subject: [PATCH] Only handle beatmap panels that are visible in song select. --- osu.Game/Beatmaps/Drawable/BeatmapGroup.cs | 10 +- .../Beatmaps/Drawable/BeatmapSetHeader.cs | 1 + osu.Game/Beatmaps/Drawable/Panel.cs | 24 +++-- ...usellContainer.cs => CarouselContainer.cs} | 99 +++++++++++-------- osu.Game/Screens/Select/PlaySongSelect.cs | 2 - osu.Game/osu.Game.csproj | 2 +- 6 files changed, 84 insertions(+), 54 deletions(-) rename osu.Game/Screens/Select/{CarousellContainer.cs => CarouselContainer.cs} (55%) diff --git a/osu.Game/Beatmaps/Drawable/BeatmapGroup.cs b/osu.Game/Beatmaps/Drawable/BeatmapGroup.cs index 1f8681c53e..348d8abb87 100644 --- a/osu.Game/Beatmaps/Drawable/BeatmapGroup.cs +++ b/osu.Game/Beatmaps/Drawable/BeatmapGroup.cs @@ -46,7 +46,10 @@ namespace osu.Game.Beatmaps.Drawable // Task.WhenAll(difficulties.Children.Select(d => d.Preload(Game))).ContinueWith(t => difficulties.Show()); //else foreach (BeatmapPanel panel in BeatmapPanels) - panel.Show(); + { + panel.Hidden = false; + panel.FadeIn(250); + } Header.State = PanelSelectedState.Selected; if (SelectedPanel != null) @@ -58,7 +61,10 @@ namespace osu.Game.Beatmaps.Drawable SelectedPanel.State = PanelSelectedState.NotSelected; foreach (BeatmapPanel panel in BeatmapPanels) - panel.Hide(); + { + panel.Hidden = true; + panel.FadeOut(250); + } break; } diff --git a/osu.Game/Beatmaps/Drawable/BeatmapSetHeader.cs b/osu.Game/Beatmaps/Drawable/BeatmapSetHeader.cs index 4d46a02388..fb083451e7 100644 --- a/osu.Game/Beatmaps/Drawable/BeatmapSetHeader.cs +++ b/osu.Game/Beatmaps/Drawable/BeatmapSetHeader.cs @@ -29,6 +29,7 @@ namespace osu.Game.Beatmaps.Drawable public BeatmapSetHeader(WorkingBeatmap beatmap) { this.beatmap = beatmap; + Hidden = false; Children = new Framework.Graphics.Drawable[] { diff --git a/osu.Game/Beatmaps/Drawable/Panel.cs b/osu.Game/Beatmaps/Drawable/Panel.cs index c51ef629de..b1f3189b36 100644 --- a/osu.Game/Beatmaps/Drawable/Panel.cs +++ b/osu.Game/Beatmaps/Drawable/Panel.cs @@ -1,11 +1,6 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using osu.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -17,15 +12,32 @@ namespace osu.Game.Beatmaps.Drawable { class Panel : Container, IStateful { + public const float MAX_HEIGHT = 80; + + public bool Hidden = true; + private Container nestedContainer; + + protected override Container Content => nestedContainer; + public Panel() { - Height = 80; + Height = MAX_HEIGHT; Masking = true; CornerRadius = 10; BorderColour = new Color4(221, 255, 255, 255); RelativeSizeAxes = Axes.X; + + AddInternal(nestedContainer = new Container + { + RelativeSizeAxes = Axes.Both, + }); + } + + public void SetMultiplicativeAlpha(float alpha) + { + nestedContainer.Alpha = alpha; } protected override void LoadComplete() diff --git a/osu.Game/Screens/Select/CarousellContainer.cs b/osu.Game/Screens/Select/CarouselContainer.cs similarity index 55% rename from osu.Game/Screens/Select/CarousellContainer.cs rename to osu.Game/Screens/Select/CarouselContainer.cs index 3416d7761f..0247a65fc4 100644 --- a/osu.Game/Screens/Select/CarousellContainer.cs +++ b/osu.Game/Screens/Select/CarouselContainer.cs @@ -18,12 +18,14 @@ namespace osu.Game.Screens.Select { private Container scrollableContent; private List groups = new List(); + private List panels = new List(); public BeatmapGroup SelectedGroup { get; private set; } public BeatmapPanel SelectedPanel { get; private set; } - private Cached yPositions = new Cached(); - + private Cached yPositionsCached = new Cached(); + private List yPositions = new List(); + public CarouselContainer() { DistanceDecayJump = 0.01; @@ -39,25 +41,32 @@ namespace osu.Game.Screens.Select group.State = BeatmapGroupState.Collapsed; groups.Add(group); + panels.Add(group.Header); + foreach (BeatmapPanel panel in group.BeatmapPanels) + panels.Add(panel); - yPositions.Invalidate(); + yPositionsCached.Invalidate(); } - private static void addPanel(Panel panel, ref float currentY) + private void movePanel(Panel panel, bool advance, ref float currentY) { - panel.Depth = -currentY; + yPositions.Add(currentY); panel.MoveToY(currentY, 750, EasingTypes.OutExpo); - currentY += panel.DrawHeight + 5; + + if (advance) + currentY += panel.DrawHeight + 5; } private void computeYPositions() { + yPositions.Clear(); + float currentY = DrawHeight / 2; float selectedY = currentY; foreach (BeatmapGroup group in groups) { - addPanel(group.Header, ref currentY); + movePanel(group.Header, true, ref currentY); if (group.State == BeatmapGroupState.Expanded) { @@ -66,14 +75,17 @@ namespace osu.Game.Screens.Select foreach (BeatmapPanel panel in group.BeatmapPanels) { if (panel == SelectedPanel) - selectedY = currentY + 1.5f * panel.DrawHeight - DrawHeight / 2; + selectedY = currentY + panel.DrawHeight / 2 - DrawHeight / 2; - addPanel(panel, ref currentY); + movePanel(panel, true, ref currentY); } } else { group.Header.MoveToX(0, 500, EasingTypes.OutExpo); + + foreach (BeatmapPanel panel in group.BeatmapPanels) + movePanel(panel, false, ref currentY); } } @@ -83,13 +95,6 @@ namespace osu.Game.Screens.Select ScrollTo(selectedY); } - private void scrollToSelected() - { - if (SelectedPanel == null) - return; - ScrollTo(getScrollPos(SelectedPanel).Y - DrawHeight / 2); - } - public void SelectBeatmap(BeatmapInfo beatmap) { foreach (BeatmapGroup group in groups) @@ -116,18 +121,18 @@ namespace osu.Game.Screens.Select panel.State = PanelSelectedState.Selected; SelectedPanel = panel; - yPositions.Invalidate(); + yPositionsCached.Invalidate(); } protected override void UpdateLayout() { base.UpdateLayout(); - if (!yPositions.EnsureValid()) - yPositions.Refresh(computeYPositions); + if (!yPositionsCached.EnsureValid()) + yPositionsCached.Refresh(computeYPositions); } - private static float offsetX(Vector2 pos, Panel panel, float dist, float halfHeight) + private static float offsetX(Panel panel, float dist, float halfHeight) { // The radius of the circle the carousel moves on. const float CIRCLE_RADIUS = 4; @@ -137,44 +142,52 @@ namespace osu.Game.Screens.Select return 125 + x; } - private Vector2 getScrollPos(Panel panel) + private void addPanel(int index) { - return panel.Position + panel.DrawSize;; - } + Panel panel = panels[index]; + if (panel.Hidden) + return; - private Vector2 getDrawPos(Panel panel) - { - return panel.ToSpaceOfOtherDrawable(panel.DrawSize / 2.0f, this); + panel.Depth = index + (panel is BeatmapSetHeader ? panels.Count : 0); + + if (!scrollableContent.Contains(panel)) + scrollableContent.Add(panel); } protected override void Update() { base.Update(); - scrollableContent.Clear(false); + float drawHeight = DrawHeight; + scrollableContent.RemoveAll(delegate (Panel p) + { + float panelPosY = p.Position.Y; + return panelPosY < Current - p.DrawHeight || panelPosY > Current + drawHeight || !IsVisible; + }); - foreach (BeatmapGroup group in groups) - { - scrollableContent.Add(group.Header); + int firstIndex = yPositions.BinarySearch(Current - Panel.MAX_HEIGHT); + if (firstIndex < 0) firstIndex = ~firstIndex; + int lastIndex = yPositions.BinarySearch(Current + drawHeight); + if (lastIndex < 0) lastIndex = ~lastIndex; - if (group.State == BeatmapGroupState.Expanded) - foreach (BeatmapPanel panel in group.BeatmapPanels) - scrollableContent.Add(panel); - } + for (int i = firstIndex; i < lastIndex; ++i) + addPanel(i); + float halfHeight = drawHeight / 2; foreach (Panel panel in scrollableContent.Children) { - if (panel.Position.Y < 0) - continue; + float panelDrawY = panel.Position.Y - Current; + float dist = Math.Abs(1f - panelDrawY / halfHeight); - Vector2 panelPosLocal = panel.Position; - Vector2 panelPos = getDrawPos(panel); + // 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(panel, dist, halfHeight), 0); - float halfHeight = DrawSize.Y / 2; - float dist = Math.Abs(1f - panelPos.Y / halfHeight); - panel.OriginPosition = new Vector2(-offsetX(panelPos, panel, dist, halfHeight), 0); - - panel.Alpha = MathHelper.Clamp(1.75f - 1.5f * dist, 0, 1); + // 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)); } } } diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index 6e35e2a627..f565f780b7 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -148,8 +148,6 @@ namespace osu.Game.Screens.Select { playMode = osuGame.PlayMode; playMode.ValueChanged += playMode_ValueChanged; - // Temporary: - carousell.Padding = new MarginPadding { Top = ToolbarPadding }; } if (database == null) diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index d193f6dd8a..3c8943853c 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -103,7 +103,7 @@ - +