Skip to content

Commit

Permalink
Add button to centre editor grid to current hit object
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Oct 1, 2024
1 parent 7d756d0 commit 26186bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
{
Expand All @@ -112,6 +115,18 @@ 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;
},
RelativeSizeAxes = Axes.X,
},
spacingSlider = new ExpandableSlider<float>
{
Current = Spacing,
Expand Down Expand Up @@ -213,6 +228,12 @@ protected override void LoadComplete()
}, true);
}

protected override void Update()
{
base.Update();
useSelectedObjectPositionButton.Enabled.Value = editorBeatmap.SelectedHitObjects.Count == 1 && StartPosition.Value != ((IHasPosition)editorBeatmap.SelectedHitObjects.Single()).Position;
}

private void nextGridSize()
{
Spacing.Value = Spacing.Value * 2 >= max_automatic_spacing ? Spacing.Value / 8 : Spacing.Value * 2;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Rulesets/Edit/ExpandableButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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

Expand Down

0 comments on commit 26186bd

Please sign in to comment.