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 { ClientInventories } from "../inventory.ts"; import { ClientMessage, CRAFTING_RESULT_SLOT } from "$/common/protocol.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; 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), ); } override on_render(): void { draw_rect(0, 0, canvas.width, canvas.height, [0, 0, 0, 0.8]); draw_gui_sprite("panel", this.x, this.y, this.inventory_width, this.inventory_height); super.on_render(); } }