Improve recipe viewer

This commit is contained in:
2026-10-03 13:41:01 -03:00
parent 50d47cedef
commit ecc0295f6d
12 changed files with 666 additions and 452 deletions
+6 -22
View File
@@ -87,20 +87,16 @@ 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();
// 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);
}
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 (hidden || g.mouse_blocked()) {
if (g.mouse_blocked()) {
this.hovering = undefined;
} else {
this.handle_interaction();
@@ -155,18 +151,6 @@ 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 = {
+23 -1
View File
@@ -2,7 +2,7 @@
// see docs/modding/networking/index.md
import { AIR } from "$/common/constants.ts";
import { BlockRegistry, EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts";
import type { ClientContext, ClientMenu, InventoryOverlay, MenuScreen } from "$/common/mod_api/client.ts";
import type { ClientContext, ClientMenu, InventoryOverlay, KeyMappings, MenuScreen } from "$/common/mod_api/client.ts";
import { ModListing, ModLoadError, RecipeBook, register_mod_data } from "$/common/mod_loader.ts";
import { type Bmod, read_bmod } from "$/common/bmod.ts";
import { display_name } from "$/common/utils.ts";
@@ -139,6 +139,7 @@ function client_context(listing: ModListing): ClientContext {
},
hud: not_yet("hud", "HUD elements") as ClientContext["hud"],
input: not_yet("input", "keybinds") as ClientContext["input"],
options: key_mappings(need_client),
net: {
on(channel, handler) {
own(channel);
@@ -189,3 +190,24 @@ function client_context(listing: ModListing): ClientContext {
log: (...args) => console.log(`[${mod}]`, ...args),
};
}
// the client's key settings as they are when read, so changing them reaches mods
function key_mappings(client: () => Client): KeyMappings {
const keys = [
"key_forward",
"key_back",
"key_left",
"key_right",
"key_jump",
"key_sprint",
"key_sneak",
"key_inventory",
"key_drop",
"key_chat",
] as const;
const mappings = {} as KeyMappings;
for (const key of keys) {
Object.defineProperty(mappings, key, { get: () => client().options[key], enumerable: true });
}
return Object.freeze(mappings);
}