2018-04-13 17:19:50 +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-11-06 16:51:26 +08:00
|
|
|
|
using System.Collections.Generic;
|
2018-10-18 15:36:06 +08:00
|
|
|
|
using System.Linq;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-11-06 16:51:26 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-11-06 16:51:26 +08:00
|
|
|
|
using osu.Framework.Input.States;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-11-06 16:51:26 +08:00
|
|
|
|
using OpenTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
|
|
|
|
{
|
2018-11-06 16:36:10 +08:00
|
|
|
|
public class BlueprintContainer : CompositeDrawable
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-06 16:51:26 +08:00
|
|
|
|
private SelectionBlueprintContainer selectionBlueprints;
|
2018-11-06 16:52:47 +08:00
|
|
|
|
private SelectionBox selectionBox;
|
2018-11-06 16:51:26 +08:00
|
|
|
|
|
|
|
|
|
private IEnumerable<SelectionMask> aliveMasks => selectionBlueprints.Children.Where(c => c.IsAlive);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-17 15:17:12 +08:00
|
|
|
|
[Resolved]
|
2018-10-17 16:41:17 +08:00
|
|
|
|
private HitObjectComposer composer { get; set; }
|
2018-10-17 15:17:12 +08:00
|
|
|
|
|
2018-11-06 16:36:10 +08:00
|
|
|
|
public BlueprintContainer()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-10-17 16:41:17 +08:00
|
|
|
|
private void load()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-06 16:52:47 +08:00
|
|
|
|
selectionBox = composer.CreateMaskSelection();
|
|
|
|
|
selectionBox.DeselectAll = deselectAll;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-06 16:51:26 +08:00
|
|
|
|
var dragBox = new DragBox(select);
|
2018-11-06 16:52:47 +08:00
|
|
|
|
dragBox.DragEnd += () => selectionBox.UpdateVisibility();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-04-20 17:19:17 +08:00
|
|
|
|
InternalChildren = new[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-06 16:24:38 +08:00
|
|
|
|
dragBox,
|
2018-11-06 16:52:47 +08:00
|
|
|
|
selectionBox,
|
2018-11-06 16:51:26 +08:00
|
|
|
|
selectionBlueprints = new SelectionBlueprintContainer { RelativeSizeAxes = Axes.Both },
|
2018-11-06 16:24:38 +08:00
|
|
|
|
dragBox.CreateProxy()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
};
|
2018-06-07 15:27:49 +08:00
|
|
|
|
|
2018-07-17 14:35:32 +08:00
|
|
|
|
foreach (var obj in composer.HitObjects)
|
2018-10-17 16:41:17 +08:00
|
|
|
|
AddMaskFor(obj);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-02 03:09:33 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-06 16:51:26 +08:00
|
|
|
|
deselectAll();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds a mask for a <see cref="DrawableHitObject"/> which adds movement support.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to create a mask for.</param>
|
2018-10-17 16:41:17 +08:00
|
|
|
|
public void AddMaskFor(DrawableHitObject hitObject)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
var mask = composer.CreateMaskFor(hitObject);
|
|
|
|
|
if (mask == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-11-06 16:51:26 +08:00
|
|
|
|
mask.Selected += onMaskSelected;
|
|
|
|
|
mask.Deselected += onMaskDeselected;
|
|
|
|
|
mask.SelectionRequested += onSelectionRequested;
|
|
|
|
|
mask.DragRequested += onDragRequested;
|
|
|
|
|
|
|
|
|
|
selectionBlueprints.Add(mask);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-10-18 15:36:06 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes a mask for a <see cref="DrawableHitObject"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hitObject">The <see cref="DrawableHitObject"/> for which to remove the mask.</param>
|
|
|
|
|
public void RemoveMaskFor(DrawableHitObject hitObject)
|
|
|
|
|
{
|
2018-11-06 16:51:26 +08:00
|
|
|
|
var maskToRemove = selectionBlueprints.Single(m => m.HitObject == hitObject);
|
2018-10-18 15:36:06 +08:00
|
|
|
|
if (maskToRemove == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
maskToRemove.Deselect();
|
2018-11-06 16:51:26 +08:00
|
|
|
|
|
|
|
|
|
maskToRemove.Selected -= onMaskSelected;
|
|
|
|
|
maskToRemove.Deselected -= onMaskDeselected;
|
|
|
|
|
maskToRemove.SelectionRequested -= onSelectionRequested;
|
|
|
|
|
maskToRemove.DragRequested -= onDragRequested;
|
|
|
|
|
|
|
|
|
|
selectionBlueprints.Remove(maskToRemove);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Select all masks in a given rectangle selection area.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="rect">The rectangle to perform a selection on in screen-space coordinates.</param>
|
|
|
|
|
private void select(RectangleF rect)
|
|
|
|
|
{
|
|
|
|
|
foreach (var mask in aliveMasks.ToList())
|
|
|
|
|
{
|
|
|
|
|
if (mask.IsPresent && rect.Contains(mask.SelectionPoint))
|
|
|
|
|
mask.Select();
|
|
|
|
|
else
|
|
|
|
|
mask.Deselect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deselects all selected <see cref="SelectionMask"/>s.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void deselectAll() => aliveMasks.ToList().ForEach(m => m.Deselect());
|
|
|
|
|
|
|
|
|
|
private void onMaskSelected(SelectionMask mask)
|
|
|
|
|
{
|
2018-11-06 16:52:47 +08:00
|
|
|
|
selectionBox.HandleSelected(mask);
|
2018-11-06 16:51:26 +08:00
|
|
|
|
selectionBlueprints.ChangeChildDepth(mask, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onMaskDeselected(SelectionMask mask)
|
|
|
|
|
{
|
2018-11-06 16:52:47 +08:00
|
|
|
|
selectionBox.HandleDeselected(mask);
|
2018-11-06 16:51:26 +08:00
|
|
|
|
selectionBlueprints.ChangeChildDepth(mask, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 16:52:47 +08:00
|
|
|
|
private void onSelectionRequested(SelectionMask mask, InputState state) => selectionBox.HandleSelectionRequested(mask, state);
|
2018-11-06 16:51:26 +08:00
|
|
|
|
|
2018-11-06 16:52:47 +08:00
|
|
|
|
private void onDragRequested(SelectionMask mask, Vector2 delta, InputState state) => selectionBox.HandleDrag(mask, delta, state);
|
2018-11-06 16:51:26 +08:00
|
|
|
|
|
|
|
|
|
private class SelectionBlueprintContainer : Container<SelectionMask>
|
|
|
|
|
{
|
|
|
|
|
protected override int Compare(Drawable x, Drawable y)
|
|
|
|
|
{
|
|
|
|
|
if (!(x is SelectionMask xMask) || !(y is SelectionMask yMask))
|
|
|
|
|
return base.Compare(x, y);
|
|
|
|
|
return Compare(xMask, yMask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Compare(SelectionMask x, SelectionMask y)
|
|
|
|
|
{
|
|
|
|
|
// dpeth is used to denote selected status (we always want selected masks to handle input first).
|
|
|
|
|
int d = x.Depth.CompareTo(y.Depth);
|
|
|
|
|
if (d != 0)
|
|
|
|
|
return d;
|
|
|
|
|
|
|
|
|
|
// Put earlier hitobjects towards the end of the list, so they handle input first
|
|
|
|
|
int i = y.HitObject.HitObject.StartTime.CompareTo(x.HitObject.HitObject.StartTime);
|
|
|
|
|
return i == 0 ? CompareReverseChildID(x, y) : i;
|
|
|
|
|
}
|
2018-10-18 15:36:06 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|