Implement `IOverlayManager` in `ScreenTestScene`

This commit is contained in:
Bartłomiej Dach 2022-05-05 16:31:02 +02:00
parent a56eab2c47
commit fdb21fedab
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
1 changed files with 31 additions and 2 deletions

View File

@ -1,12 +1,15 @@
// 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.Logging;
using osu.Framework.Testing;
using osu.Game.Graphics;
using osu.Game.Overlays;
using osu.Game.Screens;
@ -15,11 +18,12 @@ 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 class ScreenTestScene : OsuManualInputManagerTestScene
public abstract class ScreenTestScene : OsuManualInputManagerTestScene, IOverlayManager
{
protected readonly OsuScreenStack Stack;
private readonly Container content;
private readonly Container overlayContent;
protected override Container<Drawable> Content => content;
@ -36,7 +40,11 @@ protected ScreenTestScene()
RelativeSizeAxes = Axes.Both
},
content = new Container { RelativeSizeAxes = Axes.Both },
DialogOverlay = new DialogOverlay()
overlayContent = new Container
{
RelativeSizeAxes = Axes.Both,
Child = DialogOverlay = new DialogOverlay()
}
});
Stack.ScreenPushed += (lastScreen, newScreen) => Logger.Log($"{nameof(ScreenTestScene)} screen changed → {newScreen}");
@ -65,5 +73,26 @@ private void addExitAllScreensStep()
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
}
}