import { _decorator, Component, Node, Sprite, Label, ImageAsset, SpriteFrame, Texture2D } from 'cc'; import { JSB } from 'cc/env'; import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils'; import { ConfigData } from '../../Data/ConfigData'; import { RankItemData } from './RankData'; const { ccclass, property } = _decorator; @ccclass('RankItemBest') export class RankItemBest extends Component { @property({ type: Sprite, tooltip: "头像" }) imgHead: Sprite = null; @property({ type: Label, tooltip: "昵称文本" }) txtNickName: Label = null; @property({ type: Label, tooltip: "金额文本" }) txtMoney: Label = null; @property({ type: Label, tooltip: "积分文本" }) txtScore: Label = null; private data: RankItemData; private money: number = 0; public async onDataChange(data: RankItemData, index: number) { this.data = data; if (data == null) { this.txtNickName.string = `暂无玩家`; this.txtScore.string = `积分:-`; this.txtMoney.string = `0元`; return; } let rankCfg = ConfigData.configMap.get("rank"); if (index + 1 <= 100) { if (index + 1 <= 1) { this.money = rankCfg.reward1; } else if (index + 1 <= 2) { this.money = rankCfg.reward2; } else if (index + 1 <= 3) { this.money = rankCfg.reward3; } else if (index + 1 <= 10) { this.money = rankCfg.reward10; } else if (index + 1 <= 30) { this.money = rankCfg.reward30; } else if (index + 1 <= 100) { this.money = rankCfg.reward100; } else { this.money = 0; } } this.txtNickName.string = `${data.nick.length > 6 ? data.nick.slice(0, 5) + "..." : data.nick}`; this.txtScore.string = `积分:${data.score}`; this.txtMoney.string = `${this.money}元`; if (JSB && data.avator != "") { let img = await ResourcesUtils.loadRemote(data.avator, { ext: ".png" }, this); const spriteFrame = new SpriteFrame(); const texture = new Texture2D(); texture.image = img; spriteFrame.texture = texture; this.imgHead.spriteFrame = spriteFrame; } } }