This is good enough

This commit is contained in:
2026-10-02 22:38:39 -03:00
parent 4fb392adae
commit 50d47cedef
4 changed files with 35 additions and 6 deletions
+22 -6
View File
@@ -87,16 +87,20 @@ export abstract class GuiMenuScreen extends GuiScreen {
draw_rect(0, 0, canvas.width, canvas.height, [0, 0, 0, 0.8]);
const g = this.graphics;
g.begin();
g.origin_x = this.x;
g.origin_y = this.y;
this.render_background(g);
this.#render_slots();
this.render_labels(g);
// an overlay drawing something in the screen's place, like the recipe viewer's recipes, hides all of it
const hidden = this.#overlay_hides_screen();
if (!hidden) {
g.origin_x = this.x;
g.origin_y = this.y;
this.render_background(g);
this.#render_slots();
this.render_labels(g);
}
// mods' overlays go on top and get the mouse first, then the slots get what they left
g.origin_x = g.origin_y = 0;
this.#render_overlays();
if (g.mouse_blocked()) {
if (hidden || g.mouse_blocked()) {
this.hovering = undefined;
} else {
this.handle_interaction();
@@ -151,6 +155,18 @@ export abstract class GuiMenuScreen extends GuiScreen {
highlight("slot_highlight_front");
}
#overlay_hides_screen() {
for (const entry of [...inventory_overlays]) {
try {
if (entry.overlay.hides_screen?.()) return true;
} catch (e) {
console.error(`[${entry.mod}] inventory overlay's hides_screen threw, removing it:`, e);
inventory_overlays.splice(inventory_overlays.indexOf(entry), 1);
}
}
return false;
}
#render_overlays() {
const hovered = this.hovering && this.hovering.container.get_item(this.hovering.index);
const view = {
+3
View File
@@ -115,6 +115,9 @@ export interface Graphics {
// list. it gets the screen's box to lay itself out around
export interface InventoryOverlay {
on_render(g: Graphics, screen: InventoryScreenView): void;
// while it's true the screen underneath isn't drawn or clicked, panels outside its box included, for something
// drawn in its place like the recipe viewer's recipes. asked every frame, before on_render
hides_screen?(): boolean;
// the screen closed for any reason, like the player closing their inventory
on_close?(): void;
}
+4
View File
@@ -86,6 +86,10 @@ Overlays get the mouse before the slots:
- While a `g.text_input` has the keyboard, keybinds like the inventory key don't fire. Text inputs edit like chat:
selecting with shift or the mouse, ctrl+a, and copy, cut and paste.
`hides_screen()`, if the overlay has one, is asked every frame before `on_render`. While it returns `true` the screen
underneath isn't drawn and its slots don't react to the mouse, including the panels mods add outside its box, like the
curios slots. The recipe viewer does this while it shows a recipe in the screen's place.
`on_close()`, if the overlay has one, runs when the screen closes for any reason, like the player closing their
inventory. The recipe viewer goes back to its item list then.
+6
View File
@@ -66,6 +66,12 @@ class RecipeViewer {
if (this.#view && g.key_pressed("Backspace")) this.#back();
}
// the recipes are drawn where the screen was, so its slots, and the panels mods add around it like curios', don't
// show beside them
hides_screen() {
return this.#view !== undefined;
}
// the recipe views go with the inventory, it opens again on the item list
on_close() {
this.#view = undefined;