osu/osu.Game/Screens/BackgroundScreen.cs

86 lines
2.7 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-10-05 07:35:10 +00:00
using System;
2016-11-14 08:23:33 +00:00
using System.Threading;
2017-02-17 09:59:30 +00:00
using osu.Framework.Screens;
using osu.Framework.Graphics;
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
{
2017-02-17 09:59:30 +00:00
public abstract class BackgroundScreen : Screen, IEquatable<BackgroundScreen>
2016-10-05 07:35:10 +00:00
{
2017-02-17 09:59:30 +00:00
public virtual bool Equals(BackgroundScreen other)
2016-10-05 07:35:10 +00:00
{
return other?.GetType() == GetType();
}
2017-03-07 01:59:19 +00:00
private const float transition_length = 500;
private const float x_movement_amount = 50;
2016-10-05 07:35:10 +00:00
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
//we don't want to handle escape key.
return false;
}
2017-02-17 09:59:30 +00:00
public override bool Push(Screen screen)
2016-11-01 14:24:14 +00:00
{
2017-04-18 07:05:58 +00:00
// When trying to push a non-loaded screen, load it asynchronously and re-invoke Push
// once it's done.
2017-02-17 09:59:30 +00:00
if (screen.LoadState == LoadState.NotLoaded)
2016-11-01 14:24:14 +00:00
{
2017-04-02 06:56:12 +00:00
LoadComponentAsync(screen, d => Push((BackgroundScreen)d));
2016-11-01 14:24:14 +00:00
return true;
}
2016-10-05 07:35:10 +00:00
2017-04-18 07:05:58 +00:00
// Make sure the in-progress loading is complete before pushing the screen.
2017-02-17 09:59:30 +00:00
while (screen.LoadState < LoadState.Loaded)
Thread.Sleep(1);
2017-02-17 09:59:30 +00:00
base.Push(screen);
2016-11-01 14:24:14 +00:00
return true;
}
protected override void Update()
{
base.Update();
2017-03-07 01:59:19 +00:00
Content.Scale = new Vector2(1 + x_movement_amount / DrawSize.X * 2);
2016-10-05 07:35:10 +00:00
}
2017-02-17 09:59:30 +00:00
protected override void OnEntering(Screen last)
2016-10-05 07:35:10 +00:00
{
Content.FadeOut();
Content.MoveToX(x_movement_amount);
Content.FadeIn(transition_length, EasingTypes.InOutQuart);
Content.MoveToX(0, transition_length, EasingTypes.InOutQuart);
base.OnEntering(last);
}
2017-02-17 09:59:30 +00:00
protected override void OnSuspending(Screen next)
2016-10-05 07:35:10 +00:00
{
Content.MoveToX(-x_movement_amount, transition_length, EasingTypes.InOutQuart);
base.OnSuspending(next);
}
2017-02-17 09:59:30 +00:00
protected override bool OnExiting(Screen 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
}
2017-02-17 09:59:30 +00:00
protected override void OnResuming(Screen last)
2016-10-05 07:35:10 +00:00
{
Content.MoveToX(0, transition_length, EasingTypes.OutExpo);
base.OnResuming(last);
}
}
}