AllyItem.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { _decorator, Component, Node, Sprite, Label, ImageAsset, SpriteFrame, Texture2D } from 'cc';
  2. import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
  3. import { BitmapFont } from '../../core/ui/BitmapFont';
  4. import { ISJSB } from '../../data/jsb/platform';
  5. import { FriendData } from '../FightData';
  6. const { ccclass, property } = _decorator;
  7. /**盟友Item*/
  8. @ccclass('AllyItem')
  9. export class AllyItem extends Component {
  10. @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" })
  11. res: ResourceLoader = null;
  12. @property({ type: Sprite, displayName: "头像", tooltip: "头像" })
  13. imgHead: Sprite = null;
  14. @property({ type: Label, displayName: "文本昵称", tooltip: "文本昵称" })
  15. txtNickName: Label = null;
  16. @property({ type: BitmapFont, displayName: "文本贡献值", tooltip: "文本贡献值" })
  17. txtDevote: BitmapFont = null;
  18. public async onDataChange(friendData: FriendData, index: number) {
  19. this.txtNickName.string = friendData.nickName;
  20. this.txtDevote.string = `${friendData.contribution}`; //具体值从神台 列表数据中获取
  21. if (ISJSB() && friendData.avator) {
  22. let img = await this.res.loadRemote<ImageAsset>(friendData.avator, { ext: ".png" });
  23. const spriteFrame = new SpriteFrame();
  24. const texture = new Texture2D();
  25. texture.image = img;
  26. spriteFrame.texture = texture;
  27. this.imgHead.spriteFrame = spriteFrame;
  28. }
  29. }
  30. }