osu/osu.Game/Screens/BackgroundMode.cs

97 lines
2.9 KiB
C#
Raw Normal View History

2016-10-05 07:35:10 +00:00
//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;
2016-11-14 08:23:33 +00:00
using System.Threading;
using osu.Framework;
using osu.Framework.Allocation;
2016-10-05 07:35:10 +00:00
using osu.Framework.GameModes;
using osu.Framework.Graphics;
2016-11-14 08:23:33 +00:00
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
2016-11-14 08:23:33 +00:00
using OpenTK;
2016-10-05 07:35:10 +00:00
2016-11-14 08:23:33 +00:00
namespace osu.Game.Screens
2016-10-05 07:35:10 +00:00
{
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;
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
//we don't want to handle escape key.
return false;
}
2016-11-01 14:24:14 +00:00
BaseGame game;
[BackgroundDependencyLoader]
private void load(BaseGame game)
2016-10-05 07:35:10 +00:00
{
2016-11-01 14:24:14 +00:00
this.game = game;
}
public override bool Push(GameMode mode)
{
// When trying to push a non-loaded GameMode, load it asynchronously and re-invoke Push
// once it's done.
if (mode.LoadState == LoadState.NotLoaded)
2016-11-01 14:24:14 +00:00
{
mode.Preload(game, d => Push((BackgroundMode)d));
return true;
}
2016-10-05 07:35:10 +00:00
// Make sure the in-progress loading is complete before pushing the GameMode.
while (mode.LoadState < LoadState.Loaded)
Thread.Sleep(1);
2016-11-01 14:24:14 +00:00
base.Push(mode);
return true;
}
protected override void Update()
{
base.Update();
Content.Scale = new Vector2(1 + (x_movement_amount / DrawSize.X) * 2);
2016-10-05 07:35:10 +00:00
}
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 bool OnExiting(GameMode next)
2016-10-05 07:35:10 +00:00
{
Content.FadeOut(transition_length, EasingTypes.OutExpo);
Content.MoveToX(x_movement_amount, transition_length, EasingTypes.OutExpo);
return base.OnExiting(next);
2016-10-05 07:35:10 +00:00
}
protected override void OnResuming(GameMode last)
{
Content.MoveToX(0, transition_length, EasingTypes.OutExpo);
base.OnResuming(last);
}
}
}