Player rendering in the inventory

This commit is contained in:
2026-10-12 00:11:40 -03:00
parent fbef1d96d2
commit e1f3fda692
7 changed files with 242 additions and 13 deletions
+35 -3
View File
@@ -7,6 +7,11 @@ import { display_name } from "$/common/utils.ts";
import { ClientMessage, PLAYER_MENU_EXTRA } from "$/common/protocol.ts";
import { player_menu } from "../menu.ts";
import type { ModGraphics } from "./mod_graphics.ts";
import { draw_gui_player } from "../rendering/gui_player.ts";
import { InputManager } from "../input_manager.ts";
import { AssetManager } from "../assets.ts";
import type { Texture } from "../renderer/mod.ts";
import { GUI_SCALE } from "./gui_sprites.ts";
const WIDTH = 176;
const HEIGHT = 166;
@@ -18,9 +23,16 @@ const ICON = 16;
const ICON_GAP = 2;
const ICON_MARGIN = 4;
const TIME_COLOR: [number, number, number, number] = [0.66, 0.66, 0.66, 1];
// the box the player stands in, left of the crafting grid, like minecraft's
const PLAYER_BOX = { x: MARGIN, y: MARGIN, size: 64 };
const PLAYER_BOX_COLOR: [number, number, number, number] = [0, 0, 0, 0.6];
// gui pixels to a skin pixel, so the player's 32 fit in the box with room to look around
const PLAYER_PIXEL = 1.6;
// the feet, above the box's bottom
const PLAYER_FEET = 4;
// menu 0's screen: the crafting grid over the inventory, and any slots mods added, with the player's effects above.
// the recipes live on the server, which fills in the result
// menu 0's screen: the player looking at the mouse beside the crafting grid, over the inventory, and any slots mods
// added, with the player's effects above. the recipes live on the server, which fills in the result
export class GuiPlayerInventory extends GuiMenuScreen {
#player: LocalPlayer;
@@ -31,6 +43,7 @@ export class GuiPlayerInventory extends GuiMenuScreen {
render_background(g: ModGraphics): void {
g.panel(0, 0, WIDTH, HEIGHT);
this.#render_player(g);
this.#render_effects(g);
// the slots mods added outside the panel get one of their own, around them with the same margin
const outside = this.menu.slots.slice(PLAYER_MENU_EXTRA)
@@ -44,6 +57,25 @@ export class GuiPlayerInventory extends GuiMenuScreen {
}
}
// the player in their box, in their skin and what they wear, turned toward the mouse
#render_player(g: ModGraphics) {
const { x, y, size } = PLAYER_BOX;
g.rect(x, y, size, size, PLAYER_BOX_COLOR);
const skin = this.#player.skin ?? AssetManager.instance.get<Texture>("bworld:skin");
const mouse = InputManager.get_mouse_position();
draw_gui_player(
skin,
this.#player.slim,
this.x + (x + size / 2) * GUI_SCALE,
this.y + (y + size - PLAYER_FEET) * GUI_SCALE,
PLAYER_PIXEL * GUI_SCALE,
GUI_SCALE,
mouse.x,
mouse.y,
this.#player.worn,
);
}
// the ones with an icon, left to right in the order they were added. hovering one says what it is
#render_effects(g: ModGraphics) {
const shown = this.#player.effects.flatMap((effect) => {
@@ -68,7 +100,7 @@ export class GuiPlayerInventory extends GuiMenuScreen {
}
render_labels(g: ModGraphics): void {
g.text(this.menu.title, 26, 6);
g.text(this.menu.title, 79, 6);
g.text("Inventory", 8, 73);
}
}