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
+9 -7
View File
@@ -18,14 +18,17 @@ import {
measure_text,
Texture,
} from "$/client/renderer/mod.ts";
import { draw_item, draw_nine_slice } from "$/client/rendering/render_utils.ts";
import { draw_item } from "$/client/rendering/render_utils.ts";
import { get_sprite_region } from "$/client/sprites.ts";
import { draw_tooltip, item_tooltip, type TooltipLine } from "./tooltip.ts";
import { TEXT_HEIGHT, TEXT_SCALE, TextInput } from "./widgets.ts";
import { GUI_ATLAS } from "./gui_atlas.ts";
import { draw_gui_sprite, GUI_SCALE } from "./gui_sprites.ts";
const WHITE: Color = [1, 1, 1, 1];
const GREY: Color = [0.66, 0.66, 0.66, 1];
const INPUT_HEIGHT = 32;
const FIELD_BORDER = GUI_ATLAS.text_field.border[0] * GUI_SCALE;
export class ModGraphics implements Graphics {
// text inputs by id, and which one has the keyboard
@@ -83,7 +86,7 @@ export class ModGraphics implements Graphics {
}
panel(x: number, y: number, w: number, h: number) {
draw_nine_slice(AssetManager.instance.get<Texture>("bworld:ui"), 160, 0, 16, 16, 4, 4, 4, 4, x, y, w, h);
draw_gui_sprite("panel", x, y, w, h);
}
text(text: string, x: number, y: number, options: { scale?: number; color?: Color } = {}) {
@@ -129,8 +132,7 @@ export class ModGraphics implements Graphics {
button(label: string, x: number, y: number, w: number, h: number): boolean {
const hovered = point_inside_rec(this.mouse.x, this.mouse.y, x, y, w, h);
const [sx, sy] = hovered ? [224, 16] : [176, 0];
draw_nine_slice(AssetManager.instance.get<Texture>("bworld:ui"), sx, sy, 16, 16, 4, 4, 4, 4, x, y, w, h);
draw_gui_sprite(hovered ? "button_highlighted" : "button", x, y, w, h);
const text_width = measure_text(label, TEXT_SCALE);
draw_text(label, x + (w - text_width) / 2, y + (h - TEXT_HEIGHT * TEXT_SCALE) / 2, TEXT_SCALE, WHITE);
if (hovered && this.mouse.pressed) {
@@ -167,9 +169,9 @@ export class ModGraphics implements Graphics {
}
}
draw_rect(x, y, w, INPUT_HEIGHT, focused ? WHITE : GREY);
draw_rect(x + 2, y + 2, w - 4, INPUT_HEIGHT - 4, [0, 0, 0, 1]);
this.clip(x + 2, y + 2, w - 4, INPUT_HEIGHT - 4, () => {
draw_gui_sprite(focused ? "text_field_highlighted" : "text_field", x, y, w, INPUT_HEIGHT);
// inside the field's border, so long text doesn't go over it
this.clip(x + FIELD_BORDER, y + 2, w - FIELD_BORDER * 2, INPUT_HEIGHT - 4, () => {
if (focused) {
input.draw_selection(x + 6, y + 6, INPUT_HEIGHT - 12);
}