From e9343fe53dd6ffc1b81bbcf7c9f80b596307083c Mon Sep 17 00:00:00 2001 From: stanriders Date: Sun, 27 Nov 2016 04:21:12 +0300 Subject: [PATCH] Add stable-alike BackButton --- osu-framework | 2 +- osu.Game/Graphics/UserInterface/BackButton.cs | 84 +++++++++++++++++++ osu.Game/Screens/GameModeWhiteBox.cs | 11 ++- osu.Game/Screens/Select/PlaySongSelect.cs | 7 ++ osu.Game/osu.Game.csproj | 1 + 5 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 osu.Game/Graphics/UserInterface/BackButton.cs diff --git a/osu-framework b/osu-framework index 24af3b161d..ea56eab4a2 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 24af3b161da9447b678edd8ec32193df54f71e3b +Subproject commit ea56eab4a2bb4c9723052586ed30c687898fecb0 diff --git a/osu.Game/Graphics/UserInterface/BackButton.cs b/osu.Game/Graphics/UserInterface/BackButton.cs new file mode 100644 index 0000000000..f4190f3894 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/BackButton.cs @@ -0,0 +1,84 @@ +// Copyright (c) 2007-2016 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE + +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Graphics; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Graphics.Transformations; +using osu.Framework.Input; + +namespace osu.Game.Graphics.UserInterface +{ + // Basic back button as it was on stable (kinda). No skinning possible for now + class BackButton : ExtendableButton + { + private TextAwesome icon; + private Vector2 iconPos = new Vector2(20, 0); + + public BackButton() + { + InitialExtendLenght = new Vector2(40, 0); + ExtendLenght = new Vector2(60, 0); + + RelativeSizeAxes = Axes.Y; + Width = 80; + //Height = 40; // should be set or should be relative? + + Text = @"Back"; + + BGColour = new Color4(195, 40, 140, 255); + Colour = new Color4(238, 51, 153, 255); + + Children = new Drawable[] + { + icon = new TextAwesome + { + Anchor = Anchor.CentreLeft, + TextSize = 25, + Position = iconPos, + Icon = FontAwesome.fa_osu_left_o + } + }; + + // HACK: because it never uses InitialExtendLenght that we give to it on creation + textContainer.Position = Position + InitialExtendLenght; + } + protected override bool OnHover(InputState state) + { + bool result = base.OnHover(state); + + icon.ClearTransformations(); + + icon.MoveToX(iconPos.X + 10, 150, EasingTypes.OutElastic); + + int duration = 0; //(int)(Game.Audio.BeatLength / 2); + if (duration == 0) duration = 250; + + double offset = 0; //(1 - Game.Audio.SyncBeatProgress) * duration; + double startTime = Time.Current + offset; + + // basic pulse + icon.Transforms.Add(new TransformScale + { + StartValue = new Vector2(1.1f, 1.1f), + EndValue = Vector2.One, + StartTime = startTime, + EndTime = startTime + duration, + Easing = EasingTypes.Out, + LoopCount = -1, + LoopDelay = duration + }); + + return result; + } + + protected override void OnHoverLost(InputState state) + { + icon.ClearTransformations(); + icon.MoveToX(iconPos.X, 150, EasingTypes.OutElastic); + + base.OnHoverLost(state); + } + } +} diff --git a/osu.Game/Screens/GameModeWhiteBox.cs b/osu.Game/Screens/GameModeWhiteBox.cs index ac6cc5ece3..ef85f9e23e 100644 --- a/osu.Game/Screens/GameModeWhiteBox.cs +++ b/osu.Game/Screens/GameModeWhiteBox.cs @@ -10,6 +10,7 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Transformations; using osu.Framework.Graphics.UserInterface; using osu.Game.Screens.Backgrounds; +using osu.Game.Graphics.UserInterface; using OpenTK; using OpenTK.Graphics; @@ -17,7 +18,7 @@ namespace osu.Game.Screens { public class GameModeWhiteBox : OsuGameMode { - private Button popButton; + private BackButton popButton; const int transition_time = 1000; @@ -113,14 +114,12 @@ namespace osu.Game.Screens }, } }, - popButton = new Button + popButton = new BackButton { - Text = @"Back", - RelativeSizeAxes = Axes.X, - Size = new Vector2(0.1f, 40), + RelativeSizeAxes = Axes.None, + Height = 40, Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, - Colour = new Color4(235, 51, 153, 255), Alpha = 0, Action = delegate { Exit(); diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index 8c8ff39fba..9688b36a99 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -19,6 +19,7 @@ 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; @@ -120,6 +121,12 @@ namespace osu.Game.Screens.Select Size = Vector2.One, Colour = new Color4(0, 0, 0, 0.5f), }, + new BackButton + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Action = () => Exit() + }, new Button { Anchor = Anchor.CentreRight, diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index c35bafb251..f1bdd47b68 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -65,6 +65,7 @@ +