Change the gui

This commit is contained in:
2026-09-27 14:52:30 -03:00
parent d0cbec1846
commit 29e61a235b
20 changed files with 451 additions and 359 deletions
+16 -21
View File
@@ -1,16 +1,19 @@
import { SLOT_SIZE } from "$/common/constants.ts";
import { draw_gui_sprite, GUI_SCALE } from "./gui_sprites.ts";
import { click_slot, Container } from "$/common/inventory.ts";
import { ClientMessage, ContainerKey, CRAFTING_RESULT_SLOT } from "$/common/protocol.ts";
import { point_inside_rec } from "../../common/utils.ts";
import { AssetManager } from "../assets.ts";
import { InputManager } from "../input_manager.ts";
import { ClientInventories } from "../inventory.ts";
import { canvas, Texture } from "../renderer/mod.ts";
import { draw_item, draw_nine_slice } from "../rendering/render_utils.ts";
import { canvas } from "../renderer/mod.ts";
import { draw_item } from "../rendering/render_utils.ts";
import { draw_tooltip, item_tooltip } from "./tooltip.ts";
import { ModGraphics } from "./mod_graphics.ts";
import { inventory_overlays } from "../mods.ts";
// how far past the slot's edge its highlight goes
const HIGHLIGHT_OVERHANG = 3 * GUI_SCALE;
export class Slot {
container: ContainerKey;
index: number;
@@ -83,33 +86,25 @@ export class GuiInventoryScreen extends GuiScreen {
}
on_render(): void {
const ui = AssetManager.instance.get<Texture>("bworld:ui");
for (const slot of this.slots) {
const hovered = slot === this.hovering;
draw_nine_slice(
ui,
hovered ? 19 * 16 : 160 + 32,
hovered ? 16 : 0,
16,
16,
4,
4,
4,
4,
this.x + slot.x,
this.y + slot.y,
SLOT_SIZE,
SLOT_SIZE,
);
draw_gui_sprite("slot", this.x + slot.x, this.y + slot.y);
}
// like minecraft's, the highlight is a bit bigger than the slot, part of it under the item and part over
const highlight = (sprite: "slot_highlight_back" | "slot_highlight_front") => {
if (this.hovering) {
const x = this.x + this.hovering.x - HIGHLIGHT_OVERHANG;
draw_gui_sprite(sprite, x, this.y + this.hovering.y - HIGHLIGHT_OVERHANG);
}
};
highlight("slot_highlight_back");
for (const slot of this.slots) {
const item = this.get_container(slot.container)?.get_item(slot.index);
if (item) {
draw_item(item, this.x + slot.x, this.y + slot.y);
}
}
highlight("slot_highlight_front");
// mods' overlays go on top and get the mouse first, then the slots get what they left
this.#render_overlays();