Change whole gui system

This commit is contained in:
2026-10-01 16:22:02 -03:00
parent 013a4fbb97
commit deba36260e
48 changed files with 1925 additions and 1302 deletions
+15 -37
View File
@@ -1,46 +1,24 @@
import { add_player_hotbar, add_player_inventory, GuiInventoryScreen, Slot } from "./gui_screen.ts";
import { canvas, draw_rect } from "$/client/renderer/mod.ts";
import { SLOT_SIZE } from "../../common/constants.ts";
import { draw_gui_sprite, GUI_SCALE } from "./gui_sprites.ts";
import { GuiMenuScreen } from "./gui_screen.ts";
import { ClientInventories } from "../inventory.ts";
import { ClientMessage, CRAFTING_RESULT_SLOT } from "$/common/protocol.ts";
import { ClientMessage } from "$/common/protocol.ts";
import { player_menu } from "../menu.ts";
import type { ModGraphics } from "./mod_graphics.ts";
// around the slots, and between the hotbar, the rest of the inventory and what's below, like minecraft's
const MARGIN = 7 * GUI_SCALE;
const GAP = 4 * GUI_SCALE;
// the recipes live on the server, which fills in the result slot
export class GuiPlayerInventory extends GuiInventoryScreen {
override inventory_width = MARGIN * 2 + SLOT_SIZE * 9;
override inventory_height = MARGIN * 2 + GAP * 2 + SLOT_SIZE * 7;
const WIDTH = 176;
const HEIGHT = 166;
// menu 0's screen: the crafting grid over the inventory. the recipes live on the server, which fills in the result
export class GuiPlayerInventory extends GuiMenuScreen {
constructor(inventories: ClientInventories, send: (message: ClientMessage) => void) {
super(inventories, send);
add_player_hotbar(this, MARGIN, MARGIN);
add_player_inventory(this, MARGIN, MARGIN + GAP + SLOT_SIZE);
const crafting_x = MARGIN;
const crafting_y = MARGIN + GAP * 2 + SLOT_SIZE * 4;
for (let i = 0; i < 3; i += 1) {
for (let j = 0; j < 3; j += 1) {
this.slots.push(
new Slot("crafting", j * 3 + i, crafting_x + i * SLOT_SIZE, crafting_y + j * SLOT_SIZE),
);
}
}
this.slots.push(
new Slot("crafting", CRAFTING_RESULT_SLOT, crafting_x + 5 * SLOT_SIZE, crafting_y + 1 * SLOT_SIZE, true),
);
super(inventories, send, player_menu(inventories), WIDTH, HEIGHT);
}
override on_render(): void {
draw_rect(0, 0, canvas.width, canvas.height, [0, 0, 0, 0.8]);
render_background(g: ModGraphics): void {
g.panel(0, 0, WIDTH, HEIGHT);
}
draw_gui_sprite("panel", this.x, this.y, this.inventory_width, this.inventory_height);
super.on_render();
render_labels(g: ModGraphics): void {
g.text(this.menu.title, 26, 6);
g.text("Inventory", 8, 73);
}
}