2021-04-18 17:29:04 +00: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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-07-11 18:14:42 +00:00
|
|
|
using System.Linq;
|
2021-04-18 17:29:04 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-08-28 18:20:42 +00:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2021-07-11 18:14:42 +00:00
|
|
|
using osu.Framework.Testing;
|
2021-04-18 17:35:42 +00:00
|
|
|
using osu.Framework.Utils;
|
2021-07-11 18:02:39 +00:00
|
|
|
using osu.Game.Graphics.Cursor;
|
2021-07-11 18:14:42 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-04-18 17:29:04 +00:00
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
|
|
using osuTK.Graphics;
|
2021-07-11 18:14:42 +00:00
|
|
|
using osuTK.Input;
|
2021-04-18 17:29:04 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
2021-07-11 18:14:42 +00:00
|
|
|
public class TestSceneLabelledColourPalette : OsuManualInputManagerTestScene
|
2021-04-18 17:29:04 +00:00
|
|
|
{
|
|
|
|
private LabelledColourPalette component;
|
|
|
|
|
|
|
|
[Test]
|
2021-04-18 17:35:42 +00:00
|
|
|
public void TestPalette([Values] bool hasDescription)
|
|
|
|
{
|
|
|
|
createColourPalette(hasDescription);
|
|
|
|
|
|
|
|
AddRepeatStep("add random colour", () => component.Colours.Add(randomColour()), 4);
|
2021-04-18 18:15:30 +00:00
|
|
|
|
|
|
|
AddStep("set custom prefix", () => component.ColourNamePrefix = "Combo");
|
|
|
|
|
2021-04-18 17:35:42 +00:00
|
|
|
AddRepeatStep("remove random colour", () =>
|
|
|
|
{
|
|
|
|
if (component.Colours.Count > 0)
|
|
|
|
component.Colours.RemoveAt(RNG.Next(component.Colours.Count));
|
2021-04-18 18:15:30 +00:00
|
|
|
}, 8);
|
2021-04-18 17:35:42 +00:00
|
|
|
}
|
2021-04-18 17:29:04 +00:00
|
|
|
|
2021-07-11 18:14:42 +00:00
|
|
|
[Test]
|
|
|
|
public void TestUserInteractions()
|
|
|
|
{
|
|
|
|
createColourPalette();
|
|
|
|
assertColourCount(4);
|
|
|
|
|
|
|
|
clickAddColour();
|
|
|
|
assertColourCount(5);
|
|
|
|
|
|
|
|
deleteFirstColour();
|
|
|
|
assertColourCount(4);
|
|
|
|
|
|
|
|
clickFirstColour();
|
|
|
|
AddAssert("colour picker spawned", () => this.ChildrenOfType<OsuColourPicker>().Any());
|
|
|
|
}
|
|
|
|
|
2021-04-18 17:29:04 +00:00
|
|
|
private void createColourPalette(bool hasDescription = false)
|
|
|
|
{
|
|
|
|
AddStep("create component", () =>
|
|
|
|
{
|
2021-08-28 18:20:42 +00:00
|
|
|
Child = new PopoverContainer
|
2021-04-18 17:29:04 +00:00
|
|
|
{
|
2021-07-11 18:02:39 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-08-28 18:20:42 +00:00
|
|
|
Child = new OsuContextMenuContainer
|
2021-04-18 17:29:04 +00:00
|
|
|
{
|
2021-08-28 18:20:42 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = new Container
|
2021-07-11 18:02:39 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2021-08-28 18:20:42 +00:00
|
|
|
Width = 500,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Child = component = new LabelledColourPalette
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
ColourNamePrefix = "My colour #"
|
|
|
|
}
|
2021-07-11 18:02:39 +00:00
|
|
|
}
|
2021-04-18 17:29:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
component.Label = "a sample component";
|
|
|
|
component.Description = hasDescription ? "this text describes the component" : string.Empty;
|
|
|
|
|
|
|
|
component.Colours.AddRange(new[]
|
|
|
|
{
|
2021-06-20 17:37:09 +00:00
|
|
|
Colour4.DarkRed,
|
|
|
|
Colour4.Aquamarine,
|
|
|
|
Colour4.Goldenrod,
|
|
|
|
Colour4.Gainsboro
|
2021-04-18 17:29:04 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2021-04-18 17:35:42 +00:00
|
|
|
|
2021-06-20 17:37:09 +00:00
|
|
|
private Colour4 randomColour() => new Color4(
|
2021-04-18 17:35:42 +00:00
|
|
|
RNG.NextSingle(),
|
|
|
|
RNG.NextSingle(),
|
|
|
|
RNG.NextSingle(),
|
|
|
|
1);
|
2021-07-11 18:14:42 +00:00
|
|
|
|
|
|
|
private void assertColourCount(int count) => AddAssert($"colour count is {count}", () => component.Colours.Count == count);
|
|
|
|
|
|
|
|
private void clickAddColour() => AddStep("click new colour button", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<ColourPalette.AddColourButton>().Single());
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
private void clickFirstColour() => AddStep("click first colour", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<ColourDisplay>().First());
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
private void deleteFirstColour()
|
|
|
|
{
|
|
|
|
AddStep("right-click first colour", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<ColourDisplay>().First());
|
|
|
|
InputManager.Click(MouseButton.Right);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("wait for menu", () => this.ChildrenOfType<OsuContextMenu>().Any());
|
|
|
|
|
|
|
|
AddStep("click delete", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<DrawableOsuMenuItem>().Single());
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
}
|
2021-04-18 17:29:04 +00:00
|
|
|
}
|
|
|
|
}
|