1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 03:47:26 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneScreenBreadcrumbControl.cs

137 lines
4.7 KiB
C#
Raw Normal View History

// 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.
2018-05-11 08:35:26 +08:00
using System.Linq;
2018-05-11 08:35:26 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-05-15 20:08:55 +08:00
using osu.Framework.Screens;
2018-05-11 08:35:26 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-05-11 08:35:26 +08:00
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.UserInterface
2018-05-11 08:35:26 +08:00
{
[TestFixture]
public class TestSceneScreenBreadcrumbControl : OsuTestScene
2018-05-11 08:35:26 +08:00
{
2018-05-15 20:08:55 +08:00
private readonly ScreenBreadcrumbControl breadcrumbs;
2019-03-12 15:33:35 +08:00
private readonly OsuScreenStack screenStack;
2018-05-11 08:35:26 +08:00
public TestSceneScreenBreadcrumbControl()
2018-05-11 08:35:26 +08:00
{
OsuSpriteText titleText;
2019-01-23 19:52:00 +08:00
IScreen startScreen = new TestScreenOne();
2019-03-12 15:33:35 +08:00
screenStack = new OsuScreenStack(startScreen) { RelativeSizeAxes = Axes.Both };
2019-01-23 19:52:00 +08:00
2018-05-11 08:35:26 +08:00
Children = new Drawable[]
{
2019-01-23 19:52:00 +08:00
screenStack,
2018-05-11 08:35:26 +08:00
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
Children = new Drawable[]
{
2019-01-23 19:52:00 +08:00
breadcrumbs = new ScreenBreadcrumbControl(screenStack)
2018-05-11 08:35:26 +08:00
{
RelativeSizeAxes = Axes.X,
},
titleText = new OsuSpriteText(),
},
},
};
2019-07-08 15:34:11 +08:00
breadcrumbs.Current.ValueChanged += screen => titleText.Text = $"Changed to {screen.NewValue}";
2018-05-16 06:56:47 +08:00
breadcrumbs.Current.TriggerChange();
2018-07-31 12:42:47 +08:00
waitForCurrent();
pushNext();
2018-07-31 12:42:47 +08:00
waitForCurrent();
pushNext();
2018-07-31 12:42:47 +08:00
waitForCurrent();
2019-01-23 19:52:00 +08:00
AddStep(@"make start current", () => startScreen.MakeCurrent());
2018-07-31 12:42:47 +08:00
waitForCurrent();
pushNext();
2018-07-31 12:42:47 +08:00
waitForCurrent();
2018-05-16 06:52:28 +08:00
AddAssert(@"only 2 items", () => breadcrumbs.Items.Count() == 2);
2019-01-23 19:52:00 +08:00
AddStep(@"exit current", () => screenStack.CurrentScreen.Exit());
AddAssert(@"current screen is first", () => startScreen == screenStack.CurrentScreen);
2018-05-11 08:35:26 +08:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
breadcrumbs.StripColour = colours.Blue;
}
2019-01-23 19:52:00 +08:00
private void pushNext() => AddStep(@"push next screen", () => ((TestScreen)screenStack.CurrentScreen).PushNext());
2019-03-19 16:24:26 +08:00
private void waitForCurrent() => AddUntilStep("current screen", () => screenStack.CurrentScreen.IsCurrentScreen());
2018-05-11 08:35:26 +08:00
private abstract class TestScreen : OsuScreen
{
protected abstract string NextTitle { get; }
protected abstract TestScreen CreateNextScreen();
public TestScreen PushNext()
{
TestScreen screen = CreateNextScreen();
2019-02-28 12:31:40 +08:00
this.Push(screen);
return screen;
}
2018-05-11 08:35:26 +08:00
protected TestScreen()
{
2019-01-23 19:52:00 +08:00
InternalChild = new FillFlowContainer
2018-05-11 08:35:26 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
Children = new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = Title,
},
new TriangleButton
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Width = 100,
Text = $"Push {NextTitle}",
Action = () => PushNext(),
2018-05-11 08:35:26 +08:00
},
},
};
}
}
private class TestScreenOne : TestScreen
{
2018-05-28 12:02:06 +08:00
public override string Title => @"Screen One";
2018-05-11 08:35:26 +08:00
protected override string NextTitle => @"Two";
protected override TestScreen CreateNextScreen() => new TestScreenTwo();
}
private class TestScreenTwo : TestScreen
{
2018-05-28 12:02:06 +08:00
public override string Title => @"Screen Two";
2018-05-11 08:35:26 +08:00
protected override string NextTitle => @"One";
protected override TestScreen CreateNextScreen() => new TestScreenOne();
}
}
}