import { _decorator, Component, Enum, Label, Node, Sprite } from 'cc'; import { ItemKey, ItemService } from './ItemService'; import { rootMgr } from '../../scene/RootMgr'; const { ccclass, property } = _decorator; @ccclass('ItemView') export class ItemView extends Component { @property({ type: Enum(ItemKey) }) readonly type: ItemKey @property(Label) label: Label @property(Node) labelIcon: Node @property(Sprite) adIcon: Sprite protected onEnable(): void { this.flshView(this.type) let item = rootMgr.dataControl?.getCompent(ItemService) item?.evt.on('useItem',this.flshView,this) } protected onDisable(): void { let item = rootMgr.dataControl?.getCompent(ItemService) item?.evt.off('useItem',this.flshView,this) } flshView(type: ItemKey) { if (type == this.type) { let number = rootMgr.dataControl.getCompent(ItemService).get(this.type) if (this.label) { this.label.string = number + '' } if (this.labelIcon) { this.labelIcon.active = number > 0 } if (this.adIcon) { this.adIcon.node.active = number <= 0 } } } }