diff --git a/client/gui/gui_screen.ts b/client/gui/gui_screen.ts index 77deac5..39fab68 100644 --- a/client/gui/gui_screen.ts +++ b/client/gui/gui_screen.ts @@ -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 = { diff --git a/common/mod_api/client.ts b/common/mod_api/client.ts index 76d4dca..44dad82 100644 --- a/common/mod_api/client.ts +++ b/common/mod_api/client.ts @@ -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; } diff --git a/docs/modding/gui/index.md b/docs/modding/gui/index.md index 8d789df..910654a 100644 --- a/docs/modding/gui/index.md +++ b/docs/modding/gui/index.md @@ -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. diff --git a/mods/recipe_viewer/scripts/client.ts b/mods/recipe_viewer/scripts/client.ts index b54ea7f..10b4276 100644 --- a/mods/recipe_viewer/scripts/client.ts +++ b/mods/recipe_viewer/scripts/client.ts @@ -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;