mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:23:22 +08:00
Separate out mouse down/click/up handling
This commit is contained in:
parent
a07e5a269b
commit
8e4a21bee7
@ -11,6 +11,7 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Framework.Input.States;
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
using osu.Game.Rulesets.Edit.Tools;
|
using osu.Game.Rulesets.Edit.Tools;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
@ -128,27 +129,27 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
|
|
||||||
protected override bool OnMouseDown(MouseDownEvent e)
|
protected override bool OnMouseDown(MouseDownEvent e)
|
||||||
{
|
{
|
||||||
foreach (SelectionBlueprint blueprint in selectionBlueprints.AliveBlueprints)
|
beginClickSelection(e);
|
||||||
{
|
|
||||||
if (blueprint.IsHovered)
|
|
||||||
{
|
|
||||||
selectionHandler.HandleSelectionRequested(blueprint, e.CurrentState);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
if (selectionBlueprints.AliveBlueprints.Any(b => b.IsHovered))
|
// clickSelectionBegan will be true if a mouse down occurred on the blueprint but the click event was received outside of the blueprint
|
||||||
|
// otherwise, deselection should only occur if the click event did not occur on top of a selected blueprint
|
||||||
|
if (clickSelectionBegan || selectionHandler.SelectedBlueprints.Any(b => b.IsHovered))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
deselectAll();
|
deselectAll();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool OnMouseUp(MouseUpEvent e)
|
||||||
|
{
|
||||||
|
endClickSelection();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||||
{
|
{
|
||||||
if (currentPlacement != null)
|
if (currentPlacement != null)
|
||||||
@ -227,6 +228,40 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
currentPlacement.UpdatePosition(snappedScreenSpacePosition);
|
currentPlacement.UpdatePosition(snappedScreenSpacePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Selection
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether a blueprint was selected by a previous click event.
|
||||||
|
/// </summary>
|
||||||
|
private bool clickSelectionBegan;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to select any hovered blueprints.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e">The input event that triggered this selection.</param>
|
||||||
|
private void beginClickSelection(UIEvent e)
|
||||||
|
{
|
||||||
|
Debug.Assert(!clickSelectionBegan);
|
||||||
|
|
||||||
|
foreach (SelectionBlueprint blueprint in selectionBlueprints.AliveBlueprints)
|
||||||
|
{
|
||||||
|
if (blueprint.IsHovered)
|
||||||
|
{
|
||||||
|
selectionHandler.HandleSelectionRequested(blueprint, e.CurrentState);
|
||||||
|
clickSelectionBegan = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finishes the current blueprint selection.
|
||||||
|
/// </summary>
|
||||||
|
private void endClickSelection()
|
||||||
|
{
|
||||||
|
clickSelectionBegan = false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Select all masks in a given rectangle selection area.
|
/// Select all masks in a given rectangle selection area.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -263,6 +298,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
SelectionChanged?.Invoke(selectionHandler.SelectedHitObjects);
|
SelectionChanged?.Invoke(selectionHandler.SelectedHitObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Selection Movement
|
||||||
|
|
||||||
private Vector2? screenSpaceMovementStartPosition;
|
private Vector2? screenSpaceMovementStartPosition;
|
||||||
private SelectionBlueprint movementBlueprint;
|
private SelectionBlueprint movementBlueprint;
|
||||||
|
|
||||||
@ -330,6 +369,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
Loading…
Reference in New Issue
Block a user