1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 14:52:55 +08:00
osu-lazer/osu.Game/Tests/Visual/ScreenTestScene.cs

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

99 lines
3.5 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 17:19:50 +08:00
using System;
2021-06-22 23:48:41 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Development;
2019-01-31 10:00:44 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Framework.Testing;
using osu.Game.Graphics;
2021-06-22 23:48:41 +08:00
using osu.Game.Overlays;
using osu.Game.Screens;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Tests.Visual
{
/// <summary>
/// A test case which can be used to test a screen (that relies on OnEntering being called to execute startup instructions).
/// </summary>
public abstract partial class ScreenTestScene : OsuManualInputManagerTestScene, IOverlayManager
{
protected readonly OsuScreenStack Stack;
2019-01-31 13:55:48 +08:00
private readonly Container content;
private readonly Container overlayContent;
protected override Container<Drawable> Content => content;
[Cached(typeof(IDialogOverlay))]
2021-06-22 23:48:41 +08:00
protected DialogOverlay DialogOverlay { get; private set; }
protected ScreenTestScene()
{
base.Content.AddRange(new Drawable[]
{
Stack = new OsuScreenStack
{
Name = nameof(ScreenTestScene),
RelativeSizeAxes = Axes.Both
},
2021-06-22 23:48:41 +08:00
content = new Container { RelativeSizeAxes = Axes.Both },
overlayContent = new Container
{
RelativeSizeAxes = Axes.Both,
Child = DialogOverlay = new DialogOverlay()
}
});
2022-06-24 20:25:23 +08:00
Stack.ScreenPushed += (_, newScreen) => Logger.Log($"{nameof(ScreenTestScene)} screen changed → {newScreen}");
Stack.ScreenExited += (_, newScreen) => Logger.Log($"{nameof(ScreenTestScene)} screen changed ← {newScreen}");
2019-01-31 10:00:44 +08:00
}
2018-04-13 17:19:50 +08:00
protected void LoadScreen(OsuScreen screen) => Stack.Push(screen);
[SetUpSteps]
public virtual void SetUpSteps() => addExitAllScreensStep();
2020-01-31 21:09:39 +08:00
[TearDownSteps]
public virtual void TearDownSteps()
{
if (DebugUtils.IsNUnitRunning)
addExitAllScreensStep();
}
private void addExitAllScreensStep()
2019-01-31 10:00:44 +08:00
{
AddUntilStep("exit all screens", () =>
{
if (Stack.CurrentScreen == null) return true;
Stack.Exit();
return false;
});
}
#region IOverlayManager
IBindable<OverlayActivation> IOverlayManager.OverlayActivationMode { get; } = new Bindable<OverlayActivation>(OverlayActivation.All);
// in the blocking methods below it is important to be careful about threading (e.g. use `Expire()` rather than `Remove()`, and schedule transforms),
// because in the worst case the clean-up methods could be called from async disposal.
IDisposable IOverlayManager.RegisterBlockingOverlay(OverlayContainer overlayContainer)
{
overlayContent.Add(overlayContainer);
return new InvokeOnDisposal(() => overlayContainer.Expire());
}
void IOverlayManager.ShowBlockingOverlay(OverlayContainer overlay)
=> Schedule(() => Stack.FadeColour(OsuColour.Gray(0.5f), 500, Easing.OutQuint));
void IOverlayManager.HideBlockingOverlay(OverlayContainer overlay)
=> Schedule(() => Stack.FadeColour(Colour4.White, 500, Easing.OutQuint));
#endregion
}
}