yantar/assets/Scripts/ui/SensorFieldItem.ts
2025-04-09 12:23:04 +07:00

43 lines
1.7 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? field.unit: "????"}
// Отображение описания (мелким серым текстом, если есть)
if (this.descriptionLabel) {
if (field.description && field.description.trim() !== "") {
this.descriptionLabel.string = field.description;
// Применяем стили: серый цвет, мелкий шрифт
this.descriptionLabel.node.active = true;
} else {
// Если описания нет, скрываем или очищаем поле описания
this.descriptionLabel.node.active = false;
}
}
}
}