2019-01-24 16:43:03 +08:00
|
|
|
|
// 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 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2016-10-05 15:35:10 +08:00
|
|
|
|
using System;
|
2017-02-17 17:59:30 +08:00
|
|
|
|
using osu.Framework.Screens;
|
2016-10-07 17:58:20 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-11-14 16:23:33 +08:00
|
|
|
|
namespace osu.Game.Screens
|
2016-10-05 15:35:10 +08:00
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public abstract partial class BackgroundScreen : Screen, IEquatable<BackgroundScreen>
|
2016-10-05 15:35:10 +08:00
|
|
|
|
{
|
2021-08-20 16:50:49 +08:00
|
|
|
|
protected const float TRANSITION_LENGTH = 500;
|
|
|
|
|
private const float x_movement_amount = 50;
|
|
|
|
|
|
2019-08-09 19:05:28 +08:00
|
|
|
|
private readonly bool animateOnEnter;
|
|
|
|
|
|
2021-03-08 12:29:09 +08:00
|
|
|
|
public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks;
|
|
|
|
|
|
2019-08-09 19:05:28 +08:00
|
|
|
|
protected BackgroundScreen(bool animateOnEnter = true)
|
2019-01-23 19:52:00 +08:00
|
|
|
|
{
|
2019-08-09 19:05:28 +08:00
|
|
|
|
this.animateOnEnter = animateOnEnter;
|
2019-01-23 19:52:00 +08:00
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2016-10-07 17:58:59 +08:00
|
|
|
|
{
|
2020-05-05 09:31:11 +08:00
|
|
|
|
// we don't want to handle escape key.
|
2016-10-07 17:58:59 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-01-06 14:26:13 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Apply arbitrary changes to this background in a thread safe manner.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="action">The operation to perform.</param>
|
2021-01-04 17:32:23 +08:00
|
|
|
|
public void ApplyToBackground(Action<BackgroundScreen> action) => Schedule(() => action.Invoke(this));
|
|
|
|
|
|
2016-11-01 22:24:14 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2019-01-23 19:52:00 +08:00
|
|
|
|
Scale = new Vector2(1 + x_movement_amount / DrawSize.X * 2);
|
2016-10-05 15:35:10 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
|
public override void OnEntering(ScreenTransitionEvent e)
|
2016-10-05 15:35:10 +08:00
|
|
|
|
{
|
2019-08-09 19:05:28 +08:00
|
|
|
|
if (animateOnEnter)
|
|
|
|
|
{
|
|
|
|
|
this.FadeOut();
|
|
|
|
|
this.MoveToX(x_movement_amount);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-08-20 16:50:49 +08:00
|
|
|
|
this.FadeIn(TRANSITION_LENGTH, Easing.InOutQuart);
|
|
|
|
|
this.MoveToX(0, TRANSITION_LENGTH, Easing.InOutQuart);
|
2019-08-09 19:05:28 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
|
base.OnEntering(e);
|
2016-10-05 15:35:10 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
|
public override void OnSuspending(ScreenTransitionEvent e)
|
2016-10-05 15:35:10 +08:00
|
|
|
|
{
|
2021-08-20 16:50:49 +08:00
|
|
|
|
this.MoveToX(-x_movement_amount, TRANSITION_LENGTH, Easing.InOutQuart);
|
2022-04-21 23:52:44 +08:00
|
|
|
|
base.OnSuspending(e);
|
2016-10-05 15:35:10 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
2016-10-05 15:35:10 +08:00
|
|
|
|
{
|
2021-02-15 16:14:41 +08:00
|
|
|
|
if (IsLoaded)
|
|
|
|
|
{
|
2021-08-20 16:50:49 +08:00
|
|
|
|
this.FadeOut(TRANSITION_LENGTH, Easing.OutExpo);
|
|
|
|
|
this.MoveToX(x_movement_amount, TRANSITION_LENGTH, Easing.OutExpo);
|
2021-02-15 16:14:41 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
|
return base.OnExiting(e);
|
2016-10-05 15:35:10 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
|
public override void OnResuming(ScreenTransitionEvent e)
|
2016-10-05 15:35:10 +08:00
|
|
|
|
{
|
2021-02-15 16:14:41 +08:00
|
|
|
|
if (IsLoaded)
|
2021-08-20 16:50:49 +08:00
|
|
|
|
this.MoveToX(0, TRANSITION_LENGTH, Easing.OutExpo);
|
2022-04-21 23:52:44 +08:00
|
|
|
|
base.OnResuming(e);
|
2016-10-05 15:35:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|