From 4a7b3cf39171137d1ccd5f578e8758b74d0574cf Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 26 Jan 2017 23:07:49 +0900 Subject: [PATCH] Initial implementation of song select footer area. --- osu.Game/Graphics/UserInterface/BackButton.cs | 10 +- osu.Game/Screens/Select/CarouselContainer.cs | 36 ++++-- osu.Game/Screens/Select/Footer.cs | 115 +++++++++++++++++ osu.Game/Screens/Select/FooterButton.cs | 117 ++++++++++++++++++ osu.Game/Screens/Select/PlaySongSelect.cs | 54 ++------ osu.Game/osu.Game.csproj | 2 + 6 files changed, 276 insertions(+), 58 deletions(-) create mode 100644 osu.Game/Screens/Select/Footer.cs create mode 100644 osu.Game/Screens/Select/FooterButton.cs diff --git a/osu.Game/Graphics/UserInterface/BackButton.cs b/osu.Game/Graphics/UserInterface/BackButton.cs index 2f9a026b8f..d246b421a2 100644 --- a/osu.Game/Graphics/UserInterface/BackButton.cs +++ b/osu.Game/Graphics/UserInterface/BackButton.cs @@ -27,13 +27,13 @@ namespace osu.Game.Graphics.UserInterface private const float shear = 0.1f; - private static readonly Vector2 size_extended = new Vector2(140, 50); - private static readonly Vector2 size_retracted = new Vector2(100, 50); + public static readonly Vector2 SIZE_EXTENDED = new Vector2(140, 50); + public static readonly Vector2 SIZE_RETRACTED = new Vector2(100, 50); private AudioSample sampleClick; public BackButton() { - Size = size_retracted; + Size = SIZE_RETRACTED; } public override bool Contains(Vector2 screenSpacePos) => leftBox.Contains(screenSpacePos) || rightBox.Contains(screenSpacePos); @@ -42,7 +42,7 @@ namespace osu.Game.Graphics.UserInterface { icon.ClearTransformations(); - ResizeTo(size_extended, transform_time, EasingTypes.OutElastic); + ResizeTo(SIZE_EXTENDED, transform_time, EasingTypes.OutElastic); int duration = 0; //(int)(Game.Audio.BeatLength / 2); if (duration == 0) duration = pulse_length; @@ -69,7 +69,7 @@ namespace osu.Game.Graphics.UserInterface { icon.ClearTransformations(); - ResizeTo(size_retracted, transform_time, EasingTypes.OutElastic); + ResizeTo(SIZE_RETRACTED, transform_time, EasingTypes.OutElastic); int duration = 0; //(int)(Game.Audio.BeatLength); if (duration == 0) duration = pulse_length * 2; diff --git a/osu.Game/Screens/Select/CarouselContainer.cs b/osu.Game/Screens/Select/CarouselContainer.cs index 144e4cabba..258e2e03d8 100644 --- a/osu.Game/Screens/Select/CarouselContainer.cs +++ b/osu.Game/Screens/Select/CarouselContainer.cs @@ -1,21 +1,22 @@ //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.Database; -using System; -using System.Collections.Generic; -using System.Linq; -using osu.Framework.Extensions.IEnumerableExtensions; -using osu.Framework.Lists; -using osu.Game.Beatmaps.Drawables; +using OpenTK; +using osu.Framework.Caching; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Transformations; +using osu.Game.Database; +using System; +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Extensions.IEnumerableExtensions; +using osu.Framework.Lists; +using osu.Game.Beatmaps.Drawables; using osu.Framework.Timing; using osu.Framework.Input; using OpenTK.Input; +using osu.Framework.MathUtils; namespace osu.Game.Screens.Select { @@ -287,6 +288,17 @@ namespace osu.Game.Screens.Select } return base.OnKeyDown(state, args); + } + + public void SelectRandom() + { + if (groups.Count < 1) + return; + BeatmapGroup group = groups[RNG.Next(groups.Count)]; + BeatmapPanel panel = group?.BeatmapPanels.First(); + if (panel == null) + return; + SelectGroup(group, panel); } } } diff --git a/osu.Game/Screens/Select/Footer.cs b/osu.Game/Screens/Select/Footer.cs new file mode 100644 index 0000000000..bb280f56c1 --- /dev/null +++ b/osu.Game/Screens/Select/Footer.cs @@ -0,0 +1,115 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; +using osu.Game.Graphics; +using osu.Game.Graphics.UserInterface; +using osu.Game.Screens.Menu; + +namespace osu.Game.Screens.Select +{ + public class Footer : Container + { + private Box modeLight; + + private const float play_song_select_button_width = 100; + private const float play_song_select_button_height = 50; + + public const int TRANSITION_LENGTH = 300; + + private const float padding = 80; + + public Action OnBack; + public Action OnStart; + + private FlowContainer buttons; + + public void AddButton(string text, Color4 colour, Action action) + { + var button = new FooterButton + { + Text = text, + Height = play_song_select_button_height, + Width = play_song_select_button_width, + SelectedColour = colour, + DeselectedColour = colour.Opacity(0.5f), + }; + + button.Hovered = () => updateModeLight(button); + button.HoverLost = () => updateModeLight(); + button.Action = action; + buttons.Add(button); + } + + private void updateModeLight(FooterButton button = null) + { + modeLight.FadeColour(button?.SelectedColour ?? Color4.Transparent, TRANSITION_LENGTH, EasingTypes.OutQuint); + } + + public Footer() + { + const float bottomToolHeight = 50; + + RelativeSizeAxes = Axes.X; + Height = bottomToolHeight; + Anchor = Anchor.BottomCentre; + Origin = Anchor.BottomCentre; + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Size = Vector2.One, + Colour = Color4.Black.Opacity(0.5f), + }, + modeLight = new Box + { + RelativeSizeAxes = Axes.X, + Height = 3, + Position = new Vector2(0, -3), + }, + new OsuLogo() + { + Anchor = Anchor.BottomRight, + Scale = new Vector2(0.4f), + Position = new Vector2(-70, -25), + Action = () => OnStart?.Invoke() + }, + new BackButton + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Action = () => OnBack?.Invoke(), + }, + new FlowContainer + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Position = new Vector2(BackButton.SIZE_EXTENDED.X + padding, 0), + RelativeSizeAxes = Axes.Y, + AutoSizeAxes = Axes.X, + Direction = FlowDirection.HorizontalOnly, + Spacing = new Vector2(padding, 0), + Children = new Drawable[] + { + + buttons = new FlowContainer + { + Direction = FlowDirection.HorizontalOnly, + Spacing = new Vector2(0.2f, 0), + AutoSizeAxes = Axes.Both, + } + } + } + }; + + updateModeLight(); + } + } +} diff --git a/osu.Game/Screens/Select/FooterButton.cs b/osu.Game/Screens/Select/FooterButton.cs new file mode 100644 index 0000000000..9d49e88716 --- /dev/null +++ b/osu.Game/Screens/Select/FooterButton.cs @@ -0,0 +1,117 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Input; +using System; +using osu.Framework.Graphics.Transformations; + +namespace osu.Game.Screens.Select +{ + public class FooterButton : ClickableContainer + { + private static readonly Vector2 shearing = new Vector2(0.15f, 0); + + public string Text + { + get { return spriteText?.Text; } + set + { + if (spriteText != null) + spriteText.Text = value; + } + } + + private Color4 deselectedColour; + public Color4 DeselectedColour + { + get { return deselectedColour; } + set + { + deselectedColour = value; + if(light.Colour != SelectedColour) + light.Colour = value; + } + } + + private Color4 selectedColour; + public Color4 SelectedColour + { + get { return selectedColour; } + set + { + selectedColour = value; + box.Colour = selectedColour; + } + } + + private SpriteText spriteText; + private Box box; + private Box light; + + public FooterButton() + { + Children = new Drawable[] + { + box = new Box + { + RelativeSizeAxes = Axes.Both, + Shear = shearing, + EdgeSmoothness = new Vector2(2, 0), + Colour = Color4.White, + Alpha = 0, + }, + light = new Box + { + Shear = shearing, + Height = 4, + EdgeSmoothness = new Vector2(2, 0), + RelativeSizeAxes = Axes.X, + }, + spriteText = new SpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } + }; + } + + public Action Hovered; + public Action HoverLost; + + protected override bool OnHover(InputState state) + { + Hovered?.Invoke(); + light.ScaleTo(new Vector2(1, 2), Footer.TRANSITION_LENGTH, EasingTypes.OutQuint); + light.FadeColour(SelectedColour, Footer.TRANSITION_LENGTH, EasingTypes.OutQuint); + return true; + } + + protected override void OnHoverLost(InputState state) + { + HoverLost?.Invoke(); + light.ScaleTo(new Vector2(1, 1), Footer.TRANSITION_LENGTH, EasingTypes.OutQuint); + light.FadeColour(DeselectedColour, Footer.TRANSITION_LENGTH, EasingTypes.OutQuint); + box.FadeOut(Footer.TRANSITION_LENGTH, EasingTypes.OutQuint); + } + + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + { + box.FadeTo(0.3f, Footer.TRANSITION_LENGTH * 2, EasingTypes.OutQuint); + return base.OnMouseDown(state, args); + } + + protected override bool OnClick(InputState state) + { + box.ClearTransformations(); + box.Alpha = 1; + box.FadeOut(Footer.TRANSITION_LENGTH * 3, EasingTypes.OutQuint); + return base.OnClick(state); + } + + } +} diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index e0860fda4c..23aed2d1a3 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -14,12 +14,10 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.UserInterface; using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Modes; using osu.Game.Screens.Backgrounds; -using osu.Game.Graphics.UserInterface; using OpenTK; using OpenTK.Graphics; using osu.Game.Screens.Play; @@ -28,9 +26,9 @@ using osu.Framework.Audio.Sample; using osu.Framework.Graphics.Transformations; using osu.Game.Beatmaps.Drawables; using osu.Game.Graphics.Containers; +using osu.Game.Graphics; using osu.Framework.Input; using OpenTK.Input; -using osu.Game.Graphics; namespace osu.Game.Screens.Select { @@ -53,6 +51,8 @@ namespace osu.Game.Screens.Select private AudioSample sampleChangeDifficulty; private AudioSample sampleChangeBeatmap; + private Footer footer; + class WedgeBackground : Container { public WedgeBackground() @@ -111,7 +111,7 @@ namespace osu.Game.Screens.Select OsuGame osuGame, OsuColour colours) { const float carouselWidth = 640; - const float bottomToolHeight = 50; + Children = new Drawable[] { new ParallaxContainer @@ -142,41 +142,17 @@ namespace osu.Game.Screens.Select RelativeSizeAxes = Axes.X, Margin = new MarginPadding { Top = 20, Right = 20, }, }, - new Container + footer = new Footer() { - RelativeSizeAxes = Axes.X, - Height = bottomToolHeight, - Anchor = Anchor.BottomCentre, - Origin = Anchor.BottomCentre, - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Size = Vector2.One, - Colour = Color4.Black.Opacity(0.5f), - }, - new BackButton - { - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - //RelativeSizeAxes = Axes.Y, - Action = () => Exit() - }, - new Button - { - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreRight, - RelativeSizeAxes = Axes.Y, - Width = 100, - Text = "Play", - Colour = colours.Pink, - Action = start - }, - } + OnBack = Exit, + OnStart = start, } }; - + + footer.AddButton(@"mods", colours.Yellow, null); + footer.AddButton(@"random", colours.Green, carousel.SelectRandom); + footer.AddButton(@"options", colours.Blue, null); + if (osuGame != null) { playMode = osuGame.PlayMode; @@ -286,14 +262,10 @@ namespace osu.Game.Screens.Select //todo: change background in selectionChanged instead; support per-difficulty backgrounds. changeBackground(beatmap); - selectBeatmap(beatmap.BeatmapInfo); } - private void selectBeatmap(BeatmapInfo beatmap) - { - carousel.SelectBeatmap(beatmap); - } + private void selectBeatmap(BeatmapInfo beatmap) => carousel.SelectBeatmap(beatmap); /// /// selection has been changed as the result of interaction with the carousel. diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 2261605f50..207fa563ab 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -232,6 +232,8 @@ + +