1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 05:27:40 +08:00
osu-lazer/osu.Game.Tests/Visual/TestCaseScreenBreadcrumbControl.cs

137 lines
4.7 KiB
C#
Raw Normal View History

2018-05-11 08:35:26 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
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
namespace osu.Game.Tests.Visual
{
[TestFixture]
2018-05-15 20:08:55 +08:00
public class TestCaseScreenBreadcrumbControl : OsuTestCase
2018-05-11 08:35:26 +08:00
{
2018-05-15 20:08:55 +08:00
private readonly ScreenBreadcrumbControl breadcrumbs;
2019-01-23 19:52:00 +08:00
private readonly ScreenStack screenStack;
2018-05-11 08:35:26 +08:00
2018-05-15 20:08:55 +08:00
public TestCaseScreenBreadcrumbControl()
2018-05-11 08:35:26 +08:00
{
OsuSpriteText titleText;
2019-01-23 19:52:00 +08:00
IScreen startScreen = new TestScreenOne();
screenStack = new ScreenStack(startScreen) { RelativeSizeAxes = Axes.Both };
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-01-23 19:52:00 +08:00
breadcrumbs.Current.ValueChanged += s => titleText.Text = $"Changed to {s.ToString()}";
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());
private void waitForCurrent() => AddUntilStep(() => screenStack.CurrentScreen.IsCurrentScreen(), "current screen");
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-01-23 19:52:00 +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();
}
}
}