osu/osu.Game.Tests/Visual/UserInterface/TestSceneScreenBreadcrumbCo...

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