mirror of
https://github.com/osukey/osukey.git
synced 2025-05-06 06:07:26 +09:00
The general idea here is that we need the masks to handle mouse down events, as they need to handle the drag (mousedown -> drag immediately). I've rewritten the editor selections to use events, as there are some 3 different components that handle/trigger selections in different ways. 1. All selections/deselections now propagate through `HitObjectMask.Select()`/`HitObjectMask.Deselect()`. 2. Components that react to changes in the selection bind to the masks' `Selected`/`Deselected` events, and track them/change their states locally. 3. Masks provide a `SingleSelectionRequested` event which is invoked on the mouse-down event. Various components bind to this event to perform state changes locally in this scenario. 4. `DragBox` now handles all drag input locally. It triggers `Select`/`Deselect` on the masks it needs to. 5. `SelectionBox` handles the display of itself locally. 6. `SelectionBox` handles movement of groups of masks locally. 7. `HitObjectMasks` handles movement of itself locally.
106 lines
3.5 KiB
C#
106 lines
3.5 KiB
C#
// 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.Graphics.Containers;
|
|
using osu.Framework.Graphics.Primitives;
|
|
using osu.Framework.Input;
|
|
using osu.Game.Rulesets.Edit.Types;
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
using OpenTK;
|
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
{
|
|
/// <summary>
|
|
/// A mask placed above a <see cref="DrawableHitObject"/> adding editing functionality.
|
|
/// </summary>
|
|
public class HitObjectMask : VisibilityContainer
|
|
{
|
|
public event Action<HitObjectMask> Selected;
|
|
public event Action<HitObjectMask> Deselected;
|
|
public event Action<HitObjectMask> SingleSelectionRequested;
|
|
|
|
public readonly DrawableHitObject HitObject;
|
|
|
|
protected override bool ShouldBeAlive => HitObject.IsAlive || State == Visibility.Visible;
|
|
public override bool HandleMouseInput => true;
|
|
|
|
public HitObjectMask(DrawableHitObject hitObject)
|
|
{
|
|
HitObject = hitObject;
|
|
|
|
AlwaysPresent = true;
|
|
State = Visibility.Hidden;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selects this <see cref="HitObjectMask"/>, causing it to become visible.
|
|
/// </summary>
|
|
/// <returns>True if the <see cref="HitObjectMask"/> was selected. False if the <see cref="HitObjectMask"/> was already selected.</returns>
|
|
public bool Select()
|
|
{
|
|
if (State == Visibility.Visible)
|
|
return false;
|
|
|
|
Show();
|
|
Selected?.Invoke(this);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deselects this <see cref="HitObjectMask"/>, causing it to become invisible.
|
|
/// </summary>
|
|
/// <returns>True if the <see cref="HitObjectMask"/> was deselected. False if the <see cref="HitObjectMask"/> was already deselected.</returns>
|
|
public bool Deselect()
|
|
{
|
|
if (State == Visibility.Hidden)
|
|
return false;
|
|
|
|
Hide();
|
|
Deselected?.Invoke(this);
|
|
return true;
|
|
}
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
{
|
|
if (HitObject.IsPresent)
|
|
{
|
|
SingleSelectionRequested?.Invoke(this);
|
|
Select();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
protected override bool OnDragStart(InputState state) => true;
|
|
|
|
protected override bool OnDrag(InputState state)
|
|
{
|
|
// Todo: Various forms of snapping
|
|
switch (HitObject.HitObject)
|
|
{
|
|
case IHasEditablePosition editablePosition:
|
|
editablePosition.OffsetPosition(state.Mouse.Delta);
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
protected override bool OnDragEnd(InputState state) => true;
|
|
|
|
protected override void PopIn() => Alpha = 1;
|
|
protected override void PopOut() => Alpha = 0;
|
|
|
|
/// <summary>
|
|
/// The screen-space point that causes this <see cref="HitObjectMask"/> to be selected.
|
|
/// </summary>
|
|
public virtual Vector2 SelectionPoint => ScreenSpaceDrawQuad.Centre;
|
|
|
|
/// <summary>
|
|
/// The screen-space quad that outlines this <see cref="HitObjectMask"/> for selections.
|
|
/// </summary>
|
|
public virtual Quad SelectionQuad => ScreenSpaceDrawQuad;
|
|
}
|
|
}
|