Change the gui

This commit is contained in:
2026-09-27 14:52:30 -03:00
parent d0cbec1846
commit 29e61a235b
20 changed files with 451 additions and 359 deletions
+28 -171
View File
@@ -6,6 +6,8 @@ import { ItemStack } from "$/common/inventory.ts";
import { block_item_texture, cube_face_texture } from "$/common/block_models.ts";
import { draw_text, draw_texture_region, draw_texture_region_skewed, Texture } from "$/client/renderer/mod.ts";
// the corners keep their size (times scale), the edges stretch along and the middle fills the rest, like minecraft's
// nine slice gui sprites. borders are in source pixels
export function draw_nine_slice(
image: Texture,
source_x: number,
@@ -21,183 +23,38 @@ export function draw_nine_slice(
width: number,
height: number,
color = [1, 1, 1, 1],
scale = 1,
) {
const center_width = source_width - left - right;
const center_height = source_height - top - bottom;
const dest_center_width = width - left - right;
const dest_center_height = height - top - bottom;
// top left
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,
// start and size of each column and row, in the source and on screen
const source_columns = [[source_x, left], [source_x + left, source_width - left - right], [
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(
image,
source_x,
]];
const source_rows = [[source_y, top], [source_y + top, source_height - top - bottom], [
source_y + source_height - bottom,
left,
bottom,
x,
y + height - bottom,
left,
bottom,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
]];
const columns = [[x, left * scale], [x + left * scale, width - (left + right) * scale], [
x + width - right * scale,
right * scale,
]];
const rows = [[y, top * scale], [y + top * scale, height - (top + bottom) * scale], [
y + height - bottom * scale,
bottom * scale,
]];
// bottom right
draw_texture_region(
image,
source_x + source_width - right,
source_y + source_height - bottom,
right,
bottom,
x + width - right,
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,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
// bottom
draw_texture_region(
image,
source_x + left,
source_y + source_height - bottom,
center_width,
bottom,
x + left,
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,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
// right
draw_texture_region(
image,
source_x + source_width - right,
source_y + top,
right,
center_height,
x + width - right,
y + top,
right,
dest_center_height,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
// center !
draw_texture_region(
image,
source_x + left,
source_y + top,
center_width,
center_height,
x + left,
y + top,
dest_center_width,
dest_center_height,
false,
false,
color[0],
color[1],
color[2],
color[3],
);
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 3; column++) {
const [sx, sw] = source_columns[column];
const [sy, sh] = source_rows[row];
const [dx, dw] = columns[column];
const [dy, dh] = rows[row];
if (sw > 0 && sh > 0 && dw > 0 && dh > 0) {
const [r, g, b, a] = color;
draw_texture_region(image, sx, sy, sw, sh, dx, dy, dw, dh, false, false, r, g, b, a);
}
}
}
}
export function draw_item(item: ItemStack, x: number, y: number) {