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
|
|
|
|
|
|
2022-05-05 22:31:02 +08:00
|
|
|
|
using System;
|
2021-06-22 23:48:41 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2022-05-05 22:31:02 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2022-01-24 15:40:16 +08:00
|
|
|
|
using osu.Framework.Development;
|
2019-01-31 10:00:44 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-03-29 13:34:58 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-10-05 17:53:20 +08:00
|
|
|
|
using osu.Framework.Logging;
|
2020-01-31 12:54:26 +08:00
|
|
|
|
using osu.Framework.Testing;
|
2022-05-05 22:31:02 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2021-06-22 23:48:41 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Screens;
|
|
|
|
|
|
|
|
|
|
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>
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public abstract partial class ScreenTestScene : OsuManualInputManagerTestScene, IOverlayManager
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-12-10 01:30:23 +08:00
|
|
|
|
protected readonly OsuScreenStack Stack;
|
2019-01-31 13:55:48 +08:00
|
|
|
|
|
2019-03-29 13:34:58 +08:00
|
|
|
|
private readonly Container content;
|
2022-05-05 22:31:02 +08:00
|
|
|
|
private readonly Container overlayContent;
|
2019-03-29 13:34:58 +08:00
|
|
|
|
|
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
|
2022-04-18 17:09:14 +08:00
|
|
|
|
[Cached(typeof(IDialogOverlay))]
|
2021-06-22 23:48:41 +08:00
|
|
|
|
protected DialogOverlay DialogOverlay { get; private set; }
|
|
|
|
|
|
2019-05-15 03:37:25 +08:00
|
|
|
|
protected ScreenTestScene()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-03-29 13:34:58 +08:00
|
|
|
|
base.Content.AddRange(new Drawable[]
|
|
|
|
|
{
|
2021-12-20 17:24:14 +08:00
|
|
|
|
Stack = new OsuScreenStack
|
|
|
|
|
{
|
|
|
|
|
Name = nameof(ScreenTestScene),
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
2021-06-22 23:48:41 +08:00
|
|
|
|
content = new Container { RelativeSizeAxes = Axes.Both },
|
2022-05-05 22:31:02 +08:00
|
|
|
|
overlayContent = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Child = DialogOverlay = new DialogOverlay()
|
|
|
|
|
}
|
2019-03-29 13:34:58 +08:00
|
|
|
|
});
|
2021-10-05 17:53:20 +08:00
|
|
|
|
|
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
|
|
|
|
|
2020-01-31 12:54:26 +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]
|
2022-01-24 15:40:16 +08:00
|
|
|
|
public virtual void TearDownSteps()
|
|
|
|
|
{
|
|
|
|
|
if (DebugUtils.IsNUnitRunning)
|
|
|
|
|
addExitAllScreensStep();
|
|
|
|
|
}
|
2020-01-31 12:54:26 +08:00
|
|
|
|
|
|
|
|
|
private void addExitAllScreensStep()
|
2019-01-31 10:00:44 +08:00
|
|
|
|
{
|
2020-01-31 12:54:26 +08:00
|
|
|
|
AddUntilStep("exit all screens", () =>
|
|
|
|
|
{
|
|
|
|
|
if (Stack.CurrentScreen == null) return true;
|
|
|
|
|
|
2019-12-10 01:30:23 +08:00
|
|
|
|
Stack.Exit();
|
2020-01-31 12:54:26 +08:00
|
|
|
|
return false;
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2022-05-05 22:31:02 +08:00
|
|
|
|
|
|
|
|
|
#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
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|