From a7b0ad2f21b84ff929a60510729f7cda5a08da24 Mon Sep 17 00:00:00 2001 From: Greenlamp Date: Mon, 6 May 2024 00:37:37 +0200 Subject: [PATCH] in fact, checking the if the focus is lost is a better solution --- src/inputs-controller.ts | 14 ++++++++------ src/ui/menu-ui-handler.ts | 5 ----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/inputs-controller.ts b/src/inputs-controller.ts index 9196d5050c2..83182629d05 100644 --- a/src/inputs-controller.ts +++ b/src/inputs-controller.ts @@ -34,7 +34,6 @@ export class InputsController { private interactions: Map> = new Map(); private time: Time; private player: Map = new Map(); - public modalOpen: boolean = false; constructor(scene: Phaser.Scene) { this.scene = scene; @@ -55,6 +54,10 @@ export class InputsController { init(): void { this.events = new Phaser.Events.EventEmitter(); + // Handle the game losing focus + this.scene.game.events.on(Phaser.Core.Events.BLUR, () => { + this.loseFocus() + }) if (typeof this.scene.input.gamepad !== 'undefined') { this.scene.input.gamepad.on('connected', function (thisGamepad) { @@ -79,12 +82,11 @@ export class InputsController { this.setupKeyboardControls(); } + loseFocus(): void { + this.deactivatePressedKey(); + } + update(): void { - if (this.modalOpen) { - this.modalOpen = false; - this.deactivatePressedKey(); - return; - } for (const b of Utils.getEnumValues(Button)) { if (!this.interactions.hasOwnProperty(b)) continue; if (this.repeatInputDurationJustPassed(b) && this.interactions[b].isPressed) { diff --git a/src/ui/menu-ui-handler.ts b/src/ui/menu-ui-handler.ts index 1c9c098b19c..bf032667610 100644 --- a/src/ui/menu-ui-handler.ts +++ b/src/ui/menu-ui-handler.ts @@ -125,7 +125,6 @@ export default class MenuUiHandler extends MessageUiHandler { manageDataOptions.push({ label: i18next.t("menuUiHandler:importSession"), handler: () => { - this.scene.inputController.modalOpen = true; confirmSlot(i18next.t("menuUiHandler:importSlotSelect"), () => true, slotId => this.scene.gameData.importData(GameDataType.SESSION, slotId)); return true; }, @@ -156,7 +155,6 @@ export default class MenuUiHandler extends MessageUiHandler { manageDataOptions.push({ label: i18next.t("menuUiHandler:importData"), handler: () => { - this.scene.inputController.modalOpen = true; this.scene.gameData.importData(GameDataType.SYSTEM); return true; }, @@ -190,7 +188,6 @@ export default class MenuUiHandler extends MessageUiHandler { { label: 'Wiki', handler: () => { - this.scene.inputController.modalOpen = true; window.open(wikiUrl, '_blank').focus(); return true; }, @@ -199,7 +196,6 @@ export default class MenuUiHandler extends MessageUiHandler { { label: 'Discord', handler: () => { - this.scene.inputController.modalOpen = true; window.open(discordUrl, '_blank').focus(); return true; }, @@ -208,7 +204,6 @@ export default class MenuUiHandler extends MessageUiHandler { { label: 'GitHub', handler: () => { - this.scene.inputController.modalOpen = true; window.open(githubUrl, '_blank').focus(); return true; },