2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework;
|
2019-10-31 09:24:38 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-10-25 09:16:25 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2018-05-11 01:48:07 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-10-31 09:24:38 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2018-11-06 09:06:34 +00:00
|
|
|
|
/// A blueprint placed above a <see cref="DrawableHitObject"/> adding editing functionality.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// </summary>
|
2018-11-07 07:21:32 +00:00
|
|
|
|
public abstract class SelectionBlueprint : CompositeDrawable, IStateful<SelectionState>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2018-11-06 08:56:04 +00:00
|
|
|
|
/// Invoked when this <see cref="SelectionBlueprint"/> has been selected.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// </summary>
|
2018-11-06 08:56:04 +00:00
|
|
|
|
public event Action<SelectionBlueprint> Selected;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 08:56:04 +00:00
|
|
|
|
/// Invoked when this <see cref="SelectionBlueprint"/> has been deselected.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// </summary>
|
2018-11-06 08:56:04 +00:00
|
|
|
|
public event Action<SelectionBlueprint> Deselected;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 08:56:04 +00:00
|
|
|
|
/// The <see cref="DrawableHitObject"/> which this <see cref="SelectionBlueprint"/> applies to.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// </summary>
|
2019-10-21 08:04:56 +00:00
|
|
|
|
public readonly DrawableHitObject DrawableObject;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-10-21 08:04:56 +00:00
|
|
|
|
protected override bool ShouldBeAlive => (DrawableObject.IsAlive && DrawableObject.IsPresent) || State == SelectionState.Selected;
|
2018-09-26 05:01:15 +00:00
|
|
|
|
public override bool HandlePositionalInput => ShouldBeAlive;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public override bool RemoveWhenNotAlive => false;
|
|
|
|
|
|
2019-10-31 09:24:38 +00:00
|
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
|
private HitObjectComposer composer { get; set; }
|
|
|
|
|
|
2019-10-21 08:04:56 +00:00
|
|
|
|
protected SelectionBlueprint(DrawableHitObject drawableObject)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-10-21 08:04:56 +00:00
|
|
|
|
DrawableObject = drawableObject;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-25 09:16:25 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
AlwaysPresent = true;
|
|
|
|
|
Alpha = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SelectionState state;
|
|
|
|
|
|
|
|
|
|
public event Action<SelectionState> StateChanged;
|
|
|
|
|
|
|
|
|
|
public SelectionState State
|
|
|
|
|
{
|
|
|
|
|
get => state;
|
|
|
|
|
set
|
|
|
|
|
{
|
2019-04-25 08:36:17 +00:00
|
|
|
|
if (state == value)
|
|
|
|
|
return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
state = value;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case SelectionState.Selected:
|
|
|
|
|
Show();
|
|
|
|
|
Selected?.Invoke(this);
|
|
|
|
|
break;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
case SelectionState.NotSelected:
|
|
|
|
|
Hide();
|
|
|
|
|
Deselected?.Invoke(this);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-25 08:36:17 +00:00
|
|
|
|
|
|
|
|
|
StateChanged?.Invoke(state);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 02:33:37 +00: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 09:19:50 +00:00
|
|
|
|
/// <summary>
|
2018-11-06 08:56:04 +00:00
|
|
|
|
/// Selects this <see cref="SelectionBlueprint"/>, causing it to become visible.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public void Select() => State = SelectionState.Selected;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 08:56:04 +00:00
|
|
|
|
/// Deselects this <see cref="SelectionBlueprint"/>, causing it to become invisible.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public void Deselect() => State = SelectionState.NotSelected;
|
|
|
|
|
|
|
|
|
|
public bool IsSelected => State == SelectionState.Selected;
|
|
|
|
|
|
2019-10-31 09:24:38 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the <see cref="HitObject"/>, invoking <see cref="HitObject.ApplyDefaults"/> and re-processing the beatmap.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected void UpdateHitObject() => composer?.UpdateHitObject(DrawableObject.HitObject);
|
|
|
|
|
|
2019-10-21 08:04:56 +00:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => DrawableObject.ReceivePositionalInputAt(screenSpacePos);
|
2018-10-25 09:16:25 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// <summary>
|
2018-11-06 08:56:04 +00:00
|
|
|
|
/// The screen-space point that causes this <see cref="SelectionBlueprint"/> to be selected.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// </summary>
|
2019-10-21 08:04:56 +00:00
|
|
|
|
public virtual Vector2 SelectionPoint => DrawableObject.ScreenSpaceDrawQuad.Centre;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 08:56:04 +00:00
|
|
|
|
/// The screen-space quad that outlines this <see cref="SelectionBlueprint"/> for selections.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// </summary>
|
2019-10-21 08:04:56 +00:00
|
|
|
|
public virtual Quad SelectionQuad => DrawableObject.ScreenSpaceDrawQuad;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|