import RoundBox from "../../Script/module/Tool/RoundBox"; import NumberToImage from "../../Script/NumberToImage"; const { ccclass, property } = cc._decorator; @ccclass export default class CareerItem extends cc.Component { /**数据 */ public data: any = null; /**索引 0表示第一项*/ public itemIndex: number = 0; @property(cc.SpriteFrame) defaultsprite: cc.SpriteFrame = null; @property(cc.SpriteAtlas) UI: cc.SpriteAtlas = null; @property(cc.SpriteAtlas) UI2: cc.SpriteAtlas = null; randerChildren: any; /**数据改变时调用 */ public dataChanged() { this.randerChildren = []; // if (this.data == undefined) { // this.node.active = false; // return; // } // let useravatarIcon = this.data.useravatarIcon; // useravatarIcon = "kuang_" + (parseInt(useravatarIcon) + 1); // this.node.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = // this.ui.getSpriteFrame(useravatarIcon); // this.data.username = cc.fx.GameTool.subName(this.data.username, 7); // let name = this.data.username; // if (name == "user") name = "匿名玩家"; for (let i = 4; i < 12; i++) { this.node.children[i].getChildByName("name").getComponent(cc.Label).string = ""; this.node.children[i].getChildByName("level").getComponent(cc.Label).string = ""; this.node.children[i].getChildByName("mask").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = null; this.node.children[i].getChildByName("kong").active = true; } if (this.data != undefined) { this.node.opacity = 255; this.node.getChildByName("rank").getComponent(cc.Label).string = this.data.count + ""; this.node.getChildByName("cityName").getComponent(cc.Sprite).spriteFrame = this.UI2.getSpriteFrame(this.data.name); if (this.randerChildren.length == 0) { this.randerChildren = []; let length = this.data.rankingData.length + 4; if (length > 12) length = 12; for (let i = 4; i < length; i++) { this.randerChildren.push(this.node.children[i]); let username = cc.fx.GameTool.subName(this.data.rankingData[i - 4].username, 7); if (username == "user") username = "匿名玩家"; // console.log("用户名字:", username); this.node.children[i].getChildByName("kong").active = false; this.node.children[i].getChildByName("name").getComponent(cc.Label).string = username + ""; this.node.children[i].getChildByName("level").getComponent(cc.Label).string = this.data.rankingData[i - 4].addLevel; if (this.data.rankingData[i - 4].useravatar == "" || this.data.rankingData[i - 4].useravatar == null || this.data.rankingData[i - 4].useravatar == undefined ) { // this.firstRender.children[i].getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.defaultsprite; } else if (this.data.rankingData[i - 4].useravatar == "0" || this.data.rankingData[i - 4].useravatar == "1" || this.data.rankingData[i - 4].useravatar == "2" || this.data.rankingData[i - 4].useravatar == "3" || this.data.rankingData[i - 4].useravatar == "4" || this.data.rankingData[i - 4].useravatar == "5" || this.data.rankingData[i - 4].useravatar == "6" || this.data.rankingData[i - 4].useravatar == "7" || this.data.rankingData[i - 4].useravatar == "8" || this.data.rankingData[i - 4].useravatar == "9" || this.data.rankingData[i - 4].useravatar == "10") { let useravatar = this.data.rankingData[i - 4].useravatar; let useravatarTemp = "icon_" + useravatar; // console.log("头像名称", useravatarTemp, "用户名字:", username); this.node.children[i].getChildByName("mask").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.UI.getSpriteFrame(useravatarTemp); } else this.setPic(this.data.rankingData[i - 4].useravatar, this.node.children[i].getChildByName("mask").getChildByName("icon")); } } } else { this.node.opacity = 0; } } public setPic(url, node) { // this.node.getChildByName("pic").getChildByName("icon").active = false; // this.node.getChildByName("pic").active = false; var self = this; // let url = this.data.useravatar; cc.assetManager.loadRemote(url, { ext: '.png' }, (err, texture: cc.Texture2D) => { if (texture) { // this.node.getChildByName("pic").active = true; var sprite = node.getComponent(cc.Sprite); sprite.spriteFrame = new cc.SpriteFrame(texture); } else { // console.log("加载图片失败" + url); } }) } }