2 * creative_inventory.js
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.CreativeInventory = class extends dragonblocks.Inventory
26 constructor(slots, list, columns)
28 super(slots, columns);
30 this.fullList = list || this.list;
33 this.pages = Math.ceil(this.fullList.length / this.list.length);
37 for (let i = 0; i < this.slots; i++) {
38 let stack = this.list[i];
39 stack.addEventListener("update", event => {
40 if (event.stack.refilling)
43 stack.refilling = true;
44 stack.deserialize(self.fullList[self.slots * self.page + i] || "");
45 stack.refilling = false;
52 return super.calculateHeight() + dragonblocks.settings.inventory.scale;
57 if (! super.draw(parent, x, y))
60 let display = this.getDisplay();
61 display.style.height = this.calculateHeight();
63 let creativeDisplay = display.appendChild(document.createElement("div"));
64 creativeDisplay.id = "dragonblocks.inventory[" + this.id + "].creative";
65 creativeDisplay.style.height = dragonblocks.settings.inventory.scale + "px";
66 creativeDisplay.style.width = this.calculateWidth() + "px";
67 creativeDisplay.style.left = "0px";
68 creativeDisplay.style.top = super.calculateHeight() + "px";
69 creativeDisplay.style.position = "absolute";
71 let pageDisplay = creativeDisplay.appendChild(document.createElement("span"));
72 pageDisplay.id = "dragonblocks.inventory[" + this.id + "].creative.page";
73 pageDisplay.style.color = "#343434";
74 pageDisplay.style.position = "absolute";
75 pageDisplay.style.left = dragonblocks.settings.inventory.scale * 1.1 + "px";
76 pageDisplay.style.width = "100%";
77 pageDisplay.style.fontSize = dragonblocks.settings.inventory.scale / (5 / 3) + "px";
78 pageDisplay.style.height = dragonblocks.settings.inventory.scale / (5 / 3) + "px";
80 dblib.centerVertical(pageDisplay);
84 for (let dir of ["left", "right"]) {
85 let arrow = creativeDisplay.appendChild(document.createElement("div"));
86 arrow.id = "dragonblocks.inventory[" + this.id + "].creative.arrow." + dir;
87 arrow.style.position = "absolute";
88 arrow.style.width = dragonblocks.settings.inventory.scale + "px";
89 arrow.style.height = dragonblocks.settings.inventory.scale + "px";
90 arrow.style[dir] = "0px";
91 arrow.style.background = dragonblocks.getTexture("arrow.png");
92 arrow.style.cursor = "pointer";
95 arrow.style.transform = "rotate(180deg)";
97 arrow.addEventListener("click", _ => {
105 dblib.centerVertical(arrow);
116 if (this.page == this.pages)
119 document.getElementById("dragonblocks.inventory[" + this.id + "].creative.page").textContent = "Page " + (this.page + 1) + " of " + this.pages;
121 for (let slot of this.list)