2021-09-20 00:45:22 +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.
|
|
|
|
|
|
|
|
using System;
|
2021-09-20 15:43:15 +08:00
|
|
|
using osu.Framework.Input.Bindings;
|
2021-09-20 00:45:22 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2021-09-20 15:43:15 +08:00
|
|
|
using osu.Game.Input.Bindings;
|
2021-09-20 00:45:22 +08:00
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Edit
|
|
|
|
{
|
2021-09-20 15:43:15 +08:00
|
|
|
public class OsuRectangularPositionSnapGrid : RectangularPositionSnapGrid, IKeyBindingHandler<GlobalAction>
|
2021-09-20 00:45:22 +08:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void nextGridSize()
|
|
|
|
{
|
|
|
|
currentGridSizeIndex = (currentGridSizeIndex + 1) % grid_sizes.Length;
|
|
|
|
updateSpacing();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSpacing()
|
|
|
|
{
|
|
|
|
Spacing = new Vector2(grid_sizes[currentGridSizeIndex]);
|
|
|
|
}
|
2021-09-20 15:43:15 +08:00
|
|
|
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
|
|
|
{
|
|
|
|
switch (e.Action)
|
|
|
|
{
|
|
|
|
case GlobalAction.EditorCycleGridDisplayMode:
|
|
|
|
nextGridSize();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
|
|
|
{
|
|
|
|
}
|
2021-09-20 00:45:22 +08:00
|
|
|
}
|
|
|
|
}
|