diff --git a/osu.Game/GameModes/BackgroundMode.cs b/osu.Game/GameModes/BackgroundMode.cs new file mode 100644 index 0000000000..bb478dbe7d --- /dev/null +++ b/osu.Game/GameModes/BackgroundMode.cs @@ -0,0 +1,97 @@ +//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.GameModes; +using osu.Framework.Graphics.Transformations; +using osu.Game.Graphics.Background; +using OpenTK; + +namespace osu.Game.GameModes +{ + public abstract class BackgroundMode : GameMode, IEquatable + { + public virtual bool Equals(BackgroundMode other) + { + return other?.GetType() == GetType(); + } + + const float transition_length = 500; + const float x_movement_amount = 50; + + public override void Load() + { + base.Load(); + + Content.Scale *= 1 + (x_movement_amount / Size.X) * 2; + } + + protected override void OnEntering(GameMode last) + { + Content.FadeOut(); + Content.MoveToX(x_movement_amount); + + Content.FadeIn(transition_length, EasingTypes.InOutQuart); + Content.MoveToX(0, transition_length, EasingTypes.InOutQuart); + + base.OnEntering(last); + } + + protected override void OnSuspending(GameMode next) + { + Content.MoveToX(-x_movement_amount, transition_length, EasingTypes.InOutQuart); + base.OnSuspending(next); + } + + protected override void OnExiting(GameMode next) + { + Content.FadeOut(transition_length, EasingTypes.OutExpo); + Content.MoveToX(x_movement_amount, transition_length, EasingTypes.OutExpo); + + base.OnExiting(next); + } + + protected override void OnResuming(GameMode last) + { + Content.MoveToX(0, transition_length, EasingTypes.OutExpo); + base.OnResuming(last); + } + } + + public class BackgroundModeDefault : BackgroundMode + { + public override void Load() + { + base.Load(); + + Add(new Background()); + } + } + + public class BackgroundModeCustom : BackgroundMode + { + private readonly string textureName; + + public BackgroundModeCustom(string textureName) + { + this.textureName = textureName; + } + + public override void Load() + { + base.Load(); + + Add(new Background(textureName)); + } + + public override bool Equals(BackgroundMode other) + { + return base.Equals(other) && textureName == ((BackgroundModeCustom)other).textureName; + } + + } +} diff --git a/osu.Game/GameModes/GameModeWhiteBox.cs b/osu.Game/GameModes/GameModeWhiteBox.cs index 4bca922b22..a36c46885c 100644 --- a/osu.Game/GameModes/GameModeWhiteBox.cs +++ b/osu.Game/GameModes/GameModeWhiteBox.cs @@ -15,7 +15,7 @@ using OpenTK.Graphics; namespace osu.Game.GameModes { - public class GameModeWhiteBox : GameMode + public class GameModeWhiteBox : OsuGameMode { private Button popButton; @@ -25,9 +25,14 @@ namespace osu.Game.GameModes private FlowContainer childModeButtons; private Container textContainer; + private Box box; - protected override double OnEntering(GameMode last) + protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Menu/songselect"); + + protected override void OnEntering(GameMode last) { + base.OnEntering(last); + //only show the pop button if we are entered form another gamemode. if (last != null) popButton.Alpha = 1; @@ -35,31 +40,40 @@ namespace osu.Game.GameModes Content.Alpha = 0; textContainer.Position = new Vector2(Size.X / 16, 0); - Content.Delay(300); + box.ScaleTo(0.2f); + box.RotateTo(-20); + + Content.Delay(300, true); + + box.ScaleTo(1, transition_time, EasingTypes.OutElastic); + box.RotateTo(0, transition_time / 2, EasingTypes.OutQuint); + textContainer.MoveTo(Vector2.Zero, transition_time, EasingTypes.OutExpo); Content.FadeIn(transition_time, EasingTypes.OutExpo); - return 0;// transition_time * 1000; } - protected override double OnExiting(GameMode next) + protected override void OnExiting(GameMode next) { + base.OnExiting(next); + textContainer.MoveTo(new Vector2((Size.X / 16), 0), transition_time, EasingTypes.OutExpo); Content.FadeOut(transition_time, EasingTypes.OutExpo); - return transition_time; } - protected override double OnSuspending(GameMode next) + protected override void OnSuspending(GameMode next) { + base.OnSuspending(next); + textContainer.MoveTo(new Vector2(-(Size.X / 16), 0), transition_time, EasingTypes.OutExpo); Content.FadeOut(transition_time, EasingTypes.OutExpo); - return transition_time; } - protected override double OnResuming(GameMode last) + protected override void OnResuming(GameMode last) { + base.OnResuming(last); + textContainer.MoveTo(Vector2.Zero, transition_time, EasingTypes.OutExpo); Content.FadeIn(transition_time, EasingTypes.OutExpo); - return transition_time; } public override void Load() @@ -68,15 +82,15 @@ namespace osu.Game.GameModes Children = new Drawable[] { - new Box + box = new Box { RelativeSizeAxes = Axes.Both, - Size = new Vector2(0.7f), + Size = new Vector2(0.3f), Anchor = Anchor.Centre, Origin = Anchor.Centre, Colour = getColourFor(GetType()), - Alpha = 0.6f, - Additive = true + Alpha = 1, + Additive = false }, textContainer = new AutoSizeContainer { diff --git a/osu.Game/GameModes/Menu/MainMenu.cs b/osu.Game/GameModes/Menu/MainMenu.cs index fa99abed91..599639ca82 100644 --- a/osu.Game/GameModes/Menu/MainMenu.cs +++ b/osu.Game/GameModes/Menu/MainMenu.cs @@ -17,13 +17,17 @@ using OpenTK; namespace osu.Game.GameModes.Menu { - public class MainMenu : GameMode + public class MainMenu : OsuGameMode { private ButtonSystem buttons; public override string Name => @"Main Menu"; + protected override bool IsTopLevel => true; + //private AudioTrack bgm; + protected override BackgroundMode CreateBackground() => new BackgroundModeDefault(); + public override void Load() { base.Load(); @@ -64,27 +68,28 @@ namespace osu.Game.GameModes.Menu }; } - protected override double OnSuspending(GameMode next) + protected override void OnSuspending(GameMode next) { + base.OnSuspending(next); + const float length = 400; buttons.State = ButtonSystem.MenuState.EnteringMode; Content.FadeOut(length, EasingTypes.InSine); Content.MoveTo(new Vector2(-800, 0), length, EasingTypes.InSine); - - return base.OnSuspending(next); } - protected override double OnResuming(GameMode last) + protected override void OnResuming(GameMode last) { + base.OnResuming(last); + const float length = 300; buttons.State = ButtonSystem.MenuState.TopLevel; Content.FadeIn(length, EasingTypes.OutQuint); Content.MoveTo(new Vector2(0, 0), length, EasingTypes.OutQuint); - return base.OnResuming(last); } } } diff --git a/osu.Game/GameModes/OsuGameMode.cs b/osu.Game/GameModes/OsuGameMode.cs new file mode 100644 index 0000000000..a0ac4d4567 --- /dev/null +++ b/osu.Game/GameModes/OsuGameMode.cs @@ -0,0 +1,72 @@ +//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.GameModes; +using osu.Framework.Graphics.Containers; +using osu.Game.Graphics.Background; + +namespace osu.Game.GameModes +{ + public class OsuGameMode : GameMode + { + internal BackgroundMode Background { get; private set; } + + /// + /// Override to create a BackgroundMode for the current GameMode. + /// Note that the instance created may not be the used instance if it matches the BackgroundMode equality clause. + /// + protected virtual BackgroundMode CreateBackground() => null; + + protected override void OnEntering(GameMode last) + { + OsuGameMode lastOsu = last as OsuGameMode; + + BackgroundMode bg = CreateBackground(); + + if (lastOsu?.Background != null) + { + if (bg == null || lastOsu.Background.Equals(bg)) + //we can keep the previous mode's background. + Background = lastOsu.Background; + else + { + lastOsu.Background.Push(Background = bg); + } + } + else if (bg != null) + { + bg.Depth = float.MinValue; + AddTopLevel(Background = bg); + } + + + base.OnEntering(last); + } + + protected override void OnExiting(GameMode next) + { + OsuGameMode nextOsu = next as OsuGameMode; + + if (Background != null && !Background.Equals(nextOsu?.Background)) + Background.Exit(); + + base.OnExiting(next); + } + + protected override void OnResuming(GameMode last) + { + base.OnResuming(last); + } + + protected override void OnSuspending(GameMode next) + { + base.OnSuspending(next); + } + + } +} diff --git a/osu.Game/Graphics/Background/Background.cs b/osu.Game/Graphics/Background/Background.cs index f9bcc0bd15..b9e975f5db 100644 --- a/osu.Game/Graphics/Background/Background.cs +++ b/osu.Game/Graphics/Background/Background.cs @@ -15,9 +15,13 @@ namespace osu.Game.Graphics.Background { protected Sprite BackgroundSprite; - public Background() + string textureName; + + public Background(string textureName = @"Menu/background") { + this.textureName = textureName; RelativeSizeAxes = Axes.Both; + Depth = float.MinValue; } public override void Load() @@ -26,7 +30,7 @@ namespace osu.Game.Graphics.Background Add(BackgroundSprite = new Sprite { - Texture = Game.Textures.Get(@"Menu/background"), + Texture = Game.Textures.Get(textureName), Anchor = Anchor.Centre, Origin = Anchor.Centre, Colour = Color4.DarkGray diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 4148854513..27b474bb82 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -34,12 +34,6 @@ namespace osu.Game base.Load(); Add(new Drawable[] { - new ParallaxContainer - { - Children = new [] { - new Background() - } - }, MainMenu = new MainMenu(), Toolbar = new Toolbar { diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 8ef0f07fa7..806420e26c 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -69,6 +69,7 @@ + @@ -78,6 +79,7 @@ +