// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Objects.Drawables; namespace osu.Game.Rulesets.Edit.Layers.Selection { public class HitObjectOverlayLayer : CompositeDrawable { private readonly Container overlayContainer; public HitObjectOverlayLayer() { RelativeSizeAxes = Axes.Both; InternalChild = overlayContainer = new Container { RelativeSizeAxes = Axes.Both }; } /// /// Adds an overlay for a which adds movement support. /// /// The to create an overlay for. public void AddOverlay(DrawableHitObject hitObject) { var overlay = CreateOverlayFor(hitObject); if (overlay == null) return; overlayContainer.Add(overlay); } /// /// Removes the overlay for a . /// /// The to remove the overlay for. public void RemoveOverlay(DrawableHitObject hitObject) { var existing = overlayContainer.FirstOrDefault(h => h.HitObject == hitObject); if (existing == null) return; existing.Hide(); existing.Expire(); } private SelectionOverlay currentSelectionOverlay; public void AddSelectionOverlay() => AddInternal(currentSelectionOverlay = CreateSelectionOverlay(overlayContainer)); public void RemoveSelectionOverlay() { currentSelectionOverlay?.Hide(); currentSelectionOverlay?.Expire(); } /// /// Creates a for a specific . /// /// The to create the overlay for. protected virtual HitObjectOverlay CreateOverlayFor(DrawableHitObject hitObject) => null; /// /// Creates a which outlines s /// and handles all hitobject movement/pattern adjustments. /// /// The overlays. protected virtual SelectionOverlay CreateSelectionOverlay(IReadOnlyList overlays) => new SelectionOverlay(overlays); } }