import { _decorator, Component, Label, Node, sp, Sprite } from 'cc'; import { ItemData } from '../game/ConfigProjectData'; import { SpriteLoad } from '../../mx/components/SpriteLoad'; import { GBundle, GPath, UIID } from '../game/ConfigRes'; import { applyItemQualityFrame } from './ItemQualityFrame'; const { ccclass, property } = _decorator; @ccclass('ItemGrid') export class ItemGrid extends Component { @property canClick: boolean = true; bgquality: Sprite = null; icon: Sprite = null; scrap: Sprite = null; lbNum: Label = null; qDowneff: Node = null; qUpeff: Node = null; protected onLoad(): void { this.bgquality = this.node.find("bgquality").getComponent(Sprite); this.icon = this.node.find("icon").getComponent(Sprite); this.scrap = this.node.find("scrap").getComponent(Sprite); this.lbNum = this.node.find("lbNum").getComponent(Label); this.qDowneff = this.node.find("qDowneff"); this.qUpeff = this.node.find("qUpeff"); } protected onEnable(): void { this.node.on(Node.EventType.TOUCH_END, this.onClick, this); } protected onDisable(): void { this.node.off(Node.EventType.TOUCH_END, this.onClick, this); } Data: ItemData = null; setData(item: ItemData) { this.Data = item; this.updateUI(); } updateUI() { applyItemQualityFrame(this.bgquality.node.getOrAddComponent(SpriteLoad), this.Data.staticData); this.icon.node.getOrAddComponent(SpriteLoad).setSprite(GPath.Item(this.Data.staticData.icon), GBundle.Items); this.lbNum.string = this.Data.num + ""; let q = this.Data.staticData.quality; this.qDowneff.children.map(x => x.active = x.name == q + ""); this.qUpeff.children.map(x => x.active = x.name == q + ""); this.scrap.node.active = [4, 10, 11, 13].includes(this.Data.staticData.type); } onClick() { if (!this.canClick) return; gg.ui.openPanel(UIID.ItemDetailBox, { data: this.Data }) } }