mirror of https://github.com/ppy/osu
Implement grid size toggling matching stable
This commit is contained in:
parent
c403e628dd
commit
4e094b2127
|
@ -5,8 +5,8 @@
|
|||
using NUnit.Framework;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Rulesets.Osu.Edit;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
using osu.Game.Tests.Visual;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Tests.Editor
|
||||
|
@ -24,11 +24,33 @@ public void TestGridExclusivity()
|
|||
|
||||
AddStep("enable rectangular grid", () => InputManager.Key(Key.Y));
|
||||
AddUntilStep("distance snap grid hidden", () => !this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
||||
AddUntilStep("rectangular grid visible", () => this.ChildrenOfType<RectangularPositionSnapGrid>().Any());
|
||||
AddUntilStep("rectangular grid visible", () => this.ChildrenOfType<OsuRectangularPositionSnapGrid>().Any());
|
||||
|
||||
AddStep("enable distance snap grid", () => InputManager.Key(Key.T));
|
||||
AddUntilStep("distance snap grid visible", () => this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
||||
AddUntilStep("rectangular grid hidden", () => !this.ChildrenOfType<RectangularPositionSnapGrid>().Any());
|
||||
AddUntilStep("rectangular grid hidden", () => !this.ChildrenOfType<OsuRectangularPositionSnapGrid>().Any());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGridSizeToggling()
|
||||
{
|
||||
AddStep("enable rectangular grid", () => InputManager.Key(Key.Y));
|
||||
AddUntilStep("rectangular grid visible", () => this.ChildrenOfType<OsuRectangularPositionSnapGrid>().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<OsuRectangularPositionSnapGrid>().Single().Spacing == new Vector2(size));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.Osu.UI;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens.Edit.Components.TernaryButtons;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
|
@ -309,7 +308,7 @@ private void updateRectangularPositionSnapGrid()
|
|||
|
||||
if (gridSnapToggle.Value == TernaryState.True)
|
||||
{
|
||||
rectangularPositionSnapGridContainer.Add(rectangularPositionSnapGrid = new RectangularPositionSnapGrid(OsuPlayfield.BASE_SIZE / 2, new Vector2(16))
|
||||
rectangularPositionSnapGridContainer.Add(rectangularPositionSnapGrid = new OsuRectangularPositionSnapGrid(EditorBeatmap.BeatmapInfo.GridSize)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
});
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
// 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 System;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Osu.UI;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit
|
||||
{
|
||||
public class OsuRectangularPositionSnapGrid : RectangularPositionSnapGrid
|
||||
{
|
||||
private static readonly int[] grid_sizes = { 4, 8, 16, 32 };
|
||||
|
||||
private int currentGridSizeIndex;
|
||||
|
||||
public OsuRectangularPositionSnapGrid(int gridSize)
|
||||
: base(OsuPlayfield.BASE_SIZE / 2)
|
||||
{
|
||||
var gridSizeIndex = Array.IndexOf(grid_sizes, gridSize);
|
||||
if (gridSizeIndex > 0)
|
||||
currentGridSizeIndex = gridSizeIndex;
|
||||
updateSpacing();
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
{
|
||||
if (e.Key == Key.G)
|
||||
{
|
||||
nextGridSize();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void nextGridSize()
|
||||
{
|
||||
currentGridSizeIndex = (currentGridSizeIndex + 1) % grid_sizes.Length;
|
||||
updateSpacing();
|
||||
}
|
||||
|
||||
private void updateSpacing()
|
||||
{
|
||||
Spacing = new Vector2(grid_sizes[currentGridSizeIndex]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -49,9 +49,10 @@ public void TestRectangularGrid(Vector2 position, Vector2 spacing)
|
|||
{
|
||||
RectangularPositionSnapGrid grid = null;
|
||||
|
||||
AddStep("create grid", () => Child = grid = new RectangularPositionSnapGrid(position, spacing)
|
||||
AddStep("create grid", () => Child = grid = new RectangularPositionSnapGrid(position)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Spacing = spacing
|
||||
});
|
||||
|
||||
AddStep("add snapping cursor", () => Add(new SnappingCursorContainer
|
||||
|
|
|
@ -17,17 +17,29 @@ public class RectangularPositionSnapGrid : CompositeDrawable
|
|||
/// </summary>
|
||||
public Vector2 StartPosition { get; }
|
||||
|
||||
private Vector2 spacing = Vector2.One;
|
||||
|
||||
/// <summary>
|
||||
/// The spacing between grid lines of this <see cref="RectangularPositionSnapGrid"/>.
|
||||
/// </summary>
|
||||
public Vector2 Spacing { get; }
|
||||
public Vector2 Spacing
|
||||
{
|
||||
get => spacing;
|
||||
set
|
||||
{
|
||||
if (spacing.X <= 0 || spacing.Y <= 0)
|
||||
throw new ArgumentException("Grid spacing must be positive.");
|
||||
|
||||
spacing = value;
|
||||
gridCache.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly LayoutValue gridCache = new LayoutValue(Invalidation.RequiredParentSizeToFit);
|
||||
|
||||
public RectangularPositionSnapGrid(Vector2 startPosition, Vector2 spacing)
|
||||
public RectangularPositionSnapGrid(Vector2 startPosition)
|
||||
{
|
||||
StartPosition = startPosition;
|
||||
Spacing = spacing;
|
||||
|
||||
AddLayout(gridCache);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue