Better tests and implementation

This commit is contained in:
David Zhao 2019-03-26 10:48:29 +09:00
parent d37968d88d
commit a0f6718145
3 changed files with 109 additions and 26 deletions

View File

@ -9,7 +9,9 @@ using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
@ -18,6 +20,7 @@ using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens; using osu.Game.Screens;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
@ -36,6 +39,7 @@ namespace osu.Game.Tests.Visual
private readonly Bindable<float> uiScale = new Bindable<float>(); private readonly Bindable<float> uiScale = new Bindable<float>();
private TestScreen screen1;
private OsuScreen baseScreen; private OsuScreen baseScreen;
public TestCaseFacadeContainer() public TestCaseFacadeContainer()
@ -49,7 +53,6 @@ namespace osu.Game.Tests.Visual
baseScreen = null; baseScreen = null;
config.BindWith(OsuSetting.UIScale, uiScale); config.BindWith(OsuSetting.UIScale, uiScale);
AddSliderStep("Adjust scale", 1f, 1.5f, 1f, v => uiScale.Value = v); AddSliderStep("Adjust scale", 1f, 1.5f, 1f, v => uiScale.Value = v);
AddToggleStep("Toggle mods", b => { Beatmap.Value.Mods.Value = b ? Beatmap.Value.Mods.Value.Concat(new[] { new OsuModNoFail() }) : Enumerable.Empty<Mod>(); });
} }
[SetUpSteps] [SetUpSteps]
@ -58,9 +61,18 @@ namespace osu.Game.Tests.Visual
AddStep("Null screens", () => baseScreen = null); AddStep("Null screens", () => baseScreen = null);
} }
[Test]
public void IsolatedTest()
{
bool randomPositions = false;
AddToggleStep("Toggle move continuously", b => randomPositions = b);
AddStep("Move facade to random position", () => LoadScreen(screen1 = new TestScreen(randomPositions)));
}
[Test] [Test]
public void PlayerLoaderTest() public void PlayerLoaderTest()
{ {
AddToggleStep("Toggle mods", b => { Beatmap.Value.Mods.Value = b ? Beatmap.Value.Mods.Value.Concat(new[] { new OsuModNoFail() }) : Enumerable.Empty<Mod>(); });
AddStep("Add new playerloader", () => LoadScreen(baseScreen = new TestPlayerLoader(() => new TestPlayer AddStep("Add new playerloader", () => LoadScreen(baseScreen = new TestPlayerLoader(() => new TestPlayer
{ {
AllowPause = false, AllowPause = false,
@ -89,6 +101,67 @@ namespace osu.Game.Tests.Visual
}; };
} }
private class TestScreen : OsuScreen
{
private TestFacadeContainer facadeContainer;
private FacadeFlowComponent facadeFlowComponent;
private OsuLogo logo;
private readonly bool randomPositions;
public TestScreen(bool randomPositions = false)
{
this.randomPositions = randomPositions;
}
private SpriteText positionText;
private SpriteText sizeAxesText;
[BackgroundDependencyLoader]
private void load()
{
InternalChild = facadeContainer = new TestFacadeContainer
{
Child = facadeFlowComponent = new FacadeFlowComponent
{
AutoSizeAxes = Axes.Both
}
};
}
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
base.LogoArriving(logo, resuming);
logo.FadeIn(350);
logo.ScaleTo(new Vector2(0.15f), 350, Easing.In);
facadeContainer.SetLogo(logo);
moveLogoFacade();
}
private void moveLogoFacade()
{
Random random = new Random();
if (facadeFlowComponent.Transforms.Count == 0)
{
facadeFlowComponent.Delay(500).MoveTo(new Vector2(random.Next(0, 800), random.Next(0, 600)), 300);
}
if (randomPositions)
Schedule(moveLogoFacade);
}
}
private class FacadeFlowComponent : FillFlowContainer
{
[BackgroundDependencyLoader]
private void load(Facade facade)
{
facade.Anchor = Anchor.TopCentre;
facade.Origin = Anchor.TopCentre;
Child = facade;
}
}
private class TestPlayerLoader : PlayerLoader private class TestPlayerLoader : PlayerLoader
{ {
public TestPlayerLoader(Func<Player> player) public TestPlayerLoader(Func<Player> player)

View File

@ -1,10 +1,10 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.MathUtils;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using osuTK; using osuTK;
@ -18,7 +18,6 @@ namespace osu.Game.Graphics.Containers
private OsuLogo logo; private OsuLogo logo;
private bool tracking; private bool tracking;
private bool smoothTransform;
protected virtual Facade CreateFacade() => new Facade(); protected virtual Facade CreateFacade() => new Facade();
@ -29,7 +28,7 @@ namespace osu.Game.Graphics.Containers
private Vector2 logoTrackingPosition => logo.Parent.ToLocalSpace(facade.ScreenSpaceDrawQuad.Centre); private Vector2 logoTrackingPosition => logo.Parent.ToLocalSpace(facade.ScreenSpaceDrawQuad.Centre);
public void SetLogo(OsuLogo logo, bool resuming, double transformDelay) public void SetLogo(OsuLogo logo, double transformDelay = 0)
{ {
if (logo != null) if (logo != null)
{ {
@ -38,41 +37,53 @@ namespace osu.Game.Graphics.Containers
Scheduler.AddDelayed(() => Scheduler.AddDelayed(() =>
{ {
tracking = true; tracking = true;
smoothTransform = !resuming;
}, transformDelay); }, transformDelay);
} }
} }
private double startTime;
private double duration = 1000;
private Vector2 startPosition;
private Easing easing = Easing.InOutExpo;
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()
{ {
base.UpdateAfterChildren(); base.UpdateAfterChildren();
if (logo == null) if (logo == null || !tracking)
return; return;
facade.Size = new Vector2(logo.SizeForFlow * 0.3f); facade.Size = new Vector2(logo.SizeForFlow * 0.3f);
if (smoothTransform && facade.IsLoaded && logo.Transforms.Count == 0) if (facade.IsLoaded && logo.Position != logoTrackingPosition)
{ {
// Our initial movement to the tracking location should be smooth. if (logo.RelativePositionAxes != Axes.None)
Schedule(() =>
{ {
facade.Size = new Vector2(logo.SizeForFlow * 0.3f); logo.Position = logo.Parent.ToLocalSpace(logo.Position);
logo.RelativePositionAxes = Axes.None; logo.RelativePositionAxes = Axes.None;
logo.MoveTo(logoTrackingPosition, 500, Easing.InOutExpo); }
smoothTransform = false;
}); if (startTime == 0)
} {
else if (facade.IsLoaded && logo.Transforms.Count == 0) startTime = Time.Current;
{ }
// If all transforms have finished playing, the logo constantly track the position of the facade.
logo.RelativePositionAxes = Axes.None; var endTime = startTime + duration;
logo.Position = logoTrackingPosition; var remainingDuration = endTime - Time.Current;
if (remainingDuration <= 0)
{
remainingDuration = 0;
}
float currentTime = (float)Interpolation.ApplyEasing(easing, remainingDuration / duration);
logo.Position = Vector2.Lerp(logoTrackingPosition, startPosition, currentTime);
} }
} }
} }
public class Facade : Container
{
}
} }
public class Facade : Container
{
}

View File

@ -155,7 +155,7 @@ namespace osu.Game.Screens.Play
logo.MoveTo(new Vector2(0.5f), duration, Easing.In); logo.MoveTo(new Vector2(0.5f), duration, Easing.In);
logo.FadeIn(350); logo.FadeIn(350);
content.SetLogo(logo, resuming, duration); content.SetLogo(logo, duration);
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -167,7 +167,7 @@ namespace osu.Game.Screens.Play
private ScheduledDelegate pushDebounce; private ScheduledDelegate pushDebounce;
protected VisualSettings VisualSettings; protected VisualSettings VisualSettings;
// Hhere because IsHovered will not update unless we do so. // Here because IsHovered will not update unless we do so.
public override bool HandlePositionalInput => true; public override bool HandlePositionalInput => true;
private bool readyForPush => player.LoadState == LoadState.Ready && IsHovered && GetContainingInputManager()?.DraggedDrawable == null; private bool readyForPush => player.LoadState == LoadState.Ready && IsHovered && GetContainingInputManager()?.DraggedDrawable == null;
@ -306,7 +306,6 @@ namespace osu.Game.Screens.Play
private Sprite backgroundSprite; private Sprite backgroundSprite;
private ModDisplay modDisplay; private ModDisplay modDisplay;
private FillFlowContainer fillFlowContainer; private FillFlowContainer fillFlowContainer;
private FacadeContainer facadeContainer;
public bool Loading public bool Loading
{ {