osu/osu.Game.Tests/Visual/TestCaseFacadeContainer.cs

172 lines
5.1 KiB
C#
Raw Normal View History

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;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
2019-03-26 01:48:29 +00:00
using osu.Framework.Graphics.Containers;
2019-03-24 06:18:38 +00:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Play;
2019-03-26 01:48:29 +00:00
using osuTK;
2019-03-24 06:18:38 +00:00
using osuTK.Graphics;
namespace osu.Game.Tests.Visual
{
public class TestCaseFacadeContainer : ScreenTestCase
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(PlayerLoader),
typeof(Player),
typeof(Facade),
2019-03-26 02:11:27 +00:00
typeof(FacadeContainer)
2019-03-24 06:18:38 +00:00
};
[Cached]
private OsuLogo logo;
private readonly Bindable<float> uiScale = new Bindable<float>();
public TestCaseFacadeContainer()
{
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);
}
2019-03-26 01:48:29 +00:00
[Test]
public void IsolatedTest()
{
bool randomPositions = false;
AddToggleStep("Toggle move continuously", b => randomPositions = b);
2019-03-26 02:11:27 +00:00
AddStep("Move facade to random position", () => LoadScreen(new TestScreen(randomPositions)));
2019-03-26 01:48:29 +00:00
}
2019-03-24 06:18:38 +00:00
[Test]
public void PlayerLoaderTest()
{
2019-03-26 01:48:29 +00:00
AddToggleStep("Toggle mods", b => { Beatmap.Value.Mods.Value = b ? Beatmap.Value.Mods.Value.Concat(new[] { new OsuModNoFail() }) : Enumerable.Empty<Mod>(); });
2019-03-26 02:11:27 +00:00
AddStep("Add new playerloader", () => LoadScreen(new TestPlayerLoader(() => new TestPlayer
2019-03-24 06:18:38 +00:00
{
AllowPause = false,
AllowLeadIn = false,
AllowResults = false,
})));
}
[Test]
public void MainMenuTest()
{
2019-03-26 02:11:27 +00:00
AddStep("Add new Main Menu", () => LoadScreen(new MainMenu()));
2019-03-24 06:18:38 +00:00
}
private class TestFacadeContainer : FacadeContainer
{
protected override Facade CreateFacade() => new Facade
{
Colour = Color4.Tomato,
Alpha = 0.35f,
Child = new Box
{
Colour = Color4.Tomato,
RelativeSizeAxes = Axes.Both,
},
};
}
2019-03-26 01:48:29 +00:00
private class TestScreen : OsuScreen
{
private TestFacadeContainer facadeContainer;
private FacadeFlowComponent facadeFlowComponent;
private readonly bool randomPositions;
public TestScreen(bool randomPositions = false)
{
this.randomPositions = randomPositions;
}
[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;
}
}
2019-03-24 06:18:38 +00:00
private class TestPlayerLoader : PlayerLoader
{
public TestPlayerLoader(Func<Player> player)
: base(player)
{
}
protected override FacadeContainer CreateFacadeContainer() => new TestFacadeContainer();
}
private class TestPlayer : Player
{
[BackgroundDependencyLoader]
private void load()
{
// Never finish loading
while (true)
Thread.Sleep(1);
}
}
}
}