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.Menu = class{
25 let display = document.createElement("div");
26 display.id = "dragonblocks.menu";
27 display.style.position = "fixed";
28 display.style.backgroundColor = "#7E7E7E";
29 display.style.width = "500px";
30 display.style.height = "10px";
31 display.style.visibility = "hidden";
32 document.body.appendChild(display);
33 display = document.getElementById(display.id);
34 dblib.center(display);
35 dblib.centerVertical(display);
36 dragonblocks.keyHandler.down("Escape", _ => {
37 dragonblocks.menu.toggle();
39 let headlineContainer = document.createElement("div");
40 let headline = headlineContainer.appendChild(document.createElement("h2"));
41 headline.innerHTML = "Options";
42 headline.align = "center";
43 this.addElement(headlineContainer);
46 this.opened ? this.close() : this.open();
50 dragonblocks.gui.closeLayer();
51 dragonblocks.keyHandler.unlockAll();
52 document.getElementById("dragonblocks.menu").style.visibility = "hidden";
56 dragonblocks.gui.showLayer();
57 dragonblocks.keyHandler.lockAll();
58 dragonblocks.keyHandler.unlock("Escape");
59 document.getElementById("dragonblocks.menu").style.visibility = "visible";
62 let menu = document.getElementById("dragonblocks.menu");
63 elem = menu.appendChild(elem);
64 elem.style.position = "absolute";
65 elem.style.top = menu.offsetHeight + "px";
66 elem.style.width = "80%";
68 menu.style.height = menu.offsetHeight + 10 + elem.offsetHeight + "px";
69 dblib.centerVertical(menu);
72 addButton(html, func){
73 let elem = document.createElement("button");
74 elem.innerHTML = html;
75 elem.style.fontSize = "20px";
76 elem.style.borderRadius = "0%";
77 elem.addEventListener("click", event => {
78 dragonblocks.menu.close();
81 this.addElement(elem);
84 dragonblocks.menu = new dragonblocks.Menu();
85 dragonblocks.menu.addButton("Continue Playing");
86 dragonblocks.registerOnStarted( _ => {
87 dragonblocks.menu.addButton(dragonblocks.loggedin ? "Save and Quit to Title" : "Quit to Title", dragonblocks.quit);
89 dragonblocks.keyHandler.down("F5", _ => {});