osu/osu.Game/Screens/BackgroundScreen.cs

86 lines
2.6 KiB
C#
Raw Normal View History

2018-01-05 11:21:19 +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
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.
while (screen.LoadState < LoadState.Ready)
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);
2017-07-22 18:50:25 +00:00
Content.FadeIn(transition_length, Easing.InOutQuart);
Content.MoveToX(0, transition_length, Easing.InOutQuart);
2016-10-05 07:35:10 +00:00
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
{
2017-07-22 18:50:25 +00:00
Content.MoveToX(-x_movement_amount, transition_length, Easing.InOutQuart);
2016-10-05 07:35:10 +00:00
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
{
2017-07-22 18:50:25 +00:00
Content.FadeOut(transition_length, Easing.OutExpo);
Content.MoveToX(x_movement_amount, transition_length, Easing.OutExpo);
2016-10-05 07:35:10 +00:00
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
{
2017-07-22 18:50:25 +00:00
Content.MoveToX(0, transition_length, Easing.OutExpo);
2016-10-05 07:35:10 +00:00
base.OnResuming(last);
}
}
}