Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show distance in pixels to previous/next object in osu! hitobject inspector #28640

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ protected override DrawableRuleset<OsuHitObject> CreateDrawableRuleset(Ruleset r

private readonly Bindable<TernaryState> rectangularGridSnapToggle = new Bindable<TernaryState>();

protected override Drawable CreateHitObjectInspector() => new OsuHitObjectInspector();

protected override IEnumerable<TernaryButton> CreateTernaryButtons()
=> base.CreateTernaryButtons()
.Concat(DistanceSnapProvider.CreateTernaryButtons())
Expand Down Expand Up @@ -101,7 +103,7 @@ private void load()

updatePositionSnapGrid();

RightToolbox.AddRange(new EditorToolboxGroup[]
RightToolbox.AddRange(new Drawable[]
{
OsuGridToolboxGroup,
new TransformToolboxGroup
Expand Down
42 changes: 42 additions & 0 deletions osu.Game.Rulesets.Osu/Edit/OsuHitObjectInspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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 System.Diagnostics;
using System.Linq;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit.Compose.Components;

namespace osu.Game.Rulesets.Osu.Edit
{
public partial class OsuHitObjectInspector : HitObjectInspector
{
protected override void AddInspectorValues()
{
base.AddInspectorValues();

if (EditorBeatmap.SelectedHitObjects.Count > 0)
{
var firstInSelection = (OsuHitObject)EditorBeatmap.SelectedHitObjects.MinBy(ho => ho.StartTime)!;
var lastInSelection = (OsuHitObject)EditorBeatmap.SelectedHitObjects.MaxBy(ho => ho.GetEndTime())!;

Debug.Assert(firstInSelection != null && lastInSelection != null);

var precedingObject = (OsuHitObject?)EditorBeatmap.HitObjects.LastOrDefault(ho => ho.GetEndTime() < firstInSelection.StartTime);
var nextObject = (OsuHitObject?)EditorBeatmap.HitObjects.FirstOrDefault(ho => ho.StartTime > lastInSelection.GetEndTime());

if (precedingObject != null && precedingObject is not Spinner)
{
AddHeader("To previous");
AddValue($"{(firstInSelection.StackedPosition - precedingObject.StackedEndPosition).Length:#,0.##}px");
}

if (nextObject != null && nextObject is not Spinner)
{
AddHeader("To next");
AddValue($"{(nextObject.StackedPosition - lastInSelection.StackedEndPosition).Length:#,0.##}px");
}
}
}
}
}
4 changes: 3 additions & 1 deletion osu.Game/Rulesets/Edit/HitObjectComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void load(OsuConfigManager config, [CanBeNull] Editor editor)
{
Child = new EditorToolboxGroup("inspector")
{
Child = new HitObjectInspector()
Child = CreateHitObjectInspector()
},
}
}
Expand Down Expand Up @@ -329,6 +329,8 @@ protected override void Update()
/// </summary>
protected virtual ComposeBlueprintContainer CreateBlueprintContainer() => new ComposeBlueprintContainer(this);

protected virtual Drawable CreateHitObjectInspector() => new HitObjectInspector();

/// <summary>
/// Construct a drawable ruleset for the provided ruleset.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace osu.Game.Screens.Edit.Compose.Components
{
internal partial class EditorInspector : CompositeDrawable
public partial class EditorInspector : CompositeDrawable
{
protected OsuTextFlowContainer InspectorText = null!;

Expand Down
15 changes: 11 additions & 4 deletions osu.Game/Screens/Edit/Compose/Components/HitObjectInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace osu.Game.Screens.Edit.Compose.Components
{
internal partial class HitObjectInspector : EditorInspector
public partial class HitObjectInspector : EditorInspector
{
protected override void LoadComplete()
{
Expand All @@ -29,6 +29,16 @@ private void updateInspectorText()
rollingTextUpdate?.Cancel();
rollingTextUpdate = null;

AddInspectorValues();

// I'd hope there's a better way to do this, but I don't want to bind to each and every property above to watch for changes.
// This is a good middle-ground for the time being.
if (EditorBeatmap.SelectedHitObjects.Count > 0)
rollingTextUpdate ??= Scheduler.AddDelayed(updateInspectorText, 250);
}

protected virtual void AddInspectorValues()
{
switch (EditorBeatmap.SelectedHitObjects.Count)
{
case 0:
Expand Down Expand Up @@ -90,9 +100,6 @@ private void updateInspectorText()
AddValue($"{duration.Duration:#,0.##}ms");
}

// I'd hope there's a better way to do this, but I don't want to bind to each and every property above to watch for changes.
// This is a good middle-ground for the time being.
rollingTextUpdate ??= Scheduler.AddDelayed(updateInspectorText, 250);
break;

default:
Expand Down
Loading