From f9ebdadfe8da725e41f3fd4cd86a21a832457c7e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Apr 2023 18:53:25 +0900 Subject: [PATCH 01/11] Move right-side editor toolbox to base `HitObjectComposer` Move right-side editor toolbox to base `HitObjectComposer` --- .../Edit/CatchHitObjectComposer.cs | 1 - .../Edit/DistancedHitObjectComposer.cs | 53 ++++++------------- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 22 +++++++- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Edit/CatchHitObjectComposer.cs b/osu.Game.Rulesets.Catch/Edit/CatchHitObjectComposer.cs index ea5f54a775..cd8894753f 100644 --- a/osu.Game.Rulesets.Catch/Edit/CatchHitObjectComposer.cs +++ b/osu.Game.Rulesets.Catch/Edit/CatchHitObjectComposer.cs @@ -48,7 +48,6 @@ public CatchHitObjectComposer(CatchRuleset ruleset) private void load() { // todo: enable distance spacing once catch supports applying it to its existing distance snap grid implementation. - RightSideToolboxContainer.Alpha = 0; DistanceSpacingMultiplier.Disabled = true; LayerBelowRuleset.Add(new PlayfieldBorder diff --git a/osu.Game/Rulesets/Edit/DistancedHitObjectComposer.cs b/osu.Game/Rulesets/Edit/DistancedHitObjectComposer.cs index 0df481737e..aa47b4f424 100644 --- a/osu.Game/Rulesets/Edit/DistancedHitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/DistancedHitObjectComposer.cs @@ -11,8 +11,6 @@ using osu.Framework.Extensions; using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; @@ -47,8 +45,6 @@ public abstract partial class DistancedHitObjectComposer : HitObjectCom IBindable IDistanceSnapProvider.DistanceSpacingMultiplier => DistanceSpacingMultiplier; - protected ExpandingToolboxContainer RightSideToolboxContainer { get; private set; } - private ExpandableSlider> distanceSpacingSlider; private ExpandableButton currentDistanceSpacingButton; @@ -67,47 +63,29 @@ protected DistancedHitObjectComposer(Ruleset ruleset) [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider) { - AddInternal(new Container + RightToolbox.Add(new EditorToolboxGroup("snapping") { - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - RelativeSizeAxes = Axes.Y, - AutoSizeAxes = Axes.X, + Alpha = DistanceSpacingMultiplier.Disabled ? 0 : 1, Children = new Drawable[] { - new Box + distanceSpacingSlider = new ExpandableSlider> { - Colour = colourProvider.Background5, - RelativeSizeAxes = Axes.Both, + KeyboardStep = adjust_step, + // Manual binding in LoadComplete to handle one-way event flow. + Current = DistanceSpacingMultiplier.GetUnboundCopy(), }, - RightSideToolboxContainer = new ExpandingToolboxContainer(130, 250) + currentDistanceSpacingButton = new ExpandableButton { - Alpha = DistanceSpacingMultiplier.Disabled ? 0 : 1, - Child = new EditorToolboxGroup("snapping") + Action = () => { - Children = new Drawable[] - { - distanceSpacingSlider = new ExpandableSlider> - { - KeyboardStep = adjust_step, - // Manual binding in LoadComplete to handle one-way event flow. - Current = DistanceSpacingMultiplier.GetUnboundCopy(), - }, - currentDistanceSpacingButton = new ExpandableButton - { - Action = () => - { - (HitObject before, HitObject after)? objects = getObjectsOnEitherSideOfCurrentTime(); + (HitObject before, HitObject after)? objects = getObjectsOnEitherSideOfCurrentTime(); - Debug.Assert(objects != null); + Debug.Assert(objects != null); - DistanceSpacingMultiplier.Value = ReadCurrentDistanceSnap(objects.Value.before, objects.Value.after); - DistanceSnapToggle.Value = TernaryState.True; - }, - RelativeSizeAxes = Axes.X, - } - } - } + DistanceSpacingMultiplier.Value = ReadCurrentDistanceSnap(objects.Value.before, objects.Value.after); + DistanceSnapToggle.Value = TernaryState.True; + }, + RelativeSizeAxes = Axes.X, } } }); @@ -261,7 +239,8 @@ protected virtual bool AdjustDistanceSpacing(GlobalAction action, float amount) public virtual float GetBeatSnapDistanceAt(HitObject referenceObject, bool useReferenceSliderVelocity = true) { - return (float)(100 * (useReferenceSliderVelocity ? referenceObject.DifficultyControlPoint.SliderVelocity : 1) * EditorBeatmap.Difficulty.SliderMultiplier * 1 / BeatSnapProvider.BeatDivisor); + return (float)(100 * (useReferenceSliderVelocity ? referenceObject.DifficultyControlPoint.SliderVelocity : 1) * EditorBeatmap.Difficulty.SliderMultiplier * 1 + / BeatSnapProvider.BeatDivisor); } public virtual float DurationToDistance(HitObject referenceObject, double duration) diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index aee86fd942..c2250b1cd5 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -60,6 +60,10 @@ public abstract partial class HitObjectComposer : HitObjectComposer, IP protected ComposeBlueprintContainer BlueprintContainer { get; private set; } + protected ExpandingToolboxContainer LeftToolbox { get; private set; } + + protected ExpandingToolboxContainer RightToolbox { get; private set; } + private DrawableEditorRulesetWrapper drawableRulesetWrapper; protected readonly Container LayerBelowRuleset = new Container { RelativeSizeAxes = Axes.Both }; @@ -131,7 +135,7 @@ private void load(OverlayColourProvider colourProvider, OsuConfigManager config) Colour = colourProvider.Background5, RelativeSizeAxes = Axes.Both, }, - new ExpandingToolboxContainer(60, 200) + LeftToolbox = new ExpandingToolboxContainer(60, 200) { Children = new Drawable[] { @@ -153,6 +157,22 @@ private void load(OverlayColourProvider colourProvider, OsuConfigManager config) }, } }, + new Container + { + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + RelativeSizeAxes = Axes.Y, + AutoSizeAxes = Axes.X, + Children = new Drawable[] + { + new Box + { + Colour = colourProvider.Background5, + RelativeSizeAxes = Axes.Both, + }, + RightToolbox = new ExpandingToolboxContainer(130, 250) + } + } }; toolboxCollection.Items = CompositionTools From c356c163fa3b86597090751e1e4dcc3bb9598d86 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Apr 2023 19:03:45 +0900 Subject: [PATCH 02/11] Add hit object inspector view --- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 98 +++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index c2250b1cd5..9f5663747c 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -18,12 +18,15 @@ using osu.Framework.Logging; using osu.Game.Beatmaps; using osu.Game.Configuration; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; using osu.Game.Overlays; using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Edit.Tools; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Screens.Edit; @@ -33,6 +36,7 @@ using osu.Game.Screens.Edit.Compose.Components; using osuTK; using osuTK.Input; +using FontWeight = osu.Game.Graphics.FontWeight; namespace osu.Game.Rulesets.Edit { @@ -77,6 +81,14 @@ public abstract partial class HitObjectComposer : HitObjectComposer, IP private IBindable hasTiming; private Bindable autoSeekOnPlacement; + [Resolved] + private EditorBeatmap beatmap { get; set; } + + [Resolved] + private OverlayColourProvider colours { get; set; } + + private OsuTextFlowContainer inspectorText; + protected HitObjectComposer(Ruleset ruleset) : base(ruleset) { @@ -171,6 +183,16 @@ private void load(OverlayColourProvider colourProvider, OsuConfigManager config) RelativeSizeAxes = Axes.Both, }, RightToolbox = new ExpandingToolboxContainer(130, 250) + { + Child = new EditorToolboxGroup("inspector") + { + Child = inspectorText = new OsuTextFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + } + }, + } } } }; @@ -212,6 +234,13 @@ protected override void LoadComplete() }); } + protected override void Update() + { + base.Update(); + + updateInspectorText(); + } + public override Playfield Playfield => drawableRulesetWrapper.Playfield; public override IEnumerable HitObjects => drawableRulesetWrapper.Playfield.AllHitObjects; @@ -289,6 +318,75 @@ protected override bool OnKeyDown(KeyDownEvent e) return base.OnKeyDown(e); } + private void updateInspectorText() + { + if (beatmap.SelectedHitObjects.Count != 1) + { + inspectorText.Clear(); + return; + } + + var selected = beatmap.SelectedHitObjects.Single(); + + inspectorText.Clear(); + + addHeader("Time"); + addValue($"{selected.StartTime:#,0.##}ms"); + + switch (selected) + { + case IHasPosition pos: + addHeader("Position"); + addValue($"x:{pos.X:#,0.##} y:{pos.Y:#,0.##}"); + break; + + case IHasXPosition x: + addHeader("Position"); + + addValue($"x:{x.X:#,0.##} "); + break; + + case IHasYPosition y: + addHeader("Position"); + + addValue($"y:{y.Y:#,0.##}"); + break; + } + + if (selected is IHasDistance distance) + { + addHeader("Distance"); + addValue($"{distance.Distance:#,0.##}px"); + } + + if (selected is IHasRepeats repeats) + { + addHeader("Repeats"); + addValue($"{repeats.RepeatCount:#,0.##}"); + } + + if (selected is IHasDuration duration) + { + addHeader("End Time"); + addValue($"{duration.EndTime:#,0.##}ms"); + addHeader("Duration"); + addValue($"{duration.Duration:#,0.##}ms"); + } + + void addHeader(string header) => inspectorText.AddParagraph($"{header}: ", s => + { + s.Padding = new MarginPadding { Top = 2 }; + s.Font = s.Font.With(size: 12); + s.Colour = colours.Content2; + }); + + void addValue(string value) => inspectorText.AddParagraph(value, s => + { + s.Font = s.Font.With(weight: FontWeight.SemiBold); + s.Colour = colours.Content1; + }); + } + private bool checkLeftToggleFromKey(Key key, out int index) { if (key < Key.Number1 || key > Key.Number9) From b0d57616679c01c8d6ac73000ceb034331ff2cc1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Apr 2023 19:05:50 +0900 Subject: [PATCH 03/11] Add object type --- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index 9f5663747c..753667eb4a 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -10,6 +10,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.EnumExtensions; +using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -330,6 +331,9 @@ private void updateInspectorText() inspectorText.Clear(); + addHeader("Type"); + addValue($"{selected.GetType().ReadableName()}"); + addHeader("Time"); addValue($"{selected.StartTime:#,0.##}ms"); From 195b5fc3f182adfb7ffa68a98102571f635eda0b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Apr 2023 19:11:48 +0900 Subject: [PATCH 04/11] Add view for selections of size != 1 --- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 103 +++++++++++--------- 1 file changed, 59 insertions(+), 44 deletions(-) diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index 753667eb4a..b4c8c7798e 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -321,62 +321,77 @@ protected override bool OnKeyDown(KeyDownEvent e) private void updateInspectorText() { - if (beatmap.SelectedHitObjects.Count != 1) - { - inspectorText.Clear(); - return; - } - - var selected = beatmap.SelectedHitObjects.Single(); - inspectorText.Clear(); - addHeader("Type"); - addValue($"{selected.GetType().ReadableName()}"); - - addHeader("Time"); - addValue($"{selected.StartTime:#,0.##}ms"); - - switch (selected) + switch (beatmap.SelectedHitObjects.Count) { - case IHasPosition pos: - addHeader("Position"); - addValue($"x:{pos.X:#,0.##} y:{pos.Y:#,0.##}"); + case 0: + addHeader("No selection"); break; - case IHasXPosition x: - addHeader("Position"); + case 1: + var selected = beatmap.SelectedHitObjects.Single(); + + addHeader("Type"); + addValue($"{selected.GetType().ReadableName()}"); + + addHeader("Time"); + addValue($"{selected.StartTime:#,0.##}ms"); + + switch (selected) + { + case IHasPosition pos: + addHeader("Position"); + addValue($"x:{pos.X:#,0.##} y:{pos.Y:#,0.##}"); + break; + + case IHasXPosition x: + addHeader("Position"); + + addValue($"x:{x.X:#,0.##} "); + break; + + case IHasYPosition y: + addHeader("Position"); + + addValue($"y:{y.Y:#,0.##}"); + break; + } + + if (selected is IHasDistance distance) + { + addHeader("Distance"); + addValue($"{distance.Distance:#,0.##}px"); + } + + if (selected is IHasRepeats repeats) + { + addHeader("Repeats"); + addValue($"{repeats.RepeatCount:#,0.##}"); + } + + if (selected is IHasDuration duration) + { + addHeader("End Time"); + addValue($"{duration.EndTime:#,0.##}ms"); + addHeader("Duration"); + addValue($"{duration.Duration:#,0.##}ms"); + } - addValue($"x:{x.X:#,0.##} "); break; - case IHasYPosition y: - addHeader("Position"); + default: + addHeader("Selected Objects"); + addValue($"{beatmap.SelectedHitObjects.Count:#,0.##}"); - addValue($"y:{y.Y:#,0.##}"); + addHeader("Start Time"); + addValue($"{beatmap.SelectedHitObjects.Min(o => o.StartTime):#,0.##}"); + + addHeader("End Time"); + addValue($"{beatmap.SelectedHitObjects.Max(o => o.GetEndTime()):#,0.##}"); break; } - if (selected is IHasDistance distance) - { - addHeader("Distance"); - addValue($"{distance.Distance:#,0.##}px"); - } - - if (selected is IHasRepeats repeats) - { - addHeader("Repeats"); - addValue($"{repeats.RepeatCount:#,0.##}"); - } - - if (selected is IHasDuration duration) - { - addHeader("End Time"); - addValue($"{duration.EndTime:#,0.##}ms"); - addHeader("Duration"); - addValue($"{duration.Duration:#,0.##}ms"); - } - void addHeader(string header) => inspectorText.AddParagraph($"{header}: ", s => { s.Padding = new MarginPadding { Top = 2 }; From 4aed483005abf9eaf9ad3f73197cdfad6fa2f051 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Apr 2023 19:14:30 +0900 Subject: [PATCH 05/11] Tidy up dependency resolution --- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 25 +++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index b4c8c7798e..b28dfdf3f0 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -63,6 +63,9 @@ public abstract partial class HitObjectComposer : HitObjectComposer, IP [Resolved] protected IBeatSnapProvider BeatSnapProvider { get; private set; } + [Resolved] + private OverlayColourProvider colourProvider { get; set; } + protected ComposeBlueprintContainer BlueprintContainer { get; private set; } protected ExpandingToolboxContainer LeftToolbox { get; private set; } @@ -82,12 +85,6 @@ public abstract partial class HitObjectComposer : HitObjectComposer, IP private IBindable hasTiming; private Bindable autoSeekOnPlacement; - [Resolved] - private EditorBeatmap beatmap { get; set; } - - [Resolved] - private OverlayColourProvider colours { get; set; } - private OsuTextFlowContainer inspectorText; protected HitObjectComposer(Ruleset ruleset) @@ -99,7 +96,7 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); [BackgroundDependencyLoader] - private void load(OverlayColourProvider colourProvider, OsuConfigManager config) + private void load(OsuConfigManager config) { autoSeekOnPlacement = config.GetBindable(OsuSetting.EditorAutoSeekOnPlacement); @@ -323,14 +320,14 @@ private void updateInspectorText() { inspectorText.Clear(); - switch (beatmap.SelectedHitObjects.Count) + switch (EditorBeatmap.SelectedHitObjects.Count) { case 0: addHeader("No selection"); break; case 1: - var selected = beatmap.SelectedHitObjects.Single(); + var selected = EditorBeatmap.SelectedHitObjects.Single(); addHeader("Type"); addValue($"{selected.GetType().ReadableName()}"); @@ -382,13 +379,13 @@ private void updateInspectorText() default: addHeader("Selected Objects"); - addValue($"{beatmap.SelectedHitObjects.Count:#,0.##}"); + addValue($"{EditorBeatmap.SelectedHitObjects.Count:#,0.##}"); addHeader("Start Time"); - addValue($"{beatmap.SelectedHitObjects.Min(o => o.StartTime):#,0.##}"); + addValue($"{EditorBeatmap.SelectedHitObjects.Min(o => o.StartTime):#,0.##}"); addHeader("End Time"); - addValue($"{beatmap.SelectedHitObjects.Max(o => o.GetEndTime()):#,0.##}"); + addValue($"{EditorBeatmap.SelectedHitObjects.Max(o => o.GetEndTime()):#,0.##}"); break; } @@ -396,13 +393,13 @@ void addHeader(string header) => inspectorText.AddParagraph($"{header}: ", s => { s.Padding = new MarginPadding { Top = 2 }; s.Font = s.Font.With(size: 12); - s.Colour = colours.Content2; + s.Colour = colourProvider.Content2; }); void addValue(string value) => inspectorText.AddParagraph(value, s => { s.Font = s.Font.With(weight: FontWeight.SemiBold); - s.Colour = colours.Content1; + s.Colour = colourProvider.Content1; }); } From 3209b092702aaa78c376422de632d48c86792d65 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Apr 2023 19:17:14 +0900 Subject: [PATCH 06/11] Move inspector into own file --- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 107 +-------------- osu.Game/Rulesets/Edit/HitObjectInspector.cs | 132 +++++++++++++++++++ 2 files changed, 133 insertions(+), 106 deletions(-) create mode 100644 osu.Game/Rulesets/Edit/HitObjectInspector.cs diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index b28dfdf3f0..653861c11c 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -10,7 +10,6 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.EnumExtensions; -using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -19,15 +18,12 @@ using osu.Framework.Logging; using osu.Game.Beatmaps; using osu.Game.Configuration; -using osu.Game.Graphics; -using osu.Game.Graphics.Containers; using osu.Game.Overlays; using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Edit.Tools; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; -using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Screens.Edit; @@ -37,7 +33,6 @@ using osu.Game.Screens.Edit.Compose.Components; using osuTK; using osuTK.Input; -using FontWeight = osu.Game.Graphics.FontWeight; namespace osu.Game.Rulesets.Edit { @@ -85,8 +80,6 @@ public abstract partial class HitObjectComposer : HitObjectComposer, IP private IBindable hasTiming; private Bindable autoSeekOnPlacement; - private OsuTextFlowContainer inspectorText; - protected HitObjectComposer(Ruleset ruleset) : base(ruleset) { @@ -184,11 +177,7 @@ private void load(OsuConfigManager config) { Child = new EditorToolboxGroup("inspector") { - Child = inspectorText = new OsuTextFlowContainer - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - } + Child = new HitObjectInspector() }, } } @@ -232,13 +221,6 @@ protected override void LoadComplete() }); } - protected override void Update() - { - base.Update(); - - updateInspectorText(); - } - public override Playfield Playfield => drawableRulesetWrapper.Playfield; public override IEnumerable HitObjects => drawableRulesetWrapper.Playfield.AllHitObjects; @@ -316,93 +298,6 @@ protected override bool OnKeyDown(KeyDownEvent e) return base.OnKeyDown(e); } - private void updateInspectorText() - { - inspectorText.Clear(); - - switch (EditorBeatmap.SelectedHitObjects.Count) - { - case 0: - addHeader("No selection"); - break; - - case 1: - var selected = EditorBeatmap.SelectedHitObjects.Single(); - - addHeader("Type"); - addValue($"{selected.GetType().ReadableName()}"); - - addHeader("Time"); - addValue($"{selected.StartTime:#,0.##}ms"); - - switch (selected) - { - case IHasPosition pos: - addHeader("Position"); - addValue($"x:{pos.X:#,0.##} y:{pos.Y:#,0.##}"); - break; - - case IHasXPosition x: - addHeader("Position"); - - addValue($"x:{x.X:#,0.##} "); - break; - - case IHasYPosition y: - addHeader("Position"); - - addValue($"y:{y.Y:#,0.##}"); - break; - } - - if (selected is IHasDistance distance) - { - addHeader("Distance"); - addValue($"{distance.Distance:#,0.##}px"); - } - - if (selected is IHasRepeats repeats) - { - addHeader("Repeats"); - addValue($"{repeats.RepeatCount:#,0.##}"); - } - - if (selected is IHasDuration duration) - { - addHeader("End Time"); - addValue($"{duration.EndTime:#,0.##}ms"); - addHeader("Duration"); - addValue($"{duration.Duration:#,0.##}ms"); - } - - break; - - default: - addHeader("Selected Objects"); - addValue($"{EditorBeatmap.SelectedHitObjects.Count:#,0.##}"); - - addHeader("Start Time"); - addValue($"{EditorBeatmap.SelectedHitObjects.Min(o => o.StartTime):#,0.##}"); - - addHeader("End Time"); - addValue($"{EditorBeatmap.SelectedHitObjects.Max(o => o.GetEndTime()):#,0.##}"); - 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; - }); - } - private bool checkLeftToggleFromKey(Key key, out int index) { if (key < Key.Number1 || key > Key.Number9) diff --git a/osu.Game/Rulesets/Edit/HitObjectInspector.cs b/osu.Game/Rulesets/Edit/HitObjectInspector.cs new file mode 100644 index 0000000000..a6837b24f2 --- /dev/null +++ b/osu.Game/Rulesets/Edit/HitObjectInspector.cs @@ -0,0 +1,132 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Extensions.TypeExtensions; +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.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Types; +using osu.Game.Screens.Edit; + +namespace osu.Game.Rulesets.Edit +{ + internal partial class HitObjectInspector : CompositeDrawable + { + private OsuTextFlowContainer inspectorText; + + [Resolved] + protected EditorBeatmap EditorBeatmap { get; private set; } + + [Resolved] + private OverlayColourProvider colourProvider { get; set; } + + [BackgroundDependencyLoader] + private void load() + { + InternalChild = inspectorText = new OsuTextFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + }; + } + + protected override void Update() + { + base.Update(); + updateInspectorText(); + } + + private void updateInspectorText() + { + inspectorText.Clear(); + + switch (EditorBeatmap.SelectedHitObjects.Count) + { + case 0: + addHeader("No selection"); + break; + + case 1: + var selected = EditorBeatmap.SelectedHitObjects.Single(); + + addHeader("Type"); + addValue($"{selected.GetType().ReadableName()}"); + + addHeader("Time"); + addValue($"{selected.StartTime:#,0.##}ms"); + + switch (selected) + { + case IHasPosition pos: + addHeader("Position"); + addValue($"x:{pos.X:#,0.##} y:{pos.Y:#,0.##}"); + break; + + case IHasXPosition x: + addHeader("Position"); + + addValue($"x:{x.X:#,0.##} "); + break; + + case IHasYPosition y: + addHeader("Position"); + + addValue($"y:{y.Y:#,0.##}"); + break; + } + + if (selected is IHasDistance distance) + { + addHeader("Distance"); + addValue($"{distance.Distance:#,0.##}px"); + } + + if (selected is IHasRepeats repeats) + { + addHeader("Repeats"); + addValue($"{repeats.RepeatCount:#,0.##}"); + } + + if (selected is IHasDuration duration) + { + addHeader("End Time"); + addValue($"{duration.EndTime:#,0.##}ms"); + addHeader("Duration"); + addValue($"{duration.Duration:#,0.##}ms"); + } + + break; + + default: + addHeader("Selected Objects"); + addValue($"{EditorBeatmap.SelectedHitObjects.Count:#,0.##}"); + + addHeader("Start Time"); + addValue($"{EditorBeatmap.SelectedHitObjects.Min(o => o.StartTime):#,0.##}"); + + addHeader("End Time"); + addValue($"{EditorBeatmap.SelectedHitObjects.Max(o => o.GetEndTime()):#,0.##}"); + 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; + }); + } + } +} From f07d859532cc8906c298fddc59e187be1b3b2fd7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Apr 2023 19:31:33 +0900 Subject: [PATCH 07/11] Optimise how often we update the display --- osu.Game/Rulesets/Edit/HitObjectInspector.cs | 24 +++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/osu.Game/Rulesets/Edit/HitObjectInspector.cs b/osu.Game/Rulesets/Edit/HitObjectInspector.cs index a6837b24f2..71a3202f8d 100644 --- a/osu.Game/Rulesets/Edit/HitObjectInspector.cs +++ b/osu.Game/Rulesets/Edit/HitObjectInspector.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable using System.Linq; using osu.Framework.Allocation; using osu.Framework.Extensions.TypeExtensions; @@ -18,17 +17,20 @@ namespace osu.Game.Rulesets.Edit { internal partial class HitObjectInspector : CompositeDrawable { - private OsuTextFlowContainer inspectorText; + private OsuTextFlowContainer inspectorText = null!; [Resolved] - protected EditorBeatmap EditorBeatmap { get; private set; } + protected EditorBeatmap EditorBeatmap { get; private set; } = null!; [Resolved] - private OverlayColourProvider colourProvider { get; set; } + private OverlayColourProvider colourProvider { get; set; } = null!; [BackgroundDependencyLoader] private void load() { + AutoSizeAxes = Axes.Y; + RelativeSizeAxes = Axes.X; + InternalChild = inspectorText = new OsuTextFlowContainer { RelativeSizeAxes = Axes.X, @@ -36,10 +38,13 @@ private void load() }; } - protected override void Update() + protected override void LoadComplete() { - base.Update(); - updateInspectorText(); + base.LoadComplete(); + + EditorBeatmap.SelectedHitObjects.CollectionChanged += (_, _) => updateInspectorText(); + EditorBeatmap.TransactionBegan += updateInspectorText; + EditorBeatmap.TransactionEnded += updateInspectorText; } private void updateInspectorText() @@ -49,7 +54,7 @@ private void updateInspectorText() switch (EditorBeatmap.SelectedHitObjects.Count) { case 0: - addHeader("No selection"); + addValue("No selection"); break; case 1: @@ -115,6 +120,9 @@ private void updateInspectorText() break; } + if (EditorBeatmap.TransactionActive) + Scheduler.AddDelayed(updateInspectorText, 100); + void addHeader(string header) => inspectorText.AddParagraph($"{header}: ", s => { s.Padding = new MarginPadding { Top = 2 }; From 9c8b25e0348cc2b9be66c22b0d4f4b46f6b880a8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 5 Apr 2023 13:45:24 +0900 Subject: [PATCH 08/11] Fix display not always updating when expected by updating on a schedule --- osu.Game/Rulesets/Edit/HitObjectInspector.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Rulesets/Edit/HitObjectInspector.cs b/osu.Game/Rulesets/Edit/HitObjectInspector.cs index 71a3202f8d..1870476ca0 100644 --- a/osu.Game/Rulesets/Edit/HitObjectInspector.cs +++ b/osu.Game/Rulesets/Edit/HitObjectInspector.cs @@ -106,6 +106,9 @@ 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. + Scheduler.AddDelayed(updateInspectorText, 250); break; default: @@ -120,9 +123,6 @@ private void updateInspectorText() break; } - if (EditorBeatmap.TransactionActive) - Scheduler.AddDelayed(updateInspectorText, 100); - void addHeader(string header) => inspectorText.AddParagraph($"{header}: ", s => { s.Padding = new MarginPadding { Top = 2 }; From ad717d2368270b7cb04f7d4d3b70c2cc5d860fea Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 6 Apr 2023 23:39:36 +0900 Subject: [PATCH 09/11] Fix scheduled calls piling up during transactions --- osu.Game/Rulesets/Edit/HitObjectInspector.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Edit/HitObjectInspector.cs b/osu.Game/Rulesets/Edit/HitObjectInspector.cs index 1870476ca0..02270d4662 100644 --- a/osu.Game/Rulesets/Edit/HitObjectInspector.cs +++ b/osu.Game/Rulesets/Edit/HitObjectInspector.cs @@ -6,6 +6,7 @@ using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Threading; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Overlays; @@ -47,9 +48,13 @@ protected override void LoadComplete() EditorBeatmap.TransactionEnded += updateInspectorText; } + private ScheduledDelegate? rollingTextUpdate; + private void updateInspectorText() { inspectorText.Clear(); + rollingTextUpdate?.Cancel(); + rollingTextUpdate = null; switch (EditorBeatmap.SelectedHitObjects.Count) { @@ -108,7 +113,7 @@ private void updateInspectorText() // 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. - Scheduler.AddDelayed(updateInspectorText, 250); + rollingTextUpdate ??= Scheduler.AddDelayed(updateInspectorText, 250); break; default: From 641415ca3263fdff295402f965a5562c309ea8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 10 Apr 2023 14:05:32 +0200 Subject: [PATCH 10/11] Unify displayed duration format for single/multiple selection --- osu.Game/Rulesets/Edit/HitObjectInspector.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Edit/HitObjectInspector.cs b/osu.Game/Rulesets/Edit/HitObjectInspector.cs index 02270d4662..d0a022744f 100644 --- a/osu.Game/Rulesets/Edit/HitObjectInspector.cs +++ b/osu.Game/Rulesets/Edit/HitObjectInspector.cs @@ -121,10 +121,10 @@ private void updateInspectorText() addValue($"{EditorBeatmap.SelectedHitObjects.Count:#,0.##}"); addHeader("Start Time"); - addValue($"{EditorBeatmap.SelectedHitObjects.Min(o => o.StartTime):#,0.##}"); + addValue($"{EditorBeatmap.SelectedHitObjects.Min(o => o.StartTime):#,0.##}ms"); addHeader("End Time"); - addValue($"{EditorBeatmap.SelectedHitObjects.Max(o => o.GetEndTime()):#,0.##}"); + addValue($"{EditorBeatmap.SelectedHitObjects.Max(o => o.GetEndTime()):#,0.##}ms"); break; } From 60358c720392264ab4b1c51bbca89aa72710300d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 10 Apr 2023 14:13:53 +0200 Subject: [PATCH 11/11] Perform first inspector text update immediately Provides better and more consistent initial state for the inspector. --- osu.Game/Rulesets/Edit/HitObjectInspector.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Rulesets/Edit/HitObjectInspector.cs b/osu.Game/Rulesets/Edit/HitObjectInspector.cs index d0a022744f..977d00ede2 100644 --- a/osu.Game/Rulesets/Edit/HitObjectInspector.cs +++ b/osu.Game/Rulesets/Edit/HitObjectInspector.cs @@ -46,6 +46,7 @@ protected override void LoadComplete() EditorBeatmap.SelectedHitObjects.CollectionChanged += (_, _) => updateInspectorText(); EditorBeatmap.TransactionBegan += updateInspectorText; EditorBeatmap.TransactionEnded += updateInspectorText; + updateInspectorText(); } private ScheduledDelegate? rollingTextUpdate;