osukey/osu.Game.Tests/Visual/TestCaseLogoFacadeContainer.cs
David Zhao 34a33b335d oops
2019-03-27 17:29:38 +09:00

123 lines
3.9 KiB
C#

// 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 System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
using osu.Game.Screens;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Play;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual
{
public class TestCaseLogoFacadeContainer : ScreenTestCase
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(PlayerLoader),
typeof(Player),
typeof(LogoFacadeContainer.Facade),
typeof(LogoFacadeContainer),
typeof(ButtonSystem),
typeof(ButtonSystemState),
typeof(Menu),
typeof(MainMenu)
};
[Cached]
private OsuLogo logo;
private readonly Bindable<float> uiScale = new Bindable<float>();
public TestCaseLogoFacadeContainer()
{
Add(logo = new OsuLogo());
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
config.BindWith(OsuSetting.UIScale, uiScale);
AddSliderStep("Adjust scale", 1f, 1.5f, 1f, v => uiScale.Value = v);
}
[Test]
public void IsolatedTest()
{
bool randomPositions = false;
AddToggleStep("Toggle move continuously", b => randomPositions = b);
AddStep("Move facade to random position", () => LoadScreen(new TestScreen(randomPositions)));
}
private class TestLogoFacadeContainer : LogoFacadeContainer
{
protected override Facade CreateFacade() => new Facade
{
Colour = Color4.Tomato,
Alpha = 0.35f,
Child = new Box
{
Colour = Color4.Tomato,
RelativeSizeAxes = Axes.Both,
},
};
}
private class TestScreen : OsuScreen
{
private TestLogoFacadeContainer logoFacadeContainer;
private LogoFacadeContainer.Facade facadeFlowComponent;
private readonly bool randomPositions;
public TestScreen(bool randomPositions = false)
{
this.randomPositions = randomPositions;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = logoFacadeContainer = new TestLogoFacadeContainer();
logoFacadeContainer.Child = facadeFlowComponent = logoFacadeContainer.LogoFacade;
}
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
base.LogoArriving(logo, resuming);
logo.FadeIn(350);
logo.ScaleTo(new Vector2(0.15f), 350, Easing.In);
logoFacadeContainer.SetLogo(logo, 0.3f, 1000, Easing.InOutQuint);
logoFacadeContainer.Tracking = true;
moveLogoFacade();
}
protected override void LogoExiting(OsuLogo logo)
{
base.LogoExiting(logo);
logoFacadeContainer.Tracking = false;
}
private void moveLogoFacade()
{
Random random = new Random();
if (facadeFlowComponent.Transforms.Count == 0)
{
facadeFlowComponent.Delay(500).MoveTo(new Vector2(random.Next(0, (int)DrawWidth), random.Next(0, (int)DrawHeight)), 300);
}
if (randomPositions)
Schedule(moveLogoFacade);
}
}
}
}