From c7623300f22b207b185a37960a8fc52b1d3fcdb0 Mon Sep 17 00:00:00 2001 From: _Bastler <_Bastler@bstly.de> Date: Sun, 16 May 2021 14:04:45 +0200 Subject: [PATCH] add input popup --- front/src/Api/Events/ButtonClickedEvent.ts | 2 + front/src/Api/Events/ClosePopupEvent.ts | 1 + front/src/Api/Events/OpenPopupEvent.ts | 3 +- front/src/Api/IframeListener.ts | 6 +- front/src/Phaser/Game/GameScene.ts | 16 ++- front/src/iframe_api.ts | 113 +++++++++++---------- 6 files changed, 81 insertions(+), 60 deletions(-) diff --git a/front/src/Api/Events/ButtonClickedEvent.ts b/front/src/Api/Events/ButtonClickedEvent.ts index de807037..1343aa0a 100644 --- a/front/src/Api/Events/ButtonClickedEvent.ts +++ b/front/src/Api/Events/ButtonClickedEvent.ts @@ -4,6 +4,8 @@ export const isButtonClickedEvent = new tg.IsInterface().withProperties({ popupId: tg.isNumber, buttonId: tg.isNumber, + input : tg.isBoolean, + inputValue : tg.isString, }).get(); /** * A message sent from the game to the iFrame when a user enters or leaves a zone marked with the "zone" property. diff --git a/front/src/Api/Events/ClosePopupEvent.ts b/front/src/Api/Events/ClosePopupEvent.ts index 83b09c96..db64474b 100644 --- a/front/src/Api/Events/ClosePopupEvent.ts +++ b/front/src/Api/Events/ClosePopupEvent.ts @@ -3,6 +3,7 @@ import * as tg from "generic-type-guard"; export const isClosePopupEvent = new tg.IsInterface().withProperties({ popupId: tg.isNumber, + inputValue : tg.isString, }).get(); /** diff --git a/front/src/Api/Events/OpenPopupEvent.ts b/front/src/Api/Events/OpenPopupEvent.ts index 094ba555..0abcd667 100644 --- a/front/src/Api/Events/OpenPopupEvent.ts +++ b/front/src/Api/Events/OpenPopupEvent.ts @@ -11,7 +11,8 @@ export const isOpenPopupEvent = popupId: tg.isNumber, targetObject: tg.isString, message: tg.isString, - buttons: tg.isArray(isButtonDescriptor) + buttons: tg.isArray(isButtonDescriptor), + input: tg.isBoolean }).get(); /** diff --git a/front/src/Api/IframeListener.ts b/front/src/Api/IframeListener.ts index bed65f2f..19d030b6 100644 --- a/front/src/Api/IframeListener.ts +++ b/front/src/Api/IframeListener.ts @@ -222,12 +222,14 @@ class IframeListener { }); } - sendButtonClickedEvent(popupId: number, buttonId: number): void { + sendButtonClickedEvent(popupId: number, buttonId: number, input : boolean, inputValue : string | null): void { this.postMessage({ 'type': 'buttonClickedEvent', 'data': { popupId, - buttonId + buttonId, + input, + inputValue, } as ButtonClickedEvent }); } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 27ad414c..bcf997a4 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -794,9 +794,12 @@ export class GameScene extends ResizableScene implements CenterListener { return; } const escapedMessage = HtmlUtils.escapeHtml(openPopupEvent.message); - let html = `