Files
Ez2Lazer/osu.Game/Tests/Visual/ScreenTestScene.cs
Krzysztof Gutkowski b88cba0829 Refactor TestSceneScreenFooter to test entire OsuScreens (#36718)
Part of the `ScreenFooter` refactor, which intends to move the footer
content handling to `OsuScreen`. This commit updates the `ScreenFooter`
test to operate on entire `OsuScreen`s, in order to better test the
entire flow of pushing a screen, and having it create and add its own
content to the footer.

This should be 80-90% identical to the original test case structure
wise, just that instead of manually manipulating the footer with
`SetButtons()`, various screens with the appropriate buttons are being
moved around the screen stack.

Additionally this adds some more tests handling common use cases, as
well as removes `TestLoadOverlayAfterFooterIsDisplayed()`, since as far
as I understand the behaviour described in it doesn't actually happen in
production code. From what I can see, Screens instantiate their overlays
in `load()`, and then register them in `LoadComplete()`. There seems to
be no case where a `ShearedOverlayContainer` is created in the middle of
a screen's lifecycle.
2026-03-01 22:36:07 +09:00

124 lines
4.5 KiB
C#

// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Development;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Logging;
using osu.Framework.Testing;
using osu.Game.Graphics;
using osu.Game.Overlays;
using osu.Game.Screens;
using osu.Game.Screens.Footer;
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;
private readonly Container content;
private readonly Container overlayContent;
protected override Container<Drawable> Content => content;
[Cached(typeof(IDialogOverlay))]
protected DialogOverlay DialogOverlay { get; private set; }
[Cached]
protected ScreenFooter ScreenFooter { get; private set; }
protected ScreenTestScene()
{
ScreenStackFooter screenStackFooter;
ScreenFooter.BackReceptor backReceptor;
base.Content.AddRange(new Drawable[]
{
backReceptor = new ScreenFooter.BackReceptor(),
new PopoverContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
Stack = new OsuScreenStack
{
Name = nameof(ScreenTestScene),
RelativeSizeAxes = Axes.Both
},
// TODO: is this ever used? it probably shouldn't be.
content = new Container { RelativeSizeAxes = Axes.Both },
overlayContent = new Container
{
RelativeSizeAxes = Axes.Both,
Child = DialogOverlay = new DialogOverlay()
},
screenStackFooter = new ScreenStackFooter(Stack, backReceptor)
{
BackButtonPressed = BackButtonPressed,
}
}
},
});
ScreenFooter = screenStackFooter.Footer;
Stack.ScreenPushed += (_, newScreen) => Logger.Log($"{nameof(ScreenTestScene)} screen changed → {newScreen}");
Stack.ScreenExited += (_, newScreen) => Logger.Log($"{nameof(ScreenTestScene)} screen changed ← {newScreen}");
}
protected virtual void BackButtonPressed() => Stack.Exit();
protected void LoadScreen(OsuScreen screen) => Stack.Push(screen);
[SetUpSteps]
public virtual void SetUpSteps() => addExitAllScreensStep();
[TearDownSteps]
public virtual void TearDownSteps()
{
if (DebugUtils.IsNUnitRunning)
addExitAllScreensStep();
}
private void addExitAllScreensStep()
{
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
}
}