diff --git a/osu-framework b/osu-framework index 1d43e1ed56..7022964256 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 1d43e1ed56421fbbefdf6c23dab8deeeaa0f592a +Subproject commit 7022964256829c7fab596ce34ad70d09f6433bcf diff --git a/osu.Game/Beatmaps/Drawable/BeatmapGroup.cs b/osu.Game/Beatmaps/Drawable/BeatmapGroup.cs index ec9e36af3b..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; } @@ -73,15 +79,11 @@ namespace osu.Game.Beatmaps.Drawable { GainedSelection = headerGainedSelection, RelativeSizeAxes = Axes.X, - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, }; BeatmapPanels = beatmap.BeatmapSetInfo.Beatmaps.Select(b => new BeatmapPanel(b) { GainedSelection = panelGainedSelection, - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, RelativeSizeAxes = Axes.X, }).ToList(); } 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..fe633e4958 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,30 @@ 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; - - Masking = true; - CornerRadius = 10; - BorderColour = new Color4(221, 255, 255, 255); - + Height = MAX_HEIGHT; RelativeSizeAxes = Axes.X; + + AddInternal(nestedContainer = new Container + { + RelativeSizeAxes = Axes.Both, + Masking = true, + CornerRadius = 10, + BorderColour = new Color4(221, 255, 255, 255), + }); + } + + public void SetMultiplicativeAlpha(float alpha) + { + nestedContainer.Alpha = alpha; } protected override void LoadComplete() @@ -65,9 +75,8 @@ namespace osu.Game.Beatmaps.Drawable protected virtual void Selected() { - BorderThickness = 2.5f; - - EdgeEffect = new EdgeEffect + nestedContainer.BorderThickness = 2.5f; + nestedContainer.EdgeEffect = new EdgeEffect { Type = EdgeEffectType.Glow, Colour = new Color4(130, 204, 255, 150), @@ -78,9 +87,8 @@ namespace osu.Game.Beatmaps.Drawable protected virtual void Deselected() { - BorderThickness = 0; - - EdgeEffect = new EdgeEffect + nestedContainer.BorderThickness = 0; + nestedContainer.EdgeEffect = new EdgeEffect { Type = EdgeEffectType.Shadow, Offset = new Vector2(1), diff --git a/osu.Game/Screens/Select/BeatmapInfoOverlay.cs b/osu.Game/Screens/Select/BeatmapInfoOverlay.cs new file mode 100644 index 0000000000..b00bc4cdde --- /dev/null +++ b/osu.Game/Screens/Select/BeatmapInfoOverlay.cs @@ -0,0 +1,121 @@ +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Graphics.Sprites; +using osu.Game.Beatmaps; +using osu.Game.Database; +using osu.Framework.Graphics.Colour; + +namespace osu.Game.Screens.Select +{ + class BeatmapInfoOverlay : Container + { + private Container beatmapInfoContainer; + + public void UpdateBeatmap(WorkingBeatmap beatmap) + { + if (beatmap == null) + return; + + if (beatmapInfoContainer != null) + { + Drawable oldWedgedBeatmapInfo = beatmapInfoContainer; + oldWedgedBeatmapInfo.Depth = 1; + oldWedgedBeatmapInfo.FadeOut(250); + oldWedgedBeatmapInfo.Expire(); + } + + FadeIn(250); + + BeatmapSetInfo beatmapSetInfo = beatmap.BeatmapSetInfo; + BeatmapInfo beatmapInfo = beatmap.BeatmapInfo; + Add(beatmapInfoContainer = new BufferedContainer + { + PixelSnapping = true, + CacheDrawnFrameBuffer = true, + Shear = -Shear, + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + // We will create the white-to-black gradient by modulating transparency and having + // a black backdrop. This results in an sRGB-space gradient and not linear space, + // transitioning from white to black more perceptually uniformly. + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black, + }, + // We use a container, such that we can set the colour gradient to go across the + // vertices of the masked container instead of the vertices of the (larger) sprite. + beatmap.Background == null ? new Container() : new Container + { + RelativeSizeAxes = Axes.Both, + ColourInfo = ColourInfo.GradientVertical(Color4.White, new Color4(1f, 1f, 1f, 0.3f)), + Children = new [] + { + // Zoomed-in and cropped beatmap background + new Sprite + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Texture = beatmap.Background, + Scale = new Vector2(1366 / beatmap.Background.Width * 0.6f), + }, + }, + }, + // Text for beatmap info + new FlowContainer + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Direction = FlowDirection.VerticalOnly, + Margin = new MarginPadding { Top = 10, Left = 25, Right = 10, Bottom = 40 }, + AutoSizeAxes = Axes.Both, + Children = new[] + { + new SpriteText + { + Font = @"Exo2.0-MediumItalic", + Text = beatmapSetInfo.Metadata.Artist + " -- " + beatmapSetInfo.Metadata.Title, + TextSize = 28, + Shadow = true, + }, + new SpriteText + { + Font = @"Exo2.0-MediumItalic", + Text = beatmapInfo.Version, + TextSize = 17, + Shadow = true, + }, + new FlowContainer + { + Margin = new MarginPadding { Top = 10 }, + Direction = FlowDirection.HorizontalOnly, + AutoSizeAxes = Axes.Both, + Children = new [] + { + new SpriteText + { + Font = @"Exo2.0-Medium", + Text = "mapped by ", + TextSize = 15, + Shadow = true, + }, + new SpriteText + { + Font = @"Exo2.0-Bold", + Text = beatmapSetInfo.Metadata.Author, + TextSize = 15, + Shadow = true, + }, + } + } + } + } + } + }); + } + } +} diff --git a/osu.Game/Screens/Select/CarouselContainer.cs b/osu.Game/Screens/Select/CarouselContainer.cs new file mode 100644 index 0000000000..f072380e3c --- /dev/null +++ b/osu.Game/Screens/Select/CarouselContainer.cs @@ -0,0 +1,194 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using osu.Framework.Caching; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Transformations; +using osu.Game.Beatmaps.Drawable; +using osu.Game.Database; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace osu.Game.Screens.Select +{ + class CarouselContainer : ScrollContainer + { + 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 yPositionsCached = new Cached(); + private List yPositions = new List(); + + public CarouselContainer() + { + DistanceDecayJump = 0.01; + + Add(scrollableContent = new Container + { + RelativeSizeAxes = Axes.X, + }); + } + + public void AddGroup(BeatmapGroup group) + { + group.State = BeatmapGroupState.Collapsed; + + groups.Add(group); + panels.Add(group.Header); + foreach (BeatmapPanel panel in group.BeatmapPanels) + panels.Add(panel); + + yPositionsCached.Invalidate(); + } + + private void movePanel(Panel panel, bool advance, ref float currentY) + { + yPositions.Add(currentY); + panel.MoveToY(currentY, 750, EasingTypes.OutExpo); + + if (advance) + currentY += panel.DrawHeight + 5; + } + + private void computeYPositions() + { + yPositions.Clear(); + + float currentY = DrawHeight / 2; + float selectedY = currentY; + + foreach (BeatmapGroup group in groups) + { + movePanel(group.Header, true, ref currentY); + + if (group.State == BeatmapGroupState.Expanded) + { + group.Header.MoveToX(-100, 500, EasingTypes.OutExpo); + + foreach (BeatmapPanel panel in group.BeatmapPanels) + { + if (panel == SelectedPanel) + selectedY = currentY + panel.DrawHeight / 2 - DrawHeight / 2; + + movePanel(panel, true, ref currentY); + } + } + else + { + group.Header.MoveToX(0, 500, EasingTypes.OutExpo); + + foreach (BeatmapPanel panel in group.BeatmapPanels) + movePanel(panel, false, ref currentY); + } + } + + currentY += DrawHeight / 2; + scrollableContent.Height = currentY; + + ScrollTo(selectedY); + } + + public void SelectBeatmap(BeatmapInfo beatmap) + { + foreach (BeatmapGroup group in groups) + { + var panel = group.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(beatmap)); + if (panel != null) + { + SelectGroup(group, panel); + return; + } + } + } + + public void SelectGroup(BeatmapGroup group, BeatmapPanel panel) + { + if (SelectedGroup != null && SelectedGroup != group) + { + SelectedGroup.State = BeatmapGroupState.Collapsed; + foreach (BeatmapPanel p in group.BeatmapPanels) + p.MoveToY(group.Header.Position.Y); + } + + SelectedGroup = group; + panel.State = PanelSelectedState.Selected; + SelectedPanel = panel; + + yPositionsCached.Invalidate(); + } + + protected override void UpdateLayout() + { + base.UpdateLayout(); + + if (!yPositionsCached.EnsureValid()) + yPositionsCached.Refresh(computeYPositions); + } + + private static float offsetX(Panel panel, float dist, float halfHeight) + { + // The radius of the circle the carousel moves on. + const float CIRCLE_RADIUS = 4; + double discriminant = Math.Max(0, CIRCLE_RADIUS * CIRCLE_RADIUS - dist * dist); + float x = (CIRCLE_RADIUS - (float)Math.Sqrt(discriminant)) * halfHeight; + + return 125 + x; + } + + private void addPanel(int index) + { + Panel panel = panels[index]; + if (panel.Hidden) + return; + + panel.Depth = index + (panel is BeatmapSetHeader ? panels.Count : 0); + + if (!scrollableContent.Contains(panel)) + scrollableContent.Add(panel); + } + + protected override void Update() + { + base.Update(); + + float drawHeight = DrawHeight; + scrollableContent.RemoveAll(delegate (Panel p) + { + float panelPosY = p.Position.Y; + return panelPosY < Current - p.DrawHeight || panelPosY > Current + drawHeight || !IsVisible; + }); + + int firstIndex = yPositions.BinarySearch(Current - Panel.MAX_HEIGHT); + if (firstIndex < 0) firstIndex = ~firstIndex; + int lastIndex = yPositions.BinarySearch(Current + drawHeight); + if (lastIndex < 0) lastIndex = ~lastIndex; + + for (int i = firstIndex; i < lastIndex; ++i) + addPanel(i); + + float halfHeight = drawHeight / 2; + foreach (Panel panel in scrollableContent.Children) + { + 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(panel, 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)); + } + } + } +} diff --git a/osu.Game/Screens/Select/CarousellContainer.cs b/osu.Game/Screens/Select/CarousellContainer.cs deleted file mode 100644 index 4bde7838b2..0000000000 --- a/osu.Game/Screens/Select/CarousellContainer.cs +++ /dev/null @@ -1,124 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using OpenTK; -using osu.Framework.Caching; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Primitives; -using osu.Game.Beatmaps.Drawable; -using osu.Game.Database; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace osu.Game.Screens.Select -{ - class CarousellContainer : ScrollContainer - { - private Container scrollableContent; - private List groups = new List(); - public BeatmapGroup SelectedGroup { get; private set; } - - private Cached yPositions = new Cached(); - - public CarousellContainer() - { - Add(scrollableContent = new Container - { - Padding = new MarginPadding { Left = 25, Top = 25, Bottom = 25 }, - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - }); - } - - public void AddGroup(BeatmapGroup group) - { - group.State = BeatmapGroupState.Collapsed; - - groups.Add(group); - - yPositions.Invalidate(); - } - - private void computeYPositions() - { - float currentY = 0; - foreach (BeatmapGroup group in groups) - { - group.Header.Position = new Vector2(group.Header.Position.X, currentY); - currentY += group.Header.DrawSize.Y + 5; - - if (group.State == BeatmapGroupState.Expanded) - { - foreach (BeatmapPanel panel in group.BeatmapPanels) - { - panel.Position = new Vector2(panel.Position.X, currentY); - currentY += panel.DrawSize.Y + 5; - } - } - } - } - - public void SelectBeatmap(BeatmapInfo beatmap) - { - foreach (BeatmapGroup group in groups) - { - var panel = group.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(beatmap)); - if (panel != null) - SelectGroup(group, panel); - } - } - - public void SelectGroup(BeatmapGroup group, BeatmapPanel panel) - { - if (SelectedGroup != null && SelectedGroup != group) - SelectedGroup.State = BeatmapGroupState.Collapsed; - - SelectedGroup = group; - panel.State = PanelSelectedState.Selected; - - yPositions.Invalidate(); - } - - protected override void UpdateLayout() - { - base.UpdateLayout(); - - if (!yPositions.EnsureValid()) - yPositions.Refresh(computeYPositions); - } - - protected override void Update() - { - base.Update(); - - scrollableContent.Clear(false); - - foreach (BeatmapGroup group in groups) - { - scrollableContent.Add(group.Header); - - if (group.State == BeatmapGroupState.Expanded) - foreach (BeatmapPanel panel in group.BeatmapPanels) - scrollableContent.Add(panel); - } - - foreach (Panel panel in scrollableContent.Children) - { - if (panel.Position.Y < 0) - continue; - - Vector2 panelPosLocal = panel.Position; - Vector2 panelPos = panel.ToSpaceOfOtherDrawable(panel.DrawSize / 2.0f, this); - - float halfHeight = DrawSize.Y / 2; - float dist = Math.Abs(panelPos.Y - halfHeight); - panel.Position = new Vector2( - (panel is BeatmapSetHeader && panel.State == PanelSelectedState.Selected ? 0 : 100) + dist * 0.1f, panelPosLocal.Y); - - panel.Alpha = MathHelper.Clamp(1.75f - 1.5f * dist / halfHeight, 0, 1); - } - } - } -} diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index ba6cfa37cd..1b96ec923d 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -22,7 +22,6 @@ using osu.Game.Modes; using osu.Game.Screens.Backgrounds; using OpenTK; using OpenTK.Graphics; -using osu.Framework.Graphics.Colour; using osu.Game.Screens.Play; using osu.Framework; @@ -34,15 +33,14 @@ namespace osu.Game.Screens.Select private BeatmapDatabase database; protected override BackgroundMode CreateBackground() => new BackgroundModeBeatmap(Beatmap); - private CarousellContainer carousell; + private CarouselContainer carousell; private TrackManager trackManager; private Container backgroundWedgesContainer; private static readonly Vector2 wedged_container_size = new Vector2(700, 225); private static readonly Vector2 wedged_container_shear = new Vector2(0.15f, 0); private static readonly Vector2 wedged_container_start_position = new Vector2(0, 50); - private Container wedgedContainer; - private Container wedgedBeatmapInfo; + private BeatmapInfoOverlay wedgedBeatmapInfoOverlay; private static readonly Vector2 BACKGROUND_BLUR = new Vector2(20); private CancellationTokenSource initialAddSetsTask; @@ -83,18 +81,19 @@ namespace osu.Game.Screens.Select }, } }, - carousell = new CarousellContainer + carousell = new CarouselContainer { RelativeSizeAxes = Axes.Y, Size = new Vector2(scrollWidth, 1), Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, }, - wedgedContainer = new Container + wedgedBeatmapInfoOverlay = new BeatmapInfoOverlay { Alpha = 0, Position = wedged_container_start_position, Size = wedged_container_size, + Shear = wedged_container_shear, Margin = new MarginPadding { Top = 20, Right = 20, }, Masking = true, BorderColour = new Color4(221, 255, 255, 255), @@ -106,10 +105,6 @@ namespace osu.Game.Screens.Select Radius = 20, Roundness = 15, }, - Shear = wedged_container_shear, - Children = new Drawable[] - { - }, }, new Container { @@ -151,8 +146,6 @@ namespace osu.Game.Screens.Select { playMode = osuGame.PlayMode; playMode.ValueChanged += playMode_ValueChanged; - // Temporary: - carousell.Padding = new MarginPadding { Top = ToolbarPadding }; } if (database == null) @@ -231,112 +224,7 @@ namespace osu.Game.Screens.Select (Background as BackgroundModeBeatmap)?.BlurTo(BACKGROUND_BLUR, 1000); } - //todo: move to own class and fix async logic (move every call on WorkingBeatmap.* to load() and use Preload to create it. - refreshWedgedBeatmapInfo(beatmap); - } - - private void refreshWedgedBeatmapInfo(WorkingBeatmap beatmap) - { - if (beatmap == null) - return; - - if (wedgedBeatmapInfo != null) - { - Drawable oldWedgedBeatmapInfo = wedgedBeatmapInfo; - oldWedgedBeatmapInfo.Depth = 1; - oldWedgedBeatmapInfo.FadeOut(250); - oldWedgedBeatmapInfo.Expire(); - } - - wedgedContainer.FadeIn(250); - - BeatmapSetInfo beatmapSetInfo = beatmap.BeatmapSetInfo; - BeatmapInfo beatmapInfo = beatmap.BeatmapInfo; - wedgedContainer.Add(wedgedBeatmapInfo = new BufferedContainer - { - PixelSnapping = true, - CacheDrawnFrameBuffer = true, - Shear = -wedged_container_shear, - RelativeSizeAxes = Axes.Both, - Children = new Drawable[] - { - // We will create the white-to-black gradient by modulating transparency and having - // a black backdrop. This results in an sRGB-space gradient and not linear space, - // transitioning from white to black more perceptually uniformly. - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = Color4.Black, - }, - // We use a container, such that we can set the colour gradient to go across the - // vertices of the masked container instead of the vertices of the (larger) sprite. - beatmap.Background == null ? new Container() : new Container - { - RelativeSizeAxes = Axes.Both, - ColourInfo = ColourInfo.GradientVertical(Color4.White, new Color4(1f, 1f, 1f, 0.3f)), - Children = new [] - { - // Zoomed-in and cropped beatmap background - new Sprite - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Texture = beatmap.Background, - Scale = new Vector2(1366 / beatmap.Background.Width * 0.6f), - }, - }, - }, - // Text for beatmap info - new FlowContainer - { - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - Direction = FlowDirection.VerticalOnly, - Margin = new MarginPadding { Top = 10, Left = 25, Right = 10, Bottom = 40 }, - AutoSizeAxes = Axes.Both, - Children = new[] - { - new SpriteText - { - Font = @"Exo2.0-MediumItalic", - Text = beatmapSetInfo.Metadata.Artist + " -- " + beatmapSetInfo.Metadata.Title, - TextSize = 28, - Shadow = true, - }, - new SpriteText - { - Font = @"Exo2.0-MediumItalic", - Text = beatmapInfo.Version, - TextSize = 17, - Shadow = true, - }, - new FlowContainer - { - Margin = new MarginPadding { Top = 10 }, - Direction = FlowDirection.HorizontalOnly, - AutoSizeAxes = Axes.Both, - Children = new [] - { - new SpriteText - { - Font = @"Exo2.0-Medium", - Text = "mapped by ", - TextSize = 15, - Shadow = true, - }, - new SpriteText - { - Font = @"Exo2.0-Bold", - Text = beatmapSetInfo.Metadata.Author, - TextSize = 15, - Shadow = true, - }, - } - } - } - } - } - }); + wedgedBeatmapInfoOverlay.UpdateBeatmap(beatmap); } /// diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index d193f6dd8a..fb19272a7d 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -103,7 +103,7 @@ - + @@ -159,6 +159,7 @@ +