Change whole gui system

This commit is contained in:
2026-10-01 16:22:02 -03:00
parent 013a4fbb97
commit deba36260e
48 changed files with 1925 additions and 1302 deletions
+24 -5
View File
@@ -1,10 +1,13 @@
// the curios button next to every inventory screen, or G like curios' keybind, asks the server to show the slots
// the curios button next to every inventory screen, or G like curios' keybind, asks the server to open the curios
// menu, and its screen
import type { ClientContext } from "bworld/client";
import { active_slots } from "./slots.ts";
const GAP = 16;
const WIDTH = 120;
const HEIGHT = 32;
// in gui pixels
const GAP = 5;
const BUTTON_WIDTH = 40;
const BUTTON_HEIGHT = 11;
const WIDTH = 176;
export function setup(ctx: ClientContext) {
// no item goes in any slot, so there's nothing to show
@@ -12,10 +15,26 @@ export function setup(ctx: ClientContext) {
ctx.ui.add_inventory_overlay({
on_render(g, screen) {
const clicked = g.button("Curios", screen.x - WIDTH - GAP, screen.y, WIDTH, HEIGHT);
const clicked = g.button("Curios", screen.x - BUTTON_WIDTH - GAP, screen.y, BUTTON_WIDTH, BUTTON_HEIGHT);
if (clicked || g.key_pressed("KeyG")) {
ctx.net.send("curios:open", {});
}
},
});
ctx.ui.register_menu_screen("curios:curios", (menu) => {
const { rows } = menu.open_data as { rows: number };
const height = 114 + rows * 18;
return {
width: WIDTH,
height,
on_render_background(g) {
g.panel(0, 0, WIDTH, height);
},
on_render_labels(g) {
g.text(menu.title, 8, 6);
g.text("Inventory", 8, height - 93);
},
};
});
}
+22 -15
View File
@@ -72,6 +72,27 @@ export function setup(ctx: ServerContext) {
applied.delete(player.id);
});
// like curios' CuriosContainer: the slot types in rows of 9, each row centered, over the inventory. the screen is
// in scripts/client.ts
const rows = Math.ceil(active.length / 9);
const menu_type = ctx.menus.register("curios:curios", (menu, _args, player) => {
const curios = curios_of(player);
menu.title = "Curios";
menu.open_data = { rows };
for (const [i, slot] of active.entries()) {
const row = Math.floor(i / 9);
const in_row = Math.min(9, active.length - row * 9);
menu.add_slot(curios, SLOTS.indexOf(slot), {
x: 7 + ((9 - in_row) / 2 + (i % 9)) * 18,
y: 17 + row * 18,
filter: (item) => fits(ctx.tags, slot, item.id),
icon: `curios:empty_${slot}_slot`,
});
}
menu.add_player_inventory(7, 31 + rows * 18);
});
// the curios button, curios' client asks for its menu like the java mod's packet does
ctx.net.on("curios:open", (player) => {
if (active.length === 0) return;
const curios = curios_of(player);
@@ -83,21 +104,7 @@ export function setup(ctx: ServerContext) {
curios.set(index, undefined);
}
}
// in rows of 9, each row centered
ctx.ui.open_container(player, {
container: curios,
layout: active.map((slot, i) => {
const row = Math.floor(i / 9);
const in_row = Math.min(9, active.length - row * 9);
return {
slot: SLOTS.indexOf(slot),
x: (9 - in_row) / 2 + (i % 9),
y: row,
filter: (item) => fits(ctx.tags, slot, item.id),
icon: `curios:empty_${slot}_slot`,
};
}),
});
menu_type.open(player, undefined);
});
ctx.events.after.player_death.subscribe(({ player }) => {