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
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework;
|
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;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-07-21 10:38:28 +08:00
|
|
|
|
using osu.Framework.Input.States;
|
2018-05-11 09:48:07 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
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
|
|
|
|
{
|
|
|
|
|
/// <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
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
|
/// Invoked when this <see cref="SelectionBlueprint"/> has requested selection.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// Will fire even if already selected. Does not actually perform selection.
|
|
|
|
|
/// </summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
|
public event Action<SelectionBlueprint, InputState> SelectionRequested;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
|
/// Invoked when this <see cref="SelectionBlueprint"/> has requested drag.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// </summary>
|
2018-11-26 15:08:56 +08:00
|
|
|
|
public event Action<SelectionBlueprint, DragEvent> DragRequested;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
|
/// The <see cref="DrawableHitObject"/> which this <see cref="SelectionBlueprint"/> applies to.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly DrawableHitObject HitObject;
|
|
|
|
|
|
|
|
|
|
protected override bool ShouldBeAlive => HitObject.IsAlive && HitObject.IsPresent || State == SelectionState.Selected;
|
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;
|
|
|
|
|
|
2018-11-07 15:21:32 +08:00
|
|
|
|
protected SelectionBlueprint(DrawableHitObject hitObject)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
HitObject = hitObject;
|
|
|
|
|
|
2018-10-25 17:16:25 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
AlwaysPresent = true;
|
|
|
|
|
Alpha = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SelectionState state;
|
|
|
|
|
|
|
|
|
|
public event Action<SelectionState> StateChanged;
|
|
|
|
|
|
|
|
|
|
public SelectionState State
|
|
|
|
|
{
|
|
|
|
|
get => state;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (state == value) return;
|
|
|
|
|
|
|
|
|
|
state = value;
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case SelectionState.Selected:
|
|
|
|
|
Show();
|
|
|
|
|
Selected?.Invoke(this);
|
|
|
|
|
break;
|
|
|
|
|
case SelectionState.NotSelected:
|
|
|
|
|
Hide();
|
|
|
|
|
Deselected?.Invoke(this);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
|
/// Selects this <see cref="SelectionBlueprint"/>, causing it to become visible.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public void Select() => State = SelectionState.Selected;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
|
/// Deselects this <see cref="SelectionBlueprint"/>, causing it to become invisible.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public void Deselect() => State = SelectionState.NotSelected;
|
|
|
|
|
|
|
|
|
|
public bool IsSelected => State == SelectionState.Selected;
|
|
|
|
|
|
2018-10-25 17:16:25 +08:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => HitObject.ReceivePositionalInputAt(screenSpacePos);
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private bool selectionRequested;
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
selectionRequested = false;
|
|
|
|
|
|
|
|
|
|
if (State == SelectionState.NotSelected)
|
|
|
|
|
{
|
2018-09-19 19:52:57 +08:00
|
|
|
|
SelectionRequested?.Invoke(this, e.CurrentState);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
selectionRequested = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return IsSelected;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
if (State == SelectionState.Selected && !selectionRequested)
|
|
|
|
|
{
|
|
|
|
|
selectionRequested = true;
|
2018-09-19 19:52:57 +08:00
|
|
|
|
SelectionRequested?.Invoke(this, e.CurrentState);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnClick(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnDragStart(DragStartEvent e) => true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnDrag(DragEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-26 15:08:56 +08:00
|
|
|
|
DragRequested?.Invoke(this, e);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
|
/// The screen-space point that causes this <see cref="SelectionBlueprint"/> to be selected.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// </summary>
|
2018-10-25 17:16:25 +08:00
|
|
|
|
public virtual Vector2 SelectionPoint => HitObject.ScreenSpaceDrawQuad.Centre;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
|
/// The screen-space quad that outlines this <see cref="SelectionBlueprint"/> for selections.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// </summary>
|
2018-10-25 17:16:25 +08:00
|
|
|
|
public virtual Quad SelectionQuad => HitObject.ScreenSpaceDrawQuad;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|