yantar/assets/Scripts/ui/SensorFieldItem.ts

44 lines
1.9 KiB
TypeScript

import { _decorator, Component, Label, Color } from 'cc';
import { SensorDescriptionField } from '../stores/SensorDescriptionField';
const { ccclass, property } = _decorator;
@ccclass('SensorFieldItem')
export class SensorFieldItem extends Component {
@property(Label)
public nameLabel: Label | null = null;
@property(Label)
public valueLabel: Label | null = null;
@property(Label)
public unitLabel: Label | null = null;
@property(Label)
public descriptionLabel: Label | null = null;
/**
* Установить данные для отображения поля датчика.
* @param field Объект поля датчика (name, value, unit, description)
*/
public setData(field: SensorDescriptionField): void {
if (this.nameLabel) this.nameLabel.string = field.name;
if (this.valueLabel) this.valueLabel.string = String(field.value);
if (this.unitLabel) this.unitLabel.string = field.unit;
// Отображение описания (мелким серым текстом, если есть)
if (this.descriptionLabel) {
if (field.description && field.description.trim() !== "") {
this.descriptionLabel.string = field.description;
// Применяем стили: серый цвет, мелкий шрифт
this.descriptionLabel.color = new Color(150, 150, 150); // серый
this.descriptionLabel.fontSize = 12; // например, меньший шрифт
this.descriptionLabel.node.active = true;
} else {
// Если описания нет, скрываем или очищаем поле описания
this.descriptionLabel.string = "";
this.descriptionLabel.node.active = false;
}
}
}
}