Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to change position, spacing, and rotation of the positional snap grid in the editor #26309

Merged
merged 36 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f3b88c3
Add rotation to snap grid visual
OliBomby Dec 28, 2023
f2edd70
add rotation to snapped position
OliBomby Dec 28, 2023
2193601
fix typo
OliBomby Dec 28, 2023
92c3b14
Added Triangular snap grid
OliBomby Dec 28, 2023
d0c8b28
clean up code duplication
OliBomby Dec 28, 2023
a20c430
fix wrong grid cache being used
OliBomby Dec 28, 2023
b16c232
add basic control by grid tool box
OliBomby Dec 28, 2023
0ce1a48
Add comment
OliBomby Dec 28, 2023
f223487
improve code
OliBomby Dec 28, 2023
351cfbf
Fix snapping going out of bounds
OliBomby Dec 28, 2023
8ef9bdf
clarify comment
OliBomby Dec 28, 2023
040fd5e
Add option to change grid type
OliBomby Dec 29, 2023
8a33105
Make it actually possible to change grid type
OliBomby Dec 29, 2023
847f04e
reduce opacity of middle cardinal lines
OliBomby Dec 29, 2023
d0ca3f2
Add circular grid
OliBomby Dec 29, 2023
f649fa1
Added bindables and binding with BindTo
OliBomby Dec 29, 2023
1c75357
fix compile
OliBomby Dec 30, 2023
9a8c41f
Saving exact grid spacing
OliBomby Dec 30, 2023
493e3a5
use G to change grid type
OliBomby Dec 31, 2023
e47d570
improve UI
OliBomby Dec 31, 2023
904ea2e
move OutlineTriangle code down
OliBomby Dec 31, 2023
33e559f
add integer keyboard step to sliders
OliBomby Dec 31, 2023
20e338b
also hide grid from points button when not hovered
OliBomby Dec 31, 2023
8425c72
fix rectangular and triangular grid tests
OliBomby Dec 31, 2023
31d1799
Create TestSceneCircularPositionSnapGrid.cs
OliBomby Dec 31, 2023
9796fcf
Merge position snap grid tests into single file
OliBomby Dec 31, 2023
c5edf43
fix grid test
OliBomby Dec 31, 2023
594b6fe
Add back the old keybind for cycling grid spacing
OliBomby Dec 31, 2023
39f4a1a
conflict fixes
OliBomby Jan 1, 2024
de14da9
Remove other grid types
OliBomby Jan 1, 2024
460c584
fix code quality
OliBomby Jan 1, 2024
1428cbf
Remove Masking from PositionSnapGrid
OliBomby Feb 1, 2024
9f19ab0
Merge branch 'master' into grids-1
bdach May 24, 2024
4977019
fix nitpick
OliBomby May 24, 2024
4fcb902
Merge branch 'master' into grids-1
bdach Jun 3, 2024
212be6b
Merge branch 'master' into grids-1
peppy Jun 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add circular grid
  • Loading branch information
OliBomby committed Jan 1, 2024
commit d0ca3f2b2b086ddbfae4ed5f9d6e44b471804722
6 changes: 5 additions & 1 deletion osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ private void load()
() => new SpriteIcon { Icon = FontAwesome.Regular.Square }),
new RadioButton("Triangle",
() => GridType.Value = PositionSnapGridType.Triangle,
() => new Triangle())
() => new Triangle()),
new RadioButton("Circle",
() => GridType.Value = PositionSnapGridType.Circle,
() => new SpriteIcon { Icon = FontAwesome.Regular.Circle }),
}
},
};
Expand Down Expand Up @@ -177,5 +180,6 @@ public enum PositionSnapGridType
{
Square,
Triangle,
Circle,
}
}
8 changes: 8 additions & 0 deletions osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ private void updatePositionSnapGrid(ValueChangedEvent<PositionSnapGridType> obj)
positionSnapGrid = triangularPositionSnapGrid;
break;

case PositionSnapGridType.Circle:
var circularPositionSnapGrid = new CircularPositionSnapGrid();

OsuGridToolboxGroup.Spacing.BindValueChanged(s => circularPositionSnapGrid.Spacing = s.NewValue, true);

positionSnapGrid = circularPositionSnapGrid;
break;

default:
throw new NotImplementedException($"{OsuGridToolboxGroup.GridType} has an incorrect value.");
}
Expand Down
106 changes: 106 additions & 0 deletions osu.Game/Screens/Edit/Compose/Components/CircularPositionSnapGrid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// 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 System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils;
using osu.Game.Utils;
using osuTK;

namespace osu.Game.Screens.Edit.Compose.Components
{
public partial class CircularPositionSnapGrid : PositionSnapGrid
{
private float spacing = 1;

/// <summary>
/// The spacing between grid lines of this <see cref="CircularPositionSnapGrid"/>.
/// </summary>
public float Spacing
{
get => spacing;
set
{
if (spacing <= 0)
throw new ArgumentException("Grid spacing must be positive.");

spacing = value;
GridCache.Invalidate();
}
}

protected override void CreateContent()
{
var drawSize = DrawSize;

// Calculate the maximum distance from the origin to the edge of the grid.
float maxDist = MathF.Max(
MathF.Max(StartPosition.Length, (StartPosition - drawSize).Length),
MathF.Max((StartPosition - new Vector2(drawSize.X, 0)).Length, (StartPosition - new Vector2(0, drawSize.Y)).Length)
);

generateCircles((int)(maxDist / Spacing) + 1);

GenerateOutline(drawSize);
}

private void generateCircles(int count)
{
// Make lines the same width independent of display resolution.
float lineWidth = 2 * DrawWidth / ScreenSpaceDrawQuad.Width;

List<CircularContainer> generatedCircles = new List<CircularContainer>();

for (int i = 0; i < count; i++)
{
// Add a minimum diameter so the center circle is clearly visible.
float diameter = MathF.Max(lineWidth * 1.5f, i * Spacing * 2);

var gridCircle = new CircularContainer
{
BorderColour = Colour4.White,
BorderThickness = lineWidth,
Alpha = 0.2f,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.None,
Width = diameter,
Height = diameter,
Position = StartPosition,
Masking = true,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
AlwaysPresent = true,
Alpha = 0f,
}
};

generatedCircles.Add(gridCircle);
}

if (generatedCircles.Count == 0)
return;

generatedCircles.First().Alpha = 0.8f;

AddRangeInternal(generatedCircles);
}

public override Vector2 GetSnappedPosition(Vector2 original)
{
Vector2 relativeToStart = original - StartPosition;

if (relativeToStart.LengthSquared < Precision.FLOAT_EPSILON)
return StartPosition;

float length = relativeToStart.Length;
float wantedLength = MathF.Round(length / Spacing) * Spacing;

return StartPosition + Vector2.Multiply(relativeToStart, wantedLength / length);
}
}
}