// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input; using osu.Game.Rulesets.Edit.Types; using osu.Game.Rulesets.Objects.Drawables; using OpenTK; 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(); } public void MoveObjects(Vector2 offset) { // Todo: Various forms of snapping foreach (var hitObject in overlayContainer.Select(o => o.HitObject.HitObject)) { switch (hitObject) { case IHasEditablePosition editablePosition: editablePosition.SetPosition(offset); break; } } } /// /// Creates a for a specific . /// /// The to create the overlay for. protected virtual HitObjectOverlay CreateOverlayFor(DrawableHitObject hitObject) => null; } }