From 5b294ba4196bf9791b4148eea1e48c4ab53758a8 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 25 Jun 2019 18:30:43 +0900 Subject: [PATCH] Adjust backbutton animation --- .../UserInterface/TestSceneBackButton.cs | 44 +++++++++++++++++++ osu.Game/Graphics/UserInterface/BackButton.cs | 38 +++++++++++++--- osu.Game/OsuGame.cs | 6 ++- 3 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneBackButton.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneBackButton.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneBackButton.cs new file mode 100644 index 0000000000..9f627694d8 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneBackButton.cs @@ -0,0 +1,44 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics.UserInterface; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneBackButton : OsuTestScene + { + public TestSceneBackButton() + { + BackButton button; + + Child = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(300), + Masking = true, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.SlateGray + }, + button = new BackButton + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft + } + } + }; + + AddStep("show button", () => button.Show()); + AddStep("hide button", () => button.Hide()); + } + } +} diff --git a/osu.Game/Graphics/UserInterface/BackButton.cs b/osu.Game/Graphics/UserInterface/BackButton.cs index a5d85d9338..e6f7ff2261 100644 --- a/osu.Game/Graphics/UserInterface/BackButton.cs +++ b/osu.Game/Graphics/UserInterface/BackButton.cs @@ -1,28 +1,40 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Input.Bindings; using osu.Game.Input.Bindings; namespace osu.Game.Graphics.UserInterface { - public class BackButton : TwoLayerButton, IKeyBindingHandler + public class BackButton : VisibilityContainer, IKeyBindingHandler { + public Action Action; + + private readonly TwoLayerButton button; + public BackButton() { - Text = @"back"; - Icon = OsuIcon.LeftCircle; - Anchor = Anchor.BottomLeft; - Origin = Anchor.BottomLeft; + Size = TwoLayerButton.SIZE_EXTENDED; + + Child = button = new TwoLayerButton + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Text = @"back", + Icon = OsuIcon.LeftCircle, + Action = () => Action?.Invoke() + }; } [BackgroundDependencyLoader] private void load(OsuColour colours) { - BackgroundColour = colours.Pink; - HoverColour = colours.PinkDark; + button.BackgroundColour = colours.Pink; + button.HoverColour = colours.PinkDark; } public bool OnPressed(GlobalAction action) @@ -37,5 +49,17 @@ public bool OnPressed(GlobalAction action) } public bool OnReleased(GlobalAction action) => action == GlobalAction.Back; + + protected override void PopIn() + { + button.MoveToX(0, 400, Easing.OutQuint); + button.FadeIn(150, Easing.OutQuint); + } + + protected override void PopOut() + { + button.MoveToX(-TwoLayerButton.SIZE_EXTENDED.X / 2, 400); + button.FadeOut(200); + } } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 83fd049ea0..b957d3b96f 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -405,7 +405,6 @@ protected override void LoadComplete() { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, - Alpha = 0, Action = () => { if ((screenStack.CurrentScreen as IOsuScreen)?.AllowBackButton == true) @@ -809,7 +808,10 @@ protected virtual void ScreenChanged(IScreen current, IScreen newScreen) else Toolbar.Show(); - backButton.Alpha = newOsuScreen.ShowBackButton ? 1 : 0; + if (newOsuScreen.ShowBackButton) + backButton.Show(); + else + backButton.Hide(); } }