import { Container, PixelText } from '@rpg/engine';
/**
* HUD локации: название области (правый верх), подсказка управления (левый
* верх), счётчик мотов (под названием), трекер цели квеста (под подсказкой).
* Одна вьюха в uiRoot — сцена только добавляет её, тикает setMotes/setQuest
* и гасит в exit.
*/
export class LocationHud {
readonly view = new Container();
private motesLabel: PixelText;
private questLabel: PixelText;
private lastMotes = -1;
private lastQuest: string | null = null;
constructor(areaName: string) {
const label = new PixelText({ text: areaName, size: 11, color: 0x999988 });
label.anchor.set(1, 0);
label.position.set(474, 4);
this.view.addChild(label);
this.motesLabel = new PixelText({ text: '', size: 10, color: 0xd8c79a });
this.motesLabel.anchor.set(1, 0);
this.motesLabel.position.set(474, 17); // под названием локации
this.view.addChild(this.motesLabel);
const hint = new PixelText({
text: 'WASD — идти · E — действие · Space — удар (удержать — резонанс) · I — сумка · Esc — меню',
size: 10,
color: 0x999988
});
// Под сердечками (HealthBar занимает y≈13..18).
hint.position.set(6, 23);
this.view.addChild(hint);
this.questLabel = new PixelText({ text: '', size: 10, color: 0xd8c79a });
this.questLabel.position.set(6, 35); // под подсказкой управления
this.view.addChild(this.questLabel);
}
/** Счётчик мотов: текст пишем только при изменении (сбор — редкое событие). */
setMotes(count: number): void {
if (count === this.lastMotes) return;
this.lastMotes = count;
this.motesLabel.text = count > 0 ? `Пепельные моты: ${count}` : '';
}
/** Трекер цели: «Цель: <текст стадии>»; null — активных квестов нет. */
setQuest(text: string | null): void {
if (text === this.lastQuest) return;
this.lastQuest = text;
this.questLabel.text = text === null ? '' : `Цель: ${text}`;
}
destroy(): void {
this.view.destroy({ children: true });
}
}