Add button to centre editor grid to current hit object

This commit is contained in:
Dean Herbert 2024-10-01 15:14:40 +09:00
parent 7d756d0de2
commit 0409edccce
No known key found for this signature in database
2 changed files with 25 additions and 1 deletions

View File

@ -14,6 +14,7 @@
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.UI; using osu.Game.Rulesets.Osu.UI;
using osu.Game.Screens.Edit; using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Components.RadioButtons; using osu.Game.Screens.Edit.Components.RadioButtons;
@ -90,6 +91,8 @@ public partial class OsuGridToolboxGroup : EditorToolboxGroup, IKeyBindingHandle
private ExpandableSlider<float> gridLinesRotationSlider = null!; private ExpandableSlider<float> gridLinesRotationSlider = null!;
private EditorRadioButtonCollection gridTypeButtons = null!; private EditorRadioButtonCollection gridTypeButtons = null!;
private ExpandableButton useSelectedObjectPositionButton = null!;
public OsuGridToolboxGroup() public OsuGridToolboxGroup()
: base("grid") : base("grid")
{ {
@ -112,6 +115,19 @@ private void load()
Current = StartPositionY, Current = StartPositionY,
KeyboardStep = 1, KeyboardStep = 1,
}, },
useSelectedObjectPositionButton = new ExpandableButton
{
ExpandedLabelText = "Centre on selected object",
Action = () =>
{
if (editorBeatmap.SelectedHitObjects.Count != 1)
return;
StartPosition.Value = ((IHasPosition)editorBeatmap.SelectedHitObjects.Single()).Position;
updateEnabledStates();
},
RelativeSizeAxes = Axes.X,
},
spacingSlider = new ExpandableSlider<float> spacingSlider = new ExpandableSlider<float>
{ {
Current = Spacing, Current = Spacing,
@ -211,6 +227,14 @@ protected override void LoadComplete()
break; break;
} }
}, true); }, true);
editorBeatmap.BeatmapReprocessed += updateEnabledStates;
editorBeatmap.SelectedHitObjects.BindCollectionChanged((_, _) => updateEnabledStates(), true);
}
private void updateEnabledStates()
{
useSelectedObjectPositionButton.Enabled.Value = editorBeatmap.SelectedHitObjects.Count == 1 && StartPosition.Value != ((IHasPosition)editorBeatmap.SelectedHitObjects.Single()).Position;
} }
private void nextGridSize() private void nextGridSize()

View File

@ -11,7 +11,7 @@
namespace osu.Game.Rulesets.Edit namespace osu.Game.Rulesets.Edit
{ {
internal partial class ExpandableButton : RoundedButton, IExpandable public partial class ExpandableButton : RoundedButton, IExpandable
{ {
private float actualHeight; private float actualHeight;