Improving popup

If a popup message is empty, only the buttons will be displayed (not the container)

Unrelated: the Sound.play method in the API now accepts 0 arguments.
This commit is contained in:
David Négrier 2021-08-18 11:53:41 +02:00
parent 06be65c12f
commit 8a64491952
2 changed files with 24 additions and 19 deletions

View file

@ -1,38 +1,35 @@
import {sendToWorkadventure} from "../IframeApiContribution"; import { sendToWorkadventure } from "../IframeApiContribution";
import type {LoadSoundEvent} from "../../Events/LoadSoundEvent"; import type { LoadSoundEvent } from "../../Events/LoadSoundEvent";
import type {PlaySoundEvent} from "../../Events/PlaySoundEvent"; import type { PlaySoundEvent } from "../../Events/PlaySoundEvent";
import type {StopSoundEvent} from "../../Events/StopSoundEvent"; import type { StopSoundEvent } from "../../Events/StopSoundEvent";
import SoundConfig = Phaser.Types.Sound.SoundConfig; import SoundConfig = Phaser.Types.Sound.SoundConfig;
export class Sound { export class Sound {
constructor(private url: string) { constructor(private url: string) {
sendToWorkadventure({ sendToWorkadventure({
"type": 'loadSound', type: "loadSound",
"data": { data: {
url: this.url, url: this.url,
} as LoadSoundEvent } as LoadSoundEvent,
}); });
} }
public play(config: SoundConfig) { public play(config: SoundConfig | undefined) {
sendToWorkadventure({ sendToWorkadventure({
"type": 'playSound', type: "playSound",
"data": { data: {
url: this.url, url: this.url,
config config,
} as PlaySoundEvent } as PlaySoundEvent,
}); });
return this.url; return this.url;
} }
public stop() { public stop() {
sendToWorkadventure({ sendToWorkadventure({
"type": 'stopSound', type: "stopSound",
"data": { data: {
url: this.url, url: this.url,
} as StopSoundEvent } as StopSoundEvent,
}); });
return this.url; return this.url;
} }

View file

@ -953,9 +953,13 @@ export class GameScene extends DirtyScene {
return; return;
} }
const escapedMessage = HtmlUtils.escapeHtml(openPopupEvent.message); const escapedMessage = HtmlUtils.escapeHtml(openPopupEvent.message);
let html = `<div id="container" hidden><div class="nes-container with-title is-centered"> let html = '<div id="container" hidden>';
if (escapedMessage) {
html += `<div class="nes-container with-title is-centered">
${escapedMessage} ${escapedMessage}
</div> `; </div> `;
}
const buttonContainer = '<div class="buttonContainer"</div>'; const buttonContainer = '<div class="buttonContainer"</div>';
html += buttonContainer; html += buttonContainer;
let id = 0; let id = 0;
@ -985,7 +989,11 @@ ${escapedMessage}
const btnId = id; const btnId = id;
button.onclick = () => { button.onclick = () => {
iframeListener.sendButtonClickedEvent(openPopupEvent.popupId, btnId); iframeListener.sendButtonClickedEvent(openPopupEvent.popupId, btnId);
// Disable for a short amount of time to let time to the script to remove the popup
button.disabled = true; button.disabled = true;
setTimeout(() => {
button.disabled = false;
}, 100);
}; };
id++; id++;
} }