1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 08:43:20 +08:00

Reduce iterations of DragBox

This commit is contained in:
smoogipoo 2018-03-30 15:06:52 +09:00
parent 4ad776bfde
commit 082e5e4949
2 changed files with 15 additions and 9 deletions

View File

@ -24,17 +24,17 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
/// </summary>
public event Action DragEnd;
private readonly IEnumerable<HitObjectMask> hitObjectMasks;
private readonly IEnumerable<HitObjectMask> selectableMasks;
private Drawable box;
/// <summary>
/// Creates a new <see cref="DragBox"/>.
/// </summary>
/// <param name="hitObjectMasks">The selectable <see cref="HitObjectMask"/>s.</param>
public DragBox(IEnumerable<HitObjectMask> hitObjectMasks)
/// <param name="selectableMasks">The selectable <see cref="HitObjectMask"/>s.</param>
public DragBox(IEnumerable<HitObjectMask> selectableMasks)
{
this.hitObjectMasks = hitObjectMasks;
this.selectableMasks = selectableMasks;
RelativeSizeAxes = Axes.Both;
AlwaysPresent = true;
@ -79,9 +79,9 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
box.Position = topLeft;
box.Size = bottomRight - topLeft;
foreach (var mask in hitObjectMasks)
foreach (var mask in selectableMasks)
{
if (mask.IsAlive && mask.IsPresent && dragRectangle.Contains(mask.SelectionPoint))
if (mask.IsPresent && dragRectangle.Contains(mask.SelectionPoint))
mask.Select();
else
mask.Deselect();

View File

@ -18,7 +18,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
private readonly Playfield playfield;
private readonly HitObjectComposer composer;
private Container<HitObjectMask> maskContainer;
private MaskContainer maskContainer;
private SelectionBox selectionBox;
private readonly HashSet<HitObjectMask> selectedMasks = new HashSet<HitObjectMask>();
@ -34,10 +34,11 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
[BackgroundDependencyLoader]
private void load()
{
maskContainer = new Container<HitObjectMask>();
maskContainer = new MaskContainer();
selectionBox = composer.CreateSelectionBox();
var dragBox = new DragBox(maskContainer);
var dragBox = new DragBox(maskContainer.AliveChildren);
dragBox.DragEnd += () => selectionBox.UpdateVisibility();
InternalChildren = new Drawable[]
@ -104,5 +105,10 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
/// Deselects all selected <see cref="DrawableHitObject"/>s.
/// </summary>
public void DeselectAll() => selectedMasks.ToList().ForEach(m => m.Deselect());
private class MaskContainer : Container<HitObjectMask>
{
public new IEnumerable<HitObjectMask> AliveChildren => AliveInternalChildren.Cast<HitObjectMask>();
}
}
}