From 66b19b6c977ea26c215196bcd8c650245f88b4a2 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 15 Dec 2017 14:48:24 +0900 Subject: [PATCH] Expose selected objects from SelectionLayer --- .../Edit/Layers/Selection/DragSelector.cs | 14 ++++++++++++-- .../Edit/Layers/Selection/SelectionInfo.cs | 19 +++++++++++++++++++ .../Edit/Layers/Selection/SelectionLayer.cs | 11 ++++++++++- osu.Game/osu.Game.csproj | 1 + 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 osu.Game/Rulesets/Edit/Layers/Selection/SelectionInfo.cs diff --git a/osu.Game/Rulesets/Edit/Layers/Selection/DragSelector.cs b/osu.Game/Rulesets/Edit/Layers/Selection/DragSelector.cs index b83ed2e270..2201a661b7 100644 --- a/osu.Game/Rulesets/Edit/Layers/Selection/DragSelector.cs +++ b/osu.Game/Rulesets/Edit/Layers/Selection/DragSelector.cs @@ -12,6 +12,7 @@ using osu.Game.Graphics; using osu.Game.Rulesets.Objects.Drawables; using OpenTK; using OpenTK.Graphics; +using osu.Framework.Configuration; namespace osu.Game.Rulesets.Edit.Layers.Selection { @@ -20,6 +21,8 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection /// public class DragSelector : CompositeDrawable { + public readonly Bindable Selection = new Bindable(); + /// /// The s that can be selected through a drag-selection. /// @@ -103,7 +106,6 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection } private readonly List capturedHitObjects = new List(); - public IReadOnlyList CapturedHitObjects => capturedHitObjects; /// /// Processes hitobjects to determine which ones are captured by the drag selection. @@ -128,7 +130,7 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection /// public void FinishCapture() { - if (CapturedHitObjects.Count == 0) + if (capturedHitObjects.Count == 0) { Hide(); return; @@ -158,6 +160,12 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection // Transform into markers to let the user modify the drag selection further. background.Delay(50).FadeOut(200); markers.FadeIn(200); + + Selection.Value = new SelectionInfo + { + Objects = capturedHitObjects, + SelectionQuad = Parent.ToScreenSpace(dragRectangle) + }; } private bool isActive = true; @@ -167,6 +175,8 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection { isActive = false; this.FadeOut(400, Easing.OutQuint).Expire(); + + Selection.Value = null; } } } diff --git a/osu.Game/Rulesets/Edit/Layers/Selection/SelectionInfo.cs b/osu.Game/Rulesets/Edit/Layers/Selection/SelectionInfo.cs new file mode 100644 index 0000000000..402bec1706 --- /dev/null +++ b/osu.Game/Rulesets/Edit/Layers/Selection/SelectionInfo.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using osu.Framework.Graphics.Primitives; +using osu.Game.Rulesets.Objects.Drawables; + +namespace osu.Game.Rulesets.Edit.Layers.Selection +{ + public class SelectionInfo + { + /// + /// The objects that are captured by the selection. + /// + public IEnumerable Objects; + + /// + /// The screen space quad of the selection box surrounding . + /// + public Quad SelectionQuad; + } +} diff --git a/osu.Game/Rulesets/Edit/Layers/Selection/SelectionLayer.cs b/osu.Game/Rulesets/Edit/Layers/Selection/SelectionLayer.cs index a38be68461..af8eac847e 100644 --- a/osu.Game/Rulesets/Edit/Layers/Selection/SelectionLayer.cs +++ b/osu.Game/Rulesets/Edit/Layers/Selection/SelectionLayer.cs @@ -1,15 +1,21 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; +using System.Collections.Generic; +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input; +using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Edit.Layers.Selection { public class SelectionLayer : CompositeDrawable { + public readonly Bindable Selection = new Bindable(); + private readonly Playfield playfield; public SelectionLayer(Playfield playfield) @@ -25,11 +31,14 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection { // Hide the previous drag box - we won't be working with it any longer selector?.Hide(); + AddInternal(selector = new DragSelector(ToLocalSpace(state.Mouse.NativeState.Position)) { - CapturableObjects = playfield.HitObjects.Objects + CapturableObjects = playfield.HitObjects.Objects, }); + Selection.BindTo(selector.Selection); + return true; } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 207dae1b54..63cf0ae0f5 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -314,6 +314,7 @@ +