import { _decorator, CCBoolean, Component, Label, Node, sp } from 'cc'; import { SpriteLoad } from '../../mx/components/SpriteLoad'; import { GPath, GBundle, UIID } from '../game/ConfigRes'; import type { RewardData } from '../ui/sign7Day/UIsign7Day'; import { ItemData } from '../game/ConfigProjectData'; import { applyItemQualityFrame } from './ItemQualityFrame'; const { ccclass, property } = _decorator; @ccclass('itemPic') export class itemPic extends Component { @property(CCBoolean) isCanClick: boolean = false lbName: Label = null lbDesc: Label = null itemData: ItemData = null protected onLoad(): void { this.lbName = this.node.find("lbName")?.getComponent(Label) this.lbDesc = this.node.find("lbDesc")?.getComponent(Label) } goodId = 0 rewardData: RewardData[] = []; setGoodId(goodId, arr: RewardData[] = [], iconScale?: number) { this.goodId = goodId this.rewardData = arr this.refreshView(this.goodId, '', iconScale) if (this.rewardData.length > 1) this.refreshView(this.rewardData[1].prop_id, '2', iconScale); if (this.rewardData.length > 2) this.refreshView(this.rewardData[2].prop_id, '3', iconScale); } protected onEnable(): void { this.node.on(Node.EventType.TOUCH_END, this.onClick, this); } protected onDestroy(): void { if (this.itemData) { this.itemData = null; } } protected onDisable(): void { this.node.off(Node.EventType.TOUCH_END, this.onClick, this); } start() { } refreshView(goodId, index = "", iconScale?: number) { let id = goodId let itemData = gg.data.table.getItemData(id) if (!itemData) { console.log('[itemPic] Item 表缺少 id=', id); return; } if (!this.itemData) { this.itemData = new ItemData(itemData.id, 1); } let pingjiKuang = this.node.getChildByName('品级框' + index) let icon = this.node.getChildByName('icon' + index) let suipianNode = this.node.getChildByName('碎片' + index); let spineQuality3 = icon?.getChildByName('紫色'); let spineQuality4 = icon?.getChildByName('橙色'); let spineQuality5 = icon?.getChildByName('红色'); if (this.lbName) this.lbName.string = gg.lang.get(itemData.name);//itemData.name; if (this.lbDesc) this.lbDesc.string = gg.lang.get(itemData.desc); if (spineQuality3) spineQuality3.active = itemData.quality == 3 if (spineQuality4) spineQuality4.active = itemData.quality == 4 if (spineQuality5) spineQuality5.active = false if (pingjiKuang) { applyItemQualityFrame(pingjiKuang.getComponent(SpriteLoad), itemData); } if (suipianNode) { suipianNode.active = itemData.type == 10; } if (icon) { icon.getComponent(SpriteLoad).setSprite(GPath.Item(itemData.icon), GBundle.Items); const scale = iconScale ?? (itemData.type == 10 ? 0.6 : 0.35); icon.setScale(scale, scale, 1); } if (this.node.find("eff")) { let eff = this.node.find("eff"); eff.active = [3, 4].includes(itemData.quality); if (eff.active) { let anim = eff.getComponent(sp.Skeleton); let animName = ""; if (itemData.quality == 3) animName = "1紫色框"; if (itemData.quality == 4) animName = "2橙色框"; if (animName) anim.setAnimation(0, animName, true); } } } onClick() { if (!this.isCanClick) { return; } gg.ui.openPanel(UIID.ItemDetailBox, { data: this.itemData }) } }