From 1cc79a3b239729397480472b34b485bdf6a435d9 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Fri, 21 Jul 2017 13:59:22 +0100 Subject: [PATCH] Added onMove callback and event. Added processMove handler. --- v3/src/checksum.js | 2 +- v3/src/input/InteractiveObject.js | 8 +-- v3/src/input/local/SceneInputManager.js | 3 +- .../local/components/ProcessMoveEvents.js | 54 +++++++++++++++++++ .../local/components/ProcessOverOutEvents.js | 2 +- v3/src/input/local/components/SetCallbacks.js | 16 +++++- .../local/components/SetOnMoveCallback.js | 6 +++ v3/src/input/local/components/Update.js | 8 +-- v3/src/input/local/events/PointerMoveEvent.js | 28 ++++++++++ v3/src/input/local/events/index.js | 1 + v3/src/plugins/InputManager.js | 47 ++++------------ 11 files changed, 127 insertions(+), 48 deletions(-) create mode 100644 v3/src/input/local/components/ProcessMoveEvents.js create mode 100644 v3/src/input/local/components/SetOnMoveCallback.js create mode 100644 v3/src/input/local/events/PointerMoveEvent.js diff --git a/v3/src/checksum.js b/v3/src/checksum.js index 7c74f87e1..420762e95 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '2ba7f500-6dc2-11e7-a19b-db1919761fe1' +build: '5f8d0c50-6e14-11e7-a21a-f9e8835d9646' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/input/InteractiveObject.js b/v3/src/input/InteractiveObject.js index 3dc5effbd..31675c905 100644 --- a/v3/src/input/InteractiveObject.js +++ b/v3/src/input/InteractiveObject.js @@ -22,14 +22,14 @@ var InteractiveObject = function (gameObject, hitArea, hitAreaCallback) callbackContext: gameObject, + dragX: 0, + dragY: 0, + + onMove: NOOP, onDown: NOOP, onUp: NOOP, onOver: NOOP, onOut: NOOP, - - dragX: 0, - dragY: 0, - onDragStart: NOOP, onDrag: NOOP, onDragEnd: NOOP diff --git a/v3/src/input/local/SceneInputManager.js b/v3/src/input/local/SceneInputManager.js index 5ae865f46..d9fcb0b6c 100644 --- a/v3/src/input/local/SceneInputManager.js +++ b/v3/src/input/local/SceneInputManager.js @@ -59,7 +59,7 @@ var SceneInputManager = new Class({ down: { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [] } }; - this._validTypes = [ 'onDown', 'onUp', 'onOver', 'onOut' ]; + this._validTypes = [ 'onDown', 'onUp', 'onOver', 'onOut', 'onMove' ]; }, // Add option to get all IOs within a Rect or Circle @@ -90,6 +90,7 @@ var SceneInputManager = new Class({ setOnOutCallback: require('./components/SetOnOutCallback'), setOnOverCallback: require('./components/SetOnOverCallback'), setOnUpCallback: require('./components/SetOnUpCallback'), + setOnMoveCallback: require('./components/SetOnMoveCallback'), processOverOutEvents: require('./components/ProcessOverOutEvents'), processDownEvents: require('./components/ProcessDownEvents'), diff --git a/v3/src/input/local/components/ProcessMoveEvents.js b/v3/src/input/local/components/ProcessMoveEvents.js new file mode 100644 index 000000000..61bb6aca1 --- /dev/null +++ b/v3/src/input/local/components/ProcessMoveEvents.js @@ -0,0 +1,54 @@ +var InputEvent = require('../events'); + +var ProcessMoveEvents = function (pointer, currentlyOver) +{ + if (currentlyOver.length === 0) + { + // Dispatch MOVE event, even though pointer isn't over anything + this.events.dispatch(new InputEvent.MOVE(pointer)); + } + else + { + // Go through all objects the pointer is over and dispatch them + for (var i = 0; i < currentlyOver.length; i++) + { + var interactiveObject = currentlyOver[i]; + + this.events.dispatch(new InputEvent.MOVE(pointer, interactiveObject.gameObject, currentlyOver)); + + this.childOnMove(pointer, interactiveObject); + + if (this.topOnly) + { + break; + } + } + } + + // Check the list of Draggable Items + /* + for (var i = 0; i < this.children.draggable.length; i++) + { + var interactiveObject = this.children.draggable[i]; + + if (!interactiveObject.enabled) + { + continue; + } + + if (pointer.justUp && interactiveObject.isDragged) + { + // Drag End + this.childOnDragEnd(i, pointer, interactiveObject); + } + else if (interactiveObject.isDragged) + { + // Drag + this.childOnDrag(i, pointer, interactiveObject); + } + } + */ + +}; + +module.exports = ProcessMoveEvents; diff --git a/v3/src/input/local/components/ProcessOverOutEvents.js b/v3/src/input/local/components/ProcessOverOutEvents.js index 7f245d3ed..bc5422be1 100644 --- a/v3/src/input/local/components/ProcessOverOutEvents.js +++ b/v3/src/input/local/components/ProcessOverOutEvents.js @@ -25,7 +25,7 @@ var ProcessOverOutEvents = function (pointer, currentlyOver) // In the currentlyOver array stillOver.push(interactiveObject); } - }; + } // Go through the hit test results for (i = 0; i < currentlyOver.length; i++) diff --git a/v3/src/input/local/components/SetCallbacks.js b/v3/src/input/local/components/SetCallbacks.js index cb95e6920..a213a31fc 100644 --- a/v3/src/input/local/components/SetCallbacks.js +++ b/v3/src/input/local/components/SetCallbacks.js @@ -1,5 +1,14 @@ -var SetCallbacks = function (gameObjects, onDown, onUp, onOver, onOut, context) +var GetFastValue = require('../../../utils/object/GetFastValue'); + +var SetCallbacks = function (gameObjects, config) { + var onDown = GetFastValue(config, 'onDown', null); + var onUp = GetFastValue(config, 'onUp', null); + var onOver = GetFastValue(config, 'onOver', null); + var onOut = GetFastValue(config, 'onOut', null); + var onMove = GetFastValue(config, 'onMove', null); + var context = GetFastValue(config, 'context', null); + if (onDown) { this.setOnDownCallback(gameObjects, onDown, context); @@ -20,6 +29,11 @@ var SetCallbacks = function (gameObjects, onDown, onUp, onOver, onOut, context) this.setOnDownCallback(gameObjects, onOut, context); } + if (onMove) + { + this.setOnMoveCallback(gameObjects, onMove, context); + } + return this; }; diff --git a/v3/src/input/local/components/SetOnMoveCallback.js b/v3/src/input/local/components/SetOnMoveCallback.js new file mode 100644 index 000000000..4684ec246 --- /dev/null +++ b/v3/src/input/local/components/SetOnMoveCallback.js @@ -0,0 +1,6 @@ +var SetOnMoveCallback = function (gameObjects, callback, context) +{ + return this.setCallback(gameObjects, 'onMove', callback, context); +}; + +module.exports = SetOnMoveCallback; diff --git a/v3/src/input/local/components/Update.js b/v3/src/input/local/components/Update.js index 1e6f52b14..1d49e1a3d 100644 --- a/v3/src/input/local/components/Update.js +++ b/v3/src/input/local/components/Update.js @@ -56,10 +56,10 @@ var Update = function (time, delta) this.processDownEvents(pointer, results); } - // if (pointer.justMoved) - // { - // this.processMovementEvents(pointer, results); - // } + if (pointer.justMoved) + { + this.processMoveEvents(pointer, results); + } } }; diff --git a/v3/src/input/local/events/PointerMoveEvent.js b/v3/src/input/local/events/PointerMoveEvent.js new file mode 100644 index 000000000..4fda770a0 --- /dev/null +++ b/v3/src/input/local/events/PointerMoveEvent.js @@ -0,0 +1,28 @@ +var Class = require('../../../utils/Class'); +var Event = require('../../../events/Event'); + +var PointerMoveEvent = new Class({ + + Extends: Event, + + initialize: + + function PointerMoveEvent (pointer, topObject, gameObjects) + { + Event.call(this, 'POINTER_MOVE_EVENT'); + + this.pointer = pointer; + + this.x = pointer.x; + this.y = pointer.y; + + // An array of all the game objects the pointer event occurred on + this.list = gameObjects; + + // A reference to the top-most game object in the list (based on display list order) + this.gameObject = topObject; + } + +}); + +module.exports = PointerMoveEvent; diff --git a/v3/src/input/local/events/index.js b/v3/src/input/local/events/index.js index ed0af1fe9..1f14893b1 100644 --- a/v3/src/input/local/events/index.js +++ b/v3/src/input/local/events/index.js @@ -6,6 +6,7 @@ module.exports = { DRAG: require('./DragEvent'), DRAG_END: require('./DragEndEvent'), DRAG_START: require('./DragStartEvent'), + MOVE: require('./PointerMoveEvent'), OUT: require('./PointerOutEvent'), OVER: require('./PointerOverEvent'), UP: require('./PointerUpEvent') diff --git a/v3/src/plugins/InputManager.js b/v3/src/plugins/InputManager.js index 1ccaf1cb6..3038c8b42 100644 --- a/v3/src/plugins/InputManager.js +++ b/v3/src/plugins/InputManager.js @@ -13,56 +13,32 @@ var InputManager = new Class({ SceneInputManager.call(this, scene, game); }, + childOnMove: function (pointer, interactiveObject) + { + interactiveObject.onMove(interactiveObject.gameObject, pointer); + } + /* - // Has the pointer moved in this update? - processMovementEvents: function (pointer) + childOnDragStart: function (index, pointer, interactiveObject) { - // Check the list of Draggable Items - for (var i = 0; i < this._draggable.length; i++) - { - var gameObject = this._draggable[i]; - var input = gameObject.input; + interactiveObject.isDragged = true; - if (!input.enabled) - { - continue; - } - - if (pointer.justUp && input.isDragged) - { - // Drag End - this.gameObjectOnDragEnd(pointer, gameObject); - } - else if (input.isDragged) - { - // Drag - this.gameObjectOnDrag(pointer, gameObject); - } - } - }, - - gameObjectOnDragStart: function (pointer, gameObject) - { - var input = gameObject.input; - - input.isDragged = true; - - input.dragX = input.localX - gameObject.displayOriginX; - input.dragY = input.localY - gameObject.displayOriginY; + interactiveObject.dragX = interactiveObject.localX - interactiveObject.gameObject.displayOriginX; + interactiveObject.dragY = interactiveObject.localY - interactiveObject.gameObject.displayOriginY; this.events.dispatch(new InputEvent.DRAG_START(pointer, gameObject)); gameObject.input.onDragStart(gameObject, pointer); }, - gameObjectOnDrag: function (pointer, gameObject) + childOnDrag: function (index, pointer, interactiveObject) { this.events.dispatch(new InputEvent.DRAG(pointer, gameObject)); gameObject.input.onDrag(gameObject, pointer); }, - gameObjectOnDragEnd: function (pointer, gameObject) + childOnDragEnd: function (index, pointer, interactiveObject) { var input = gameObject.input; @@ -73,7 +49,6 @@ var InputManager = new Class({ gameObject.input.onDragEnd(gameObject, pointer); }, */ - }); module.exports = InputManager;