implement ingame menu

This commit is contained in:
LabyStudio
2022-02-03 16:02:55 +01:00
parent 64b84c3f64
commit 5eb1d03e5d
14 changed files with 179 additions and 69 deletions
+19 -7
View File
@@ -1,5 +1,7 @@
window.Gui = class {
static FONT = "normal 20px Minecraftia";
drawRect(stack, left, top, right, bottom, color, alpha = 1) {
stack.save();
stack.fillStyle = color;
@@ -8,18 +10,28 @@ window.Gui = class {
stack.restore();
}
drawString(stack, string, x, y, color) {
this._drawString(stack, string, x, y, color, 0, false);
drawCenteredString(stack, string, x, y, color = 'white') {
this._drawString(stack, string, x + this.getStringWidth(stack, string) / 2, y, color, 1);
}
_drawString(stack, string, x, y, color, alignment, bold) {
let size = 24;
stack.font = (bold ? "bold" : "normal") + " " + size + "px Minecraftia";
stack.fillStyle = color;
drawString(stack, string, x, y, color = 'white') {
this._drawString(stack, string, x, y, color, 0);
}
_drawString(stack, string, x, y, color, alignment) {
stack.font = Gui.FONT;
stack.fillStyle = 'black';
stack.textAlign = alignment === 0 ? "center" : alignment < 0 ? "left" : "right";
stack.fillText(string, x + 2, y + 2);
stack.fillStyle = color;
stack.fillText(string, x, y);
}
getStringWidth(stack, string) {
stack.font = Gui.FONT;
return stack.measureText(string).width;
}
drawTexture(stack, texture, x, y, width, height, alpha = 1.0) {
this.drawSprite(stack, texture, 0, 0, 256, 256, x, y, width, height, alpha);
}
@@ -42,7 +54,7 @@ window.Gui = class {
stack.restore();
}
loadTexture(path) {
static loadTexture(path) {
let img = new Image();
img.src = path;
return img;