mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
Add BackgroundMode stack.
This commit is contained in:
parent
3c01f59e00
commit
03aea04a00
97
osu.Game/GameModes/BackgroundMode.cs
Normal file
97
osu.Game/GameModes/BackgroundMode.cs
Normal file
@ -0,0 +1,97 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//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<BackgroundMode>
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
72
osu.Game/GameModes/OsuGameMode.cs
Normal file
72
osu.Game/GameModes/OsuGameMode.cs
Normal file
@ -0,0 +1,72 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//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; }
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -34,12 +34,6 @@ namespace osu.Game
|
||||
base.Load();
|
||||
|
||||
Add(new Drawable[] {
|
||||
new ParallaxContainer
|
||||
{
|
||||
Children = new [] {
|
||||
new Background()
|
||||
}
|
||||
},
|
||||
MainMenu = new MainMenu(),
|
||||
Toolbar = new Toolbar
|
||||
{
|
||||
|
@ -69,6 +69,7 @@
|
||||
<Compile Include="Beatmaps\Timing\SampleChange.cs" />
|
||||
<Compile Include="Beatmaps\Timing\TimingChange.cs" />
|
||||
<Compile Include="Configuration\OsuConfigManager.cs" />
|
||||
<Compile Include="GameModes\BackgroundMode.cs" />
|
||||
<Compile Include="GameModes\Charts\ChartInfo.cs" />
|
||||
<Compile Include="GameModes\Edit\Editor.cs" />
|
||||
<Compile Include="GameModes\GameModeWhiteBox.cs" />
|
||||
@ -78,6 +79,7 @@
|
||||
<Compile Include="GameModes\Multiplayer\Match.cs" />
|
||||
<Compile Include="GameModes\Multiplayer\MatchCreate.cs" />
|
||||
<Compile Include="GameModes\Multiplayer\MatchSongSelect.cs" />
|
||||
<Compile Include="GameModes\OsuGameMode.cs" />
|
||||
<Compile Include="GameModes\Play\ModSelect.cs" />
|
||||
<Compile Include="GameModes\Play\Player.cs" />
|
||||
<Compile Include="GameModes\Charts\ChartListing.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user