-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26310 from OliBomby/grids-2
Add hexgrid and circular grid to the osu editor
- Loading branch information
Showing
7 changed files
with
380 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Framework.Testing; | ||
|
@@ -160,6 +161,8 @@ private Vector2 uniqueSnappingPosition(PositionSnapGrid grid) | |
return grid switch | ||
{ | ||
RectangularPositionSnapGrid rectangular => rectangular.StartPosition.Value + GeometryUtils.RotateVector(rectangular.Spacing.Value, -rectangular.GridLineRotation.Value), | ||
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), | ||
_ => Vector2.Zero | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Linq; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Shapes; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Input.Bindings; | ||
using osu.Framework.Input.Events; | ||
using osu.Game.Graphics.Containers; | ||
using osu.Game.Graphics.UserInterface; | ||
using osu.Game.Input.Bindings; | ||
using osu.Game.Rulesets.Edit; | ||
using osu.Game.Rulesets.Osu.UI; | ||
using osu.Game.Screens.Edit; | ||
using osu.Game.Screens.Edit.Components.RadioButtons; | ||
using osuTK; | ||
using osuTK.Graphics; | ||
|
||
namespace osu.Game.Rulesets.Osu.Edit | ||
{ | ||
|
@@ -20,6 +27,9 @@ public partial class OsuGridToolboxGroup : EditorToolboxGroup, IKeyBindingHandle | |
[Resolved] | ||
private EditorBeatmap editorBeatmap { get; set; } = null!; | ||
|
||
[Resolved] | ||
private IExpandingContainer? expandingContainer { get; set; } | ||
|
||
/// <summary> | ||
/// X position of the grid's origin. | ||
/// </summary> | ||
|
@@ -55,8 +65,8 @@ public partial class OsuGridToolboxGroup : EditorToolboxGroup, IKeyBindingHandle | |
/// </summary> | ||
public BindableFloat GridLinesRotation { get; } = new BindableFloat(0f) | ||
{ | ||
MinValue = -45f, | ||
MaxValue = 45f, | ||
MinValue = -180f, | ||
MaxValue = 180f, | ||
Precision = 1f | ||
}; | ||
|
||
|
@@ -72,10 +82,13 @@ public partial class OsuGridToolboxGroup : EditorToolboxGroup, IKeyBindingHandle | |
/// </summary> | ||
public Bindable<Vector2> SpacingVector { get; } = new Bindable<Vector2>(); | ||
|
||
public Bindable<PositionSnapGridType> GridType { get; } = new Bindable<PositionSnapGridType>(); | ||
|
||
private ExpandableSlider<float> startPositionXSlider = null!; | ||
private ExpandableSlider<float> startPositionYSlider = null!; | ||
private ExpandableSlider<float> spacingSlider = null!; | ||
private ExpandableSlider<float> gridLinesRotationSlider = null!; | ||
private EditorRadioButtonCollection gridTypeButtons = null!; | ||
|
||
public OsuGridToolboxGroup() | ||
: base("grid") | ||
|
@@ -109,6 +122,31 @@ private void load() | |
Current = GridLinesRotation, | ||
KeyboardStep = 1, | ||
}, | ||
new FillFlowContainer | ||
{ | ||
RelativeSizeAxes = Axes.X, | ||
AutoSizeAxes = Axes.Y, | ||
Spacing = new Vector2(0f, 10f), | ||
Children = new Drawable[] | ||
{ | ||
gridTypeButtons = new EditorRadioButtonCollection | ||
{ | ||
RelativeSizeAxes = Axes.X, | ||
Items = new[] | ||
{ | ||
new RadioButton("Square", | ||
() => GridType.Value = PositionSnapGridType.Square, | ||
() => new SpriteIcon { Icon = FontAwesome.Regular.Square }), | ||
new RadioButton("Triangle", | ||
() => GridType.Value = PositionSnapGridType.Triangle, | ||
() => new OutlineTriangle(true, 20)), | ||
new RadioButton("Circle", | ||
() => GridType.Value = PositionSnapGridType.Circle, | ||
() => new SpriteIcon { Icon = FontAwesome.Regular.Circle }), | ||
} | ||
}, | ||
} | ||
}, | ||
}; | ||
|
||
Spacing.Value = editorBeatmap.BeatmapInfo.GridSize; | ||
|
@@ -118,6 +156,8 @@ protected override void LoadComplete() | |
{ | ||
base.LoadComplete(); | ||
|
||
gridTypeButtons.Items.First().Select(); | ||
|
||
StartPositionX.BindValueChanged(x => | ||
{ | ||
startPositionXSlider.ContractedLabelText = $"X: {x.NewValue:N0}"; | ||
|
@@ -145,6 +185,32 @@ protected override void LoadComplete() | |
gridLinesRotationSlider.ContractedLabelText = $"R: {rotation.NewValue:#,0.##}"; | ||
gridLinesRotationSlider.ExpandedLabelText = $"Rotation: {rotation.NewValue:#,0.##}"; | ||
}, true); | ||
|
||
expandingContainer?.Expanded.BindValueChanged(v => | ||
{ | ||
gridTypeButtons.FadeTo(v.NewValue ? 1f : 0f, 500, Easing.OutQuint); | ||
gridTypeButtons.BypassAutoSizeAxes = !v.NewValue ? Axes.Y : Axes.None; | ||
}, true); | ||
|
||
GridType.BindValueChanged(v => | ||
{ | ||
GridLinesRotation.Disabled = v.NewValue == PositionSnapGridType.Circle; | ||
switch (v.NewValue) | ||
{ | ||
case PositionSnapGridType.Square: | ||
GridLinesRotation.Value = ((GridLinesRotation.Value + 405) % 90) - 45; | ||
GridLinesRotation.MinValue = -45; | ||
GridLinesRotation.MaxValue = 45; | ||
break; | ||
case PositionSnapGridType.Triangle: | ||
GridLinesRotation.Value = ((GridLinesRotation.Value + 390) % 60) - 30; | ||
GridLinesRotation.MinValue = -30; | ||
GridLinesRotation.MaxValue = 30; | ||
break; | ||
} | ||
}, true); | ||
} | ||
|
||
private void nextGridSize() | ||
|
@@ -167,5 +233,42 @@ public bool OnPressed(KeyBindingPressEvent<GlobalAction> e) | |
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) | ||
{ | ||
} | ||
|
||
public partial class OutlineTriangle : BufferedContainer | ||
{ | ||
public OutlineTriangle(bool outlineOnly, float size) | ||
: base(cachedFrameBuffer: true) | ||
{ | ||
Size = new Vector2(size); | ||
|
||
InternalChildren = new Drawable[] | ||
{ | ||
new EquilateralTriangle { RelativeSizeAxes = Axes.Both }, | ||
}; | ||
|
||
if (outlineOnly) | ||
{ | ||
AddInternal(new EquilateralTriangle | ||
{ | ||
Anchor = Anchor.TopCentre, | ||
Origin = Anchor.Centre, | ||
RelativePositionAxes = Axes.Y, | ||
Y = 0.48f, | ||
Colour = Color4.Black, | ||
Size = new Vector2(size - 7), | ||
Blending = BlendingParameters.None, | ||
}); | ||
} | ||
|
||
Blending = BlendingParameters.Additive; | ||
} | ||
} | ||
} | ||
|
||
public enum PositionSnapGridType | ||
{ | ||
Square, | ||
Triangle, | ||
Circle, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.