1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 07:27:25 +08:00

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.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
@ -18,6 +20,7 @@ using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Play;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual
@ -36,6 +39,7 @@ namespace osu.Game.Tests.Visual
private readonly Bindable<float> uiScale = new Bindable<float>();
private TestScreen screen1;
private OsuScreen baseScreen;
public TestCaseFacadeContainer()
@ -49,7 +53,6 @@ namespace osu.Game.Tests.Visual
baseScreen = null;
config.BindWith(OsuSetting.UIScale, uiScale);
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]
@ -58,9 +61,18 @@ namespace osu.Game.Tests.Visual
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]
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
{
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
{
public TestPlayerLoader(Func<Player> player)

View File

@ -1,10 +1,10 @@
// 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.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.MathUtils;
using osu.Game.Screens.Menu;
using osuTK;
@ -18,7 +18,6 @@ namespace osu.Game.Graphics.Containers
private OsuLogo logo;
private bool tracking;
private bool smoothTransform;
protected virtual Facade CreateFacade() => new Facade();
@ -29,7 +28,7 @@ namespace osu.Game.Graphics.Containers
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)
{
@ -38,41 +37,53 @@ namespace osu.Game.Graphics.Containers
Scheduler.AddDelayed(() =>
{
tracking = true;
smoothTransform = !resuming;
}, transformDelay);
}
}
private double startTime;
private double duration = 1000;
private Vector2 startPosition;
private Easing easing = Easing.InOutExpo;
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
if (logo == null)
if (logo == null || !tracking)
return;
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.
Schedule(() =>
if (logo.RelativePositionAxes != Axes.None)
{
facade.Size = new Vector2(logo.SizeForFlow * 0.3f);
logo.Position = logo.Parent.ToLocalSpace(logo.Position);
logo.RelativePositionAxes = Axes.None;
logo.MoveTo(logoTrackingPosition, 500, Easing.InOutExpo);
smoothTransform = false;
});
}
else if (facade.IsLoaded && logo.Transforms.Count == 0)
{
// If all transforms have finished playing, the logo constantly track the position of the facade.
logo.RelativePositionAxes = Axes.None;
logo.Position = logoTrackingPosition;
}
if (startTime == 0)
{
startTime = Time.Current;
}
var endTime = startTime + duration;
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.FadeIn(350);
content.SetLogo(logo, resuming, duration);
content.SetLogo(logo, duration);
}
protected override void LoadComplete()
@ -167,7 +167,7 @@ namespace osu.Game.Screens.Play
private ScheduledDelegate pushDebounce;
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;
private bool readyForPush => player.LoadState == LoadState.Ready && IsHovered && GetContainingInputManager()?.DraggedDrawable == null;
@ -306,7 +306,6 @@ namespace osu.Game.Screens.Play
private Sprite backgroundSprite;
private ModDisplay modDisplay;
private FillFlowContainer fillFlowContainer;
private FacadeContainer facadeContainer;
public bool Loading
{