2021-09-19 15:58:32 +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.
|
|
|
|
|
|
2024-01-01 14:46:07 +00:00
|
|
|
|
using System;
|
2021-09-19 15:58:32 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.Testing;
|
2021-09-20 18:32:34 +00:00
|
|
|
|
using osu.Framework.Utils;
|
2024-05-02 11:59:40 +00:00
|
|
|
|
using osu.Game.Rulesets.Edit;
|
2021-09-19 15:58:32 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Edit;
|
2021-09-20 18:32:34 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles;
|
2023-12-28 22:10:06 +00:00
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
2021-09-19 15:58:32 +00:00
|
|
|
|
using osu.Game.Tests.Visual;
|
2023-12-31 18:53:32 +00:00
|
|
|
|
using osu.Game.Utils;
|
2021-09-19 16:45:22 +00:00
|
|
|
|
using osuTK;
|
2021-09-19 15:58:32 +00:00
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests.Editor
|
|
|
|
|
{
|
|
|
|
|
public partial class TestSceneOsuEditorGrids : EditorTestScene
|
|
|
|
|
{
|
|
|
|
|
protected override Ruleset CreateEditorRuleset() => new OsuRuleset();
|
|
|
|
|
|
|
|
|
|
[Test]
|
2022-10-25 05:32:08 +00:00
|
|
|
|
public void TestGridToggles()
|
2021-09-19 15:58:32 +00:00
|
|
|
|
{
|
2024-08-20 07:14:05 +00:00
|
|
|
|
AddStep("enable distance snap grid", () => InputManager.Key(Key.Y));
|
2021-09-19 15:58:32 +00:00
|
|
|
|
AddStep("select second object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.ElementAt(1)));
|
2022-10-25 05:32:08 +00:00
|
|
|
|
|
2021-09-19 15:58:32 +00:00
|
|
|
|
AddUntilStep("distance snap grid visible", () => this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
2023-12-31 18:53:32 +00:00
|
|
|
|
gridActive<RectangularPositionSnapGrid>(false);
|
2021-09-19 15:58:32 +00:00
|
|
|
|
|
2024-08-20 07:14:05 +00:00
|
|
|
|
AddStep("enable rectangular grid", () => InputManager.Key(Key.T));
|
2022-10-25 05:32:08 +00:00
|
|
|
|
|
|
|
|
|
AddStep("select second object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.ElementAt(1)));
|
|
|
|
|
AddUntilStep("distance snap grid still visible", () => this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
2023-12-31 18:53:32 +00:00
|
|
|
|
gridActive<RectangularPositionSnapGrid>(true);
|
2021-09-19 15:58:32 +00:00
|
|
|
|
|
2024-08-20 07:14:05 +00:00
|
|
|
|
AddStep("disable distance snap grid", () => InputManager.Key(Key.Y));
|
2022-10-25 05:32:08 +00:00
|
|
|
|
AddUntilStep("distance snap grid hidden", () => !this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
2021-09-20 18:32:34 +00:00
|
|
|
|
AddStep("select second object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.ElementAt(1)));
|
2023-12-31 18:53:32 +00:00
|
|
|
|
gridActive<RectangularPositionSnapGrid>(true);
|
2022-10-25 05:32:08 +00:00
|
|
|
|
|
2024-08-20 07:14:05 +00:00
|
|
|
|
AddStep("disable rectangular grid", () => InputManager.Key(Key.T));
|
2022-10-25 05:32:08 +00:00
|
|
|
|
AddUntilStep("distance snap grid still hidden", () => !this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
2023-12-31 18:53:32 +00:00
|
|
|
|
gridActive<RectangularPositionSnapGrid>(false);
|
2021-09-20 18:32:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 05:36:35 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestDistanceSnapMomentaryToggle()
|
|
|
|
|
{
|
|
|
|
|
AddStep("select second object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.ElementAt(1)));
|
|
|
|
|
|
|
|
|
|
AddUntilStep("distance snap grid hidden", () => !this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
|
|
|
|
AddStep("hold alt", () => InputManager.PressKey(Key.AltLeft));
|
|
|
|
|
AddUntilStep("distance snap grid visible", () => this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
|
|
|
|
AddStep("release alt", () => InputManager.ReleaseKey(Key.AltLeft));
|
|
|
|
|
AddUntilStep("distance snap grid hidden", () => !this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
2024-05-02 12:15:46 +00:00
|
|
|
|
|
2024-08-20 07:14:05 +00:00
|
|
|
|
AddStep("enable distance snap grid", () => InputManager.Key(Key.Y));
|
2024-05-02 12:15:46 +00:00
|
|
|
|
AddUntilStep("distance snap grid visible", () => this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
|
|
|
|
AddStep("hold alt", () => InputManager.PressKey(Key.AltLeft));
|
|
|
|
|
AddUntilStep("distance snap grid hidden", () => !this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
|
|
|
|
AddStep("release alt", () => InputManager.ReleaseKey(Key.AltLeft));
|
|
|
|
|
AddUntilStep("distance snap grid visible", () => this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
2022-10-25 05:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-02 11:59:40 +00:00
|
|
|
|
[Test]
|
2024-05-02 12:15:46 +00:00
|
|
|
|
public void TestDistanceSnapAdjustDoesNotHideTheGridIfStartingEnabled()
|
2024-05-02 11:59:40 +00:00
|
|
|
|
{
|
|
|
|
|
double distanceSnap = double.PositiveInfinity;
|
|
|
|
|
|
2024-08-20 07:14:05 +00:00
|
|
|
|
AddStep("enable distance snap grid", () => InputManager.Key(Key.Y));
|
2024-05-02 11:59:40 +00:00
|
|
|
|
|
|
|
|
|
AddStep("select second object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.ElementAt(1)));
|
|
|
|
|
AddUntilStep("distance snap grid visible", () => this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
|
|
|
|
AddStep("store distance snap", () => distanceSnap = this.ChildrenOfType<IDistanceSnapProvider>().First().DistanceSpacingMultiplier.Value);
|
|
|
|
|
|
|
|
|
|
AddStep("increase distance", () =>
|
|
|
|
|
{
|
|
|
|
|
InputManager.PressKey(Key.AltLeft);
|
|
|
|
|
InputManager.PressKey(Key.ControlLeft);
|
|
|
|
|
InputManager.ScrollVerticalBy(1);
|
|
|
|
|
InputManager.ReleaseKey(Key.ControlLeft);
|
|
|
|
|
InputManager.ReleaseKey(Key.AltLeft);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("distance snap increased", () => this.ChildrenOfType<IDistanceSnapProvider>().First().DistanceSpacingMultiplier.Value, () => Is.GreaterThan(distanceSnap));
|
|
|
|
|
AddUntilStep("distance snap grid still visible", () => this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-02 12:15:46 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestDistanceSnapAdjustShowsGridMomentarilyIfStartingDisabled()
|
|
|
|
|
{
|
|
|
|
|
double distanceSnap = double.PositiveInfinity;
|
|
|
|
|
|
|
|
|
|
AddStep("select second object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.ElementAt(1)));
|
|
|
|
|
AddUntilStep("distance snap grid hidden", () => !this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
|
|
|
|
AddStep("store distance snap", () => distanceSnap = this.ChildrenOfType<IDistanceSnapProvider>().First().DistanceSpacingMultiplier.Value);
|
|
|
|
|
|
|
|
|
|
AddStep("start increasing distance", () =>
|
|
|
|
|
{
|
|
|
|
|
InputManager.PressKey(Key.AltLeft);
|
|
|
|
|
InputManager.PressKey(Key.ControlLeft);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("distance snap grid visible", () => this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
|
|
|
|
|
|
|
|
|
AddStep("finish increasing distance", () =>
|
|
|
|
|
{
|
|
|
|
|
InputManager.ScrollVerticalBy(1);
|
|
|
|
|
InputManager.ReleaseKey(Key.ControlLeft);
|
|
|
|
|
InputManager.ReleaseKey(Key.AltLeft);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("distance snap increased", () => this.ChildrenOfType<IDistanceSnapProvider>().First().DistanceSpacingMultiplier.Value, () => Is.GreaterThan(distanceSnap));
|
|
|
|
|
AddUntilStep("distance snap hidden in the end", () => !this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
2022-10-25 05:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGridSnapMomentaryToggle()
|
|
|
|
|
{
|
2023-12-31 18:53:32 +00:00
|
|
|
|
gridActive<RectangularPositionSnapGrid>(false);
|
2022-10-25 05:36:35 +00:00
|
|
|
|
AddStep("hold shift", () => InputManager.PressKey(Key.ShiftLeft));
|
2023-12-31 18:53:32 +00:00
|
|
|
|
gridActive<RectangularPositionSnapGrid>(true);
|
2022-10-25 05:36:35 +00:00
|
|
|
|
AddStep("release shift", () => InputManager.ReleaseKey(Key.ShiftLeft));
|
2023-12-31 18:53:32 +00:00
|
|
|
|
gridActive<RectangularPositionSnapGrid>(false);
|
2022-10-25 05:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-31 18:53:32 +00:00
|
|
|
|
private void gridActive<T>(bool active) where T : PositionSnapGrid
|
2021-09-20 18:32:34 +00:00
|
|
|
|
{
|
|
|
|
|
AddStep("choose placement tool", () => InputManager.Key(Key.Number2));
|
2023-12-31 18:53:32 +00:00
|
|
|
|
AddStep("move cursor to spacing + (1, 1)", () =>
|
2021-09-20 18:32:34 +00:00
|
|
|
|
{
|
2023-12-31 18:53:32 +00:00
|
|
|
|
var composer = Editor.ChildrenOfType<T>().Single();
|
|
|
|
|
InputManager.MoveMouseTo(composer.ToScreenSpace(uniqueSnappingPosition(composer) + new Vector2(1, 1)));
|
2021-09-20 18:32:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (active)
|
2023-12-31 18:53:32 +00:00
|
|
|
|
{
|
|
|
|
|
AddAssert("placement blueprint at spacing + (0, 0)", () =>
|
|
|
|
|
{
|
|
|
|
|
var composer = Editor.ChildrenOfType<T>().Single();
|
|
|
|
|
return Precision.AlmostEquals(Editor.ChildrenOfType<HitCirclePlacementBlueprint>().Single().HitObject.Position,
|
|
|
|
|
uniqueSnappingPosition(composer));
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-09-20 18:32:34 +00:00
|
|
|
|
else
|
2023-12-31 18:53:32 +00:00
|
|
|
|
{
|
|
|
|
|
AddAssert("placement blueprint at spacing + (1, 1)", () =>
|
|
|
|
|
{
|
|
|
|
|
var composer = Editor.ChildrenOfType<T>().Single();
|
|
|
|
|
return Precision.AlmostEquals(Editor.ChildrenOfType<HitCirclePlacementBlueprint>().Single().HitObject.Position,
|
|
|
|
|
uniqueSnappingPosition(composer) + new Vector2(1, 1));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Vector2 uniqueSnappingPosition(PositionSnapGrid grid)
|
|
|
|
|
{
|
|
|
|
|
return grid switch
|
|
|
|
|
{
|
|
|
|
|
RectangularPositionSnapGrid rectangular => rectangular.StartPosition.Value + GeometryUtils.RotateVector(rectangular.Spacing.Value, -rectangular.GridLineRotation.Value),
|
2024-01-01 14:46:07 +00:00
|
|
|
|
TriangularPositionSnapGrid triangular => triangular.StartPosition.Value + GeometryUtils.RotateVector(new Vector2(triangular.Spacing.Value / 2, triangular.Spacing.Value / 2 * MathF.Sqrt(3)), -triangular.GridLineRotation.Value),
|
|
|
|
|
CircularPositionSnapGrid circular => circular.StartPosition.Value + GeometryUtils.RotateVector(new Vector2(circular.Spacing.Value, 0), -45),
|
2023-12-31 18:53:32 +00:00
|
|
|
|
_ => Vector2.Zero
|
|
|
|
|
};
|
2021-09-19 15:58:32 +00:00
|
|
|
|
}
|
2021-09-19 16:45:22 +00:00
|
|
|
|
|
2023-12-31 20:57:11 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGridSizeToggling()
|
|
|
|
|
{
|
2024-08-20 07:14:05 +00:00
|
|
|
|
AddStep("enable rectangular grid", () => InputManager.Key(Key.T));
|
2023-12-31 20:57:11 +00:00
|
|
|
|
AddUntilStep("rectangular grid visible", () => this.ChildrenOfType<RectangularPositionSnapGrid>().Any());
|
|
|
|
|
gridSizeIs(4);
|
|
|
|
|
|
|
|
|
|
nextGridSizeIs(8);
|
|
|
|
|
nextGridSizeIs(16);
|
|
|
|
|
nextGridSizeIs(32);
|
|
|
|
|
nextGridSizeIs(4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void nextGridSizeIs(int size)
|
|
|
|
|
{
|
|
|
|
|
AddStep("toggle to next grid size", () => InputManager.Key(Key.G));
|
|
|
|
|
gridSizeIs(size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void gridSizeIs(int size)
|
|
|
|
|
=> AddAssert($"grid size is {size}", () => this.ChildrenOfType<RectangularPositionSnapGrid>().Single().Spacing.Value == new Vector2(size)
|
|
|
|
|
&& EditorBeatmap.BeatmapInfo.GridSize == size);
|
2021-09-19 15:58:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|