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'; 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[] = [], moduleType: number = 0) { this.goodId = goodId this.rewardData = arr this.refreshView(this.goodId, '', moduleType) if (this.rewardData.length > 1) this.refreshView(this.rewardData[1].prop_id, '2', moduleType); if (this.rewardData.length > 2) this.refreshView(this.rewardData[2].prop_id, '3', moduleType); } 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 = "", moduleType) { let id = goodId console.log(id); let itemData = gg.data.table.getItemData(id) 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); if (this.lbName) this.lbName.string = gg.lang.get(itemData.name);//itemData.name; if (this.lbDesc) this.lbDesc.string = gg.lang.get(itemData.desc1);//itemData.desc1; if (icon) { if (icon.getChildByName('紫色') && icon.getChildByName('橙色')) { icon.getChildByName('紫色').active = false icon.getChildByName('橙色').active = false } } if(moduleType == 1){ //签到 pingjiKuang.getComponent(SpriteLoad).setSprite(GPath.PingjiKuang("签到品质" + itemData.quality), GBundle.Comm2); }else{ pingjiKuang.getComponent(SpriteLoad).setSprite(GPath.PingjiKuang("品质" + itemData.quality), GBundle.Comm2); } if (itemData.quality == 3) { if (icon) { if (icon.getChildByName('紫色') && icon.getChildByName('橙色')) { icon.getChildByName('紫色').active = true icon.getChildByName('橙色').active = false } } } else if (itemData.quality == 4) { if (icon) { if (icon.getChildByName('紫色') && icon.getChildByName('橙色')) { icon.getChildByName('紫色').active = false icon.getChildByName('橙色').active = true } } } if (suipianNode) { suipianNode.active = itemData.type == 10; } icon.getComponent(SpriteLoad).setSprite(GPath.Item(itemData.icon), GBundle.Items); 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; } console.log("执行了点击事件"); console.log("点击了物品"+JSON.stringify(this.itemData)); gg.ui.openPanel(UIID.ItemDetailBox, { data: this.itemData }) } }