import { _decorator, Component, Node, Sprite, Label, SpriteFrame, RichText, utils, ImageAsset, Texture2D } from 'cc'; import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils'; import { Utils } from '../core/utils/Utils'; import { g } from '../Data/g'; import { ISJSB } from '../Data/platform'; import { FsUtils } from '../FsUtils/FsUtils'; const { ccclass, property } = _decorator; /**战斗记录 */ @ccclass('BattleLogItem') export class BattleLogItem extends Component { @property({ type: Sprite, tooltip: "好友头像" }) headSprite: Sprite; @property({ type: Label, tooltip: "时间信息文本" }) timeInfoLabel: Label; @property({ type: RichText, tooltip: "玩家文本" }) userNameLabel: RichText; start() { } public async setData(data: any) { if (ISJSB) { let avator = ''; if (data.attackUserID == g.userData.id) { avator = data.beAttackUserAvator; } else { avator = data.attackUserAvator; } if (avator) { let img = await ResourcesUtils.loadRemote(avator, { ext: ".png" }, this); const spriteFrame = new SpriteFrame(); const texture = new Texture2D(); texture.image = img; spriteFrame.texture = texture; this.headSprite.spriteFrame = spriteFrame; } } this.timeInfoLabel.string = FsUtils.formatBattleTime(Date.now() / 1000 - data.createTime) + '前'; if (g.userData.id == data.attackUserID) {//我是挑战者 let colorStr = ` ${(data.win == 1 ? '获胜了' : '战败了')} `; this.userNameLabel.string = `< color=#AA343D > 我挑战了 < color=#ff0000 > [${FsUtils.beautySub(data.beAttackUserName, 4)}] < /color>的队伍, ${colorStr} `; } else { let colorStr = ` ${(data.win == 1 ? '获胜了' : '战败了')} `; this.userNameLabel.string = `[${FsUtils.beautySub(data.attackUserName, 4)}]攻击了你的队伍,${colorStr} `; } } }