From 958797d7c061c74c6c9928488302972e7471bcf6 Mon Sep 17 00:00:00 2001 From: David Triphon Date: Mon, 20 Jul 2020 12:46:40 -0700 Subject: [PATCH] Fixed some mouse press/release action interaction conflicts. --- src/js/game/camera.js | 4 ++-- src/js/game/hud/parts/building_placer_logic.js | 15 ++++++++++++++- src/js/game/hud/parts/mass_selector.js | 7 ++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/js/game/camera.js b/src/js/game/camera.js index ba2bc267..dc1b3700 100644 --- a/src/js/game/camera.js +++ b/src/js/game/camera.js @@ -87,7 +87,7 @@ export class Camera extends BasicSerializableObject { this.downPreHandler = /** @type {TypedSignal<[Vector, enumMouseButton]>} */ (new Signal()); this.movePreHandler = /** @type {TypedSignal<[Vector]>} */ (new Signal()); // this.pinchPreHandler = /** @type {TypedSignal<[Vector]>} */ (new Signal()); - this.upPostHandler = /** @type {TypedSignal<[Vector]>} */ (new Signal()); + this.upPostHandler = /** @type {TypedSignal<[Vector, enumMouseButton]>} */ (new Signal()); this.internalInitEvents(); this.clampZoomLevel(); @@ -767,7 +767,7 @@ export class Camera extends BasicSerializableObject { this.userInteraction.dispatch(USER_INTERACT_TOUCHEND); this.didMoveSinceTouchStart = false; } - this.upPostHandler.dispatch(new Vector(x, y)); + this.upPostHandler.dispatch(new Vector(x, y), buttonKey); } /** diff --git a/src/js/game/hud/parts/building_placer_logic.js b/src/js/game/hud/parts/building_placer_logic.js index f0266b77..c91d7200 100644 --- a/src/js/game/hud/parts/building_placer_logic.js +++ b/src/js/game/hud/parts/building_placer_logic.js @@ -824,11 +824,24 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { /** * Mouse up handler */ - onMouseUp() { + onMouseUp(pos, mouseButton) { if (this.root.camera.getIsMapOverlayActive()) { return; } + // prevent releasing the wrong mouse button from cancelling other actions: + // if not dragging, OR + // if not deleting and the released mouse button is not left click, OR + // if deleting and the released mouse button is not right click, + // then ignore the release + if ( + !this.currentlyDragging || + (!this.currentlyDeleting && mouseButton !== enumMouseButton.left) || + (this.currentlyDeleting && mouseButton !== enumMouseButton.right) + ) { + return; + } + // Check for direction lock if (this.lastDragTile && this.currentlyDragging && this.isDirectionLockActive) { this.executeDirectionLockedPlacement(); diff --git a/src/js/game/hud/parts/mass_selector.js b/src/js/game/hud/parts/mass_selector.js index 68d480e4..156318d8 100644 --- a/src/js/game/hud/parts/mass_selector.js +++ b/src/js/game/hud/parts/mass_selector.js @@ -213,7 +213,12 @@ export class HUDMassSelector extends BaseHUDPart { } } - onMouseUp() { + onMouseUp(pos, mouseButton) { + // prevent releasing other mouse buttons from stopping a left click action + if (mouseButton !== enumMouseButton.left) { + return; + } + if (this.currentSelectionStartWorld) { const worldStart = this.currentSelectionStartWorld; const worldEnd = this.root.camera.screenToWorld(this.currentSelectionEnd);