Watering can lore

This commit is contained in:
2026-03-07 22:01:11 -03:00
parent 897a9e68c7
commit a0886f8f24
11 changed files with 197 additions and 10 deletions
+34 -2
View File
@@ -3,7 +3,8 @@ import { AssetManager } from "$/client/assets.ts";
import { PlayerInventory } from "$/client/components/inventory.ts";
import { InputManager } from "$/client/input_manager.ts";
import { draw_item, draw_nine_slice } from "./render_utils.ts";
import { canvas, Texture } from "$/client/renderer.ts";
import { canvas, draw_text, measure_text, Texture } from "$/client/renderer.ts";
import { EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
const PADDING = 10;
@@ -55,10 +56,41 @@ export function render_player_inventory(player_inventory: PlayerInventory) {
}
}
const mouse = InputManager.get_mouse_position();
if (player_inventory.holding_item) {
const mouse = InputManager.get_mouse_position();
draw_item(player_inventory.holding_item, mouse.x, mouse.y);
}
if (player_inventory.hovering_slot !== -1) {
const item = player_inventory.container.get_item(player_inventory.hovering_slot);
if (item) {
const item_info = EverythingRegistry.get<ItemRegistry>("items", item.type_id);
const item_name = item.type_id;
const box_width = measure_text(item_name, 2) + 4 * 3;
const lines = item_info?.get_lore ? 2 : 1;
draw_nine_slice(
ui,
16 * 11,
0,
16,
16,
4,
4,
4,
4,
mouse.x + 4,
mouse.y,
box_width,
32 * lines + 4 * (lines + 2),
[1, 1, 1, 0.8],
);
draw_text(item_name, mouse.x + 4, mouse.y, 2);
if (item_info?.get_lore) {
draw_text(item_info.get_lore(item), mouse.x + 4, mouse.y + 32, 2);
}
}
}
}
export function render_player_hotbar(player_inventory: PlayerInventory) {
+99 -4
View File
@@ -18,6 +18,7 @@ export function draw_nine_slice(
y: number,
width: number,
height: number,
color = [1, 1, 1, 1],
) {
const center_width = source_width - left - right;
const center_height = source_height - top - bottom;
@@ -26,10 +27,42 @@ export function draw_nine_slice(
const dest_center_height = height - top - bottom;
// top left
draw_texture_region(image, source_x, source_y, left, top, x, y, left, top);
draw_texture_region(
image,
source_x,
source_y,
left,
top,
x,
y,
left,
top,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
// top right
draw_texture_region(image, source_x + source_width - right, source_y, right, top, x + width - right, y, right, top);
draw_texture_region(
image,
source_x + source_width - right,
source_y,
right,
top,
x + width - right,
y,
right,
top,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
// bottom left
draw_texture_region(
@@ -42,6 +75,12 @@ export function draw_nine_slice(
y + height - bottom,
left,
bottom,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
// bottom right
@@ -55,10 +94,32 @@ export function draw_nine_slice(
y + height - bottom,
right,
bottom,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
// top
draw_texture_region(image, source_x + left, source_y, center_width, top, x + left, y, dest_center_width, top);
draw_texture_region(
image,
source_x + left,
source_y,
center_width,
top,
x + left,
y,
dest_center_width,
top,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
// bottom
draw_texture_region(
@@ -71,10 +132,32 @@ export function draw_nine_slice(
y + height - bottom,
dest_center_width,
bottom,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
// left
draw_texture_region(image, source_x, source_y + top, left, center_height, x, y + top, left, dest_center_height);
draw_texture_region(
image,
source_x,
source_y + top,
left,
center_height,
x,
y + top,
left,
dest_center_height,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
// right
draw_texture_region(
@@ -87,6 +170,12 @@ export function draw_nine_slice(
y + top,
right,
dest_center_height,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
// center !
@@ -100,6 +189,12 @@ export function draw_nine_slice(
y + top,
dest_center_width,
dest_center_height,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
}