Change the gui
This commit is contained in:
+8
-10
@@ -1,8 +1,7 @@
|
||||
import { point_inside_rec } from "$/common/utils.ts";
|
||||
import { AssetManager } from "$/client/assets.ts";
|
||||
import { InputManager, type KeyCode } from "$/client/input_manager.ts";
|
||||
import { draw_nine_slice } from "$/client/rendering/render_utils.ts";
|
||||
import { draw_rect, draw_text, measure_text, Texture } from "$/client/renderer/mod.ts";
|
||||
import { draw_rect, draw_text, measure_text } from "$/client/renderer/mod.ts";
|
||||
import { draw_gui_sprite } from "./gui_sprites.ts";
|
||||
|
||||
export const TEXT_SCALE = 2;
|
||||
// how tall the font is at scale 1
|
||||
@@ -12,7 +11,8 @@ const REPEAT_DELAY_MS = 400;
|
||||
const REPEAT_RATE_MS = 40;
|
||||
const CARET_BLINK_MS = 500;
|
||||
const DOUBLE_CLICK_MS = 400;
|
||||
const SELECTION_COLOR: [number, number, number, number] = [0.25, 0.45, 1, 0.6];
|
||||
// catppuccin mocha's pink, like the gui sprites' highlights
|
||||
const SELECTION_COLOR: [number, number, number, number] = [0.96, 0.76, 0.91, 0.45];
|
||||
|
||||
// editing a line of text, like minecraft's EditBox without the drawing. typing, backspace and delete, arrows, home
|
||||
// and end. shift with those selects, ctrl (alt on macs) moves and deletes whole words, ctrl+a selects everything, and
|
||||
@@ -270,10 +270,8 @@ export class Button {
|
||||
}
|
||||
|
||||
render() {
|
||||
const ui = AssetManager.instance.get<Texture>("bworld:ui");
|
||||
const [sx, sy] = this.#hovered ? [224, 16] : [176, 0];
|
||||
const tint = this.active ? [1, 1, 1, 1] : [0.6, 0.6, 0.6, 1];
|
||||
draw_nine_slice(ui, sx, sy, 16, 16, 4, 4, 4, 4, this.x, this.y, this.width, this.height, tint);
|
||||
const sprite = !this.active ? "button_disabled" : this.#hovered ? "button_highlighted" : "button";
|
||||
draw_gui_sprite(sprite, this.x, this.y, this.width, this.height);
|
||||
|
||||
const text_width = measure_text(this.label, TEXT_SCALE);
|
||||
draw_text(
|
||||
@@ -322,8 +320,8 @@ export class EditBox {
|
||||
}
|
||||
|
||||
render() {
|
||||
const ui = AssetManager.instance.get<Texture>("bworld:ui");
|
||||
draw_nine_slice(ui, this.focused ? 320 : 304, 0, 16, 16, 4, 4, 4, 4, this.x, this.y, this.width, this.height);
|
||||
const sprite = this.focused ? "text_field_highlighted" : "text_field";
|
||||
draw_gui_sprite(sprite, this.x, this.y, this.width, this.height);
|
||||
|
||||
const text_x = this.#text_x;
|
||||
const text_y = this.y + (this.height - TEXT_HEIGHT * TEXT_SCALE) / 2;
|
||||
|
||||
Reference in New Issue
Block a user