Remove hitobject terminology from base classes

This commit is contained in:
Dean Herbert
2021-04-27 18:33:47 +09:00
parent ff06a27a12
commit 7ec5ea1eb5
5 changed files with 52 additions and 44 deletions

View File

@ -8,13 +8,12 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK; using osuTK;
namespace osu.Game.Rulesets.Edit namespace osu.Game.Rulesets.Edit
{ {
/// <summary> /// <summary>
/// A blueprint placed above a <see cref="DrawableHitObject"/> adding editing functionality. /// A blueprint placed above a displaying item adding editing functionality.
/// </summary> /// </summary>
public abstract class SelectionBlueprint<T> : CompositeDrawable, IStateful<SelectionState> public abstract class SelectionBlueprint<T> : CompositeDrawable, IStateful<SelectionState>
{ {
@ -86,7 +85,7 @@ namespace osu.Game.Rulesets.Edit
protected virtual void OnDeselected() protected virtual void OnDeselected()
{ {
// selection blueprints are AlwaysPresent while the related DrawableHitObject is visible // selection blueprints are AlwaysPresent while the related item is visible
// set the body piece's alpha directly to avoid arbitrarily rendering frame buffers etc. of children. // set the body piece's alpha directly to avoid arbitrarily rendering frame buffers etc. of children.
foreach (var d in InternalChildren) foreach (var d in InternalChildren)
d.Hide(); d.Hide();

View File

@ -14,15 +14,13 @@ using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK; using osuTK;
using osuTK.Input; using osuTK.Input;
namespace osu.Game.Screens.Edit.Compose.Components namespace osu.Game.Screens.Edit.Compose.Components
{ {
/// <summary> /// <summary>
/// A container which provides a "blueprint" display of hitobjects. /// A container which provides a "blueprint" display of items.
/// Includes selection and manipulation support via a <see cref="Components.SelectionHandler{T}"/>. /// Includes selection and manipulation support via a <see cref="Components.SelectionHandler{T}"/>.
/// </summary> /// </summary>
public abstract class BlueprintContainer<T> : CompositeDrawable, IKeyBindingHandler<PlatformAction> public abstract class BlueprintContainer<T> : CompositeDrawable, IKeyBindingHandler<PlatformAction>
@ -65,15 +63,15 @@ namespace osu.Game.Screens.Edit.Compose.Components
protected virtual Container<SelectionBlueprint<T>> CreateSelectionBlueprintContainer() => new Container<SelectionBlueprint<T>> { RelativeSizeAxes = Axes.Both }; protected virtual Container<SelectionBlueprint<T>> CreateSelectionBlueprintContainer() => new Container<SelectionBlueprint<T>> { RelativeSizeAxes = Axes.Both };
/// <summary> /// <summary>
/// Creates a <see cref="Components.SelectionHandler{T}"/> which outlines <see cref="DrawableHitObject"/>s and handles movement of selections. /// Creates a <see cref="Components.SelectionHandler{T}"/> which outlines items and handles movement of selections.
/// </summary> /// </summary>
protected abstract SelectionHandler<T> CreateSelectionHandler(); protected abstract SelectionHandler<T> CreateSelectionHandler();
/// <summary> /// <summary>
/// Creates a <see cref="SelectionBlueprint{T}"/> for a specific <see cref="DrawableHitObject"/>. /// Creates a <see cref="SelectionBlueprint{T}"/> for a specific item.
/// </summary> /// </summary>
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to create the overlay for.</param> /// <param name="item">The item to create the overlay for.</param>
protected virtual SelectionBlueprint<T> CreateBlueprintFor(T hitObject) => null; protected virtual SelectionBlueprint<T> CreateBlueprintFor(T item) => null;
protected virtual DragBox CreateDragBox(Action<RectangleF> performSelect) => new DragBox(performSelect); protected virtual DragBox CreateDragBox(Action<RectangleF> performSelect) => new DragBox(performSelect);
@ -103,7 +101,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
ClickedBlueprint = SelectionHandler.SelectedBlueprints.FirstOrDefault(b => b.IsHovered); ClickedBlueprint = SelectionHandler.SelectedBlueprints.FirstOrDefault(b => b.IsHovered);
// Deselection should only occur if no selected blueprints are hovered // Deselection should only occur if no selected blueprints are hovered
// A special case for when a blueprint was selected via this click is added since OnClick() may occur outside the hitobject and should not trigger deselection // A special case for when a blueprint was selected via this click is added since OnClick() may occur outside the item and should not trigger deselection
if (endClickSelection(e) || ClickedBlueprint != null) if (endClickSelection(e) || ClickedBlueprint != null)
return true; return true;
@ -237,7 +235,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
SelectionBlueprints.Add(blueprint); SelectionBlueprints.Add(blueprint);
OnBlueprintAdded(blueprint); if (SelectionHandler.SelectedItems.Contains(item))
blueprint.Select();
OnBlueprintAdded(blueprint.Item);
} }
protected void RemoveBlueprintFor(T item) protected void RemoveBlueprintFor(T item)
@ -254,22 +255,24 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (movementBlueprints?.Contains(blueprint) == true) if (movementBlueprints?.Contains(blueprint) == true)
finishSelectionMovement(); finishSelectionMovement();
OnBlueprintRemoved(blueprint); OnBlueprintRemoved(blueprint.Item);
} }
/// <summary> /// <summary>
/// Called after a <see cref="HitObject"/> blueprint has been added. /// Called after an item's blueprint has been added.
/// </summary> /// </summary>
/// <param name="blueprint">The <see cref="HitObject"/> for which the blueprint has been added.</param> /// <param name="item">The item for which the blueprint has been added.</param>
protected virtual void OnBlueprintAdded(SelectionBlueprint<T> blueprint) protected virtual void OnBlueprintAdded(T item)
{ {
if (SelectionHandler.SelectedItems.Contains(item))
blueprintMap[item].Select();
} }
/// <summary> /// <summary>
/// Called after a <see cref="HitObject"/> blueprint has been removed. /// Called after an item's blueprint has been removed.
/// </summary> /// </summary>
/// <param name="item">The <see cref="HitObject"/> for which the blueprint has been removed.</param> /// <param name="item">The item for which the blueprint has been removed.</param>
protected virtual void OnBlueprintRemoved(SelectionBlueprint<T> item) protected virtual void OnBlueprintRemoved(T item)
{ {
} }
@ -398,16 +401,21 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (!SelectionHandler.SelectedBlueprints.Any()) if (!SelectionHandler.SelectedBlueprints.Any())
return; return;
// Any selected blueprint that is hovered can begin the movement of the group, however only the earliest hitobject is used for movement // Any selected blueprint that is hovered can begin the movement of the group, however only the first item (according to SortForMovement) is used for movement.
// A special case is added for when a click selection occurred before the drag // A special case is added for when a click selection occurred before the drag
if (!clickSelectionBegan && !SelectionHandler.SelectedBlueprints.Any(b => b.IsHovered)) if (!clickSelectionBegan && !SelectionHandler.SelectedBlueprints.Any(b => b.IsHovered))
return; return;
// Movement is tracked from the blueprint of the earliest hitobject, since it only makes sense to distance snap from that hitobject // Movement is tracked from the blueprint of the earliest item, since it only makes sense to distance snap from that item
movementBlueprints = SortForMovement(SelectionHandler.SelectedBlueprints).ToArray(); movementBlueprints = SortForMovement(SelectionHandler.SelectedBlueprints).ToArray();
movementBlueprintOriginalPositions = movementBlueprints.Select(m => m.ScreenSpaceSelectionPoint).ToArray(); movementBlueprintOriginalPositions = movementBlueprints.Select(m => m.ScreenSpaceSelectionPoint).ToArray();
} }
/// <summary>
/// Apply sorting of selected blueprints before performing movement. Generally used to surface the "main" item to the beginning of the collection.
/// </summary>
/// <param name="blueprints">The blueprints to be moved.</param>
/// <returns>Sorted blueprints.</returns>
protected virtual IEnumerable<SelectionBlueprint<T>> SortForMovement(IReadOnlyList<SelectionBlueprint<T>> blueprints) => blueprints; protected virtual IEnumerable<SelectionBlueprint<T>> SortForMovement(IReadOnlyList<SelectionBlueprint<T>> blueprints) => blueprints;
/// <summary> /// <summary>
@ -442,7 +450,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
} }
// if no positional snapping could be performed, try unrestricted snapping from the earliest // if no positional snapping could be performed, try unrestricted snapping from the earliest
// hitobject in the selection. // item in the selection.
// The final movement position, relative to movementBlueprintOriginalPosition. // The final movement position, relative to movementBlueprintOriginalPosition.
Vector2 movePosition = movementBlueprintOriginalPositions.First() + distanceTravelled; Vector2 movePosition = movementBlueprintOriginalPositions.First() + distanceTravelled;

View File

@ -239,9 +239,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
updatePlacementPosition(); updatePlacementPosition();
} }
protected sealed override SelectionBlueprint<HitObject> CreateBlueprintFor(HitObject hitObject) protected sealed override SelectionBlueprint<HitObject> CreateBlueprintFor(HitObject item)
{ {
var drawable = Composer.HitObjects.FirstOrDefault(d => d.HitObject == hitObject); var drawable = Composer.HitObjects.FirstOrDefault(d => d.HitObject == item);
if (drawable == null) if (drawable == null)
return null; return null;

View File

@ -15,26 +15,27 @@ using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK; using osuTK;
using osuTK.Input; using osuTK.Input;
namespace osu.Game.Screens.Edit.Compose.Components namespace osu.Game.Screens.Edit.Compose.Components
{ {
/// <summary> /// <summary>
/// A component which outlines <see cref="DrawableHitObject"/>s and handles movement of selections. /// A component which outlines items and handles movement of selections.
/// </summary> /// </summary>
public abstract class SelectionHandler<T> : CompositeDrawable, IKeyBindingHandler<PlatformAction> public abstract class SelectionHandler<T> : CompositeDrawable, IKeyBindingHandler<PlatformAction>
{ {
/// <summary> /// <summary>
/// The currently selected blueprints. /// The currently selected blueprints.
/// Should be used when operations are dealing directly with the visible blueprints. /// Should be used when operations are dealing directly with the visible blueprints.
/// For more general selection operations, use <see cref="osu.Game.Screens.Edit.EditorBeatmap.SelectedHitObjects"/> instead. /// For more general selection operations, use <see cref="SelectedItems"/> instead.
/// </summary> /// </summary>
public IReadOnlyList<SelectionBlueprint<T>> SelectedBlueprints => selectedBlueprints; public IReadOnlyList<SelectionBlueprint<T>> SelectedBlueprints => selectedBlueprints;
public BindableList<T> SelectedItems = new BindableList<T>(); /// <summary>
/// The currently selected items.
/// </summary>
public readonly BindableList<T> SelectedItems = new BindableList<T>();
private readonly List<SelectionBlueprint<T>> selectedBlueprints; private readonly List<SelectionBlueprint<T>> selectedBlueprints;
@ -124,45 +125,45 @@ namespace osu.Game.Screens.Edit.Compose.Components
#region User Input Handling #region User Input Handling
/// <summary> /// <summary>
/// Handles the selected <see cref="DrawableHitObject"/>s being moved. /// Handles the selected items being moved.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Just returning true is enough to allow <see cref="HitObject.StartTime"/> updates to take place. /// Just returning true is enough to allow default movement to take place.
/// Custom implementation is only required if other attributes are to be considered, like changing columns. /// Custom implementation is only required if other attributes are to be considered, like changing columns.
/// </remarks> /// </remarks>
/// <param name="moveEvent">The move event.</param> /// <param name="moveEvent">The move event.</param>
/// <returns> /// <returns>
/// Whether any <see cref="DrawableHitObject"/>s could be moved. /// Whether any items could be moved.
/// Returning true will also propagate StartTime changes provided by the closest <see cref="IPositionSnapProvider.SnapScreenSpacePositionToValidTime"/>. /// Returning true will also propagate StartTime changes provided by the closest <see cref="IPositionSnapProvider.SnapScreenSpacePositionToValidTime"/>.
/// </returns> /// </returns>
public virtual bool HandleMovement(MoveSelectionEvent<T> moveEvent) => false; public virtual bool HandleMovement(MoveSelectionEvent<T> moveEvent) => false;
/// <summary> /// <summary>
/// Handles the selected <see cref="DrawableHitObject"/>s being rotated. /// Handles the selected items being rotated.
/// </summary> /// </summary>
/// <param name="angle">The delta angle to apply to the selection.</param> /// <param name="angle">The delta angle to apply to the selection.</param>
/// <returns>Whether any <see cref="DrawableHitObject"/>s could be rotated.</returns> /// <returns>Whether any items could be rotated.</returns>
public virtual bool HandleRotation(float angle) => false; public virtual bool HandleRotation(float angle) => false;
/// <summary> /// <summary>
/// Handles the selected <see cref="DrawableHitObject"/>s being scaled. /// Handles the selected items being scaled.
/// </summary> /// </summary>
/// <param name="scale">The delta scale to apply, in playfield local coordinates.</param> /// <param name="scale">The delta scale to apply, in playfield local coordinates.</param>
/// <param name="anchor">The point of reference where the scale is originating from.</param> /// <param name="anchor">The point of reference where the scale is originating from.</param>
/// <returns>Whether any <see cref="DrawableHitObject"/>s could be scaled.</returns> /// <returns>Whether any items could be scaled.</returns>
public virtual bool HandleScale(Vector2 scale, Anchor anchor) => false; public virtual bool HandleScale(Vector2 scale, Anchor anchor) => false;
/// <summary> /// <summary>
/// Handles the selected <see cref="DrawableHitObject"/>s being flipped. /// Handles the selected items being flipped.
/// </summary> /// </summary>
/// <param name="direction">The direction to flip</param> /// <param name="direction">The direction to flip</param>
/// <returns>Whether any <see cref="DrawableHitObject"/>s could be flipped.</returns> /// <returns>Whether any items could be flipped.</returns>
public virtual bool HandleFlip(Direction direction) => false; public virtual bool HandleFlip(Direction direction) => false;
/// <summary> /// <summary>
/// Handles the selected <see cref="DrawableHitObject"/>s being reversed pattern-wise. /// Handles the selected items being reversed pattern-wise.
/// </summary> /// </summary>
/// <returns>Whether any <see cref="DrawableHitObject"/>s could be reversed.</returns> /// <returns>Whether any items could be reversed.</returns>
public virtual bool HandleReverse() => false; public virtual bool HandleReverse() => false;
public bool OnPressed(PlatformAction action) public bool OnPressed(PlatformAction action)
@ -196,7 +197,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <param name="blueprint">The blueprint.</param> /// <param name="blueprint">The blueprint.</param>
internal virtual void HandleSelected(SelectionBlueprint<T> blueprint) internal virtual void HandleSelected(SelectionBlueprint<T> blueprint)
{ {
// there are potentially multiple SelectionHandlers active, but we only want to add hitobjects to the selected list once. // there are potentially multiple SelectionHandlers active, but we only want to add items to the selected list once.
if (!SelectedItems.Contains(blueprint.Item)) if (!SelectedItems.Contains(blueprint.Item))
SelectedItems.Add(blueprint.Item); SelectedItems.Add(blueprint.Item);
@ -323,7 +324,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (selectedBlueprints.Count == 0) if (selectedBlueprints.Count == 0)
return; return;
// Move the rectangle to cover the hitobjects // Move the rectangle to cover the items
var topLeft = new Vector2(float.MaxValue, float.MaxValue); var topLeft = new Vector2(float.MaxValue, float.MaxValue);
var bottomRight = new Vector2(float.MinValue, float.MinValue); var bottomRight = new Vector2(float.MinValue, float.MinValue);

View File

@ -179,9 +179,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
protected override SelectionHandler<HitObject> CreateSelectionHandler() => new TimelineSelectionHandler(); protected override SelectionHandler<HitObject> CreateSelectionHandler() => new TimelineSelectionHandler();
protected override SelectionBlueprint<HitObject> CreateBlueprintFor(HitObject hitObject) protected override SelectionBlueprint<HitObject> CreateBlueprintFor(HitObject item)
{ {
return new TimelineHitObjectBlueprint(hitObject) return new TimelineHitObjectBlueprint(item)
{ {
OnDragHandled = handleScrollViaDrag OnDragHandled = handleScrollViaDrag
}; };