4 * Copyright 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 dragonblocks.registeredSkins = {};
26 dragonblocks.registerSkin = def => {
27 if (! def || ! def.name || ! def.texture)
28 dragonblocks.error("Cannot register skin");
30 dragonblocks.registeredSkins[def.name] = def;
34 let gui = new dragonblocks.gui.Box({keylock: true});
36 let headline = gui.create("h1");
37 headline.innerHTML = "Skins";
38 headline.align = "center";
40 let status = gui.create("span");
41 status.style.position = "absolute";
42 status.style.top = "5px";
43 status.style.left = "5px";
45 let columns = parseInt(parseInt(gui.display.style.width) / (dragonblocks.settings.mapDisplay.scale * 1.5));
47 let container = gui.create("div");
48 container.style.width = parseInt(columns * dragonblocks.settings.mapDisplay.scale * 1.5) + "px";
49 container.style.position = "absolute";
50 container.style.top = "80px";
51 dblib.center(container);
53 dragonblocks.registerOnStarted(_ => {
54 status.innerHTML = dragonblocks.player.skin;
58 for (let skin in dragonblocks.registeredSkins) {
60 let y = (i - x) / columns;
64 let def = dragonblocks.registeredSkins[skin];
66 let skinDisplay = container.appendChild(document.createElement("div"));
67 skinDisplay.style.position = "absolute";
68 skinDisplay.style.left = parseInt(x * dragonblocks.settings.map.scale * 1.5) + "px";
69 skinDisplay.style.top = parseInt(y * dragonblocks.settings.map.scale * 2 * 1.5) + "px";
70 skinDisplay.style.width = parseInt(dragonblocks.settings.map.scale) + "px";
71 skinDisplay.style.height = parseInt(dragonblocks.settings.map.scale * 2) + "px";
72 skinDisplay.style.background = dragonblocks.getTexture(def.texture);
73 skinDisplay.style.backgroundSize = "cover";
74 skinDisplay.title = def.name + (def.desc ? "\n" + def.desc : "");
76 if (dragonblocks.player.skin == def.name)
77 skinDisplay.style.boxShadow = "0 0 0 3px #BEBEBE";
79 skinDisplay.addEventListener("click", event => {
80 event.srcElement.style.boxShadow = "0 0 0 3px #BEBEBE";
82 dragonblocks.player.skin = def.name;
83 status.innerHTML = dragonblocks.player.skin;
85 container.dispatchEvent(new Event("update"));
88 container.addEventListener("update", event => {
89 if (dragonblocks.player.skin != def.name)
90 skinDisplay.style.boxShadow = "none";
93 skinDisplay.addEventListener("mouseover", event => {
94 if (dragonblocks.player.skin != def.name)
95 event.srcElement.style.boxShadow = "0 0 0 1px black";
98 skinDisplay.addEventListener("mouseleave", event => {
99 if (dragonblocks.player.skin != def.name)
100 event.srcElement.style.boxShadow = "none";
105 dragonblocks.menu.addButton("Change Skin", _ => {