/
difight
/
ruEngine
Обзор
Документация
Войти
/
difight
/
ruEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
client/src/game/ui/Button.ts
46 строк
1 KB
Andrey Bashkirev
Сильно переделал логику всего движка плюс немного структурировал всю логику движка
16 июл 2025, 18:03
16 июл 2025, 18:03
059fab3
Код
Авторство
О чём код?
import type { IInteractable } from "../../engine/core/ui/IInteractable"; import { Logger } from "../../engine/utils/Logger"; export class Button implements IInteractable { private x: number; private y: number; private width: number; private height: number; private label: string; private onClickCallback?: () => void; constructor(x: number, y: number, width: number, height: number, label: string) { this.x = x; this.y = y; this.width = width; this.height = height; this.label = label; } contains(x: number, y: number): boolean { return ( x >= this.x && x <= this.x + this.width && y >= this.y && y <= this.y + this.height ); } render(ctx: CanvasRenderingContext2D): void { //Logger.debug("Rendering button at:", this.x, this.y); ctx.fillStyle = "#222"; ctx.fillRect(this.x, this.y, this.width, this.height); ctx.fillStyle = "#fff"; ctx.font = "24px Arial"; ctx.textAlign = "center"; ctx.fillText(this.label, this.x + this.width / 2, this.y + this.height / 2); } setOnClick(callback: () => void): void { this.onClickCallback = callback; } onClick?(): void { this.onClickCallback?.(); } }