BattleLogItem.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { _decorator, Component, Node, Sprite, Label, SpriteFrame, RichText, utils, ImageAsset, Texture2D } from 'cc';
  2. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  3. import { Utils } from '../core/utils/Utils';
  4. import { g } from '../Data/g';
  5. import { ISJSB } from '../Data/platform';
  6. import { FsUtils } from '../FsUtils/FsUtils';
  7. const { ccclass, property } = _decorator;
  8. /**战斗记录 */
  9. @ccclass('BattleLogItem')
  10. export class BattleLogItem extends Component {
  11. @property({ type: Sprite, tooltip: "好友头像" })
  12. headSprite: Sprite;
  13. @property({ type: Label, tooltip: "时间信息文本" })
  14. timeInfoLabel: Label;
  15. @property({ type: RichText, tooltip: "玩家文本" })
  16. userNameLabel: RichText;
  17. start() {
  18. }
  19. public async setData(data: any) {
  20. if (ISJSB) {
  21. let avator = '';
  22. if (data.attackUserID == g.userData.id) {
  23. avator = data.beAttackUserAvator;
  24. } else {
  25. avator = data.attackUserAvator;
  26. }
  27. if (avator) {
  28. let img = await ResourcesUtils.loadRemote<ImageAsset>(avator, { ext: ".png" }, this);
  29. const spriteFrame = new SpriteFrame();
  30. const texture = new Texture2D();
  31. texture.image = img;
  32. spriteFrame.texture = texture;
  33. this.headSprite.spriteFrame = spriteFrame;
  34. }
  35. }
  36. this.timeInfoLabel.string = FsUtils.formatBattleTime(Date.now() / 1000 - data.createTime) + '前';
  37. if (g.userData.id == data.attackUserID) {//我是挑战者
  38. let colorStr = `<color=${(data.win == 1 ? "#36E20B" : "#ff0000")}> ${(data.win == 1 ? '获胜了' : '战败了')} </color>`;
  39. this.userNameLabel.string = `< color=#AA343D > 我挑战了 < color=#ff0000 > [${FsUtils.beautySub(data.beAttackUserName, 4)}] < /color>的队伍,</color > ${colorStr} </color>`;
  40. } else {
  41. let colorStr = `<color=${(data.win == 1 ? "#36E20B" : "#ff0000")}> ${(data.win == 1 ? '获胜了' : '战败了')} </color>`;
  42. this.userNameLabel.string = `<color=#ff0000>[${FsUtils.beautySub(data.attackUserName, 4)}]<color=#AA343D>攻击了你的队伍,</color>${colorStr} </color>`;
  43. }
  44. }
  45. }