| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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<ImageAsset>(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 = `<color=${(data.win == 1 ? "#36E20B" : "#ff0000")}> ${(data.win == 1 ? '获胜了' : '战败了')} </color>`;
- this.userNameLabel.string = `< color=#AA343D > 我挑战了 < color=#ff0000 > [${FsUtils.beautySub(data.beAttackUserName, 4)}] < /color>的队伍,</color > ${colorStr} </color>`;
- } else {
- let colorStr = `<color=${(data.win == 1 ? "#36E20B" : "#ff0000")}> ${(data.win == 1 ? '获胜了' : '战败了')} </color>`;
- this.userNameLabel.string = `<color=#ff0000>[${FsUtils.beautySub(data.attackUserName, 4)}]<color=#AA343D>攻击了你的队伍,</color>${colorStr} </color>`;
- }
- }
- }
|