2021-03-15 17:37:46 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-09-06 13:14:42 +08:00
|
|
|
using System.Linq;
|
2021-03-15 17:37:46 +08:00
|
|
|
using NUnit.Framework;
|
2021-10-12 05:10:56 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-03-16 13:45:21 +08:00
|
|
|
using osu.Framework.Bindables;
|
2021-03-15 17:37:46 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Input.Handlers.Tablet;
|
2021-09-04 14:35:54 +08:00
|
|
|
using osu.Framework.Testing;
|
2021-03-16 22:47:08 +08:00
|
|
|
using osu.Framework.Utils;
|
2022-11-21 11:15:40 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2021-03-16 15:24:08 +08:00
|
|
|
using osu.Game.Overlays;
|
2021-09-06 13:14:42 +08:00
|
|
|
using osu.Game.Overlays.Settings;
|
2021-03-15 17:37:46 +08:00
|
|
|
using osu.Game.Overlays.Settings.Sections.Input;
|
2021-03-17 11:50:02 +08:00
|
|
|
using osuTK;
|
2021-03-15 17:37:46 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Settings
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class TestSceneTabletSettings : OsuTestScene
|
|
|
|
{
|
2021-09-04 14:35:54 +08:00
|
|
|
private TestTabletHandler tabletHandler;
|
|
|
|
private TabletSettings settings;
|
2021-03-15 17:37:46 +08:00
|
|
|
|
2021-10-12 05:10:56 +08:00
|
|
|
[Cached]
|
|
|
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
|
|
|
|
2021-09-04 14:35:54 +08:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
|
|
|
{
|
|
|
|
AddStep("create settings", () =>
|
2021-03-15 17:37:46 +08:00
|
|
|
{
|
2021-09-04 14:35:54 +08:00
|
|
|
tabletHandler = new TestTabletHandler();
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
2021-03-16 15:24:08 +08:00
|
|
|
{
|
2022-11-21 11:15:40 +08:00
|
|
|
new OsuScrollContainer(Direction.Vertical)
|
2021-09-04 14:35:54 +08:00
|
|
|
{
|
2022-11-22 02:27:06 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-11-21 11:15:40 +08:00
|
|
|
Child = settings = new TabletSettings(tabletHandler)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
Width = SettingsPanel.PANEL_WIDTH,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
}
|
2021-09-04 14:35:54 +08:00
|
|
|
}
|
|
|
|
};
|
2021-03-15 17:37:46 +08:00
|
|
|
});
|
2021-03-16 13:45:21 +08:00
|
|
|
|
2021-09-04 14:35:54 +08:00
|
|
|
AddStep("set square size", () => tabletHandler.SetTabletSize(new Vector2(100, 100)));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestVariousTabletSizes()
|
|
|
|
{
|
2021-03-17 11:50:02 +08:00
|
|
|
AddStep("Test with wide tablet", () => tabletHandler.SetTabletSize(new Vector2(160, 100)));
|
|
|
|
AddStep("Test with square tablet", () => tabletHandler.SetTabletSize(new Vector2(300, 300)));
|
|
|
|
AddStep("Test with tall tablet", () => tabletHandler.SetTabletSize(new Vector2(100, 300)));
|
|
|
|
AddStep("Test with very tall tablet", () => tabletHandler.SetTabletSize(new Vector2(100, 700)));
|
|
|
|
AddStep("Test no tablet present", () => tabletHandler.SetTabletSize(Vector2.Zero));
|
2021-03-16 13:45:21 +08:00
|
|
|
}
|
|
|
|
|
2021-09-06 13:14:42 +08:00
|
|
|
[Test]
|
|
|
|
public void TestWideAspectRatioValidity()
|
|
|
|
{
|
|
|
|
AddStep("Test with wide tablet", () => tabletHandler.SetTabletSize(new Vector2(160, 100)));
|
|
|
|
|
|
|
|
AddStep("Reset to full area", () => settings.ChildrenOfType<DangerousSettingsButton>().First().TriggerClick());
|
|
|
|
ensureValid();
|
|
|
|
|
|
|
|
AddStep("rotate 10", () => tabletHandler.Rotation.Value = 10);
|
|
|
|
ensureInvalid();
|
|
|
|
|
|
|
|
AddStep("scale down", () => tabletHandler.AreaSize.Value *= 0.9f);
|
|
|
|
ensureInvalid();
|
|
|
|
|
|
|
|
AddStep("scale down", () => tabletHandler.AreaSize.Value *= 0.9f);
|
|
|
|
ensureInvalid();
|
|
|
|
|
|
|
|
AddStep("scale down", () => tabletHandler.AreaSize.Value *= 0.9f);
|
|
|
|
ensureValid();
|
|
|
|
}
|
|
|
|
|
2021-09-04 14:35:54 +08:00
|
|
|
[Test]
|
2021-09-04 22:19:05 +08:00
|
|
|
public void TestRotationValidity()
|
2021-09-04 14:35:54 +08:00
|
|
|
{
|
|
|
|
AddAssert("area valid", () => settings.AreaSelection.IsWithinBounds);
|
|
|
|
|
|
|
|
AddStep("rotate 90", () => tabletHandler.Rotation.Value = 90);
|
2021-09-04 21:55:14 +08:00
|
|
|
ensureValid();
|
2021-09-04 14:35:54 +08:00
|
|
|
|
|
|
|
AddStep("rotate 180", () => tabletHandler.Rotation.Value = 180);
|
2021-09-04 21:55:14 +08:00
|
|
|
|
|
|
|
ensureValid();
|
|
|
|
|
|
|
|
AddStep("rotate 270", () => tabletHandler.Rotation.Value = 270);
|
|
|
|
|
|
|
|
ensureValid();
|
2021-09-04 14:35:54 +08:00
|
|
|
|
|
|
|
AddStep("rotate 360", () => tabletHandler.Rotation.Value = 360);
|
2021-09-04 21:55:14 +08:00
|
|
|
|
|
|
|
ensureValid();
|
2021-09-04 14:35:54 +08:00
|
|
|
|
|
|
|
AddStep("rotate 0", () => tabletHandler.Rotation.Value = 0);
|
2021-09-04 21:55:14 +08:00
|
|
|
ensureValid();
|
2021-09-04 22:19:05 +08:00
|
|
|
|
2021-09-05 10:14:28 +08:00
|
|
|
AddStep("rotate 45", () => tabletHandler.Rotation.Value = 45);
|
2021-09-04 22:19:05 +08:00
|
|
|
ensureInvalid();
|
|
|
|
|
|
|
|
AddStep("rotate 0", () => tabletHandler.Rotation.Value = 0);
|
|
|
|
ensureValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestOffsetValidity()
|
|
|
|
{
|
|
|
|
ensureValid();
|
|
|
|
AddStep("move right", () => tabletHandler.AreaOffset.Value = Vector2.Zero);
|
|
|
|
ensureInvalid();
|
|
|
|
AddStep("move back", () => tabletHandler.AreaOffset.Value = tabletHandler.AreaSize.Value / 2);
|
|
|
|
ensureValid();
|
2021-09-04 21:55:14 +08:00
|
|
|
}
|
|
|
|
|
2021-09-06 13:09:40 +08:00
|
|
|
private void ensureValid() => AddAssert("area valid", () => settings.AreaSelection.IsWithinBounds);
|
2021-09-04 14:35:54 +08:00
|
|
|
|
2021-09-06 13:09:40 +08:00
|
|
|
private void ensureInvalid() => AddAssert("area invalid", () => !settings.AreaSelection.IsWithinBounds);
|
2021-09-04 22:19:05 +08:00
|
|
|
|
2021-03-16 13:45:21 +08:00
|
|
|
public class TestTabletHandler : ITabletHandler
|
|
|
|
{
|
2021-03-17 11:50:02 +08:00
|
|
|
public Bindable<Vector2> AreaOffset { get; } = new Bindable<Vector2>();
|
|
|
|
public Bindable<Vector2> AreaSize { get; } = new Bindable<Vector2>();
|
|
|
|
|
2021-03-30 11:40:50 +08:00
|
|
|
public Bindable<float> Rotation { get; } = new Bindable<float>();
|
|
|
|
|
2021-03-17 11:50:02 +08:00
|
|
|
public IBindable<TabletInfo> Tablet => tablet;
|
|
|
|
|
|
|
|
private readonly Bindable<TabletInfo> tablet = new Bindable<TabletInfo>();
|
2021-03-16 13:45:21 +08:00
|
|
|
|
|
|
|
public BindableBool Enabled { get; } = new BindableBool(true);
|
|
|
|
|
2021-03-17 11:50:02 +08:00
|
|
|
public void SetTabletSize(Vector2 size)
|
2021-03-16 22:47:08 +08:00
|
|
|
{
|
2021-03-17 11:50:02 +08:00
|
|
|
tablet.Value = size != Vector2.Zero ? new TabletInfo($"test tablet T-{RNG.Next(999):000}", size) : null;
|
|
|
|
|
|
|
|
AreaSize.Default = new Vector2(size.X, size.Y);
|
|
|
|
|
|
|
|
// if it's clear the user has not configured the area, take the full area from the tablet that was just found.
|
|
|
|
if (AreaSize.Value == Vector2.Zero)
|
|
|
|
AreaSize.SetDefault();
|
|
|
|
|
|
|
|
AreaOffset.Default = new Vector2(size.X / 2, size.Y / 2);
|
|
|
|
|
|
|
|
// likewise with the position, use the centre point if it has not been configured.
|
|
|
|
// it's safe to assume no user would set their centre point to 0,0 for now.
|
|
|
|
if (AreaOffset.Value == Vector2.Zero)
|
|
|
|
AreaOffset.SetDefault();
|
2021-03-16 22:47:08 +08:00
|
|
|
}
|
2021-03-15 17:37:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|