import { _decorator, Color, Component, instantiate, Label, Node } from 'cc'; import { GEvent } from 'db://assets/mx/module/event/GEvent'; import { UIBase } from 'db://assets/mx/module/ui/UIBase'; const { ccclass, property } = _decorator; @ccclass('DingdanScript') export class DingdanScript extends UIBase { descName:Label labItemNode:Node descView:Node start() { //更新任务 GEvent.Ins.on(GEvent.OnTaskUpdate, this.onTaskUpdate, this) GEvent.Ins.on(GEvent.UpdateItemNum, this.UpdateItemNum, this) this.node.getChildByName('箭头').active = true this.descName = this.node.getChildByName('name').getComponent(Label) this.labItemNode = this.node.getChildByName('labItem') this.descView = this.node.getChildByName('descView') this.labItemNode.active =false //创建物品 this.descName.string = gg.task.Curent.name this.createView() } UpdateItemNum(){ if(this.node.getChildByName('收集完成').active){ return } let para2 = gg.task.Curent.para2 + '' if(para2 == ''){ return } let array = para2.split("|") for(let i = 0; i < array.length; i++){ let item = this.descView.children[i] // let name = item.getChildByName('goodName') let num = item.getChildByName('num') let goodData= gg.data.table.getItemData(Number(array[i])) if(goodData){ let goodNum = gg.data.getItemNum(Number(array[i])); // name.getComponent(Label).string = goodData.name if(Number(array[i]) == 1){ goodNum = 0 } num.getComponent(Label).string = goodNum+'/1' if(goodNum>=1){ num.getComponent(Label).outlineColor = new Color().fromHEX('#4AD514') }else{ num.getComponent(Label).outlineColor = new Color().fromHEX('#EE1526') } } } } createView(){ // let para2 = gg.task.Curent.para2 + '' let array = para2.split("|") //创建item for(let i = 0; i < array.length; i++){ let item = instantiate(this.labItemNode) item.active = true item.parent = this.descView //物品名字+数字 let name = item.getChildByName('goodName') let num = item.getChildByName('num') let goodData= gg.data.table.getItemData(Number(array[i])) if(goodData){ let goodNum = gg.data.getItemNum(Number(array[i])); if(Number(array[i]) == 1){ goodNum = 0 } name.getComponent(Label).string = goodData.name num.getComponent(Label).string = goodNum+'/1' if(goodNum>=1){ num.getComponent(Label).outlineColor = new Color().fromHEX('#4AD514') }else{ num.getComponent(Label).outlineColor = new Color().fromHEX('#EE1526') } } } } onTaskUpdate(){ // //全部展示为1 for(let i = 0; i < this.descView.children.length; i++){ let item = this.descView.children[i] let num = item.getChildByName('num') num.getComponent(Label).string = '1/1' num.getComponent(Label).outlineColor = new Color().fromHEX('#4AD514') } this.node.getChildByName('箭头').active = false this.node.getChildByName('收集完成').active = true } }