From 58c8184ad7f7b008d001a048cfcbf998f14e1423 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 17 Nov 2020 22:56:21 +0900 Subject: [PATCH 1/3] Define blueprint order similarly to hitobjects --- .../Compose/Components/BlueprintContainer.cs | 6 +- .../Components/SelectionBlueprintContainer.cs | 76 +++++++++++++++++++ .../Timeline/TimelineBlueprintContainer.cs | 6 +- 3 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 osu.Game/Screens/Edit/Compose/Components/SelectionBlueprintContainer.cs diff --git a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs index 53b6e14940..3aaa0c7d89 100644 --- a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs @@ -118,8 +118,8 @@ namespace osu.Game.Screens.Edit.Compose.Components } } - protected virtual Container CreateSelectionBlueprintContainer() => - new Container { RelativeSizeAxes = Axes.Both }; + protected virtual SelectionBlueprintContainer CreateSelectionBlueprintContainer() => + new SelectionBlueprintContainer { RelativeSizeAxes = Axes.Both }; /// /// Creates a which outlines s and handles movement of selections. @@ -338,7 +338,7 @@ namespace osu.Game.Screens.Edit.Compose.Components /// Whether a selection was performed. private bool beginClickSelection(MouseButtonEvent e) { - foreach (SelectionBlueprint blueprint in SelectionBlueprints.AliveChildren) + foreach (SelectionBlueprint blueprint in SelectionBlueprints.AliveChildren.Reverse()) { if (!blueprint.IsHovered) continue; diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionBlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionBlueprintContainer.cs new file mode 100644 index 0000000000..54932f6252 --- /dev/null +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionBlueprintContainer.cs @@ -0,0 +1,76 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Rulesets.Edit; + +namespace osu.Game.Screens.Edit.Compose.Components +{ + public class SelectionBlueprintContainer : Container + { + public override void Add(SelectionBlueprint drawable) + { + base.Add(drawable); + + if (Content == this) + bindStartTime(drawable); + } + + public override bool Remove(SelectionBlueprint drawable) + { + if (!base.Remove(drawable)) + return false; + + if (Content == this) + unbindStartTime(drawable); + return true; + } + + public override void Clear(bool disposeChildren) + { + base.Clear(disposeChildren); + unbindAllStartTimes(); + } + + private readonly Dictionary startTimeMap = new Dictionary(); + + private void bindStartTime(SelectionBlueprint blueprint) + { + var bindable = blueprint.HitObject.StartTimeBindable.GetBoundCopy(); + + bindable.BindValueChanged(_ => + { + if (LoadState >= LoadState.Ready) + SortInternal(); + }); + + startTimeMap[blueprint] = bindable; + } + + private void unbindStartTime(SelectionBlueprint blueprint) + { + startTimeMap[blueprint].UnbindAll(); + startTimeMap.Remove(blueprint); + } + + private void unbindAllStartTimes() + { + foreach (var kvp in startTimeMap) + kvp.Value.UnbindAll(); + startTimeMap.Clear(); + } + + protected override int Compare(Drawable x, Drawable y) + { + if (!(x is SelectionBlueprint xObj) || !(y is SelectionBlueprint yObj)) + return base.Compare(x, y); + + // Put earlier blueprints towards the end of the list, so they handle input first + int i = yObj.HitObject.StartTime.CompareTo(xObj.HitObject.StartTime); + return i == 0 ? CompareReverseChildID(x, y) : i; + } + } +} diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineBlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineBlueprintContainer.cs index eef02e61a6..2bd4ac2f91 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineBlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineBlueprintContainer.cs @@ -75,7 +75,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline } } - protected override Container CreateSelectionBlueprintContainer() => new TimelineSelectionBlueprintContainer { RelativeSizeAxes = Axes.Both }; + protected override SelectionBlueprintContainer CreateSelectionBlueprintContainer() => new TimelineSelectionBlueprintContainer { RelativeSizeAxes = Axes.Both }; protected override void OnDrag(DragEvent e) { @@ -195,13 +195,13 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline } } - protected class TimelineSelectionBlueprintContainer : Container + protected class TimelineSelectionBlueprintContainer : SelectionBlueprintContainer { protected override Container Content { get; } public TimelineSelectionBlueprintContainer() { - AddInternal(new TimelinePart(Content = new Container { RelativeSizeAxes = Axes.Both }) { RelativeSizeAxes = Axes.Both }); + AddInternal(new TimelinePart(Content = new SelectionBlueprintContainer { RelativeSizeAxes = Axes.Both }) { RelativeSizeAxes = Axes.Both }); } } } From 783c172b5de26e53b1ff0982f8f49a9bcd7bbad1 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 18 Nov 2020 13:33:22 +0900 Subject: [PATCH 2/3] Make sealed and cleanup comparator --- .../Edit/Compose/Components/BlueprintContainer.cs | 3 +-- ...ner.cs => HitObjectOrderedSelectionContainer.cs} | 13 +++++-------- .../Timeline/TimelineBlueprintContainer.cs | 6 +++--- 3 files changed, 9 insertions(+), 13 deletions(-) rename osu.Game/Screens/Edit/Compose/Components/{SelectionBlueprintContainer.cs => HitObjectOrderedSelectionContainer.cs} (85%) diff --git a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs index 3aaa0c7d89..4b98d42c7c 100644 --- a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs @@ -118,8 +118,7 @@ namespace osu.Game.Screens.Edit.Compose.Components } } - protected virtual SelectionBlueprintContainer CreateSelectionBlueprintContainer() => - new SelectionBlueprintContainer { RelativeSizeAxes = Axes.Both }; + protected virtual Container CreateSelectionBlueprintContainer() => new HitObjectOrderedSelectionContainer { RelativeSizeAxes = Axes.Both }; /// /// Creates a which outlines s and handles movement of selections. diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionBlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/HitObjectOrderedSelectionContainer.cs similarity index 85% rename from osu.Game/Screens/Edit/Compose/Components/SelectionBlueprintContainer.cs rename to osu.Game/Screens/Edit/Compose/Components/HitObjectOrderedSelectionContainer.cs index 54932f6252..ae50b0fd61 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionBlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/HitObjectOrderedSelectionContainer.cs @@ -9,14 +9,12 @@ using osu.Game.Rulesets.Edit; namespace osu.Game.Screens.Edit.Compose.Components { - public class SelectionBlueprintContainer : Container + public sealed class HitObjectOrderedSelectionContainer : Container { public override void Add(SelectionBlueprint drawable) { base.Add(drawable); - - if (Content == this) - bindStartTime(drawable); + bindStartTime(drawable); } public override bool Remove(SelectionBlueprint drawable) @@ -24,8 +22,7 @@ namespace osu.Game.Screens.Edit.Compose.Components if (!base.Remove(drawable)) return false; - if (Content == this) - unbindStartTime(drawable); + unbindStartTime(drawable); return true; } @@ -65,8 +62,8 @@ namespace osu.Game.Screens.Edit.Compose.Components protected override int Compare(Drawable x, Drawable y) { - if (!(x is SelectionBlueprint xObj) || !(y is SelectionBlueprint yObj)) - return base.Compare(x, y); + var xObj = (SelectionBlueprint)x; + var yObj = (SelectionBlueprint)y; // Put earlier blueprints towards the end of the list, so they handle input first int i = yObj.HitObject.StartTime.CompareTo(xObj.HitObject.StartTime); diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineBlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineBlueprintContainer.cs index 2bd4ac2f91..2f14c607c2 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineBlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineBlueprintContainer.cs @@ -75,7 +75,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline } } - protected override SelectionBlueprintContainer CreateSelectionBlueprintContainer() => new TimelineSelectionBlueprintContainer { RelativeSizeAxes = Axes.Both }; + protected override Container CreateSelectionBlueprintContainer() => new TimelineSelectionBlueprintContainer { RelativeSizeAxes = Axes.Both }; protected override void OnDrag(DragEvent e) { @@ -195,13 +195,13 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline } } - protected class TimelineSelectionBlueprintContainer : SelectionBlueprintContainer + protected class TimelineSelectionBlueprintContainer : Container { protected override Container Content { get; } public TimelineSelectionBlueprintContainer() { - AddInternal(new TimelinePart(Content = new SelectionBlueprintContainer { RelativeSizeAxes = Axes.Both }) { RelativeSizeAxes = Axes.Both }); + AddInternal(new TimelinePart(Content = new HitObjectOrderedSelectionContainer { RelativeSizeAxes = Axes.Both }) { RelativeSizeAxes = Axes.Both }); } } } From f00c23b4a07367179d67c7291e1305f1ca01ab3d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 18 Nov 2020 13:37:15 +0900 Subject: [PATCH 3/3] Add comment + xmldoc --- .../Screens/Edit/Compose/Components/BlueprintContainer.cs | 1 + .../Compose/Components/HitObjectOrderedSelectionContainer.cs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs index 4b98d42c7c..df9cadebfc 100644 --- a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs @@ -337,6 +337,7 @@ namespace osu.Game.Screens.Edit.Compose.Components /// Whether a selection was performed. private bool beginClickSelection(MouseButtonEvent e) { + // Iterate from the top of the input stack (blueprints closest to the front of the screen first). foreach (SelectionBlueprint blueprint in SelectionBlueprints.AliveChildren.Reverse()) { if (!blueprint.IsHovered) continue; diff --git a/osu.Game/Screens/Edit/Compose/Components/HitObjectOrderedSelectionContainer.cs b/osu.Game/Screens/Edit/Compose/Components/HitObjectOrderedSelectionContainer.cs index ae50b0fd61..9e95fe4fa1 100644 --- a/osu.Game/Screens/Edit/Compose/Components/HitObjectOrderedSelectionContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/HitObjectOrderedSelectionContainer.cs @@ -6,9 +6,13 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Objects; namespace osu.Game.Screens.Edit.Compose.Components { + /// + /// A container for ordered by their start times. + /// public sealed class HitObjectOrderedSelectionContainer : Container { public override void Add(SelectionBlueprint drawable)