2019-01-24 08:43:03 +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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
2020-03-18 21:23:06 +00:00
|
|
|
|
using System.Linq;
|
2020-03-18 19:04:38 +00:00
|
|
|
|
using NUnit.Framework;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2020-03-18 21:23:06 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Testing;
|
2018-11-06 09:28:22 +00:00
|
|
|
|
using osu.Game.Screens.Edit;
|
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2020-03-18 20:55:35 +00:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-04-23 08:07:55 +00:00
|
|
|
|
namespace osu.Game.Tests.Visual.Editing
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-03-23 01:01:33 +00:00
|
|
|
|
public class TestSceneBeatDivisorControl : OsuManualInputManagerTestScene
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-03-18 19:04:38 +00:00
|
|
|
|
private BeatDivisorControl beatDivisorControl;
|
|
|
|
|
private BindableBeatDivisor bindableBeatDivisor;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-03-18 21:23:06 +00:00
|
|
|
|
private SliderBar<int> tickSliderBar;
|
|
|
|
|
private EquilateralTriangle tickMarkerHead;
|
|
|
|
|
|
2020-03-18 20:54:17 +00:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() => Schedule(() =>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-03-18 20:54:17 +00:00
|
|
|
|
Child = beatDivisorControl = new BeatDivisorControl(bindableBeatDivisor = new BindableBeatDivisor(16))
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(90, 90)
|
|
|
|
|
};
|
2020-03-18 21:23:06 +00:00
|
|
|
|
|
|
|
|
|
tickSliderBar = beatDivisorControl.ChildrenOfType<SliderBar<int>>().Single();
|
|
|
|
|
tickMarkerHead = tickSliderBar.ChildrenOfType<EquilateralTriangle>().Single();
|
2020-03-18 20:54:17 +00:00
|
|
|
|
});
|
2020-03-18 19:04:38 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestBindableBeatDivisor()
|
|
|
|
|
{
|
2020-03-18 21:23:06 +00:00
|
|
|
|
AddRepeatStep("move previous", () => bindableBeatDivisor.Previous(), 4);
|
|
|
|
|
AddAssert("divisor is 4", () => bindableBeatDivisor.Value == 4);
|
|
|
|
|
AddRepeatStep("move next", () => bindableBeatDivisor.Next(), 3);
|
|
|
|
|
AddAssert("divisor is 12", () => bindableBeatDivisor.Value == 12);
|
2020-03-18 19:04:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestMouseInput()
|
|
|
|
|
{
|
2020-03-18 21:23:06 +00:00
|
|
|
|
AddStep("hold marker", () =>
|
2020-03-18 19:04:38 +00:00
|
|
|
|
{
|
2020-03-18 21:23:06 +00:00
|
|
|
|
InputManager.MoveMouseTo(tickMarkerHead.ScreenSpaceDrawQuad.Centre);
|
2020-03-18 20:55:35 +00:00
|
|
|
|
InputManager.PressButton(MouseButton.Left);
|
2020-03-18 19:04:38 +00:00
|
|
|
|
});
|
2020-03-18 21:23:06 +00:00
|
|
|
|
AddStep("move to 8 and release", () =>
|
2020-03-18 19:04:38 +00:00
|
|
|
|
{
|
2020-03-18 21:23:06 +00:00
|
|
|
|
InputManager.MoveMouseTo(tickSliderBar.ScreenSpaceDrawQuad.Centre);
|
2020-03-18 20:55:35 +00:00
|
|
|
|
InputManager.ReleaseButton(MouseButton.Left);
|
2020-03-18 19:04:38 +00:00
|
|
|
|
});
|
2020-03-18 21:23:06 +00:00
|
|
|
|
AddAssert("divisor is 8", () => bindableBeatDivisor.Value == 8);
|
|
|
|
|
AddStep("hold marker", () => InputManager.PressButton(MouseButton.Left));
|
|
|
|
|
AddStep("move to 16", () => InputManager.MoveMouseTo(getPositionForDivisor(16)));
|
|
|
|
|
AddStep("move to ~10 and release", () =>
|
2020-03-18 19:04:38 +00:00
|
|
|
|
{
|
2020-03-18 21:23:06 +00:00
|
|
|
|
InputManager.MoveMouseTo(getPositionForDivisor(10));
|
2020-03-18 20:55:35 +00:00
|
|
|
|
InputManager.ReleaseButton(MouseButton.Left);
|
2020-03-18 19:04:38 +00:00
|
|
|
|
});
|
2020-03-18 21:23:06 +00:00
|
|
|
|
AddAssert("divisor clamped to 8", () => bindableBeatDivisor.Value == 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Vector2 getPositionForDivisor(int divisor)
|
|
|
|
|
{
|
|
|
|
|
var relativePosition = (float)Math.Clamp(divisor, 0, 16) / 16;
|
|
|
|
|
var sliderDrawQuad = tickSliderBar.ScreenSpaceDrawQuad;
|
|
|
|
|
return new Vector2(
|
|
|
|
|
sliderDrawQuad.TopLeft.X + sliderDrawQuad.Width * relativePosition,
|
|
|
|
|
sliderDrawQuad.Centre.Y
|
|
|
|
|
);
|
2020-03-18 19:04:38 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|