diff --git a/src/input/InputPlugin.js b/src/input/InputPlugin.js index 0d67dbe46..2ead76e74 100644 --- a/src/input/InputPlugin.js +++ b/src/input/InputPlugin.js @@ -526,7 +526,7 @@ var InputPlugin = new Class({ }, /** - * Checks to see if both this plugin and the Scene to which it belongs is active. + * Checks to see if the Input Manager, this plugin and the Scene to which it belongs are all active and input enabled. * * @method Phaser.Input.InputPlugin#isActive * @since 3.10.0 @@ -535,7 +535,22 @@ var InputPlugin = new Class({ */ isActive: function () { - return (this.enabled && this.scene.sys.canInput()); + return (this.manager && this.manager.enabled && this.enabled && this.scene.sys.canInput()); + }, + + /** + * Forces the Input Manager to clear the custom or hand cursor, regardless of the + * interactive state of any Game Objects. + * + * @method Phaser.Input.InputPlugin#resetCursor + * @since 3.85.0 + */ + resetCursor: function () + { + if (this.manager) + { + this.manager.resetCursor(null, true); + } }, /** @@ -818,11 +833,14 @@ var InputPlugin = new Class({ * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to have its input system disabled. + * @param {boolean} [resetCursor=false] - Reset the cursor to the default? * * @return {this} This Input Plugin. */ - disable: function (gameObject) + disable: function (gameObject, resetCursor) { + if (resetCursor === undefined) { resetCursor = false; } + var input = gameObject.input; if (input) @@ -853,6 +871,11 @@ var InputPlugin = new Class({ } } + if (resetCursor) + { + this.resetCursor(); + } + return this; }, @@ -984,8 +1007,6 @@ var InputPlugin = new Class({ _eventData.cancelled = false; - var aborted = false; - // Go through all objects the pointer was over and fire their events / callbacks for (var i = 0; i < currentlyOver.length; i++) { @@ -998,32 +1019,41 @@ var InputPlugin = new Class({ total++; + // 1) GAMEOBJECT_POINTER_DOWN gameObject.emit(Events.GAMEOBJECT_POINTER_DOWN, pointer, gameObject.input.localX, gameObject.input.localY, _eventContainer); - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + if (_eventData.cancelled || !this.isActive()) { - aborted = true; + // They cancelled the whole event, it can't go any further break; } - this.emit(Events.GAMEOBJECT_DOWN, pointer, gameObject, _eventContainer); - - if (_eventData.cancelled || !gameObject.input) + // Check that the game object wasn't input disabled or destroyed as a result of its input event + if (gameObject.input && gameObject.input.enabled) { - aborted = true; - break; + // 2) GAMEOBJECT_DOWN + + this.emit(Events.GAMEOBJECT_DOWN, pointer, gameObject, _eventContainer); + + if (_eventData.cancelled || !this.isActive()) + { + // They cancelled the whole event, it can't go any further + break; + } } } - // If they released outside the canvas, but pressed down inside it, we'll still dispatch the event. - if (!aborted && this.manager) + // If they pressed down outside the canvas, dispatch that event. + if (!_eventData.cancelled && this.isActive()) { if (pointer.downElement === this.manager.game.canvas) { + // 3) POINTER_DOWN this.emit(Events.POINTER_DOWN, pointer, currentlyOver); } else { + // 4) POINTER_DOWN_OUTSIDE this.emit(Events.POINTER_DOWN_OUTSIDE, pointer); } } @@ -1492,8 +1522,6 @@ var InputPlugin = new Class({ _eventData.cancelled = false; - var aborted = false; - // Go through all objects the pointer was over and fire their events / callbacks for (var i = 0; i < currentlyOver.length; i++) { @@ -1508,27 +1536,31 @@ var InputPlugin = new Class({ gameObject.emit(Events.GAMEOBJECT_POINTER_MOVE, pointer, gameObject.input.localX, gameObject.input.localY, _eventContainer); - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + if (_eventData.cancelled || !this.isActive()) { - aborted = true; + // They cancelled the whole event, it can't go any further break; } - this.emit(Events.GAMEOBJECT_MOVE, pointer, gameObject, _eventContainer); - - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + // Check that the game object wasn't input disabled or destroyed as a result of its input event + if (gameObject.input && gameObject.input.enabled) { - aborted = true; - break; - } + this.emit(Events.GAMEOBJECT_MOVE, pointer, gameObject, _eventContainer); - if (this.topOnly) - { - break; + if (_eventData.cancelled || !this.isActive()) + { + // They cancelled the whole event, it can't go any further + break; + } + + if (this.topOnly) + { + break; + } } } - if (!aborted) + if (!_eventData.cancelled && this.isActive()) { this.emit(Events.POINTER_MOVE, pointer, currentlyOver); } @@ -1560,8 +1592,6 @@ var InputPlugin = new Class({ _eventData.cancelled = false; - var aborted = false; - var dx = pointer.deltaX; var dy = pointer.deltaY; var dz = pointer.deltaZ; @@ -1580,22 +1610,26 @@ var InputPlugin = new Class({ gameObject.emit(Events.GAMEOBJECT_POINTER_WHEEL, pointer, dx, dy, dz, _eventContainer); - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + if (_eventData.cancelled || !this.isActive()) { - aborted = true; + // They cancelled the whole event, it can't go any further break; } - this.emit(Events.GAMEOBJECT_WHEEL, pointer, gameObject, dx, dy, dz, _eventContainer); - - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + // Check that the game object wasn't input disabled or destroyed as a result of its input event + if (gameObject.input && gameObject.input.enabled) { - aborted = true; - break; + this.emit(Events.GAMEOBJECT_WHEEL, pointer, gameObject, dx, dy, dz, _eventContainer); + + if (_eventData.cancelled || !this.isActive()) + { + // They cancelled the whole event, it can't go any further + break; + } } } - if (!aborted) + if (!_eventData.cancelled && this.isActive()) { this.emit(Events.POINTER_WHEEL, pointer, currentlyOver, dx, dy, dz); } @@ -1637,8 +1671,6 @@ var InputPlugin = new Class({ _eventData.cancelled = false; - var aborted = false; - for (var i = 0; i < total; i++) { var gameObject = currentlyOver[i]; @@ -1656,22 +1688,26 @@ var InputPlugin = new Class({ totalInteracted++; - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + if (_eventData.cancelled || !this.isActive()) { - aborted = true; + // They cancelled the whole event, it can't go any further break; } - this.emit(Events.GAMEOBJECT_OVER, pointer, gameObject, _eventContainer); - - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + // Check that the game object wasn't input disabled or destroyed as a result of its input event + if (gameObject.input && gameObject.input.enabled) { - aborted = true; - break; + this.emit(Events.GAMEOBJECT_OVER, pointer, gameObject, _eventContainer); + + if (_eventData.cancelled || !this.isActive()) + { + // They cancelled the whole event, it can't go any further + break; + } } } - if (!aborted) + if (!_eventData.cancelled && this.isActive()) { this.emit(Events.POINTER_OVER, pointer, justOver); } @@ -1715,8 +1751,6 @@ var InputPlugin = new Class({ _eventData.cancelled = false; - var aborted = false; - this.sortGameObjects(previouslyOver, pointer); for (var i = 0; i < total; i++) @@ -1737,26 +1771,29 @@ var InputPlugin = new Class({ totalInteracted++; - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + if (_eventData.cancelled || !this.isActive()) { - aborted = true; + // They cancelled the whole event, it can't go any further break; } - this.emit(Events.GAMEOBJECT_OUT, pointer, gameObject, _eventContainer); - - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + if (gameObject.input && gameObject.input.enabled) { - aborted = true; - break; - } + this.emit(Events.GAMEOBJECT_OUT, pointer, gameObject, _eventContainer); - if (!aborted) - { - this.emit(Events.POINTER_OUT, pointer, previouslyOver); + if (_eventData.cancelled || !this.isActive()) + { + // They cancelled the whole event, it can't go any further + break; + } } } + if (!_eventData.cancelled && this.isActive()) + { + this.emit(Events.POINTER_OUT, pointer, previouslyOver); + } + this._over[pointer.id] = []; } @@ -1839,8 +1876,6 @@ var InputPlugin = new Class({ _eventData.cancelled = false; - var aborted = false; - if (total > 0) { this.sortGameObjects(justOut, pointer); @@ -1862,22 +1897,26 @@ var InputPlugin = new Class({ totalInteracted++; - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + if (_eventData.cancelled || !this.isActive()) { - aborted = true; + // They cancelled the whole event, it can't go any further break; } - this.emit(Events.GAMEOBJECT_OUT, pointer, gameObject, _eventContainer); - - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + // Check that the game object wasn't input disabled or destroyed as a result of its input event + if (gameObject.input && gameObject.input.enabled) { - aborted = true; - break; + this.emit(Events.GAMEOBJECT_OUT, pointer, gameObject, _eventContainer); + + if (_eventData.cancelled || !this.isActive()) + { + // They cancelled the whole event, it can't go any further + break; + } } } - if (!aborted) + if (!_eventData.cancelled || this.isActive()) { this.emit(Events.POINTER_OUT, pointer, justOut); } @@ -1888,8 +1927,6 @@ var InputPlugin = new Class({ _eventData.cancelled = false; - aborted = false; - if (total > 0) { this.sortGameObjects(justOver, pointer); @@ -1911,22 +1948,26 @@ var InputPlugin = new Class({ totalInteracted++; - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + if (_eventData.cancelled || !this.isActive()) { - aborted = true; + // They cancelled the whole event, it can't go any further break; } - this.emit(Events.GAMEOBJECT_OVER, pointer, gameObject, _eventContainer); - - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + // Check that the game object wasn't input disabled or destroyed as a result of its input event + if (gameObject.input && gameObject.input.enabled) { - aborted = true; - break; + this.emit(Events.GAMEOBJECT_OVER, pointer, gameObject, _eventContainer); + + if (_eventData.cancelled || !this.isActive()) + { + // They cancelled the whole event, it can't go any further + break; + } } } - if (!aborted) + if (!_eventData.cancelled && this.isActive()) { this.emit(Events.POINTER_OVER, pointer, justOver); } @@ -1965,8 +2006,6 @@ var InputPlugin = new Class({ _eventData.cancelled = false; - var aborted = false; - // Go through all objects the pointer was over and fire their events / callbacks for (var i = 0; i < currentlyOver.length; i++) { @@ -1977,25 +2016,32 @@ var InputPlugin = new Class({ continue; } + // 1) GAMEOBJECT_POINTER_UP gameObject.emit(Events.GAMEOBJECT_POINTER_UP, pointer, gameObject.input.localX, gameObject.input.localY, _eventContainer); - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + if (_eventData.cancelled || !this.isActive()) { - aborted = true; + // They cancelled the whole event, it can't go any further break; } - this.emit(Events.GAMEOBJECT_UP, pointer, gameObject, _eventContainer); - - if (_eventData.cancelled || !gameObject.input || !gameObject.input.enabled) + // Check that the game object wasn't input disabled or destroyed as a result of its input event + if (gameObject.input && gameObject.input.enabled) { - aborted = true; - break; + // 2) GAMEOBJECT_UP + + this.emit(Events.GAMEOBJECT_UP, pointer, gameObject, _eventContainer); + + if (_eventData.cancelled || !this.isActive()) + { + // They cancelled the whole event, it can't go any further + break; + } } } // If they released outside the canvas, but pressed down inside it, we'll still dispatch the event. - if (!aborted && this.manager) + if (!_eventData.cancelled && this.isActive()) { if (pointer.upElement === this.manager.game.canvas) {