Change curios to always show on inventory
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
# Curios
|
||||
|
||||
A port of [Curios](https://github.com/TheIllusiveC4/Curios): accessory slots, like rings, necklaces and belts, for any
|
||||
mod's items. Players open them with the Curios button next to their inventory, or G while an inventory is open.
|
||||
mod's items. They're in 2 columns left of the player's inventory, there whenever it's open. Shift clicking a curio in
|
||||
the inventory puts it in the first slot it fits.
|
||||
|
||||
Like the original, Curios adds no items and no slots of its own. A slot type only shows up once some mod puts an item in
|
||||
its tag.
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
"game_version": ">=0.1.0",
|
||||
"credits": "CREDITS.md",
|
||||
"scripts": {
|
||||
"server": "scripts/server.ts",
|
||||
"client": "scripts/client.ts"
|
||||
"server": "scripts/server.ts"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
// 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";
|
||||
|
||||
// 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
|
||||
if (active_slots(ctx.tags).length === 0) return;
|
||||
|
||||
ctx.ui.add_inventory_overlay({
|
||||
on_render(g, screen) {
|
||||
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);
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
// curios: accessory slots, shown with the player's inventory from the curios button. each player's curios are a
|
||||
// curios: accessory slots, in 2 columns left of the player's inventory. each player's curios are a
|
||||
// container of their own, and fall out when they die like the rest of what they carry. items with the
|
||||
// curios:attribute_modifiers component change the wearer's attributes, like curios' attribute modifiers
|
||||
import type { AttributeModifier, Container, Player, ServerContext } from "bworld/server";
|
||||
import { active_slots, fits, SLOTS } from "./slots.ts";
|
||||
|
||||
// where the left column of slots goes, from the inventory screen's left edge. the panel around them ends just left of it
|
||||
const COLUMNS_X = -45;
|
||||
|
||||
// curios:attribute_modifiers' params, a list of these
|
||||
interface WornModifier {
|
||||
attribute: string;
|
||||
@@ -24,7 +27,7 @@ export function setup(ctx: ServerContext) {
|
||||
const applied = new Map<string, { attribute: string; id: string }[]>();
|
||||
const stop_watching = new Map<string, () => void>();
|
||||
|
||||
// by player name, like the players themselves are saved. undefined until they first open curios
|
||||
// by player name, like the players themselves are saved. undefined until they first join with curios
|
||||
function saved_curios(player: Player): Container | undefined {
|
||||
const id = ctx.storage.get<Record<string, string>>("containers")?.[player.name];
|
||||
return id ? ctx.containers.get(id) : undefined;
|
||||
@@ -72,28 +75,8 @@ 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) => {
|
||||
// the slot types in 2 columns left of the inventory, always there while it's open. the engine draws their panel
|
||||
ctx.menus.extend_player_menu((menu, player) => {
|
||||
if (active.length === 0) return;
|
||||
const curios = curios_of(player);
|
||||
// what's in slot types no item goes in anymore, since the mod that added them was removed, goes back to them
|
||||
@@ -104,7 +87,14 @@ export function setup(ctx: ServerContext) {
|
||||
curios.set(index, undefined);
|
||||
}
|
||||
}
|
||||
menu_type.open(player, undefined);
|
||||
for (const [i, slot] of active.entries()) {
|
||||
menu.add_slot(curios, SLOTS.indexOf(slot), {
|
||||
x: COLUMNS_X + (i % 2) * 18,
|
||||
y: 7 + Math.floor(i / 2) * 18,
|
||||
filter: (item) => fits(ctx.tags, slot, item.id),
|
||||
icon: `curios:empty_${slot}_slot`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ctx.events.after.player_death.subscribe(({ player }) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// curios' slot types, both scripts share them
|
||||
// curios' slot types
|
||||
import type { TagApi } from "bworld/server";
|
||||
|
||||
// in curios' order. every player has one of each, at its index here in their curios container, so slots keep their
|
||||
|
||||
Reference in New Issue
Block a user