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
|
|
|
|
|
|
2018-05-11 15:45:27 +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
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
private Screen currentScreen, changedScreen;
|
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
|
|
|
|
{
|
|
|
|
|
TestScreen startScreen;
|
|
|
|
|
OsuSpriteText titleText;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-05-16 06:56:47 +08:00
|
|
|
|
currentScreen = startScreen = new TestScreenOne(),
|
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[]
|
|
|
|
|
{
|
2018-05-15 20:08:55 +08:00
|
|
|
|
breadcrumbs = new ScreenBreadcrumbControl(startScreen)
|
2018-05-11 08:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
},
|
|
|
|
|
titleText = new OsuSpriteText(),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2018-05-15 20:08:55 +08:00
|
|
|
|
breadcrumbs.Current.ValueChanged += s =>
|
2018-05-11 08:52:26 +08:00
|
|
|
|
{
|
|
|
|
|
titleText.Text = $"Changed to {s.ToString()}";
|
|
|
|
|
changedScreen = s;
|
|
|
|
|
};
|
|
|
|
|
|
2018-05-16 06:56:47 +08:00
|
|
|
|
breadcrumbs.Current.TriggerChange();
|
|
|
|
|
|
2018-07-31 12:42:47 +08:00
|
|
|
|
waitForCurrent();
|
2018-05-11 08:52:26 +08:00
|
|
|
|
pushNext();
|
2018-07-31 12:42:47 +08:00
|
|
|
|
waitForCurrent();
|
2018-05-11 08:52:26 +08:00
|
|
|
|
pushNext();
|
2018-07-31 12:42:47 +08:00
|
|
|
|
waitForCurrent();
|
2018-05-11 08:52:26 +08:00
|
|
|
|
|
|
|
|
|
AddStep(@"make start current", () =>
|
|
|
|
|
{
|
|
|
|
|
startScreen.MakeCurrent();
|
|
|
|
|
currentScreen = startScreen;
|
|
|
|
|
});
|
|
|
|
|
|
2018-07-31 12:42:47 +08:00
|
|
|
|
waitForCurrent();
|
2018-05-11 15:45:27 +08:00
|
|
|
|
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);
|
|
|
|
|
AddStep(@"exit current", () => changedScreen.Exit());
|
|
|
|
|
AddAssert(@"current screen is first", () => startScreen == changedScreen);
|
2018-05-11 08:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
breadcrumbs.StripColour = colours.Blue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-15 20:08:55 +08:00
|
|
|
|
private void pushNext() => AddStep(@"push next screen", () => currentScreen = ((TestScreen)currentScreen).PushNext());
|
2018-07-31 12:42:47 +08:00
|
|
|
|
private void waitForCurrent() => AddUntilStep(() => currentScreen.IsCurrentScreen, "current screen");
|
2018-05-11 08:52:26 +08:00
|
|
|
|
|
2018-05-11 08:35:26 +08:00
|
|
|
|
private abstract class TestScreen : OsuScreen
|
|
|
|
|
{
|
|
|
|
|
protected abstract string NextTitle { get; }
|
|
|
|
|
protected abstract TestScreen CreateNextScreen();
|
|
|
|
|
|
2018-05-11 08:52:26 +08:00
|
|
|
|
public TestScreen PushNext()
|
|
|
|
|
{
|
|
|
|
|
TestScreen screen = CreateNextScreen();
|
|
|
|
|
Push(screen);
|
|
|
|
|
|
|
|
|
|
return screen;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-11 08:35:26 +08:00
|
|
|
|
protected TestScreen()
|
|
|
|
|
{
|
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
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}",
|
2018-05-11 08:52:26 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|