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.Input.Bindings;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Components.RadioButtons;
@ -90,6 +91,8 @@ public partial class OsuGridToolboxGroup : EditorToolboxGroup, IKeyBindingHandle
private ExpandableSlider<float> gridLinesRotationSlider = null!;
private EditorRadioButtonCollection gridTypeButtons = null!;
private ExpandableButton useSelectedObjectPositionButton = null!;
public OsuGridToolboxGroup()
: base("grid")
{
@ -112,6 +115,19 @@ private void load()
Current = StartPositionY,
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>
{
Current = Spacing,
@ -211,6 +227,14 @@ protected override void LoadComplete()
break;
}
}, 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()

View File

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