2023-12-29 05:36:30 +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 osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
2023-12-29 06:10:06 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
|
using osu.Framework.Input.Events;
|
2023-12-29 05:36:30 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2023-12-29 06:10:06 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
2023-12-29 05:36:30 +08:00
|
|
|
|
using osu.Game.Screens.Edit;
|
2023-12-30 07:43:41 +08:00
|
|
|
|
using osuTK;
|
2023-12-29 05:36:30 +08:00
|
|
|
|
|
2023-12-29 06:10:06 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Edit
|
2023-12-29 05:36:30 +08:00
|
|
|
|
{
|
2023-12-29 06:10:06 +08:00
|
|
|
|
public partial class OsuGridToolboxGroup : EditorToolboxGroup, IKeyBindingHandler<GlobalAction>
|
2023-12-29 05:36:30 +08:00
|
|
|
|
{
|
|
|
|
|
[Resolved]
|
|
|
|
|
private EditorBeatmap editorBeatmap { get; set; } = null!;
|
|
|
|
|
|
2023-12-30 07:43:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// X position of the grid's origin.
|
|
|
|
|
/// </summary>
|
2023-12-29 06:10:06 +08:00
|
|
|
|
public BindableFloat StartPositionX { get; } = new BindableFloat(OsuPlayfield.BASE_SIZE.X / 2)
|
2023-12-29 05:36:30 +08:00
|
|
|
|
{
|
|
|
|
|
MinValue = 0f,
|
2023-12-29 06:10:06 +08:00
|
|
|
|
MaxValue = OsuPlayfield.BASE_SIZE.X,
|
2023-12-29 05:36:30 +08:00
|
|
|
|
Precision = 1f
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-30 07:43:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Y position of the grid's origin.
|
|
|
|
|
/// </summary>
|
2023-12-29 06:10:06 +08:00
|
|
|
|
public BindableFloat StartPositionY { get; } = new BindableFloat(OsuPlayfield.BASE_SIZE.Y / 2)
|
2023-12-29 05:36:30 +08:00
|
|
|
|
{
|
|
|
|
|
MinValue = 0f,
|
2023-12-29 06:10:06 +08:00
|
|
|
|
MaxValue = OsuPlayfield.BASE_SIZE.Y,
|
2023-12-29 05:36:30 +08:00
|
|
|
|
Precision = 1f
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-30 07:43:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The spacing between grid lines.
|
|
|
|
|
/// </summary>
|
2023-12-29 05:36:30 +08:00
|
|
|
|
public BindableFloat Spacing { get; } = new BindableFloat(4f)
|
|
|
|
|
{
|
|
|
|
|
MinValue = 4f,
|
|
|
|
|
MaxValue = 128f,
|
|
|
|
|
Precision = 1f
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-30 07:43:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Rotation of the grid lines in degrees.
|
|
|
|
|
/// </summary>
|
2023-12-29 05:36:30 +08:00
|
|
|
|
public BindableFloat GridLinesRotation { get; } = new BindableFloat(0f)
|
|
|
|
|
{
|
2023-12-29 06:10:06 +08:00
|
|
|
|
MinValue = -45f,
|
|
|
|
|
MaxValue = 45f,
|
2023-12-29 05:36:30 +08:00
|
|
|
|
Precision = 1f
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-30 07:43:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Read-only bindable representing the grid's origin.
|
|
|
|
|
/// Equivalent to <code>new Vector2(StartPositionX, StartPositionY)</code>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Bindable<Vector2> StartPosition { get; } = new Bindable<Vector2>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Read-only bindable representing the grid's spacing in both the X and Y dimension.
|
|
|
|
|
/// Equivalent to <code>new Vector2(Spacing)</code>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Bindable<Vector2> SpacingVector { get; } = new Bindable<Vector2>();
|
|
|
|
|
|
2023-12-29 05:36:30 +08:00
|
|
|
|
private ExpandableSlider<float> startPositionXSlider = null!;
|
|
|
|
|
private ExpandableSlider<float> startPositionYSlider = null!;
|
|
|
|
|
private ExpandableSlider<float> spacingSlider = null!;
|
|
|
|
|
private ExpandableSlider<float> gridLinesRotationSlider = null!;
|
|
|
|
|
|
2023-12-29 06:10:06 +08:00
|
|
|
|
public OsuGridToolboxGroup()
|
|
|
|
|
: base("grid")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-01 04:57:11 +08:00
|
|
|
|
private const float max_automatic_spacing = 64;
|
|
|
|
|
|
2023-12-29 05:36:30 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
startPositionXSlider = new ExpandableSlider<float>
|
|
|
|
|
{
|
2023-12-31 23:41:22 +08:00
|
|
|
|
Current = StartPositionX,
|
|
|
|
|
KeyboardStep = 1,
|
2023-12-29 05:36:30 +08:00
|
|
|
|
},
|
|
|
|
|
startPositionYSlider = new ExpandableSlider<float>
|
|
|
|
|
{
|
2023-12-31 23:41:22 +08:00
|
|
|
|
Current = StartPositionY,
|
|
|
|
|
KeyboardStep = 1,
|
2023-12-29 05:36:30 +08:00
|
|
|
|
},
|
|
|
|
|
spacingSlider = new ExpandableSlider<float>
|
|
|
|
|
{
|
2023-12-31 23:41:22 +08:00
|
|
|
|
Current = Spacing,
|
|
|
|
|
KeyboardStep = 1,
|
2023-12-29 05:36:30 +08:00
|
|
|
|
},
|
|
|
|
|
gridLinesRotationSlider = new ExpandableSlider<float>
|
|
|
|
|
{
|
2023-12-31 23:41:22 +08:00
|
|
|
|
Current = GridLinesRotation,
|
|
|
|
|
KeyboardStep = 1,
|
2023-12-29 23:59:12 +08:00
|
|
|
|
},
|
2023-12-29 05:36:30 +08:00
|
|
|
|
};
|
2023-12-29 06:10:06 +08:00
|
|
|
|
|
2023-12-30 21:32:20 +08:00
|
|
|
|
Spacing.Value = editorBeatmap.BeatmapInfo.GridSize;
|
2023-12-29 05:36:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
StartPositionX.BindValueChanged(x =>
|
|
|
|
|
{
|
|
|
|
|
startPositionXSlider.ContractedLabelText = $"X: {x.NewValue:N0}";
|
|
|
|
|
startPositionXSlider.ExpandedLabelText = $"X Offset: {x.NewValue:N0}";
|
2023-12-30 07:43:41 +08:00
|
|
|
|
StartPosition.Value = new Vector2(x.NewValue, StartPosition.Value.Y);
|
2023-12-29 05:36:30 +08:00
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
StartPositionY.BindValueChanged(y =>
|
|
|
|
|
{
|
|
|
|
|
startPositionYSlider.ContractedLabelText = $"Y: {y.NewValue:N0}";
|
|
|
|
|
startPositionYSlider.ExpandedLabelText = $"Y Offset: {y.NewValue:N0}";
|
2023-12-30 07:43:41 +08:00
|
|
|
|
StartPosition.Value = new Vector2(StartPosition.Value.X, y.NewValue);
|
2023-12-29 05:36:30 +08:00
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
Spacing.BindValueChanged(spacing =>
|
|
|
|
|
{
|
|
|
|
|
spacingSlider.ContractedLabelText = $"S: {spacing.NewValue:N0}";
|
|
|
|
|
spacingSlider.ExpandedLabelText = $"Spacing: {spacing.NewValue:N0}";
|
2023-12-30 07:43:41 +08:00
|
|
|
|
SpacingVector.Value = new Vector2(spacing.NewValue);
|
2023-12-30 21:32:20 +08:00
|
|
|
|
editorBeatmap.BeatmapInfo.GridSize = (int)spacing.NewValue;
|
2023-12-29 05:36:30 +08:00
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
GridLinesRotation.BindValueChanged(rotation =>
|
|
|
|
|
{
|
2023-12-31 23:45:21 +08:00
|
|
|
|
gridLinesRotationSlider.ContractedLabelText = $"R: {rotation.NewValue:#,0.##}";
|
|
|
|
|
gridLinesRotationSlider.ExpandedLabelText = $"Rotation: {rotation.NewValue:#,0.##}";
|
|
|
|
|
}, true);
|
2023-12-29 05:36:30 +08:00
|
|
|
|
}
|
2023-12-29 06:10:06 +08:00
|
|
|
|
|
2024-01-01 04:57:11 +08:00
|
|
|
|
private void nextGridSize()
|
2023-12-29 06:10:06 +08:00
|
|
|
|
{
|
2024-01-01 04:57:11 +08:00
|
|
|
|
Spacing.Value = Spacing.Value * 2 >= max_automatic_spacing ? Spacing.Value / 8 : Spacing.Value * 2;
|
2023-12-29 06:10:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
|
|
|
|
{
|
|
|
|
|
switch (e.Action)
|
|
|
|
|
{
|
|
|
|
|
case GlobalAction.EditorCycleGridDisplayMode:
|
2024-01-01 04:57:11 +08:00
|
|
|
|
nextGridSize();
|
2023-12-29 06:10:06 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
|
|
|
|
{
|
|
|
|
|
}
|
2023-12-29 23:59:12 +08:00
|
|
|
|
}
|
2023-12-29 05:36:30 +08:00
|
|
|
|
}
|