2019-01-24 16:43:03 +08: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.
|
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;
|
2022-11-24 15:26:57 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2018-05-11 08:35:26 +08:00
|
|
|
|
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]
|
2019-05-15 03:37:25 +08:00
|
|
|
|
public partial 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
|
|
|
|
|
2019-05-15 03:37:25 +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();
|
2020-01-31 18:10:44 +08:00
|
|
|
|
|
|
|
|
|
screenStack = new OsuScreenStack { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
screenStack.Push(startScreen);
|
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();
|
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
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
|
AddStep(@"make start current", () => startScreen.MakeCurrent());
|
2018-05-11 08:52:26 +08:00
|
|
|
|
|
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();
|
2020-01-18 14:27:21 +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:52:26 +08:00
|
|
|
|
|
2018-05-11 08:35:26 +08:00
|
|
|
|
private abstract partial 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();
|
2019-02-28 12:31:40 +08:00
|
|
|
|
this.Push(screen);
|
2018-05-11 08:52:26 +08:00
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
},
|
2022-11-24 15:26:57 +08:00
|
|
|
|
new RoundedButton
|
2018-05-11 08:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
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 partial 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 partial 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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|