mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:47:26 +08:00
Allow HitObjectMasks to handle drag events directly
This commit is contained in:
parent
b87a92dbf8
commit
24b9a8c983
@ -32,6 +32,11 @@ namespace osu.Game.Rulesets.Edit
|
||||
/// </summary>
|
||||
public event Action<HitObjectMask, InputState> SelectionRequested;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when this <see cref="HitObjectMask"/> has requested drag.
|
||||
/// </summary>
|
||||
public event Action<HitObjectMask, InputState> DragRequested;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="DrawableHitObject"/> which this <see cref="HitObjectMask"/> applies to.
|
||||
/// </summary>
|
||||
@ -99,7 +104,7 @@ namespace osu.Game.Rulesets.Edit
|
||||
selectionRequested = true;
|
||||
}
|
||||
|
||||
return base.OnMouseDown(state, args);
|
||||
return IsSelected;
|
||||
}
|
||||
|
||||
protected override bool OnClick(InputState state)
|
||||
@ -108,11 +113,20 @@ namespace osu.Game.Rulesets.Edit
|
||||
{
|
||||
selectionRequested = true;
|
||||
SelectionRequested?.Invoke(this, state);
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnClick(state);
|
||||
}
|
||||
|
||||
protected override bool OnDragStart(InputState state) => true;
|
||||
|
||||
protected override bool OnDrag(InputState state)
|
||||
{
|
||||
DragRequested?.Invoke(this, state);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The screen-space point that causes this <see cref="HitObjectMask"/> to be selected.
|
||||
/// </summary>
|
||||
|
@ -37,6 +37,8 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
maskContainer.MaskSelected += maskSelection.HandleSelected;
|
||||
maskContainer.MaskDeselected += maskSelection.HandleDeselected;
|
||||
maskContainer.MaskSelectionRequested += maskSelection.HandleSelectionRequested;
|
||||
maskContainer.MaskDragRequested += maskSelection.HandleDrag;
|
||||
|
||||
maskSelection.DeselectAll = maskContainer.DeselectAll;
|
||||
|
||||
var dragLayer = new DragLayer(maskContainer.Select);
|
||||
|
@ -29,6 +29,11 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
/// </summary>
|
||||
public event Action<HitObjectMask, InputState> MaskSelectionRequested;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when any <see cref="HitObjectMask"/> requests drag.
|
||||
/// </summary>
|
||||
public event Action<HitObjectMask, InputState> MaskDragRequested;
|
||||
|
||||
private IEnumerable<HitObjectMask> aliveMasks => AliveInternalChildren.Cast<HitObjectMask>();
|
||||
|
||||
public MaskContainer()
|
||||
@ -43,6 +48,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
drawable.Selected += onMaskSelected;
|
||||
drawable.Deselected += onMaskDeselected;
|
||||
drawable.SelectionRequested += onSelectionRequested;
|
||||
drawable.DragRequested += onDragRequested;
|
||||
}
|
||||
|
||||
public override bool Remove(HitObjectMask drawable)
|
||||
@ -54,6 +60,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
drawable.Selected -= onMaskSelected;
|
||||
drawable.Deselected -= onMaskDeselected;
|
||||
drawable.SelectionRequested -= onSelectionRequested;
|
||||
drawable.DragRequested -= onDragRequested;
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -82,6 +89,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
private void onMaskSelected(HitObjectMask mask) => MaskSelected?.Invoke(mask);
|
||||
private void onMaskDeselected(HitObjectMask mask) => MaskDeselected?.Invoke(mask);
|
||||
private void onSelectionRequested(HitObjectMask mask, InputState state) => MaskSelectionRequested?.Invoke(mask, state);
|
||||
private void onDragRequested(HitObjectMask mask, InputState state) => MaskDragRequested?.Invoke(mask, state);
|
||||
|
||||
protected override int Compare(Drawable x, Drawable y)
|
||||
{
|
||||
|
@ -55,22 +55,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
|
||||
#region User Input Handling
|
||||
|
||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => handleInput(state);
|
||||
|
||||
protected override bool OnDragStart(InputState state) => handleInput(state);
|
||||
|
||||
protected override bool OnDragEnd(InputState state) => true;
|
||||
|
||||
private bool handleInput(InputState state)
|
||||
{
|
||||
if (!selectedMasks.Any(m => m.ReceiveMouseInputAt(state.Mouse.NativeState.PositionMouseDown ?? state.Mouse.NativeState.Position)))
|
||||
return false;
|
||||
|
||||
UpdateVisibility();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnDrag(InputState state)
|
||||
public void HandleDrag(HitObjectMask m, InputState state)
|
||||
{
|
||||
// Todo: Various forms of snapping
|
||||
|
||||
@ -83,8 +68,6 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
Loading…
Reference in New Issue
Block a user