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 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;
|
2018-03-09 22:43:50 +08:00
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Game.Rulesets.Edit.Types;
|
2018-02-20 17:01:45 +08:00
|
|
|
|
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:02:51 +08:00
|
|
|
|
public void MoveObjects(InputState state)
|
2018-03-09 22:43:50 +08:00
|
|
|
|
{
|
|
|
|
|
// Todo: Various forms of snapping
|
|
|
|
|
foreach (var hitObject in overlayContainer.Select(o => o.HitObject.HitObject))
|
|
|
|
|
{
|
|
|
|
|
switch (hitObject)
|
|
|
|
|
{
|
|
|
|
|
case IHasEditablePosition editablePosition:
|
2018-03-09 23:02:13 +08:00
|
|
|
|
editablePosition.OffsetPosition(state.Mouse.Delta);
|
2018-03-09 22:43:50 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|