1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 18:07:28 +08:00

Split out EditorInspector implementation for reuse

This commit is contained in:
Dean Herbert 2023-05-05 15:40:34 +09:00
parent 76b2f0e6dd
commit 4663057060
2 changed files with 79 additions and 70 deletions

View File

@ -0,0 +1,50 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osu.Game.Screens.Edit;
namespace osu.Game.Rulesets.Edit
{
internal partial class EditorInspector : CompositeDrawable
{
protected OsuTextFlowContainer InspectorText = null!;
[Resolved]
protected EditorBeatmap EditorBeatmap { get; private set; } = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
InternalChild = InspectorText = new OsuTextFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
};
}
protected void AddHeader(string header) => InspectorText.AddParagraph($"{header}: ", s =>
{
s.Padding = new MarginPadding { Top = 2 };
s.Font = s.Font.With(size: 12);
s.Colour = colourProvider.Content2;
});
protected void AddValue(string value) => InspectorText.AddParagraph(value, s =>
{
s.Font = s.Font.With(weight: FontWeight.SemiBold);
s.Colour = colourProvider.Content1;
});
}
}

View File

@ -2,43 +2,15 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Edit;
namespace osu.Game.Rulesets.Edit namespace osu.Game.Rulesets.Edit
{ {
internal partial class HitObjectInspector : CompositeDrawable internal partial class HitObjectInspector : EditorInspector
{ {
private OsuTextFlowContainer inspectorText = null!;
[Resolved]
protected EditorBeatmap EditorBeatmap { get; private set; } = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
InternalChild = inspectorText = new OsuTextFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
};
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
@ -53,69 +25,69 @@ namespace osu.Game.Rulesets.Edit
private void updateInspectorText() private void updateInspectorText()
{ {
inspectorText.Clear(); InspectorText.Clear();
rollingTextUpdate?.Cancel(); rollingTextUpdate?.Cancel();
rollingTextUpdate = null; rollingTextUpdate = null;
switch (EditorBeatmap.SelectedHitObjects.Count) switch (EditorBeatmap.SelectedHitObjects.Count)
{ {
case 0: case 0:
addValue("No selection"); AddValue("No selection");
break; break;
case 1: case 1:
var selected = EditorBeatmap.SelectedHitObjects.Single(); var selected = EditorBeatmap.SelectedHitObjects.Single();
addHeader("Type"); AddHeader("Type");
addValue($"{selected.GetType().ReadableName()}"); AddValue($"{selected.GetType().ReadableName()}");
addHeader("Time"); AddHeader("Time");
addValue($"{selected.StartTime:#,0.##}ms"); AddValue($"{selected.StartTime:#,0.##}ms");
switch (selected) switch (selected)
{ {
case IHasPosition pos: case IHasPosition pos:
addHeader("Position"); AddHeader("Position");
addValue($"x:{pos.X:#,0.##} y:{pos.Y:#,0.##}"); AddValue($"x:{pos.X:#,0.##} y:{pos.Y:#,0.##}");
break; break;
case IHasXPosition x: case IHasXPosition x:
addHeader("Position"); AddHeader("Position");
addValue($"x:{x.X:#,0.##} "); AddValue($"x:{x.X:#,0.##} ");
break; break;
case IHasYPosition y: case IHasYPosition y:
addHeader("Position"); AddHeader("Position");
addValue($"y:{y.Y:#,0.##}"); AddValue($"y:{y.Y:#,0.##}");
break; break;
} }
if (selected is IHasDistance distance) if (selected is IHasDistance distance)
{ {
addHeader("Distance"); AddHeader("Distance");
addValue($"{distance.Distance:#,0.##}px"); AddValue($"{distance.Distance:#,0.##}px");
} }
if (selected is IHasSliderVelocity sliderVelocity) if (selected is IHasSliderVelocity sliderVelocity)
{ {
addHeader("Slider Velocity"); AddHeader("Slider Velocity");
addValue($"{sliderVelocity.SliderVelocity:#,0.00}x"); AddValue($"{sliderVelocity.SliderVelocity:#,0.00}x");
} }
if (selected is IHasRepeats repeats) if (selected is IHasRepeats repeats)
{ {
addHeader("Repeats"); AddHeader("Repeats");
addValue($"{repeats.RepeatCount:#,0.##}"); AddValue($"{repeats.RepeatCount:#,0.##}");
} }
if (selected is IHasDuration duration) if (selected is IHasDuration duration)
{ {
addHeader("End Time"); AddHeader("End Time");
addValue($"{duration.EndTime:#,0.##}ms"); AddValue($"{duration.EndTime:#,0.##}ms");
addHeader("Duration"); AddHeader("Duration");
addValue($"{duration.Duration:#,0.##}ms"); 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. // 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.
@ -124,29 +96,16 @@ namespace osu.Game.Rulesets.Edit
break; break;
default: default:
addHeader("Selected Objects"); AddHeader("Selected Objects");
addValue($"{EditorBeatmap.SelectedHitObjects.Count:#,0.##}"); AddValue($"{EditorBeatmap.SelectedHitObjects.Count:#,0.##}");
addHeader("Start Time"); AddHeader("Start Time");
addValue($"{EditorBeatmap.SelectedHitObjects.Min(o => o.StartTime):#,0.##}ms"); AddValue($"{EditorBeatmap.SelectedHitObjects.Min(o => o.StartTime):#,0.##}ms");
addHeader("End Time"); AddHeader("End Time");
addValue($"{EditorBeatmap.SelectedHitObjects.Max(o => o.GetEndTime()):#,0.##}ms"); AddValue($"{EditorBeatmap.SelectedHitObjects.Max(o => o.GetEndTime()):#,0.##}ms");
break; break;
} }
void addHeader(string header) => inspectorText.AddParagraph($"{header}: ", s =>
{
s.Padding = new MarginPadding { Top = 2 };
s.Font = s.Font.With(size: 12);
s.Colour = colourProvider.Content2;
});
void addValue(string value) => inspectorText.AddParagraph(value, s =>
{
s.Font = s.Font.With(weight: FontWeight.SemiBold);
s.Colour = colourProvider.Content1;
});
} }
} }
} }