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;
|
2018-11-06 17:02:55 +08:00
|
|
|
|
using osu.Game.Rulesets.Edit.Tools;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
|
2018-11-06 17:28:22 +08:00
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
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-13 11:52:04 +08:00
|
|
|
|
|
2018-11-06 17:04:03 +08:00
|
|
|
|
private Container<PlacementBlueprint> placementBlueprintContainer;
|
2018-11-13 11:52:04 +08:00
|
|
|
|
private PlacementBlueprint currentPlacement;
|
|
|
|
|
|
2018-11-06 16:52:47 +08:00
|
|
|
|
private SelectionBox selectionBox;
|
2018-11-06 16:51:26 +08:00
|
|
|
|
|
2018-11-06 16:56:04 +08:00
|
|
|
|
private IEnumerable<SelectionBlueprint> selections => 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:56:04 +08:00
|
|
|
|
selectionBox = composer.CreateSelectionBox();
|
2018-11-06 16:52:47 +08:00
|
|
|
|
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 17:04:03 +08:00
|
|
|
|
placementBlueprintContainer = new Container<PlacementBlueprint> { 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-11-06 16:56:04 +08:00
|
|
|
|
AddBlueprintFor(obj);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 17:02:55 +08:00
|
|
|
|
private HitObjectCompositionTool currentTool;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The current placement tool.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public HitObjectCompositionTool CurrentTool
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-06 17:02:55 +08:00
|
|
|
|
get => currentTool;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (currentTool == value)
|
|
|
|
|
return;
|
|
|
|
|
currentTool = value;
|
|
|
|
|
|
|
|
|
|
refreshTool();
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 17:02:55 +08:00
|
|
|
|
/// Adds a blueprint for a <see cref="DrawableHitObject"/> which adds movement support.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// </summary>
|
2018-11-06 17:02:55 +08:00
|
|
|
|
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to create a blueprint for.</param>
|
2018-11-06 16:56:04 +08:00
|
|
|
|
public void AddBlueprintFor(DrawableHitObject hitObject)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-06 17:02:55 +08:00
|
|
|
|
refreshTool();
|
|
|
|
|
|
2018-11-06 17:03:21 +08:00
|
|
|
|
var blueprint = composer.CreateBlueprintFor(hitObject);
|
2018-11-06 17:02:55 +08:00
|
|
|
|
if (blueprint == null)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2018-11-06 17:02:55 +08:00
|
|
|
|
blueprint.Selected += onBlueprintSelected;
|
|
|
|
|
blueprint.Deselected += onBlueprintDeselected;
|
|
|
|
|
blueprint.SelectionRequested += onSelectionRequested;
|
|
|
|
|
blueprint.DragRequested += onDragRequested;
|
2018-11-06 16:51:26 +08:00
|
|
|
|
|
2018-11-06 17:02:55 +08:00
|
|
|
|
selectionBlueprints.Add(blueprint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-10-18 15:36:06 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 17:02:55 +08:00
|
|
|
|
/// Removes a blueprint for a <see cref="DrawableHitObject"/>.
|
2018-10-18 15:36:06 +08:00
|
|
|
|
/// </summary>
|
2018-11-06 17:02:55 +08:00
|
|
|
|
/// <param name="hitObject">The <see cref="DrawableHitObject"/> for which to remove the blueprint.</param>
|
2018-11-06 16:56:04 +08:00
|
|
|
|
public void RemoveBlueprintFor(DrawableHitObject hitObject)
|
2018-10-18 15:36:06 +08:00
|
|
|
|
{
|
2018-11-06 17:02:55 +08:00
|
|
|
|
var blueprint = selectionBlueprints.Single(m => m.HitObject == hitObject);
|
|
|
|
|
if (blueprint == null)
|
2018-10-18 15:36:06 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2018-11-06 17:02:55 +08:00
|
|
|
|
blueprint.Deselect();
|
2018-11-06 16:51:26 +08:00
|
|
|
|
|
2018-11-06 17:02:55 +08:00
|
|
|
|
blueprint.Selected -= onBlueprintSelected;
|
|
|
|
|
blueprint.Deselected -= onBlueprintDeselected;
|
|
|
|
|
blueprint.SelectionRequested -= onSelectionRequested;
|
|
|
|
|
blueprint.DragRequested -= onDragRequested;
|
2018-11-06 16:51:26 +08:00
|
|
|
|
|
2018-11-06 17:02:55 +08:00
|
|
|
|
selectionBlueprints.Remove(blueprint);
|
2018-11-06 16:51:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 17:02:55 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
|
{
|
|
|
|
|
deselectAll();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 11:52:04 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2018-11-13 12:00:00 +08:00
|
|
|
|
if (currentPlacement != null)
|
|
|
|
|
{
|
2018-11-14 17:34:13 +08:00
|
|
|
|
if (composer.CursorInPlacementArea)
|
2018-11-13 12:00:00 +08:00
|
|
|
|
currentPlacement.State = PlacementState.Shown;
|
|
|
|
|
else if (currentPlacement?.PlacementBegun == false)
|
|
|
|
|
currentPlacement.State = PlacementState.Hidden;
|
|
|
|
|
}
|
2018-11-13 11:52:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 17:02:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refreshes the current placement tool.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void refreshTool()
|
|
|
|
|
{
|
|
|
|
|
placementBlueprintContainer.Clear();
|
2018-11-13 11:52:04 +08:00
|
|
|
|
currentPlacement = null;
|
2018-11-06 17:02:55 +08:00
|
|
|
|
|
2018-11-06 17:06:34 +08:00
|
|
|
|
var blueprint = CurrentTool?.CreatePlacementBlueprint();
|
2018-11-06 17:02:55 +08:00
|
|
|
|
if (blueprint != null)
|
2018-11-13 11:52:04 +08:00
|
|
|
|
placementBlueprintContainer.Child = currentPlacement = blueprint;
|
2018-11-06 17:02:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 16:51:26 +08:00
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2018-11-06 17:02:55 +08:00
|
|
|
|
foreach (var blueprint in selections.ToList())
|
2018-11-06 16:51:26 +08:00
|
|
|
|
{
|
2018-11-06 17:02:55 +08:00
|
|
|
|
if (blueprint.IsPresent && rect.Contains(blueprint.SelectionPoint))
|
|
|
|
|
blueprint.Select();
|
2018-11-06 16:51:26 +08:00
|
|
|
|
else
|
2018-11-06 17:02:55 +08:00
|
|
|
|
blueprint.Deselect();
|
2018-11-06 16:51:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
|
/// Deselects all selected <see cref="SelectionBlueprint"/>s.
|
2018-11-06 16:51:26 +08:00
|
|
|
|
/// </summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
|
private void deselectAll() => selections.ToList().ForEach(m => m.Deselect());
|
2018-11-06 16:51:26 +08:00
|
|
|
|
|
2018-11-06 16:56:04 +08:00
|
|
|
|
private void onBlueprintSelected(SelectionBlueprint blueprint)
|
2018-11-06 16:51:26 +08:00
|
|
|
|
{
|
2018-11-06 16:56:04 +08:00
|
|
|
|
selectionBox.HandleSelected(blueprint);
|
|
|
|
|
selectionBlueprints.ChangeChildDepth(blueprint, 1);
|
2018-11-06 16:51:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 16:56:04 +08:00
|
|
|
|
private void onBlueprintDeselected(SelectionBlueprint blueprint)
|
2018-11-06 16:51:26 +08:00
|
|
|
|
{
|
2018-11-06 16:56:04 +08:00
|
|
|
|
selectionBox.HandleDeselected(blueprint);
|
|
|
|
|
selectionBlueprints.ChangeChildDepth(blueprint, 0);
|
2018-11-06 16:51:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 16:56:04 +08:00
|
|
|
|
private void onSelectionRequested(SelectionBlueprint blueprint, InputState state) => selectionBox.HandleSelectionRequested(blueprint, state);
|
2018-11-06 16:51:26 +08:00
|
|
|
|
|
2018-11-07 15:21:32 +08:00
|
|
|
|
private void onDragRequested(DragEvent dragEvent) => selectionBox.HandleDrag(dragEvent);
|
2018-11-06 16:51:26 +08:00
|
|
|
|
|
2018-11-06 16:56:04 +08:00
|
|
|
|
private class SelectionBlueprintContainer : Container<SelectionBlueprint>
|
2018-11-06 16:51:26 +08:00
|
|
|
|
{
|
|
|
|
|
protected override int Compare(Drawable x, Drawable y)
|
|
|
|
|
{
|
2018-11-06 16:56:04 +08:00
|
|
|
|
if (!(x is SelectionBlueprint xBlueprint) || !(y is SelectionBlueprint yBlueprint))
|
2018-11-06 16:51:26 +08:00
|
|
|
|
return base.Compare(x, y);
|
2018-11-06 16:56:04 +08:00
|
|
|
|
return Compare(xBlueprint, yBlueprint);
|
2018-11-06 16:51:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 16:56:04 +08:00
|
|
|
|
public int Compare(SelectionBlueprint x, SelectionBlueprint y)
|
2018-11-06 16:51:26 +08:00
|
|
|
|
{
|
2018-11-06 16:56:04 +08:00
|
|
|
|
// dpeth is used to denote selected status (we always want selected blueprints to handle input first).
|
2018-11-06 16:51:26 +08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|