can manage position and width/height of a popUp using a square in Tiled

This commit is contained in:
DESKTOP-FMM8UI0\CLV 2021-03-10 09:23:45 +01:00
parent 5e4940dba6
commit 8d0411e8a3
2 changed files with 11 additions and 8 deletions

View File

@ -391,7 +391,6 @@ export class GameScene extends ResizableScene implements CenterListener {
this.popUpWidth = Math.floor(object.width); this.popUpWidth = Math.floor(object.width);
this.popUpHeight = Math.floor(object.height); this.popUpHeight = Math.floor(object.height);
} }
} }
} }
} }
@ -757,17 +756,21 @@ export class GameScene extends ResizableScene implements CenterListener {
private listenToIframeEvents(): void { private listenToIframeEvents(): void {
iframeListener.openPopupStream.subscribe((openPopupEvent) => { iframeListener.openPopupStream.subscribe((openPopupEvent) => {
const escapedMessage = HtmlUtils.escapeHtml(openPopupEvent.message); const escapedMessage = HtmlUtils.escapeHtml(openPopupEvent.message);
let html = ` <div class="nes-container with-title is-centered" let html = `<div id="container" <div class="nes-container with-title is-centered"
> >
${escapedMessage} ${escapedMessage}
</div> `; </div> </div>`;
let id = 0; let id = 0;
for (const button of openPopupEvent.buttons) { for (const button of openPopupEvent.buttons) {
html += `<button type="button" class="nes-btn is-${HtmlUtils.escapeHtml(button.className ?? '')}" id="popup-${openPopupEvent.popupId}-${id}">${HtmlUtils.escapeHtml(button.label)}</button>`; html += `<button type="button" class="nes-btn is-${HtmlUtils.escapeHtml(button.className ?? '')}" id="popup-${openPopupEvent.popupId}-${id}">${HtmlUtils.escapeHtml(button.label)}</button>`;
id++; id++;
} }
const domElement = this.add.dom(this.popUpX, this.popUpY,).createFromHTML(html); const domElement = this.add.dom(this.popUpX + this.popUpWidth/2 ,
this.popUpY + this.popUpHeight/2).createFromHTML(html);
let container : HTMLDivElement = domElement.getChildByID("container") as HTMLDivElement;
container.style.width = this.popUpWidth + "px";
container.style.height = this.popUpHeight + "px";
domElement.scale = 0; domElement.scale = 0;
domElement.setClassName('popUpElement'); domElement.setClassName('popUpElement');

View File

@ -75,15 +75,15 @@
"name":"floorLayer", "name":"floorLayer",
"objects":[ "objects":[
{ {
"height":195.65688359926, "height":162.662798398032,
"id":1, "id":1,
"name":"myPopup", "name":"myPopup",
"rotation":0, "rotation":0,
"type":"", "type":"",
"visible":true, "visible":true,
"width":315.393884378036, "width":16.3413326605909,
"x":-0.29745661104063, "x":275.392367109435,
"y":-0.433231160918936 "y":141.649957637921
}], }],
"opacity":1, "opacity":1,
"type":"objectgroup", "type":"objectgroup",