in fact, checking the if the focus is lost is a better solution

This commit is contained in:
Greenlamp 2024-05-06 00:37:37 +02:00
parent 30826c2101
commit a7b0ad2f21
2 changed files with 8 additions and 11 deletions

View File

@ -34,7 +34,6 @@ export class InputsController {
private interactions: Map<Button, Map<string, boolean>> = new Map();
private time: Time;
private player: Map<String, GamepadMapping> = 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) {

View File

@ -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;
},