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,
23 dragonblocks.CreativeInventory = class extends dragonblocks.Inventory{
24 constructor(slots, list, columns){
25 super(slots, columns);
26 this.fullList = list || this.list;
28 this.pages = Math.ceil(this.fullList.length / this.list.length);
30 for(let i = 0; i < this.slots; i++){
32 this.list[i].addUpdateListener(_ => {
33 if(inventory.list[i].refilling)
35 inventory.list[i].refilling = true;
36 inventory.list[i].parse(inventory.fullList[inventory.slots * inventory.page + i] || "");
37 inventory.list[i].refilling = false;
42 return super.calculateHeight() + dragonblocks.settings.inventory.scale;
45 if (!super.draw(parent, x, y))
48 this.getDisplay().style.height = this.calculateHeight();
49 let creativeDisplay = document.createElement("div");
50 creativeDisplay.id = "dragonblocks.inventory[" + this.id + "].creative";
51 creativeDisplay.style.height = dragonblocks.settings.inventory.scale + "px";
52 creativeDisplay.style.width = this.calculateWidth();
53 creativeDisplay.style.left = "0px";
54 creativeDisplay.style.top = super.calculateHeight() + "px";
55 creativeDisplay.style.position = "absolute";
56 this.getDisplay().appendChild(creativeDisplay);
57 creativeDisplay = document.getElementById(creativeDisplay.id);
58 let pageDisplay = document.createElement("span");
59 pageDisplay.id = "dragonblocks.inventory[" + this.id + "].creative.page";
60 pageDisplay.style.color = "343434";
61 pageDisplay.style.position = "absolute";
62 pageDisplay.style.left = dragonblocks.settings.inventory.scale * 1.1 + "px";
63 pageDisplay.style.width = "100%";
64 pageDisplay.style.fontSize = dragonblocks.settings.inventory.scale / (5/3) + "px";
65 pageDisplay.style.height = dragonblocks.settings.inventory.scale / (5/3) + "px";
66 creativeDisplay.appendChild(pageDisplay);
67 dblib.centerVertical(document.getElementById(pageDisplay.id));
68 for(let dir of ["left", "right"]){
69 let arrow = document.createElement("div");
70 arrow.id = "dragonblocks.inventory[" + this.id + "].creative.arrow." + dir;
71 arrow.style.position = "absolute";
72 arrow.style.width = dragonblocks.settings.inventory.scale + "px";
73 arrow.style.height = dragonblocks.settings.inventory.scale + "px";
74 arrow.style.position = "absolute";
75 arrow.style[dir] = "0px";
76 arrow.style.background = dragonblocks.getTexture("arrow.png");
77 arrow.style.backgroundSize = "cover";
78 arrow.style.cursor = "pointer";
80 arrow.style.transform = "rotate(180deg)";
81 arrow.addEventListener("click", _ => {
88 creativeDisplay.appendChild(arrow);
89 dblib.centerVertical(document.getElementById(arrow.id));
96 if(this.page == this.pages)
98 document.getElementById("dragonblocks.inventory[" + this.id + "].creative.page").textContent = "Page " + (this.page + 1 ) + " of " + this.pages;
99 for(let slot of this.list)