1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-06 15:57:19 +08:00
osu-lazer/osu.Game/Screens/BackgroundScreen.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
2.6 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 18:19:50 +09:00
2022-06-17 16:37:17 +09:00
#nullable disable
2016-10-05 16:35:10 +09:00
using System;
2017-02-17 18:59:30 +09:00
using osu.Framework.Screens;
using osu.Framework.Graphics;
2018-10-02 12:02:47 +09:00
using osu.Framework.Input.Events;
2018-11-20 16:51:59 +09:00
using osuTK;
2018-04-13 18:19:50 +09:00
2016-11-14 17:23:33 +09:00
namespace osu.Game.Screens
2016-10-05 16:35:10 +09:00
{
2017-02-17 18:59:30 +09:00
public abstract partial class BackgroundScreen : Screen, IEquatable<BackgroundScreen>
2016-10-05 16:35:10 +09:00
{
public const float TRANSITION_LENGTH = 500;
2021-08-20 17:50:49 +09:00
private const float x_movement_amount = 50;
public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks;
public bool AnimateEntry { get; set; } = true;
protected BackgroundScreen()
2019-01-23 20:52:00 +09:00
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}
2017-02-17 18:59:30 +09:00
public virtual bool Equals(BackgroundScreen other)
2016-10-05 16:35:10 +09:00
{
return other?.GetType() == GetType();
}
2018-04-13 18:19:50 +09:00
2018-10-02 12:02:47 +09:00
protected override bool OnKeyDown(KeyDownEvent e)
{
2020-05-04 18:31:11 -07:00
// we don't want to handle escape key.
return false;
}
2018-04-13 18:19:50 +09:00
/// <summary>
/// Apply arbitrary changes to this background in a thread safe manner.
/// </summary>
/// <param name="action">The operation to perform.</param>
public void ApplyToBackground(Action<BackgroundScreen> action) => Schedule(() => action.Invoke(this));
2016-11-01 23:24:14 +09:00
protected override void Update()
{
base.Update();
2019-01-23 20:52:00 +09:00
Scale = new Vector2(1 + x_movement_amount / DrawSize.X * 2);
2016-10-05 16:35:10 +09:00
}
2018-04-13 18:19:50 +09:00
public override void OnEntering(ScreenTransitionEvent e)
2016-10-05 16:35:10 +09:00
{
if (AnimateEntry)
2019-08-09 20:05:28 +09:00
{
this.FadeOut();
2021-08-20 17:50:49 +09:00
this.FadeIn(TRANSITION_LENGTH, Easing.InOutQuart);
this.MoveToX(x_movement_amount);
2021-08-20 17:50:49 +09:00
this.MoveToX(0, TRANSITION_LENGTH, Easing.InOutQuart);
2019-08-09 20:05:28 +09:00
}
2018-04-13 18:19:50 +09:00
base.OnEntering(e);
2016-10-05 16:35:10 +09:00
}
2018-04-13 18:19:50 +09:00
public override void OnSuspending(ScreenTransitionEvent e)
2016-10-05 16:35:10 +09:00
{
2021-08-20 17:50:49 +09:00
this.MoveToX(-x_movement_amount, TRANSITION_LENGTH, Easing.InOutQuart);
base.OnSuspending(e);
2016-10-05 16:35:10 +09:00
}
2018-04-13 18:19:50 +09:00
public override bool OnExiting(ScreenExitEvent e)
2016-10-05 16:35:10 +09:00
{
if (IsLoaded)
{
2021-08-20 17:50:49 +09:00
this.FadeOut(TRANSITION_LENGTH, Easing.OutExpo);
this.MoveToX(x_movement_amount, TRANSITION_LENGTH, Easing.OutExpo);
}
2018-04-13 18:19:50 +09:00
return base.OnExiting(e);
2016-10-05 16:35:10 +09:00
}
2018-04-13 18:19:50 +09:00
public override void OnResuming(ScreenTransitionEvent e)
2016-10-05 16:35:10 +09:00
{
if (IsLoaded)
2021-08-20 17:50:49 +09:00
this.MoveToX(0, TRANSITION_LENGTH, Easing.OutExpo);
base.OnResuming(e);
2016-10-05 16:35:10 +09:00
}
}
}