1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 03:02:53 +08:00
osu-lazer/osu.Game/Screens/BackgroundScreen.cs

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