2017-07-20 16:10:12 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
|
|
|
|
// Drag Events
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API
|
2017-07-25 03:53:23 +00:00
|
|
|
// Mouse Events
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
|
2017-07-20 16:10:12 +00:00
|
|
|
|
|
|
|
var SceneInputManager = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-08-15 22:35:35 +00:00
|
|
|
function SceneInputManager (scene)
|
2017-07-20 16:10:12 +00:00
|
|
|
{
|
|
|
|
// The Scene that owns this plugin
|
|
|
|
this.scene = scene;
|
|
|
|
|
|
|
|
// GlobalInputManager
|
2017-08-15 22:35:35 +00:00
|
|
|
this.manager = scene.sys.game.input;
|
2017-07-20 16:10:12 +00:00
|
|
|
|
|
|
|
// A reference to this.scene.sys.displayList (set in boot)
|
|
|
|
this.displayList;
|
|
|
|
|
2017-07-29 00:55:17 +00:00
|
|
|
// A reference to the this.scene.sys.cameras (set in boot)
|
2017-07-20 16:10:12 +00:00
|
|
|
this.cameras;
|
|
|
|
|
2017-11-02 16:14:11 +00:00
|
|
|
// The Scene event dispatcher
|
|
|
|
this.events = scene.sys.events;
|
2017-07-20 16:10:12 +00:00
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
// Proxy references available via the Scene
|
|
|
|
this.keyboard = this.manager.keyboard;
|
|
|
|
this.mouse = this.manager.mouse;
|
2017-09-09 02:17:13 +00:00
|
|
|
this.gamepad = this.manager.gamepad;
|
2017-07-20 16:10:12 +00:00
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
// Only fire callbacks and events on the top-most Game Object in the display list (emulating DOM behavior)
|
|
|
|
// and ignore any GOs below it, or call them all?
|
2017-07-20 16:10:12 +00:00
|
|
|
this.topOnly = true;
|
|
|
|
|
|
|
|
// How often should the pointer input be checked?
|
|
|
|
// Time given in ms
|
|
|
|
// Pointer will *always* be checked if it has been moved by the user.
|
|
|
|
// This controls how often it will be polled if it hasn't been moved.
|
|
|
|
// Set to 0 to poll constantly. Set to -1 to only poll on user movement.
|
|
|
|
this.pollRate = -1;
|
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
// Internal counter
|
2017-07-20 16:10:12 +00:00
|
|
|
this._pollTimer = 0;
|
|
|
|
|
2017-07-27 02:40:58 +00:00
|
|
|
// The distance, in pixels, the pointer has to move while being held down, before it thinks it is being dragged.
|
|
|
|
this.dragDistanceThreshold = 0;
|
|
|
|
|
|
|
|
// The amount of time, in ms, the pointer has to be held down before it thinks it is dragging.
|
|
|
|
this.dragTimeThreshold = 0;
|
|
|
|
|
2017-07-25 01:47:26 +00:00
|
|
|
// Used to temporarily store the results of the Hit Test
|
|
|
|
this._temp = [];
|
|
|
|
|
2017-07-25 03:10:50 +00:00
|
|
|
// list: A list of all Game Objects that have been set to be interactive
|
|
|
|
this._list = [];
|
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
// pendingInsertion: Objects waiting to be inserted to the list on the next call to 'begin'
|
2017-07-25 03:10:50 +00:00
|
|
|
this._pendingInsertion = [];
|
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
// pendingRemoval: Objects waiting to be removed from the list on the next call to 'begin'
|
2017-07-25 03:10:50 +00:00
|
|
|
this._pendingRemoval = [];
|
|
|
|
|
2017-07-27 17:24:04 +00:00
|
|
|
// draggable: A list of all Game Objects that have been enabled for dragging
|
2017-07-27 02:40:58 +00:00
|
|
|
this._draggable = [];
|
|
|
|
|
|
|
|
// drag: A list of all Interactive Objects currently considered as being 'draggable' by any pointer, indexed by pointer ID
|
|
|
|
this._drag = { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [] };
|
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
// over: A list of all Interactive Objects currently considered as being 'over' by any pointer, indexed by pointer ID
|
2017-07-25 03:10:50 +00:00
|
|
|
this._over = { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [] };
|
2017-07-20 16:10:12 +00:00
|
|
|
|
2017-07-27 17:24:04 +00:00
|
|
|
this._validTypes = [ 'onDown', 'onUp', 'onOver', 'onOut', 'onMove', 'onDragStart', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragLeave', 'onDragOver', 'onDrop' ];
|
2017-07-20 16:10:12 +00:00
|
|
|
},
|
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
// Add option to get all IOs within a Rect or Circle
|
|
|
|
|
2017-09-13 13:17:38 +00:00
|
|
|
boot: require('./inc/Boot'),
|
|
|
|
begin: require('./inc/Begin'),
|
|
|
|
clear: require('./inc/Clear'),
|
|
|
|
update: require('./inc/Update'),
|
|
|
|
hitTestPointer: require('./inc/HitTestPointer'),
|
|
|
|
disable: require('./inc/Disable'),
|
|
|
|
enable: require('./inc/Enable'),
|
|
|
|
queueForInsertion: require('./inc/QueueForInsertion'),
|
|
|
|
queueForRemoval: require('./inc/QueueForRemoval'),
|
|
|
|
|
2017-10-08 21:38:32 +00:00
|
|
|
setPollRate: require('./inc/SetPollRate'),
|
|
|
|
setPollAlways: require('./inc/SetPollAlways'),
|
|
|
|
setPollOnMove: require('./inc/SetPollOnMove'),
|
2017-09-13 13:17:38 +00:00
|
|
|
|
2018-01-03 15:09:06 +00:00
|
|
|
setTopOnly: require('./inc/SetTopOnly'),
|
|
|
|
|
2017-09-13 13:17:38 +00:00
|
|
|
setHitArea: require('./inc/SetHitArea'),
|
|
|
|
setHitAreaCircle: require('./inc/SetHitAreaCircle'),
|
|
|
|
setHitAreaEllipse: require('./inc/SetHitAreaEllipse'),
|
|
|
|
setHitAreaFromTexture: require('./inc/SetHitAreaFromTexture'),
|
|
|
|
setHitAreaRectangle: require('./inc/SetHitAreaRectangle'),
|
|
|
|
setHitAreaTriangle: require('./inc/SetHitAreaTriangle'),
|
|
|
|
|
|
|
|
setDraggable: require('./inc/SetDraggable'),
|
|
|
|
|
|
|
|
setCallback: require('./inc/SetCallback'),
|
|
|
|
setCallbacks: require('./inc/SetCallbacks'),
|
|
|
|
setOnDownCallback: require('./inc/SetOnDownCallback'),
|
|
|
|
setOnOutCallback: require('./inc/SetOnOutCallback'),
|
|
|
|
setOnOverCallback: require('./inc/SetOnOverCallback'),
|
|
|
|
setOnUpCallback: require('./inc/SetOnUpCallback'),
|
|
|
|
setOnMoveCallback: require('./inc/SetOnMoveCallback'),
|
2017-09-29 10:40:11 +00:00
|
|
|
setOnDragStartCallback: require('./inc/SetOnDragStartCallback'),
|
|
|
|
setOnDragCallback: require('./inc/SetOnDragCallback'),
|
|
|
|
setOnDragEndCallback: require('./inc/SetOnDragEndCallback'),
|
2017-09-13 13:17:38 +00:00
|
|
|
|
|
|
|
processOverOutEvents: require('./inc/ProcessOverOutEvents'),
|
|
|
|
processDownEvents: require('./inc/ProcessDownEvents'),
|
|
|
|
processDragEvents: require('./inc/ProcessDragEvents'),
|
|
|
|
processUpEvents: require('./inc/ProcessUpEvents'),
|
|
|
|
processMoveEvents: require('./inc/ProcessMoveEvents'),
|
|
|
|
sortGameObjects: require('./inc/SortGameObjects'),
|
|
|
|
sortInteractiveObjects: require('./inc/SortInteractiveObjects'),
|
|
|
|
sortHandlerGO: require('./inc/SortHandlerGO'),
|
|
|
|
sortHandlerIO: require('./inc/SortHandlerIO'),
|
2017-07-20 16:10:12 +00:00
|
|
|
|
2017-11-28 11:15:35 +00:00
|
|
|
activePointer: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.manager.activePointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2017-09-07 21:26:53 +00:00
|
|
|
// The x/y coordinates of the ActivePointer based on the first camera in the camera list.
|
|
|
|
// This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch.
|
|
|
|
x: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.manager.activePointer.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
y: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.manager.activePointer.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2017-07-20 16:10:12 +00:00
|
|
|
// Scene that owns this is shutting down
|
|
|
|
shutdown: function ()
|
|
|
|
{
|
2017-07-25 03:10:50 +00:00
|
|
|
this._temp.length = 0;
|
|
|
|
this._list.length = 0;
|
2017-07-27 02:40:58 +00:00
|
|
|
this._draggable.length = 0;
|
2017-07-25 03:10:50 +00:00
|
|
|
this._pendingRemoval.length = 0;
|
|
|
|
this._pendingInsertion.length = 0;
|
2017-07-24 16:10:30 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < 10; i++)
|
|
|
|
{
|
2017-07-27 02:40:58 +00:00
|
|
|
this._drag[i] = [];
|
2017-07-25 03:10:50 +00:00
|
|
|
this._over[i] = [];
|
2017-07-24 16:10:30 +00:00
|
|
|
}
|
2017-07-20 16:10:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Game level nuke
|
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.shutdown();
|
|
|
|
|
|
|
|
this.scene = undefined;
|
|
|
|
this.cameras = undefined;
|
|
|
|
this.manager = undefined;
|
|
|
|
this.events = undefined;
|
|
|
|
this.keyboard = undefined;
|
|
|
|
this.mouse = undefined;
|
2017-09-09 02:17:13 +00:00
|
|
|
this.gamepad = undefined;
|
2017-07-20 16:10:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = SceneInputManager;
|