osu/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 07:35:10 +00:00
using System;
2016-11-14 08:23:33 +00:00
using System.Threading;
using osu.Framework.Allocation;
2017-02-17 09:59:30 +00:00
using osu.Framework.Screens;
using osu.Framework.Graphics;
2017-02-25 12:12:39 +00:00
using osu.Framework.Graphics.Transforms;
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();
}
const float transition_length = 500;
const float x_movement_amount = 50;
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
//we don't want to handle escape key.
return false;
}
2017-02-23 06:38:17 +00:00
Framework.Game game;
2016-11-01 14:24:14 +00:00
[BackgroundDependencyLoader]
2017-02-23 06:38:17 +00:00
private void load(Framework.Game game)
2016-10-05 07:35:10 +00:00
{
2016-11-01 14:24:14 +00:00
this.game = game;
}
2017-02-17 09:59:30 +00:00
public override bool Push(Screen screen)
2016-11-01 14:24:14 +00:00
{
// When trying to push a non-loaded GameMode, 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
{
screen.LoadAsync(game, d => Push((BackgroundScreen)d));
2016-11-01 14:24:14 +00:00
return true;
}
2016-10-05 07:35:10 +00:00
// Make sure the in-progress loading is complete before pushing the GameMode.
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();
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);
}
}
}