yantar/assets/Scripts/ux/ItemButton.ts
Georgy Shive f0479d5c5c добавил класс описания оборудования,
добавил стейт менеджер оборудования,
добавил индекс в префаб кнопки оборудования
добавил логику отображения списка оборудования в списке
2025-02-11 08:57:51 +07:00

37 lines
1016 B
TypeScript

// ItemButton.ts
import { _decorator, Component, Label, Button } from 'cc';
import { apiSensors } from '../stores/apiSensors';
const { ccclass, property } = _decorator;
@ccclass('ItemButton')
export class ItemButton extends Component {
@property(Label)
public nameLabel: Label | null = null;
@property(Label)
public timeLabel: Label | null = null;
@property(Button)
public button: Button | null = null;
// Добавляем публичное свойство для хранения индекса элемента
public itemIndex: number = 0;
private itemData: apiSensors | null = null;
public initialize(data: apiSensors) {
this.itemData = data;
if (this.nameLabel) {
this.nameLabel.string = data.name;
}
if (this.timeLabel) {
this.timeLabel.string = data.connect_time;
}
}
public onClick() {
console.log('Нажата кнопка для элемента:', this.itemData);
}
}