mirror of
https://github.com/photonstorm/phaser
synced 2024-11-21 20:23:19 +00:00
Multiple updates. See description.
The `InputPlugin.isActive` method will now check if the InputPlugin has the InputManager reference set, and if that is also enabled, as well as checking its own enabled state and that of the Scene. `InputPlugin.resetCursor` is a new method that will reset a custom CSS cursor from the main canvas, regardless of the interactive state of any Game Objects. The `InputPlugin.disable` method has a new optional boolean parameter `resetCursor` which will reset the CSS custom cursor if true. All of the core Input Plugin process methods have been rewritten. The methods that have changed are: * `InputPlugin.processMoveEvents` * `InputPlugin.processWheelEvent` * `InputPlugin.processOverEvents` * `InputPlugin.processOutEvents` * `InputPlugin.processOverOutEvents` * `InputPlugin.processUpEvents` * `InputPlugin.processDownEvents` And they all now do the following flow: 1) They will now iterate over the array of objects to be inspected. If the object doesn't have an input handler, or their handler has been disabled, they are skipped for event consideration. 2) If they have an input handler, the Game Object specific event is dispatched (i.e. `sprite.on('pointerdown')`) 3) The result of this call is checked. If the Event has been cancelled, or if the Input Plugin now returns `isActive() false` then it will break from the handler loop. This will only happen if the user explicitly tells the event to stop propogation, or if they disable either the Input Plugin, or the entire Input Manager, during the event handler. Previously, only the state of cancelled event was checked. Also previously, if the Game Objects own input handler was removed or disabled as a result of their event handler, it would break from the process loop. This no longer happens. It will carry on inspecting the remaining interactive objects in the loop, as long as the Input system itself wasn't disabled. 4) After this, the Game Object is checked to see if it is still input enabled. If it is, the Scene level events, like `this.input.on('gameobjectdown')` are emitted. 5) The results of this call are also checked. Again, if the Event has been cancelled, or if the Input Plugin now returns `isActive() false` then it will break from the handler loop, otherwise it carries on. 6) After the loop is complete it does one final check to see if the Event was cancelled, or if the Input Plugin is no longer active. If both of those pass, it emits the final event from the Input Plugin itself (i.e. `this.input.on('pointerdown')` from a Scene)
This commit is contained in:
parent
2a05c49d9e
commit
a5d465cb19
1 changed files with 137 additions and 91 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue