1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 22:22:55 +08:00

Add clearSelection method

This commit is contained in:
smoogipoo 2018-02-14 17:53:04 +09:00
parent 27c6f4ee83
commit a9d14eadac

View File

@ -27,12 +27,11 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
private SelectionBox selectionBox; private SelectionBox selectionBox;
private CaptureBox captureBox; private CaptureBox captureBox;
private readonly List<DrawableHitObject> capturedHitObjects = new List<DrawableHitObject>(); private readonly List<DrawableHitObject> selectedHitObjects = new List<DrawableHitObject>();
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{ {
capturedHitObjects.Clear(); clearSelection();
captureBox?.Hide();
return true; return true;
} }
@ -71,6 +70,15 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
return true; return true;
} }
/// <summary>
/// Deselects all selected <see cref="DrawableHitObject"/>s.
/// </summary>
private void clearSelection()
{
selectedHitObjects.Clear();
captureBox?.Hide();
}
/// <summary> /// <summary>
/// Captures all hitobjects that are present within the area of a <see cref="Quad"/>. /// Captures all hitobjects that are present within the area of a <see cref="Quad"/>.
/// </summary> /// </summary>
@ -78,7 +86,7 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
private void captureQuad(Quad screenSpaceQuad) private void captureQuad(Quad screenSpaceQuad)
{ {
foreach (var obj in playfield.HitObjects.Objects.Where(h => h.IsAlive && h.IsPresent && screenSpaceQuad.Contains(h.SelectionPoint))) foreach (var obj in playfield.HitObjects.Objects.Where(h => h.IsAlive && h.IsPresent && screenSpaceQuad.Contains(h.SelectionPoint)))
capturedHitObjects.Add(obj); selectedHitObjects.Add(obj);
} }
/// <summary> /// <summary>
@ -91,12 +99,12 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
if (captured == null) if (captured == null)
return; return;
capturedHitObjects.Add(captured); selectedHitObjects.Add(captured);
} }
private void finishCapture(bool fromDrag) private void finishCapture(bool fromDrag)
{ {
if (capturedHitObjects.Count == 0) if (selectedHitObjects.Count == 0)
return; return;
// Due to https://github.com/ppy/osu-framework/issues/1382, we may get here through both // Due to https://github.com/ppy/osu-framework/issues/1382, we may get here through both
@ -104,9 +112,9 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
captureBox?.Hide(); captureBox?.Hide();
if (fromDrag) if (fromDrag)
AddInternal(captureBox = new DragCaptureBox(this, capturedHitObjects.ToList(), selectionBox.Position, selectionBox.Size)); AddInternal(captureBox = new DragCaptureBox(this, selectedHitObjects.ToList(), selectionBox.Position, selectionBox.Size));
else else
AddInternal(captureBox = new InstantCaptureBox(this, capturedHitObjects.ToList())); AddInternal(captureBox = new InstantCaptureBox(this, selectedHitObjects.ToList()));
} }
} }
} }