1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 03:22:57 +08:00
osu-lazer/osu.Game/Screens/Edit/Compose/Components/HitObjectInspector.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
4.0 KiB
C#
Raw Normal View History

2023-04-04 18:17:14 +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 System.Linq;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Threading;
2023-04-04 18:17:14 +08:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Screens.Edit.Compose.Components
2023-04-04 18:17:14 +08:00
{
internal partial class HitObjectInspector : EditorInspector
2023-04-04 18:17:14 +08:00
{
protected override void LoadComplete()
2023-04-04 18:17:14 +08:00
{
base.LoadComplete();
EditorBeatmap.SelectedHitObjects.CollectionChanged += (_, _) => updateInspectorText();
EditorBeatmap.TransactionBegan += updateInspectorText;
EditorBeatmap.TransactionEnded += updateInspectorText;
updateInspectorText();
2023-04-04 18:17:14 +08:00
}
private ScheduledDelegate? rollingTextUpdate;
2023-04-04 18:17:14 +08:00
private void updateInspectorText()
{
InspectorText.Clear();
rollingTextUpdate?.Cancel();
rollingTextUpdate = null;
2023-04-04 18:17:14 +08:00
switch (EditorBeatmap.SelectedHitObjects.Count)
{
case 0:
AddValue("No selection");
2023-04-04 18:17:14 +08:00
break;
case 1:
var selected = EditorBeatmap.SelectedHitObjects.Single();
AddHeader("Type");
AddValue($"{selected.GetType().ReadableName()}");
2023-04-04 18:17:14 +08:00
AddHeader("Time");
AddValue($"{selected.StartTime:#,0.##}ms");
2023-04-04 18:17:14 +08:00
switch (selected)
{
case IHasPosition pos:
AddHeader("Position");
AddValue($"x:{pos.X:#,0.##} y:{pos.Y:#,0.##}");
2023-04-04 18:17:14 +08:00
break;
case IHasXPosition x:
AddHeader("Position");
2023-04-04 18:17:14 +08:00
AddValue($"x:{x.X:#,0.##} ");
2023-04-04 18:17:14 +08:00
break;
case IHasYPosition y:
AddHeader("Position");
2023-04-04 18:17:14 +08:00
AddValue($"y:{y.Y:#,0.##}");
2023-04-04 18:17:14 +08:00
break;
}
if (selected is IHasDistance distance)
{
AddHeader("Distance");
AddValue($"{distance.Distance:#,0.##}px");
2023-04-04 18:17:14 +08:00
}
if (selected is IHasSliderVelocity sliderVelocity)
{
AddHeader("Slider Velocity");
AddValue($"{sliderVelocity.SliderVelocity:#,0.00}x ({sliderVelocity.SliderVelocity * EditorBeatmap.Difficulty.SliderMultiplier:#,0.00}x)");
}
2023-04-04 18:17:14 +08:00
if (selected is IHasRepeats repeats)
{
AddHeader("Repeats");
AddValue($"{repeats.RepeatCount:#,0.##}");
2023-04-04 18:17:14 +08:00
}
if (selected is IHasDuration duration)
{
AddHeader("End Time");
AddValue($"{duration.EndTime:#,0.##}ms");
AddHeader("Duration");
AddValue($"{duration.Duration:#,0.##}ms");
2023-04-04 18:17:14 +08:00
}
// 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);
2023-04-04 18:17:14 +08:00
break;
default:
AddHeader("Selected Objects");
AddValue($"{EditorBeatmap.SelectedHitObjects.Count:#,0.##}");
2023-04-04 18:17:14 +08:00
AddHeader("Start Time");
AddValue($"{EditorBeatmap.SelectedHitObjects.Min(o => o.StartTime):#,0.##}ms");
2023-04-04 18:17:14 +08:00
AddHeader("End Time");
AddValue($"{EditorBeatmap.SelectedHitObjects.Max(o => o.GetEndTime()):#,0.##}ms");
2023-04-04 18:17:14 +08:00
break;
}
}
}
}