2020-02-14 00:12:24 +01:00
|
|
|
import GraphicSet from "../../../js/GraphicSet.js";
|
|
|
|
import Setting from "../../../js/Setting.js";
|
|
|
|
import TilorswiftTilesetSelectedEvent from "../events/TilorswiftTilesetSelectedEvent.js";
|
|
|
|
|
2020-02-09 00:23:58 +01:00
|
|
|
export default class Dialog
|
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
this.htmlElement = document.createElement('div');
|
|
|
|
this.htmlElement.classList.add('dialog');
|
|
|
|
this.boxElement = document.createElement('div');
|
|
|
|
this.boxElement.classList.add('dialog-box');
|
|
|
|
this.htmlElement.appendChild(this.boxElement);
|
|
|
|
this.messageElement = document.createElement('div');
|
|
|
|
this.messageElement.classList.add('dialog-message');
|
|
|
|
this.boxElement.appendChild(this.messageElement);
|
|
|
|
this.inputAreaElement = document.createElement('div');
|
|
|
|
this.inputAreaElement.classList.add('dialog-input-area');
|
|
|
|
this.boxElement.appendChild(this.inputAreaElement);
|
|
|
|
this.buttonAreaElement = document.createElement('div');
|
|
|
|
this.buttonAreaElement.classList.add('dialog-button-area');
|
|
|
|
this.boxElement.appendChild(this.buttonAreaElement);
|
|
|
|
|
|
|
|
document.body.appendChild(this.htmlElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
createButton(text)
|
|
|
|
{
|
|
|
|
let button = document.createElement('span');
|
|
|
|
button.classList.add('dialog-button');
|
|
|
|
button.innerText = text;
|
|
|
|
this.buttonAreaElement.appendChild(button);
|
|
|
|
|
|
|
|
button.addEventListener(
|
|
|
|
'click',
|
|
|
|
() => {
|
|
|
|
this.htmlElement.remove();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2020-02-16 00:53:03 +01:00
|
|
|
createInputNumber(label, value = 0, min = 0, max = 999999, step = 1)
|
2020-02-09 00:23:58 +01:00
|
|
|
{
|
|
|
|
let htmlElement = document.createElement('div');
|
|
|
|
htmlElement.classList.add('dialog-input-area');
|
|
|
|
|
|
|
|
let htmlElementLabel = document.createElement('div');
|
|
|
|
htmlElementLabel.classList.add('dialog-label');
|
|
|
|
htmlElementLabel.innerText = label;
|
|
|
|
|
|
|
|
let htmlElementInput = document.createElement('input');
|
|
|
|
htmlElementInput.classList.add('dialog-input');
|
|
|
|
htmlElementInput.type = 'number';
|
|
|
|
htmlElementInput.value = value;
|
2020-02-16 00:53:03 +01:00
|
|
|
htmlElementInput.max = max;
|
|
|
|
htmlElementInput.min = min;
|
|
|
|
htmlElementInput.step = step;
|
2020-02-09 00:23:58 +01:00
|
|
|
|
|
|
|
htmlElement.appendChild(htmlElementLabel);
|
|
|
|
htmlElement.appendChild(htmlElementInput);
|
|
|
|
|
|
|
|
this.inputAreaElement.appendChild(htmlElement);
|
|
|
|
|
|
|
|
return htmlElementInput;
|
|
|
|
}
|
|
|
|
|
2020-02-14 00:12:24 +01:00
|
|
|
createTilesetSelector()
|
|
|
|
{
|
|
|
|
let htmlElement = document.createElement('div');
|
|
|
|
htmlElement.id = 'tileset-selector';
|
|
|
|
|
|
|
|
let htmlElementLabel = document.createElement('div');
|
|
|
|
htmlElementLabel.classList.add('dialog-label');
|
|
|
|
htmlElementLabel.innerText = 'Terrain';
|
|
|
|
|
|
|
|
let htmlAvatarElement = document.createElement('div');
|
|
|
|
htmlAvatarElement.id = 'tileset-avatar';
|
2021-09-14 20:11:01 +02:00
|
|
|
htmlAvatarElement.style.backgroundImage = 'url("../' + Setting.TILESET_LOCATION + GraphicSet[0].tileset + '")';
|
2020-02-14 00:12:24 +01:00
|
|
|
|
|
|
|
let htmlListElement = document.createElement('div');
|
|
|
|
htmlListElement.id = 'tileset-list';
|
|
|
|
|
|
|
|
htmlElement.appendChild(htmlElementLabel);
|
|
|
|
htmlElement.appendChild(htmlAvatarElement);
|
|
|
|
htmlElement.appendChild(htmlListElement);
|
|
|
|
|
|
|
|
htmlAvatarElement.addEventListener(
|
|
|
|
'click',
|
|
|
|
() => {
|
|
|
|
htmlListElement.style.display = 'block';
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
GraphicSet.forEach(
|
|
|
|
(graphicSet, index) => {
|
|
|
|
let htmlTilesetElement = document.createElement('div');
|
|
|
|
htmlTilesetElement.classList.add('tileset');
|
|
|
|
|
|
|
|
let htmlThumbnail = document.createElement('div');
|
|
|
|
htmlThumbnail.classList.add('tileset-thumbnail');
|
2021-09-14 20:11:01 +02:00
|
|
|
htmlThumbnail.style.backgroundImage = 'url("../' + Setting.TILESET_LOCATION + graphicSet.tileset + '")';
|
2020-02-14 00:12:24 +01:00
|
|
|
htmlTilesetElement.appendChild(htmlThumbnail);
|
|
|
|
|
|
|
|
let htmlTitleElement = document.createElement('div');
|
|
|
|
htmlTitleElement.classList.add('tileset-title');
|
|
|
|
htmlTitleElement.innerText = graphicSet.name;
|
|
|
|
htmlTilesetElement.appendChild(htmlTitleElement);
|
|
|
|
|
|
|
|
htmlTilesetElement.addEventListener(
|
|
|
|
'click',
|
|
|
|
() => {
|
|
|
|
htmlListElement.style.display = 'none';
|
2021-09-14 20:11:01 +02:00
|
|
|
htmlAvatarElement.style.backgroundImage = 'url("../' + Setting.TILESET_LOCATION + GraphicSet[index].tileset + '")';
|
2020-02-14 00:12:24 +01:00
|
|
|
window.dispatchEvent(new TilorswiftTilesetSelectedEvent(index));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
htmlListElement.appendChild(htmlTilesetElement);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.inputAreaElement.appendChild(htmlElement);
|
|
|
|
|
|
|
|
return htmlElement;
|
|
|
|
}
|
|
|
|
|
2023-09-17 14:18:21 +02:00
|
|
|
createFileInput(types = [])
|
|
|
|
{
|
|
|
|
let input = document.createElement('input');
|
|
|
|
input.type = 'file';
|
|
|
|
|
|
|
|
if (types.length > 0) {
|
|
|
|
for (const t in types) {
|
|
|
|
types[t] = '.' + types[t]
|
|
|
|
}
|
|
|
|
|
|
|
|
input.accept = types.join(', ');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.inputAreaElement.appendChild(input);
|
|
|
|
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
2020-02-09 00:23:58 +01:00
|
|
|
setMessage(message)
|
|
|
|
{
|
|
|
|
this.messageElement.innerText = message;
|
|
|
|
}
|
2023-09-17 14:18:21 +02:00
|
|
|
|
|
|
|
close()
|
|
|
|
{
|
|
|
|
this.htmlElement.remove();
|
|
|
|
}
|
2021-09-14 20:11:01 +02:00
|
|
|
}
|