From 8e4a21bee756c610c61e4be2d1737b6d5d2aa7f7 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 24 Oct 2019 15:58:22 +0900 Subject: [PATCH] Separate out mouse down/click/up handling --- .../Compose/Components/BlueprintContainer.cs | 61 ++++++++++++++++--- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs index e442e1b0b2..123fdc78e6 100644 --- a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs @@ -11,6 +11,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Input; using osu.Framework.Input.Events; +using osu.Framework.Input.States; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Tools; using osu.Game.Rulesets.Objects; @@ -128,27 +129,27 @@ namespace osu.Game.Screens.Edit.Compose.Components protected override bool OnMouseDown(MouseDownEvent e) { - foreach (SelectionBlueprint blueprint in selectionBlueprints.AliveBlueprints) - { - if (blueprint.IsHovered) - { - selectionHandler.HandleSelectionRequested(blueprint, e.CurrentState); - break; - } - } - + beginClickSelection(e); return true; } 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; deselectAll(); return true; } + protected override bool OnMouseUp(MouseUpEvent e) + { + endClickSelection(); + return true; + } + protected override bool OnMouseMove(MouseMoveEvent e) { if (currentPlacement != null) @@ -227,6 +228,40 @@ namespace osu.Game.Screens.Edit.Compose.Components currentPlacement.UpdatePosition(snappedScreenSpacePosition); } + #region Selection + + /// + /// Whether a blueprint was selected by a previous click event. + /// + private bool clickSelectionBegan; + + /// + /// Attempts to select any hovered blueprints. + /// + /// The input event that triggered this selection. + 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; + } + } + } + + /// + /// Finishes the current blueprint selection. + /// + private void endClickSelection() + { + clickSelectionBegan = false; + } + /// /// Select all masks in a given rectangle selection area. /// @@ -263,6 +298,10 @@ namespace osu.Game.Screens.Edit.Compose.Components SelectionChanged?.Invoke(selectionHandler.SelectedHitObjects); } + #endregion + + #region Selection Movement + private Vector2? screenSpaceMovementStartPosition; private SelectionBlueprint movementBlueprint; @@ -330,6 +369,8 @@ namespace osu.Game.Screens.Edit.Compose.Components return true; } + #endregion + protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing);