From c96c6a357cea7f26d69c92b01d5986e0bb790921 Mon Sep 17 00:00:00 2001 From: Alexis Faizeau Date: Fri, 6 May 2022 15:29:20 +0200 Subject: [PATCH] Add joystick & click to move on disable controls --- front/src/Phaser/UserInput/GameSceneUserInputHandler.ts | 5 +++++ front/src/Phaser/UserInput/UserInputManager.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/front/src/Phaser/UserInput/GameSceneUserInputHandler.ts b/front/src/Phaser/UserInput/GameSceneUserInputHandler.ts index babd4f2d..7b8ce348 100644 --- a/front/src/Phaser/UserInput/GameSceneUserInputHandler.ts +++ b/front/src/Phaser/UserInput/GameSceneUserInputHandler.ts @@ -25,6 +25,11 @@ export class GameSceneUserInputHandler implements UserInputHandlerInterface { if ((!pointer.wasTouch && pointer.leftButtonReleased()) || pointer.getDuration() > 250) { return; } + + if (!this.gameScene.userInputManager.isControlsEnable()) { + return; + } + for (const object of gameObjects) { if (object instanceof Player || object instanceof RemotePlayer) { return; diff --git a/front/src/Phaser/UserInput/UserInputManager.ts b/front/src/Phaser/UserInput/UserInputManager.ts index b454de56..98e87bf3 100644 --- a/front/src/Phaser/UserInput/UserInputManager.ts +++ b/front/src/Phaser/UserInput/UserInputManager.ts @@ -176,7 +176,6 @@ export class UserInputManager { this.scene.input.keyboard.removeAllListeners(); } - //todo: should we also disable the joystick? disableControls() { this.scene.input.keyboard.removeAllKeys(); this.isInputDisabled = true; @@ -186,6 +185,11 @@ export class UserInputManager { this.initKeyBoardEvent(); this.isInputDisabled = false; } + + isControlsEnable() { + return !this.isInputDisabled; + } + getEventListForGameTick(): ActiveEventList { const eventsMap = new ActiveEventList(); if (this.isInputDisabled) { @@ -266,7 +270,7 @@ export class UserInputManager { this.scene.input.on( Phaser.Input.Events.POINTER_DOWN, (pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]) => { - if (!pointer.wasTouch) { + if (!pointer.wasTouch || this.isInputDisabled) { return; } this.userInputHandler.handlePointerDownEvent(pointer, gameObjects);