2018-04-13 09:19:50 +00:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
|
using osu.Framework.Graphics;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens
|
|
|
|
|
{
|
|
|
|
|
public abstract class BackgroundScreen : Screen, IEquatable<BackgroundScreen>
|
|
|
|
|
{
|
|
|
|
|
public virtual bool Equals(BackgroundScreen other)
|
|
|
|
|
{
|
|
|
|
|
return other?.GetType() == GetType();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private const float transition_length = 500;
|
|
|
|
|
private const float x_movement_amount = 50;
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
//we don't want to handle escape key.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-20 07:52:15 +00:00
|
|
|
|
public override void Push(Screen screen)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
// When trying to push a non-loaded screen, load it asynchronously and re-invoke Push
|
|
|
|
|
// once it's done.
|
|
|
|
|
if (screen.LoadState == LoadState.NotLoaded)
|
|
|
|
|
{
|
|
|
|
|
LoadComponentAsync(screen, d => Push((BackgroundScreen)d));
|
2018-04-20 07:52:15 +00:00
|
|
|
|
return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the in-progress loading is complete before pushing the screen.
|
2018-06-29 11:16:24 +00:00
|
|
|
|
while (screen.LoadState < LoadState.Ready)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Thread.Sleep(1);
|
|
|
|
|
|
2018-06-20 03:43:48 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
base.Push(screen);
|
|
|
|
|
}
|
2018-06-29 11:13:29 +00:00
|
|
|
|
catch (ScreenAlreadyExitedException)
|
2018-06-20 03:43:48 +00:00
|
|
|
|
{
|
|
|
|
|
// screen may have exited before the push was successful.
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
Content.Scale = new Vector2(1 + x_movement_amount / DrawSize.X * 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnEntering(Screen last)
|
|
|
|
|
{
|
|
|
|
|
Content.FadeOut();
|
|
|
|
|
Content.MoveToX(x_movement_amount);
|
|
|
|
|
|
|
|
|
|
Content.FadeIn(transition_length, Easing.InOutQuart);
|
|
|
|
|
Content.MoveToX(0, transition_length, Easing.InOutQuart);
|
|
|
|
|
|
|
|
|
|
base.OnEntering(last);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnSuspending(Screen next)
|
|
|
|
|
{
|
|
|
|
|
Content.MoveToX(-x_movement_amount, transition_length, Easing.InOutQuart);
|
|
|
|
|
base.OnSuspending(next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnExiting(Screen next)
|
|
|
|
|
{
|
|
|
|
|
Content.FadeOut(transition_length, Easing.OutExpo);
|
|
|
|
|
Content.MoveToX(x_movement_amount, transition_length, Easing.OutExpo);
|
|
|
|
|
|
|
|
|
|
return base.OnExiting(next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnResuming(Screen last)
|
|
|
|
|
{
|
|
|
|
|
Content.MoveToX(0, transition_length, Easing.OutExpo);
|
|
|
|
|
base.OnResuming(last);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|