2019-03-24 06:18:38 +00:00
|
|
|
// 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;
|
2020-08-04 12:16:59 +00:00
|
|
|
using System.Linq;
|
2019-03-24 06:18:38 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
2019-03-27 11:04:01 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-03-24 06:18:38 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-01-09 04:43:44 +00:00
|
|
|
using osu.Framework.Utils;
|
2019-04-03 10:57:22 +00:00
|
|
|
using osu.Framework.Testing;
|
2019-03-24 06:18:38 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Screens.Menu;
|
2019-03-26 01:48:29 +00:00
|
|
|
using osuTK;
|
2019-03-24 06:18:38 +00:00
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2019-04-04 04:05:34 +00:00
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
2019-03-24 06:18:38 +00:00
|
|
|
{
|
2019-05-14 19:37:25 +00:00
|
|
|
public class TestSceneLogoTrackingContainer : OsuTestScene
|
2019-03-24 06:18:38 +00:00
|
|
|
{
|
|
|
|
private OsuLogo logo;
|
2019-04-05 03:02:47 +00:00
|
|
|
private TestLogoTrackingContainer trackingContainer;
|
2019-04-03 10:57:22 +00:00
|
|
|
private Container transferContainer;
|
|
|
|
private Box visualBox;
|
|
|
|
private Box transferContainerBox;
|
2019-04-05 03:02:47 +00:00
|
|
|
private Drawable logoFacade;
|
2019-04-04 02:22:05 +00:00
|
|
|
private bool randomPositions;
|
2019-03-24 06:18:38 +00:00
|
|
|
|
2019-04-04 04:13:03 +00:00
|
|
|
private const float visual_box_size = 72;
|
|
|
|
|
2019-04-03 10:57:22 +00:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
|
|
|
{
|
|
|
|
AddStep("Clear facades", () =>
|
|
|
|
{
|
|
|
|
Clear();
|
2019-04-04 02:22:05 +00:00
|
|
|
Add(logo = new OsuLogo { Scale = new Vector2(0.15f), RelativePositionAxes = Axes.Both });
|
2019-04-05 03:02:47 +00:00
|
|
|
trackingContainer = null;
|
2019-04-03 10:57:22 +00:00
|
|
|
transferContainer = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-27 11:04:01 +00:00
|
|
|
/// <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>
|
2019-03-26 01:48:29 +00:00
|
|
|
[Test]
|
2019-04-17 08:15:23 +00:00
|
|
|
public void TestMoveFacade()
|
2019-03-26 01:48:29 +00:00
|
|
|
{
|
|
|
|
AddToggleStep("Toggle move continuously", b => randomPositions = b);
|
2019-04-05 03:02:47 +00:00
|
|
|
AddStep("Add tracking containers", addFacadeContainers);
|
2019-04-08 06:24:09 +00:00
|
|
|
AddStep("Move facade to random position", moveLogoFacade);
|
2019-03-27 11:04:01 +00:00
|
|
|
waitForMove();
|
2019-04-05 03:02:47 +00:00
|
|
|
AddAssert("Logo is tracking", () => trackingContainer.IsLogoTracking);
|
2019-03-26 01:48:29 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 11:04:01 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Check if the facade is removed from the container, the logo stops tracking.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
2019-04-17 08:15:23 +00:00
|
|
|
public void TestRemoveFacade()
|
2019-03-24 06:18:38 +00:00
|
|
|
{
|
2019-04-05 03:02:47 +00:00
|
|
|
AddStep("Add tracking containers", addFacadeContainers);
|
2019-04-08 06:24:09 +00:00
|
|
|
AddStep("Move facade to random position", moveLogoFacade);
|
2019-04-04 02:22:05 +00:00
|
|
|
AddStep("Remove facade from FacadeContainer", removeFacade);
|
2019-03-27 11:04:01 +00:00
|
|
|
waitForMove();
|
2019-04-05 03:02:47 +00:00
|
|
|
AddAssert("Logo is not tracking", () => !trackingContainer.IsLogoTracking);
|
2019-03-27 11:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Check if the facade gets added to a new container, tracking starts on the new facade.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
2019-04-17 08:15:23 +00:00
|
|
|
public void TestTransferFacade()
|
2019-03-27 11:04:01 +00:00
|
|
|
{
|
2019-04-05 03:02:47 +00:00
|
|
|
AddStep("Add tracking containers", addFacadeContainers);
|
2019-04-08 06:24:09 +00:00
|
|
|
AddStep("Move facade to random position", moveLogoFacade);
|
2019-04-04 02:22:05 +00:00
|
|
|
AddStep("Remove facade from FacadeContainer", removeFacade);
|
2019-04-05 06:48:48 +00:00
|
|
|
AddStep("Transfer facade to a new container", () =>
|
|
|
|
{
|
|
|
|
transferContainer.Add(logoFacade);
|
|
|
|
transferContainerBox.Colour = Color4.Tomato;
|
|
|
|
moveLogoFacade();
|
|
|
|
});
|
2019-04-17 08:15:23 +00:00
|
|
|
|
2019-03-27 11:04:01 +00:00
|
|
|
waitForMove();
|
2019-04-05 03:02:47 +00:00
|
|
|
AddAssert("Logo is tracking", () => trackingContainer.IsLogoTracking);
|
2019-03-24 06:18:38 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 10:57:22 +00:00
|
|
|
/// <summary>
|
2019-04-04 04:13:03 +00:00
|
|
|
/// Add a facade to a flow container, move the logo to the center of the screen, then start tracking on the facade.
|
2019-04-03 10:57:22 +00:00
|
|
|
/// </summary>
|
|
|
|
[Test]
|
2019-04-17 08:15:23 +00:00
|
|
|
public void TestFlowContainer()
|
2019-03-26 01:48:29 +00:00
|
|
|
{
|
2019-04-03 10:57:22 +00:00
|
|
|
FillFlowContainer flowContainer;
|
2019-03-26 01:48:29 +00:00
|
|
|
|
2019-04-04 02:22:05 +00:00
|
|
|
AddStep("Create new flow container with facade", () =>
|
2019-03-26 01:48:29 +00:00
|
|
|
{
|
2019-04-05 03:02:47 +00:00
|
|
|
Add(trackingContainer = new TestLogoTrackingContainer
|
2019-03-27 11:04:01 +00:00
|
|
|
{
|
2019-04-03 10:57:22 +00:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Child = flowContainer = new FillFlowContainer
|
2019-03-27 11:04:01 +00:00
|
|
|
{
|
2019-04-03 10:57:22 +00:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
flowContainer.Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Colour = Color4.Azure,
|
2019-04-04 04:13:03 +00:00
|
|
|
Size = new Vector2(visual_box_size)
|
2019-03-27 11:04:01 +00:00
|
|
|
},
|
2019-04-03 10:57:22 +00:00
|
|
|
new Container
|
2019-03-27 11:04:01 +00:00
|
|
|
{
|
|
|
|
Alpha = 0.35f,
|
|
|
|
RelativeSizeAxes = Axes.None,
|
2019-04-04 04:13:03 +00:00
|
|
|
Size = new Vector2(visual_box_size),
|
2019-04-03 10:57:22 +00:00
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Children = new Drawable[]
|
2019-03-27 11:04:01 +00:00
|
|
|
{
|
2019-04-03 10:57:22 +00:00
|
|
|
visualBox = new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.White,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2019-04-05 03:02:47 +00:00
|
|
|
trackingContainer.LogoFacade,
|
2019-03-27 11:04:01 +00:00
|
|
|
}
|
|
|
|
},
|
2019-04-03 10:57:22 +00:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Colour = Color4.Azure,
|
2019-04-04 04:13:03 +00:00
|
|
|
Size = new Vector2(visual_box_size)
|
2019-04-03 10:57:22 +00:00
|
|
|
},
|
2019-03-27 11:04:01 +00:00
|
|
|
};
|
2019-04-03 10:57:22 +00:00
|
|
|
});
|
2019-03-27 11:04:01 +00:00
|
|
|
|
2019-04-03 10:57:22 +00:00
|
|
|
AddStep("Perform logo movements", () =>
|
2019-03-27 11:04:01 +00:00
|
|
|
{
|
2019-04-08 06:24:09 +00:00
|
|
|
trackingContainer.StopTracking();
|
2019-04-03 10:57:22 +00:00
|
|
|
logo.MoveTo(new Vector2(0.5f), 500, Easing.InOutExpo);
|
2019-04-08 06:24:09 +00:00
|
|
|
|
2019-03-27 11:04:01 +00:00
|
|
|
visualBox.Colour = Color4.White;
|
|
|
|
|
2019-04-03 10:57:22 +00:00
|
|
|
Scheduler.AddDelayed(() =>
|
|
|
|
{
|
2019-04-08 06:24:09 +00:00
|
|
|
trackingContainer.StartTracking(logo, 1000, Easing.InOutExpo);
|
2019-04-03 10:57:22 +00:00
|
|
|
visualBox.Colour = Color4.Tomato;
|
|
|
|
}, 700);
|
|
|
|
});
|
2019-04-04 02:22:05 +00:00
|
|
|
|
2019-04-04 04:25:24 +00:00
|
|
|
waitForMove(8);
|
2019-04-05 03:02:47 +00:00
|
|
|
AddAssert("Logo is tracking", () => trackingContainer.IsLogoTracking);
|
|
|
|
}
|
|
|
|
|
2019-04-05 06:30:09 +00:00
|
|
|
[Test]
|
2019-04-17 08:15:23 +00:00
|
|
|
public void TestSetFacadeSize()
|
2019-04-05 06:30:09 +00:00
|
|
|
{
|
|
|
|
bool failed = false;
|
2019-04-17 08:15:23 +00:00
|
|
|
|
2019-04-05 06:48:48 +00:00
|
|
|
AddStep("Set up scenario", () =>
|
|
|
|
{
|
|
|
|
failed = false;
|
|
|
|
addFacadeContainers();
|
|
|
|
});
|
2019-04-17 08:15:23 +00:00
|
|
|
|
2019-04-05 06:30:09 +00:00
|
|
|
AddStep("Try setting facade size", () =>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
logoFacade.Size = new Vector2(0, 0);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
if (e is InvalidOperationException)
|
|
|
|
failed = true;
|
|
|
|
}
|
|
|
|
});
|
2019-04-17 08:15:23 +00:00
|
|
|
|
2019-04-05 06:30:09 +00:00
|
|
|
AddAssert("Exception thrown", () => failed);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2019-04-17 08:15:23 +00:00
|
|
|
public void TestSetMultipleContainers()
|
2019-04-05 06:30:09 +00:00
|
|
|
{
|
|
|
|
bool failed = false;
|
|
|
|
LogoTrackingContainer newContainer = new LogoTrackingContainer();
|
2019-04-17 08:15:23 +00:00
|
|
|
|
2019-04-05 06:48:48 +00:00
|
|
|
AddStep("Set up scenario", () =>
|
|
|
|
{
|
|
|
|
failed = false;
|
|
|
|
newContainer = new LogoTrackingContainer();
|
|
|
|
addFacadeContainers();
|
2019-04-08 06:24:09 +00:00
|
|
|
moveLogoFacade();
|
2019-04-05 06:48:48 +00:00
|
|
|
});
|
2019-04-17 08:15:23 +00:00
|
|
|
|
2019-04-05 06:30:09 +00:00
|
|
|
AddStep("Try tracking new container", () =>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-04-08 06:24:09 +00:00
|
|
|
newContainer.StartTracking(logo);
|
2019-04-05 06:30:09 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
if (e is InvalidOperationException)
|
|
|
|
failed = true;
|
|
|
|
}
|
|
|
|
});
|
2019-04-17 08:15:23 +00:00
|
|
|
|
2019-04-05 06:30:09 +00:00
|
|
|
AddAssert("Exception thrown", () => failed);
|
|
|
|
}
|
|
|
|
|
2019-04-03 10:57:22 +00:00
|
|
|
private void addFacadeContainers()
|
|
|
|
{
|
|
|
|
AddRange(new Drawable[]
|
2019-03-26 01:48:29 +00:00
|
|
|
{
|
2019-04-05 03:02:47 +00:00
|
|
|
trackingContainer = new TestLogoTrackingContainer
|
2019-04-03 10:57:22 +00:00
|
|
|
{
|
|
|
|
Alpha = 0.35f,
|
|
|
|
RelativeSizeAxes = Axes.None,
|
2019-04-04 04:13:03 +00:00
|
|
|
Size = new Vector2(visual_box_size),
|
2019-04-03 10:57:22 +00:00
|
|
|
Child = visualBox = new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.Tomato,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
transferContainer = new Container
|
|
|
|
{
|
|
|
|
Alpha = 0.35f,
|
|
|
|
RelativeSizeAxes = Axes.None,
|
2019-04-04 04:13:03 +00:00
|
|
|
Size = new Vector2(visual_box_size),
|
2019-04-03 10:57:22 +00:00
|
|
|
Child = transferContainerBox = new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.White,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2019-03-26 01:48:29 +00:00
|
|
|
|
2019-04-05 03:02:47 +00:00
|
|
|
trackingContainer.Add(logoFacade = trackingContainer.LogoFacade);
|
2019-04-08 06:24:09 +00:00
|
|
|
trackingContainer.StartTracking(logo, 1000);
|
2019-04-03 10:57:22 +00:00
|
|
|
}
|
2019-03-26 08:18:35 +00:00
|
|
|
|
2019-04-04 04:25:24 +00:00
|
|
|
private void waitForMove(int count = 5) => AddWaitStep("Wait for transforms to finish", count);
|
2019-04-03 10:57:22 +00:00
|
|
|
|
2019-04-04 02:22:05 +00:00
|
|
|
private void removeFacade()
|
2019-04-03 10:57:22 +00:00
|
|
|
{
|
2019-04-05 03:02:47 +00:00
|
|
|
trackingContainer.Remove(logoFacade);
|
2019-04-03 10:57:22 +00:00
|
|
|
visualBox.Colour = Color4.White;
|
|
|
|
moveLogoFacade();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void moveLogoFacade()
|
|
|
|
{
|
2020-08-04 12:16:59 +00:00
|
|
|
if (!(logoFacade?.Transforms).Any() && !(transferContainer?.Transforms).Any())
|
2019-04-03 10:57:22 +00:00
|
|
|
{
|
2019-04-04 02:22:05 +00:00
|
|
|
Random random = new Random();
|
2019-04-05 03:02:47 +00:00
|
|
|
trackingContainer.Delay(500).MoveTo(new Vector2(random.Next(0, (int)logo.Parent.DrawWidth), random.Next(0, (int)logo.Parent.DrawHeight)), 300);
|
2019-04-03 10:57:22 +00:00
|
|
|
transferContainer.Delay(500).MoveTo(new Vector2(random.Next(0, (int)logo.Parent.DrawWidth), random.Next(0, (int)logo.Parent.DrawHeight)), 300);
|
2019-03-26 01:48:29 +00:00
|
|
|
}
|
2019-04-03 10:57:22 +00:00
|
|
|
|
|
|
|
if (randomPositions)
|
|
|
|
Schedule(moveLogoFacade);
|
2019-03-26 01:48:29 +00:00
|
|
|
}
|
2019-04-04 02:22:05 +00:00
|
|
|
|
2019-04-05 03:02:47 +00:00
|
|
|
private class TestLogoTrackingContainer : LogoTrackingContainer
|
2019-04-04 02:22:05 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Check that the logo is tracking the position of the facade, with an acceptable precision lenience.
|
|
|
|
/// </summary>
|
2019-04-08 06:24:09 +00:00
|
|
|
public bool IsLogoTracking => Precision.AlmostEquals(Logo.Position, ComputeLogoTrackingPosition());
|
2019-04-04 02:22:05 +00:00
|
|
|
}
|
2019-03-24 06:18:38 +00:00
|
|
|
}
|
|
|
|
}
|