yantar/assets/Scripts/ui/SensorFieldItem.ts
Georgy Shive 6eb39e0791 добавил в компонент описания дополнительную логику
сокрытия кнопки с вопросом если нет
описания .
2025-04-23 15:41:34 +07:00

61 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { _decorator, Component, Label, Node } from 'cc'; // <-- добавили Node
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;
/** Нода-контейнер для анимации (спрайт + Label) */
@property({ type: Node })
public descriptionContainer: Node | null = null;
/** Нода Morph, которую нужно скрывать при наличии описания */
@property({ type: Node })
public Morph: Node | null = null;
protected onLoad(): void {
// Сразу прячем контейнер, теперь active доступен
if (this.descriptionContainer) {
this.descriptionContainer.active = false;
}
}
/**
* Установить данные для отображения поля датчика.
* @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 ?? "????";
const hasDesc = !!field.description?.trim();
// Работаем с описанием
if (this.descriptionLabel) {
this.descriptionLabel.string = hasDesc ? field.description! : "";
}
if (this.descriptionContainer) {
this.descriptionContainer.active = hasDesc;
}
// Morph: теперь показываем его только при наличии описания,
// и скрываем, когда описания нет
if (this.Morph) {
this.Morph.active = hasDesc;
}
}
}