mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 20:32:55 +08:00
Merge MaskContainer into BlueprintContainer
This commit is contained in:
parent
26c9390c16
commit
65bb91dcf7
@ -1,19 +1,26 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Framework.Input.States;
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
using osu.Game.Rulesets.Objects.Drawables;
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
|
using OpenTK;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||||
{
|
{
|
||||||
public class BlueprintContainer : CompositeDrawable
|
public class BlueprintContainer : CompositeDrawable
|
||||||
{
|
{
|
||||||
private MaskContainer maskContainer;
|
private SelectionBlueprintContainer selectionBlueprints;
|
||||||
|
private MaskSelection maskSelection;
|
||||||
|
|
||||||
|
private IEnumerable<SelectionMask> aliveMasks => selectionBlueprints.Children.Where(c => c.IsAlive);
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private HitObjectComposer composer { get; set; }
|
private HitObjectComposer composer { get; set; }
|
||||||
@ -26,25 +33,17 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
maskContainer = new MaskContainer();
|
maskSelection = composer.CreateMaskSelection();
|
||||||
|
maskSelection.DeselectAll = deselectAll;
|
||||||
|
|
||||||
var maskSelection = composer.CreateMaskSelection();
|
var dragBox = new DragBox(select);
|
||||||
|
|
||||||
maskContainer.MaskSelected += maskSelection.HandleSelected;
|
|
||||||
maskContainer.MaskDeselected += maskSelection.HandleDeselected;
|
|
||||||
maskContainer.MaskSelectionRequested += maskSelection.HandleSelectionRequested;
|
|
||||||
maskContainer.MaskDragRequested += maskSelection.HandleDrag;
|
|
||||||
|
|
||||||
maskSelection.DeselectAll = maskContainer.DeselectAll;
|
|
||||||
|
|
||||||
var dragBox = new DragBox(maskContainer.Select);
|
|
||||||
dragBox.DragEnd += () => maskSelection.UpdateVisibility();
|
dragBox.DragEnd += () => maskSelection.UpdateVisibility();
|
||||||
|
|
||||||
InternalChildren = new[]
|
InternalChildren = new[]
|
||||||
{
|
{
|
||||||
dragBox,
|
dragBox,
|
||||||
maskSelection,
|
maskSelection,
|
||||||
maskContainer,
|
selectionBlueprints = new SelectionBlueprintContainer { RelativeSizeAxes = Axes.Both },
|
||||||
dragBox.CreateProxy()
|
dragBox.CreateProxy()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
|||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
maskContainer.DeselectAll();
|
deselectAll();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +67,12 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
|||||||
if (mask == null)
|
if (mask == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
maskContainer.Add(mask);
|
mask.Selected += onMaskSelected;
|
||||||
|
mask.Deselected += onMaskDeselected;
|
||||||
|
mask.SelectionRequested += onSelectionRequested;
|
||||||
|
mask.DragRequested += onDragRequested;
|
||||||
|
|
||||||
|
selectionBlueprints.Add(mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -77,12 +81,76 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
|||||||
/// <param name="hitObject">The <see cref="DrawableHitObject"/> for which to remove the mask.</param>
|
/// <param name="hitObject">The <see cref="DrawableHitObject"/> for which to remove the mask.</param>
|
||||||
public void RemoveMaskFor(DrawableHitObject hitObject)
|
public void RemoveMaskFor(DrawableHitObject hitObject)
|
||||||
{
|
{
|
||||||
var maskToRemove = maskContainer.Single(m => m.HitObject == hitObject);
|
var maskToRemove = selectionBlueprints.Single(m => m.HitObject == hitObject);
|
||||||
if (maskToRemove == null)
|
if (maskToRemove == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
maskToRemove.Deselect();
|
maskToRemove.Deselect();
|
||||||
maskContainer.Remove(maskToRemove);
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
maskSelection.HandleSelected(mask);
|
||||||
|
selectionBlueprints.ChangeChildDepth(mask, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onMaskDeselected(SelectionMask mask)
|
||||||
|
{
|
||||||
|
maskSelection.HandleDeselected(mask);
|
||||||
|
selectionBlueprints.ChangeChildDepth(mask, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onSelectionRequested(SelectionMask mask, InputState state) => maskSelection.HandleSelectionRequested(mask, state);
|
||||||
|
|
||||||
|
private void onDragRequested(SelectionMask mask, Vector2 delta, InputState state) => maskSelection.HandleDrag(mask, delta, state);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,128 +0,0 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Input.States;
|
|
||||||
using osu.Game.Rulesets.Edit;
|
|
||||||
using OpenTK;
|
|
||||||
using RectangleF = osu.Framework.Graphics.Primitives.RectangleF;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
|
||||||
{
|
|
||||||
public class MaskContainer : Container<SelectionMask>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Invoked when any <see cref="SelectionMask"/> is selected.
|
|
||||||
/// </summary>
|
|
||||||
public event Action<SelectionMask> MaskSelected;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Invoked when any <see cref="SelectionMask"/> is deselected.
|
|
||||||
/// </summary>
|
|
||||||
public event Action<SelectionMask> MaskDeselected;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Invoked when any <see cref="SelectionMask"/> requests selection.
|
|
||||||
/// </summary>
|
|
||||||
public event Action<SelectionMask, InputState> MaskSelectionRequested;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Invoked when any <see cref="SelectionMask"/> requests drag.
|
|
||||||
/// </summary>
|
|
||||||
public event Action<SelectionMask, Vector2, InputState> MaskDragRequested;
|
|
||||||
|
|
||||||
private IEnumerable<SelectionMask> aliveMasks => AliveInternalChildren.Cast<SelectionMask>();
|
|
||||||
|
|
||||||
public MaskContainer()
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Add(SelectionMask drawable)
|
|
||||||
{
|
|
||||||
if (drawable == null) throw new ArgumentNullException(nameof(drawable));
|
|
||||||
|
|
||||||
base.Add(drawable);
|
|
||||||
|
|
||||||
drawable.Selected += onMaskSelected;
|
|
||||||
drawable.Deselected += onMaskDeselected;
|
|
||||||
drawable.SelectionRequested += onSelectionRequested;
|
|
||||||
drawable.DragRequested += onDragRequested;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool Remove(SelectionMask drawable)
|
|
||||||
{
|
|
||||||
if (drawable == null) throw new ArgumentNullException(nameof(drawable));
|
|
||||||
|
|
||||||
var result = base.Remove(drawable);
|
|
||||||
|
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
drawable.Selected -= onMaskSelected;
|
|
||||||
drawable.Deselected -= onMaskDeselected;
|
|
||||||
drawable.SelectionRequested -= onSelectionRequested;
|
|
||||||
drawable.DragRequested -= onDragRequested;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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>
|
|
||||||
public 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>
|
|
||||||
public void DeselectAll() => aliveMasks.ToList().ForEach(m => m.Deselect());
|
|
||||||
|
|
||||||
private void onMaskSelected(SelectionMask mask)
|
|
||||||
{
|
|
||||||
MaskSelected?.Invoke(mask);
|
|
||||||
ChangeChildDepth(mask, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onMaskDeselected(SelectionMask mask)
|
|
||||||
{
|
|
||||||
MaskDeselected?.Invoke(mask);
|
|
||||||
ChangeChildDepth(mask, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onSelectionRequested(SelectionMask mask, InputState state) => MaskSelectionRequested?.Invoke(mask, state);
|
|
||||||
private void onDragRequested(SelectionMask mask, Vector2 delta, InputState state) => MaskDragRequested?.Invoke(mask, delta, state);
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user