2019-10-10 12:55:48 +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.
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2019-10-25 08:25:46 +00:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2021-09-01 09:05:10 +00:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2022-01-12 14:17:35 +00:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2019-10-10 12:55:48 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
|
|
|
using osu.Game.Screens.Edit;
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2020-04-23 08:07:55 +00:00
|
|
|
namespace osu.Game.Tests.Visual.Editing
|
2019-10-10 12:55:48 +00:00
|
|
|
{
|
2019-10-17 06:32:02 +00:00
|
|
|
public class TestSceneDistanceSnapGrid : EditorClockTestScene
|
2019-10-10 12:55:48 +00:00
|
|
|
{
|
|
|
|
private const double beat_length = 100;
|
|
|
|
private static readonly Vector2 grid_position = new Vector2(512, 384);
|
|
|
|
|
2019-12-27 10:46:33 +00:00
|
|
|
[Cached(typeof(EditorBeatmap))]
|
2019-12-27 10:39:30 +00:00
|
|
|
private readonly EditorBeatmap editorBeatmap;
|
2019-10-10 12:55:48 +00:00
|
|
|
|
2020-05-20 08:48:43 +00:00
|
|
|
[Cached(typeof(IPositionSnapProvider))]
|
2019-10-25 08:25:46 +00:00
|
|
|
private readonly SnapProvider snapProvider = new SnapProvider();
|
2019-10-10 12:55:48 +00:00
|
|
|
|
2019-10-17 06:32:02 +00:00
|
|
|
public TestSceneDistanceSnapGrid()
|
2019-10-10 12:55:48 +00:00
|
|
|
{
|
2022-01-12 14:17:35 +00:00
|
|
|
editorBeatmap = new EditorBeatmap(new OsuBeatmap
|
|
|
|
{
|
|
|
|
BeatmapInfo =
|
|
|
|
{
|
|
|
|
Ruleset = new OsuRuleset().RulesetInfo
|
|
|
|
}
|
|
|
|
});
|
2019-10-25 10:48:01 +00:00
|
|
|
editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = beat_length });
|
2019-11-06 07:20:13 +00:00
|
|
|
}
|
2019-10-11 08:17:08 +00:00
|
|
|
|
2019-11-06 07:20:13 +00:00
|
|
|
[SetUp]
|
|
|
|
public void Setup() => Schedule(() =>
|
|
|
|
{
|
2019-10-25 08:25:46 +00:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.SlateGray
|
|
|
|
},
|
2019-12-10 07:00:09 +00:00
|
|
|
new TestDistanceSnapGrid()
|
2019-10-25 08:25:46 +00:00
|
|
|
};
|
2019-11-06 07:20:13 +00:00
|
|
|
});
|
2019-10-10 12:55:48 +00:00
|
|
|
|
|
|
|
[TestCase(1)]
|
|
|
|
[TestCase(2)]
|
|
|
|
[TestCase(3)]
|
|
|
|
[TestCase(4)]
|
|
|
|
[TestCase(6)]
|
|
|
|
[TestCase(8)]
|
|
|
|
[TestCase(12)]
|
|
|
|
[TestCase(16)]
|
2019-10-25 08:25:46 +00:00
|
|
|
public void TestBeatDivisor(int divisor)
|
2019-10-10 12:55:48 +00:00
|
|
|
{
|
|
|
|
AddStep($"set beat divisor = {divisor}", () => BeatDivisor.Value = divisor);
|
|
|
|
}
|
|
|
|
|
2019-11-06 07:20:13 +00:00
|
|
|
[Test]
|
|
|
|
public void TestLimitedDistance()
|
|
|
|
{
|
|
|
|
AddStep("create limited grid", () =>
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.SlateGray
|
|
|
|
},
|
2019-12-10 07:00:09 +00:00
|
|
|
new TestDistanceSnapGrid(100)
|
2019-11-06 07:20:13 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-17 06:32:02 +00:00
|
|
|
private class TestDistanceSnapGrid : DistanceSnapGrid
|
2019-10-10 12:55:48 +00:00
|
|
|
{
|
|
|
|
public new float DistanceSpacing => base.DistanceSpacing;
|
|
|
|
|
2019-12-10 07:00:09 +00:00
|
|
|
public TestDistanceSnapGrid(double? endTime = null)
|
2021-09-01 09:05:10 +00:00
|
|
|
: base(new HitObject(), grid_position, 0, endTime)
|
2019-10-10 12:55:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-01-28 02:59:21 +00:00
|
|
|
protected override void CreateContent()
|
2019-10-10 12:55:48 +00:00
|
|
|
{
|
|
|
|
AddInternal(new Circle
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(5),
|
2020-01-28 02:59:21 +00:00
|
|
|
Position = StartPosition
|
2019-10-10 12:55:48 +00:00
|
|
|
});
|
|
|
|
|
2020-01-28 02:59:21 +00:00
|
|
|
int indexFromPlacement = 0;
|
2019-10-10 12:55:48 +00:00
|
|
|
|
2020-01-28 02:59:21 +00:00
|
|
|
for (float s = StartPosition.X + DistanceSpacing; s <= DrawWidth && indexFromPlacement < MaxIntervals; s += DistanceSpacing, indexFromPlacement++)
|
2019-10-10 12:55:48 +00:00
|
|
|
{
|
|
|
|
AddInternal(new Circle
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(5, 10),
|
2020-01-28 02:59:21 +00:00
|
|
|
Position = new Vector2(s, StartPosition.Y),
|
|
|
|
Colour = GetColourForIndexFromPlacement(indexFromPlacement)
|
2019-10-10 12:55:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-28 02:59:21 +00:00
|
|
|
indexFromPlacement = 0;
|
2019-10-10 12:55:48 +00:00
|
|
|
|
2020-01-28 02:59:21 +00:00
|
|
|
for (float s = StartPosition.X - DistanceSpacing; s >= 0 && indexFromPlacement < MaxIntervals; s -= DistanceSpacing, indexFromPlacement++)
|
2019-10-10 12:55:48 +00:00
|
|
|
{
|
|
|
|
AddInternal(new Circle
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(5, 10),
|
2020-01-28 02:59:21 +00:00
|
|
|
Position = new Vector2(s, StartPosition.Y),
|
|
|
|
Colour = GetColourForIndexFromPlacement(indexFromPlacement)
|
2019-10-10 12:55:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-28 02:59:21 +00:00
|
|
|
indexFromPlacement = 0;
|
2019-10-10 12:55:48 +00:00
|
|
|
|
2020-01-28 02:59:21 +00:00
|
|
|
for (float s = StartPosition.Y + DistanceSpacing; s <= DrawHeight && indexFromPlacement < MaxIntervals; s += DistanceSpacing, indexFromPlacement++)
|
2019-10-10 12:55:48 +00:00
|
|
|
{
|
|
|
|
AddInternal(new Circle
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(10, 5),
|
2020-01-28 02:59:21 +00:00
|
|
|
Position = new Vector2(StartPosition.X, s),
|
|
|
|
Colour = GetColourForIndexFromPlacement(indexFromPlacement)
|
2019-10-10 12:55:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-28 02:59:21 +00:00
|
|
|
indexFromPlacement = 0;
|
2019-10-10 12:55:48 +00:00
|
|
|
|
2020-01-28 02:59:21 +00:00
|
|
|
for (float s = StartPosition.Y - DistanceSpacing; s >= 0 && indexFromPlacement < MaxIntervals; s -= DistanceSpacing, indexFromPlacement++)
|
2019-10-10 12:55:48 +00:00
|
|
|
{
|
|
|
|
AddInternal(new Circle
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(10, 5),
|
2020-01-28 02:59:21 +00:00
|
|
|
Position = new Vector2(StartPosition.X, s),
|
|
|
|
Colour = GetColourForIndexFromPlacement(indexFromPlacement)
|
2019-10-10 12:55:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 03:34:49 +00:00
|
|
|
public override (Vector2 position, double time) GetSnappedPosition(Vector2 screenSpacePosition)
|
|
|
|
=> (Vector2.Zero, 0);
|
2019-10-10 12:55:48 +00:00
|
|
|
}
|
2019-10-25 08:25:46 +00:00
|
|
|
|
2020-05-20 08:48:43 +00:00
|
|
|
private class SnapProvider : IPositionSnapProvider
|
2019-10-25 08:25:46 +00:00
|
|
|
{
|
2020-11-24 08:14:39 +00:00
|
|
|
public SnapResult SnapScreenSpacePositionToValidPosition(Vector2 screenSpacePosition) =>
|
|
|
|
new SnapResult(screenSpacePosition, null);
|
|
|
|
|
2020-05-20 09:19:21 +00:00
|
|
|
public SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition) => new SnapResult(screenSpacePosition, 0);
|
2019-10-25 08:25:46 +00:00
|
|
|
|
2021-09-01 09:05:10 +00:00
|
|
|
public float GetBeatSnapDistanceAt(HitObject referenceObject) => 10;
|
2019-10-25 08:25:46 +00:00
|
|
|
|
2021-09-01 09:05:10 +00:00
|
|
|
public float DurationToDistance(HitObject referenceObject, double duration) => (float)duration;
|
2019-10-25 08:25:46 +00:00
|
|
|
|
2021-09-01 09:05:10 +00:00
|
|
|
public double DistanceToDuration(HitObject referenceObject, float distance) => distance;
|
2019-10-25 08:25:46 +00:00
|
|
|
|
2021-09-01 09:05:10 +00:00
|
|
|
public double GetSnappedDurationFromDistance(HitObject referenceObject, float distance) => 0;
|
2019-10-10 12:55:48 +00:00
|
|
|
|
2021-09-01 09:05:10 +00:00
|
|
|
public float GetSnappedDistanceFromDistance(HitObject referenceObject, float distance) => 0;
|
2019-10-10 12:55:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|