mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 16:52:54 +08:00
Add new automated tests for logofacade, reset interpolation
This commit is contained in:
parent
2e3791be1c
commit
061527a260
@ -7,8 +7,10 @@ using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Screens;
|
||||
@ -25,7 +27,6 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
typeof(PlayerLoader),
|
||||
typeof(Player),
|
||||
typeof(LogoFacadeContainer.Facade),
|
||||
typeof(LogoFacadeContainer),
|
||||
typeof(ButtonSystem),
|
||||
typeof(ButtonSystemState),
|
||||
@ -47,36 +48,65 @@ namespace osu.Game.Tests.Visual
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
config.BindWith(OsuSetting.UIScale, uiScale);
|
||||
AddSliderStep("Adjust scale", 1f, 1.5f, 1f, v => uiScale.Value = v);
|
||||
AddSliderStep("Adjust scale", 0.8f, 1.5f, 1f, v => uiScale.Value = v);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move the facade to 0,0, then move it to a random new location while the logo is still transforming to it.
|
||||
/// Check if the logo is still tracking the facade.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void IsolatedTest()
|
||||
public void MoveFacadeTest()
|
||||
{
|
||||
TestScreen screen = null;
|
||||
bool randomPositions = false;
|
||||
AddToggleStep("Toggle move continuously", b => randomPositions = b);
|
||||
AddStep("Move facade to random position", () => LoadScreen(new TestScreen(randomPositions)));
|
||||
AddStep("Move facade to random position", () => LoadScreen(screen = new TestScreen(randomPositions)));
|
||||
AddUntilStep("Screen is current", () => screen.IsCurrentScreen());
|
||||
waitForMove();
|
||||
AddAssert("Logo is tracking", () => screen.IsLogoTracking);
|
||||
}
|
||||
|
||||
private class TestLogoFacadeContainer : LogoFacadeContainer
|
||||
/// <summary>
|
||||
/// Check if the facade is removed from the container, the logo stops tracking.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void RemoveFacadeTest()
|
||||
{
|
||||
protected override Facade CreateFacade() => new Facade
|
||||
{
|
||||
Colour = Color4.Tomato,
|
||||
Alpha = 0.35f,
|
||||
Child = new Box
|
||||
{
|
||||
Colour = Color4.Tomato,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
};
|
||||
TestScreen screen = null;
|
||||
AddStep("Move facade to random position", () => LoadScreen(screen = new TestScreen()));
|
||||
AddUntilStep("Screen is current", () => screen.IsCurrentScreen());
|
||||
AddStep("Remove facade from FacadeContainer", () => screen.RemoveFacade());
|
||||
waitForMove();
|
||||
AddAssert("Logo is not tracking", () => !screen.IsLogoTracking);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the facade gets added to a new container, tracking starts on the new facade.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TransferFacadeTest()
|
||||
{
|
||||
TestScreen screen = null;
|
||||
AddStep("Move facade to random position", () => LoadScreen(screen = new TestScreen()));
|
||||
AddUntilStep("Screen is current", () => screen.IsCurrentScreen());
|
||||
AddStep("Remove facade from FacadeContainer", () => screen.RemoveFacade());
|
||||
AddStep("Transfer facade to a new container", () => screen.TransferFacade());
|
||||
waitForMove();
|
||||
AddAssert("Logo is tracking", () => screen.IsLogoTracking);
|
||||
}
|
||||
|
||||
private void waitForMove() => AddWaitStep("Wait for transforms to finish", 5);
|
||||
|
||||
private class TestScreen : OsuScreen
|
||||
{
|
||||
private TestLogoFacadeContainer logoFacadeContainer;
|
||||
private LogoFacadeContainer.Facade facadeFlowComponent;
|
||||
private LogoFacadeContainer logoFacadeContainer;
|
||||
private Container transferContainer;
|
||||
private Container logoFacade;
|
||||
private readonly bool randomPositions;
|
||||
private OsuLogo logo;
|
||||
private Box visualBox;
|
||||
private Box transferContainerBox;
|
||||
|
||||
public TestScreen(bool randomPositions = false)
|
||||
{
|
||||
@ -86,13 +116,55 @@ namespace osu.Game.Tests.Visual
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
InternalChild = logoFacadeContainer = new TestLogoFacadeContainer();
|
||||
logoFacadeContainer.Child = facadeFlowComponent = logoFacadeContainer.LogoFacade;
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
logoFacadeContainer = new LogoFacadeContainer
|
||||
{
|
||||
Alpha = 0.35f,
|
||||
RelativeSizeAxes = Axes.None,
|
||||
Size = new Vector2(107),
|
||||
Child = visualBox = new Box
|
||||
{
|
||||
Colour = Color4.Tomato,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
},
|
||||
transferContainer = new Container
|
||||
{
|
||||
Alpha = 0.35f,
|
||||
RelativeSizeAxes = Axes.None,
|
||||
Size = new Vector2(107),
|
||||
Child = transferContainerBox = new Box
|
||||
{
|
||||
Colour = Color4.White,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
logoFacadeContainer.Add(logoFacade = logoFacadeContainer.LogoFacade);
|
||||
}
|
||||
|
||||
public bool IsLogoTracking => logo.Position == logo.Parent.ToLocalSpace(logoFacadeContainer.LogoFacade.ScreenSpaceDrawQuad.Centre);
|
||||
|
||||
public void RemoveFacade()
|
||||
{
|
||||
logoFacadeContainer.Remove(logoFacade);
|
||||
visualBox.Colour = Color4.White;
|
||||
moveLogoFacade();
|
||||
}
|
||||
|
||||
public void TransferFacade()
|
||||
{
|
||||
transferContainer.Add(logoFacade);
|
||||
transferContainerBox.Colour = Color4.Tomato;
|
||||
moveLogoFacade();
|
||||
}
|
||||
|
||||
protected override void LogoArriving(OsuLogo logo, bool resuming)
|
||||
{
|
||||
base.LogoArriving(logo, resuming);
|
||||
this.logo = logo;
|
||||
logo.FadeIn(350);
|
||||
logo.ScaleTo(new Vector2(0.15f), 350, Easing.In);
|
||||
logoFacadeContainer.SetLogo(logo, 0.3f, 1000, Easing.InOutQuint);
|
||||
@ -109,9 +181,10 @@ namespace osu.Game.Tests.Visual
|
||||
private void moveLogoFacade()
|
||||
{
|
||||
Random random = new Random();
|
||||
if (facadeFlowComponent.Transforms.Count == 0)
|
||||
if (logoFacade.Transforms.Count == 0 && transferContainer.Transforms.Count == 0)
|
||||
{
|
||||
facadeFlowComponent.Delay(500).MoveTo(new Vector2(random.Next(0, (int)DrawWidth), random.Next(0, (int)DrawHeight)), 300);
|
||||
logoFacadeContainer.Delay(500).MoveTo(new Vector2(random.Next(0, (int)DrawWidth), random.Next(0, (int)DrawHeight)), 300);
|
||||
transferContainer.Delay(500).MoveTo(new Vector2(random.Next(0, (int)DrawWidth), random.Next(0, (int)DrawHeight)), 300);
|
||||
}
|
||||
|
||||
if (randomPositions)
|
||||
|
@ -26,8 +26,8 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
private OsuLogo logo;
|
||||
private float facadeScale;
|
||||
private Vector2 startPosition;
|
||||
private Easing easing;
|
||||
private Vector2? startPosition;
|
||||
private double? startTime;
|
||||
private double duration;
|
||||
|
||||
@ -49,6 +49,9 @@ namespace osu.Game.Graphics.Containers
|
||||
this.facadeScale = facadeScale;
|
||||
this.duration = duration;
|
||||
this.easing = easing;
|
||||
|
||||
startTime = null;
|
||||
startPosition = null;
|
||||
}
|
||||
|
||||
private Vector2 logoTrackingPosition => logo.Parent.ToLocalSpace(LogoFacade.ScreenSpaceDrawQuad.Centre);
|
||||
@ -68,7 +71,7 @@ namespace osu.Game.Graphics.Containers
|
||||
logo.RelativePositionAxes = Axes.None;
|
||||
|
||||
// If this is our first update since tracking has started, initialize our starting values for interpolation
|
||||
if (startTime == null)
|
||||
if (startTime == null || startPosition == null)
|
||||
{
|
||||
startTime = Time.Current;
|
||||
startPosition = logo.Position;
|
||||
@ -76,12 +79,12 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
if (duration != 0)
|
||||
{
|
||||
double elapsedDuration = Time.Current - startTime ?? 0;
|
||||
double elapsedDuration = Time.Current - startTime ?? throw new ArgumentNullException(nameof(startTime));
|
||||
|
||||
var mount = (float)Interpolation.ApplyEasing(easing, Math.Min(elapsedDuration / duration, 1));
|
||||
|
||||
// Interpolate the position of the logo, where mount 0 is where the logo was when it first began interpolating, and mount 1 is the target location.
|
||||
logo.Position = Vector2.Lerp(startPosition, logoTrackingPosition, mount);
|
||||
logo.Position = Vector2.Lerp(startPosition ?? throw new ArgumentNullException(nameof(startPosition)), logoTrackingPosition, mount);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -311,7 +311,7 @@ namespace osu.Game.Screens.Play
|
||||
}
|
||||
|
||||
private readonly WorkingBeatmap beatmap;
|
||||
private readonly LogoFacadeContainer.Facade facade;
|
||||
private readonly Container facade;
|
||||
private LoadingAnimation loading;
|
||||
private Sprite backgroundSprite;
|
||||
private ModDisplay modDisplay;
|
||||
@ -333,7 +333,7 @@ namespace osu.Game.Screens.Play
|
||||
}
|
||||
}
|
||||
|
||||
public BeatmapMetadataDisplay(WorkingBeatmap beatmap, LogoFacadeContainer.Facade facade)
|
||||
public BeatmapMetadataDisplay(WorkingBeatmap beatmap, Container facade)
|
||||
{
|
||||
this.beatmap = beatmap;
|
||||
this.facade = facade;
|
||||
|
Loading…
Reference in New Issue
Block a user