2018-02-20 17:01:45 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2018-03-09 23:48:57 +08:00
|
|
|
|
using System.Collections.Generic;
|
2018-03-09 22:43:50 +08:00
|
|
|
|
using System.Linq;
|
2018-02-20 17:01:45 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2018-03-09 22:43:50 +08:00
|
|
|
|
private readonly Container<HitObjectOverlay> overlayContainer;
|
2018-02-20 17:01:45 +08:00
|
|
|
|
|
|
|
|
|
public HitObjectOverlayLayer()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2018-03-09 22:43:50 +08:00
|
|
|
|
|
|
|
|
|
InternalChild = overlayContainer = new Container<HitObjectOverlay> { RelativeSizeAxes = Axes.Both };
|
2018-02-20 17:01:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds an overlay for a <see cref="DrawableHitObject"/> which adds movement support.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to create an overlay for.</param>
|
|
|
|
|
public void AddOverlay(DrawableHitObject hitObject)
|
|
|
|
|
{
|
|
|
|
|
var overlay = CreateOverlayFor(hitObject);
|
|
|
|
|
if (overlay == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-03-09 22:43:50 +08:00
|
|
|
|
overlayContainer.Add(overlay);
|
2018-02-20 17:01:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes the overlay for a <see cref="DrawableHitObject"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to remove the overlay for.</param>
|
|
|
|
|
public void RemoveOverlay(DrawableHitObject hitObject)
|
|
|
|
|
{
|
2018-03-09 22:43:50 +08:00
|
|
|
|
var existing = overlayContainer.FirstOrDefault(h => h.HitObject == hitObject);
|
|
|
|
|
if (existing == null)
|
2018-02-20 17:01:45 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
existing.Hide();
|
|
|
|
|
existing.Expire();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 23:48:57 +08:00
|
|
|
|
private SelectionOverlay currentSelectionOverlay;
|
|
|
|
|
|
|
|
|
|
public void AddSelectionOverlay() => AddInternal(currentSelectionOverlay = CreateSelectionOverlay(overlayContainer));
|
|
|
|
|
|
|
|
|
|
public void RemoveSelectionOverlay()
|
2018-03-09 22:43:50 +08:00
|
|
|
|
{
|
2018-03-09 23:48:57 +08:00
|
|
|
|
currentSelectionOverlay?.Hide();
|
|
|
|
|
currentSelectionOverlay?.Expire();
|
2018-03-09 22:43:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 17:01:45 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a <see cref="HitObjectOverlay"/> for a specific <see cref="DrawableHitObject"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to create the overlay for.</param>
|
|
|
|
|
protected virtual HitObjectOverlay CreateOverlayFor(DrawableHitObject hitObject) => null;
|
2018-03-09 23:48:57 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a <see cref="SelectionOverlay"/> which outlines <see cref="DrawableHitObject"/>s
|
|
|
|
|
/// and handles all hitobject movement/pattern adjustments.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="overlays">The <see cref="DrawableHitObject"/> overlays.</param>
|
|
|
|
|
protected virtual SelectionOverlay CreateSelectionOverlay(IReadOnlyList<HitObjectOverlay> overlays) => new SelectionOverlay(overlays);
|
2018-02-20 17:01:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|