1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 11:27:24 +08:00

Expose selected objects from SelectionLayer

This commit is contained in:
smoogipoo 2017-12-15 14:48:24 +09:00
parent eeb3440ffa
commit 66b19b6c97
4 changed files with 42 additions and 3 deletions

View File

@ -12,6 +12,7 @@ using osu.Game.Graphics;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Configuration;
namespace osu.Game.Rulesets.Edit.Layers.Selection namespace osu.Game.Rulesets.Edit.Layers.Selection
{ {
@ -20,6 +21,8 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
/// </summary> /// </summary>
public class DragSelector : CompositeDrawable public class DragSelector : CompositeDrawable
{ {
public readonly Bindable<SelectionInfo> Selection = new Bindable<SelectionInfo>();
/// <summary> /// <summary>
/// The <see cref="DrawableHitObject"/>s that can be selected through a drag-selection. /// The <see cref="DrawableHitObject"/>s that can be selected through a drag-selection.
/// </summary> /// </summary>
@ -103,7 +106,6 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
} }
private readonly List<DrawableHitObject> capturedHitObjects = new List<DrawableHitObject>(); private readonly List<DrawableHitObject> capturedHitObjects = new List<DrawableHitObject>();
public IReadOnlyList<DrawableHitObject> CapturedHitObjects => capturedHitObjects;
/// <summary> /// <summary>
/// Processes hitobjects to determine which ones are captured by the drag selection. /// Processes hitobjects to determine which ones are captured by the drag selection.
@ -128,7 +130,7 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
/// </summary> /// </summary>
public void FinishCapture() public void FinishCapture()
{ {
if (CapturedHitObjects.Count == 0) if (capturedHitObjects.Count == 0)
{ {
Hide(); Hide();
return; return;
@ -158,6 +160,12 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
// Transform into markers to let the user modify the drag selection further. // Transform into markers to let the user modify the drag selection further.
background.Delay(50).FadeOut(200); background.Delay(50).FadeOut(200);
markers.FadeIn(200); markers.FadeIn(200);
Selection.Value = new SelectionInfo
{
Objects = capturedHitObjects,
SelectionQuad = Parent.ToScreenSpace(dragRectangle)
};
} }
private bool isActive = true; private bool isActive = true;
@ -167,6 +175,8 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
{ {
isActive = false; isActive = false;
this.FadeOut(400, Easing.OutQuint).Expire(); this.FadeOut(400, Easing.OutQuint).Expire();
Selection.Value = null;
} }
} }
} }

View File

@ -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
{
/// <summary>
/// The objects that are captured by the selection.
/// </summary>
public IEnumerable<DrawableHitObject> Objects;
/// <summary>
/// The screen space quad of the selection box surrounding <see cref="Objects"/>.
/// </summary>
public Quad SelectionQuad;
}
}

View File

@ -1,15 +1,21 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // 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;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Edit.Layers.Selection namespace osu.Game.Rulesets.Edit.Layers.Selection
{ {
public class SelectionLayer : CompositeDrawable public class SelectionLayer : CompositeDrawable
{ {
public readonly Bindable<SelectionInfo> Selection = new Bindable<SelectionInfo>();
private readonly Playfield playfield; private readonly Playfield playfield;
public SelectionLayer(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 // Hide the previous drag box - we won't be working with it any longer
selector?.Hide(); selector?.Hide();
AddInternal(selector = new DragSelector(ToLocalSpace(state.Mouse.NativeState.Position)) AddInternal(selector = new DragSelector(ToLocalSpace(state.Mouse.NativeState.Position))
{ {
CapturableObjects = playfield.HitObjects.Objects CapturableObjects = playfield.HitObjects.Objects,
}); });
Selection.BindTo(selector.Selection);
return true; return true;
} }

View File

@ -314,6 +314,7 @@
<Compile Include="Rulesets\Edit\Layers\Selection\DragSelector.cs" /> <Compile Include="Rulesets\Edit\Layers\Selection\DragSelector.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\Marker.cs" /> <Compile Include="Rulesets\Edit\Layers\Selection\Marker.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\MarkerContainer.cs" /> <Compile Include="Rulesets\Edit\Layers\Selection\MarkerContainer.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\SelectionInfo.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\SelectionLayer.cs" /> <Compile Include="Rulesets\Edit\Layers\Selection\SelectionLayer.cs" />
<Compile Include="Screens\Edit\Components\BottomBarContainer.cs" /> <Compile Include="Screens\Edit\Components\BottomBarContainer.cs" />
<Compile Include="Screens\Edit\Components\PlaybackControl.cs" /> <Compile Include="Screens\Edit\Components\PlaybackControl.cs" />