1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 11:27:24 +08:00
osu-lazer/osu.Game/Screens/BackgroundScreen.cs

96 lines
2.9 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;
using osu.Framework.Allocation;
2017-02-17 17:59:30 +08:00
using osu.Framework.Screens;
using osu.Framework.Graphics;
2017-02-25 20:12:39 +08:00
using osu.Framework.Graphics.Transforms;
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-03-07 09:59:19 +08:00
private Framework.Game game;
2016-11-01 22:24:14 +08:00
[BackgroundDependencyLoader]
2017-02-23 14:38:17 +08:00
private void load(Framework.Game game)
2016-10-05 15:35:10 +08:00
{
2016-11-01 22:24:14 +08:00
this.game = game;
}
2017-02-17 17:59:30 +08:00
public override bool Push(Screen screen)
2016-11-01 22:24:14 +08:00
{
// When trying to push a non-loaded GameMode, 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
{
screen.LoadAsync(game, d => Push((BackgroundScreen)d));
2016-11-01 22:24:14 +08:00
return true;
}
2016-10-05 15:35:10 +08:00
// Make sure the in-progress loading is complete before pushing the GameMode.
2017-02-17 17:59:30 +08:00
while (screen.LoadState < LoadState.Loaded)
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);
Content.FadeIn(transition_length, EasingTypes.InOutQuart);
Content.MoveToX(0, transition_length, EasingTypes.InOutQuart);
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
{
Content.MoveToX(-x_movement_amount, transition_length, EasingTypes.InOutQuart);
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
{
Content.FadeOut(transition_length, EasingTypes.OutExpo);
Content.MoveToX(x_movement_amount, transition_length, EasingTypes.OutExpo);
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
{
Content.MoveToX(0, transition_length, EasingTypes.OutExpo);
base.OnResuming(last);
}
}
}