2020-01-20 23:53:59 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework;
|
2019-10-31 17:24:38 +08:00
|
|
|
using osu.Framework.Allocation;
|
2018-10-25 17:16:25 +08:00
|
|
|
using osu.Framework.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2019-11-12 12:38:42 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-05-11 09:48:07 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-10-31 17:24:38 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
|
|
{
|
|
|
|
/// <summary>
|
2018-11-06 17:06:34 +08:00
|
|
|
/// A blueprint placed above a <see cref="DrawableHitObject"/> adding editing functionality.
|
2018-04-13 17:19:50 +08:00
|
|
|
/// </summary>
|
2018-11-07 15:21:32 +08:00
|
|
|
public abstract class SelectionBlueprint : CompositeDrawable, IStateful<SelectionState>
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2020-01-20 23:53:59 +08:00
|
|
|
public readonly HitObject HitObject;
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
/// <summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
/// Invoked when this <see cref="SelectionBlueprint"/> has been selected.
|
2018-04-13 17:19:50 +08:00
|
|
|
/// </summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
public event Action<SelectionBlueprint> Selected;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
/// Invoked when this <see cref="SelectionBlueprint"/> has been deselected.
|
2018-04-13 17:19:50 +08:00
|
|
|
/// </summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
public event Action<SelectionBlueprint> Deselected;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
public override bool HandlePositionalInput => ShouldBeAlive;
|
2018-04-13 17:19:50 +08:00
|
|
|
public override bool RemoveWhenNotAlive => false;
|
|
|
|
|
2019-10-31 17:24:38 +08:00
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
private HitObjectComposer composer { get; set; }
|
|
|
|
|
2020-01-20 23:53:59 +08:00
|
|
|
protected SelectionBlueprint(HitObject hitObject)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2020-01-21 16:36:21 +08:00
|
|
|
HitObject = hitObject;
|
2020-01-24 16:51:24 +08:00
|
|
|
|
2018-10-25 17:16:25 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
2020-01-24 16:51:24 +08:00
|
|
|
AlwaysPresent = true;
|
2020-01-21 16:36:21 +08:00
|
|
|
}
|
2018-10-25 17:16:25 +08:00
|
|
|
|
2020-01-24 16:51:24 +08:00
|
|
|
protected override void LoadComplete()
|
2020-01-21 16:36:21 +08:00
|
|
|
{
|
2020-01-24 16:51:24 +08:00
|
|
|
base.LoadComplete();
|
|
|
|
updateState();
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private SelectionState state;
|
|
|
|
|
|
|
|
public event Action<SelectionState> StateChanged;
|
|
|
|
|
|
|
|
public SelectionState State
|
|
|
|
{
|
|
|
|
get => state;
|
|
|
|
set
|
|
|
|
{
|
2019-04-25 16:36:17 +08:00
|
|
|
if (state == value)
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
state = value;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
2020-01-24 16:51:24 +08:00
|
|
|
if (IsLoaded)
|
|
|
|
updateState();
|
2019-04-25 16:36:17 +08:00
|
|
|
|
|
|
|
StateChanged?.Invoke(state);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:51:24 +08:00
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case SelectionState.Selected:
|
|
|
|
OnSelected();
|
|
|
|
Selected?.Invoke(this);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SelectionState.NotSelected:
|
|
|
|
OnDeselected();
|
|
|
|
Deselected?.Invoke(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-09 13:03:13 +08:00
|
|
|
protected virtual void OnDeselected()
|
|
|
|
{
|
|
|
|
// selection blueprints are AlwaysPresent while the related DrawableHitObject is visible
|
|
|
|
// set the body piece's alpha directly to avoid arbitrarily rendering frame buffers etc. of children.
|
|
|
|
foreach (var d in InternalChildren)
|
|
|
|
d.Hide();
|
|
|
|
|
|
|
|
Hide();
|
|
|
|
}
|
2020-01-21 13:21:00 +08:00
|
|
|
|
2020-10-09 13:03:13 +08:00
|
|
|
protected virtual void OnSelected()
|
|
|
|
{
|
|
|
|
foreach (var d in InternalChildren)
|
|
|
|
d.Show();
|
|
|
|
|
|
|
|
Show();
|
|
|
|
}
|
2020-01-21 13:21:00 +08:00
|
|
|
|
2019-11-05 10:33:37 +08:00
|
|
|
// When not selected, input is only required for the blueprint itself to receive IsHovering
|
|
|
|
protected override bool ShouldBeConsideredForInput(Drawable child) => State == SelectionState.Selected;
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
/// <summary>
|
2020-01-20 23:53:59 +08:00
|
|
|
/// Selects this <see cref="OverlaySelectionBlueprint"/>, causing it to become visible.
|
2018-04-13 17:19:50 +08:00
|
|
|
/// </summary>
|
|
|
|
public void Select() => State = SelectionState.Selected;
|
|
|
|
|
|
|
|
/// <summary>
|
2020-01-20 23:53:59 +08:00
|
|
|
/// Deselects this <see cref="OverlaySelectionBlueprint"/>, causing it to become invisible.
|
2018-04-13 17:19:50 +08:00
|
|
|
/// </summary>
|
|
|
|
public void Deselect() => State = SelectionState.NotSelected;
|
|
|
|
|
2020-10-27 05:16:28 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Toggles the selection state of this <see cref="OverlaySelectionBlueprint"/>.
|
|
|
|
/// </summary>
|
|
|
|
public void ToggleSelection() => State = IsSelected ? SelectionState.NotSelected : SelectionState.Selected;
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
public bool IsSelected => State == SelectionState.Selected;
|
|
|
|
|
2019-11-12 12:38:42 +08:00
|
|
|
/// <summary>
|
2020-01-20 23:53:59 +08:00
|
|
|
/// The <see cref="MenuItem"/>s to be displayed in the context menu for this <see cref="OverlaySelectionBlueprint"/>.
|
2019-11-12 12:38:42 +08:00
|
|
|
/// </summary>
|
|
|
|
public virtual MenuItem[] ContextMenuItems => Array.Empty<MenuItem>();
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
/// <summary>
|
2020-01-20 23:53:59 +08:00
|
|
|
/// The screen-space point that causes this <see cref="OverlaySelectionBlueprint"/> to be selected.
|
2018-04-13 17:19:50 +08:00
|
|
|
/// </summary>
|
2020-05-20 16:48:43 +08:00
|
|
|
public virtual Vector2 ScreenSpaceSelectionPoint => ScreenSpaceDrawQuad.Centre;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2020-01-20 23:53:59 +08:00
|
|
|
/// The screen-space quad that outlines this <see cref="OverlaySelectionBlueprint"/> for selections.
|
2018-04-13 17:19:50 +08:00
|
|
|
/// </summary>
|
2020-01-20 23:53:59 +08:00
|
|
|
public virtual Quad SelectionQuad => ScreenSpaceDrawQuad;
|
2020-01-21 16:36:21 +08:00
|
|
|
|
2020-01-21 22:58:51 +08:00
|
|
|
public virtual Vector2 GetInstantDelta(Vector2 screenSpacePosition) => Parent.ToLocalSpace(screenSpacePosition) - Position;
|
2020-11-03 19:45:48 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Handle to perform a partial deletion when the user requests a quick delete (Shift+Right Click).
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>True if the deletion operation was handled by this blueprint. Returning false will delete the full blueprint.</returns>
|
|
|
|
public virtual bool HandleQuickDeletion() => false;
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|