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];
40 stack.addEventListener("update", event => {
41 if (event.stack.refilling)
44 stack.refilling = true;
45 stack.deserialize(self.fullList[self.slots * self.page + i] || "");
46 stack.refilling = false;
53 return super.calculateHeight() + dragonblocks.settings.inventory.scale;
61 if (this.page == this.pages)
64 this.pageDisplay.textContent = "Page " + (this.page + 1) + " of " + this.pages;
66 for (let slot of this.list)
74 let pageContainer = this.display.appendChild(document.createElement("div"));
75 pageContainer.style.height = dragonblocks.settings.inventory.scale + "px";
76 pageContainer.style.width = this.calculateWidth() + "px";
77 pageContainer.style.left = "0px";
78 pageContainer.style.top = super.calculateHeight() + "px";
79 pageContainer.style.position = "absolute";
81 this.pageDisplay = pageContainer.appendChild(document.createElement("span"));
82 this.pageDisplay.style.color = "#343434";
83 this.pageDisplay.style.position = "absolute";
84 this.pageDisplay.style.left = dragonblocks.settings.inventory.scale * 1.1 + "px";
85 this.pageDisplay.style.width = "100%";
86 this.pageDisplay.style.fontSize = dragonblocks.settings.inventory.scale / (5 / 3) + "px";
87 this.pageDisplay.style.height = dragonblocks.settings.inventory.scale / (5 / 3) + "px";
89 dblib.centerVertical(this.pageDisplay);
93 for (let dir of ["left", "right"]) {
94 let arrow = pageContainer.appendChild(document.createElement("div"));
95 arrow.style.position = "absolute";
96 arrow.style.width = dragonblocks.settings.inventory.scale + "px";
97 arrow.style.height = dragonblocks.settings.inventory.scale + "px";
98 arrow.style[dir] = "0px";
99 arrow.style.background = dragonblocks.getTexture("arrow.png");
100 arrow.style.cursor = "pointer";
103 arrow.style.transform = "rotate(180deg)";
105 arrow.addEventListener("click", _ => {
114 dblib.centerVertical(arrow);