PVPCardItem.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { _decorator, Component, SpriteFrame, Sprite, Label, Node, ImageAsset, Texture2D } from 'cc';
  2. import { DataSystem } from '../core/data/DataSystem';
  3. import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
  4. import { BitmapFont } from '../core/ui/BitmapFont';
  5. import { ConfigData } from '../data/ConfigData';
  6. import { ISJSB } from '../data/jsb/platform';
  7. import { PVPCardData } from './PVP';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('PVPCardItem')
  10. export class PVPCardItem extends Component {
  11. @property({ type: ResourceLoader, tooltip: "资源加载器" }) res: ResourceLoader;
  12. @property({ tooltip: "名字", type: Label })
  13. public nameLabel: Label;
  14. @property({ tooltip: "名字背景", type: Sprite })
  15. public nameBg: Sprite;
  16. @property({ tooltip: "所有名字背景", type: [SpriteFrame] })
  17. public nameBgList: SpriteFrame[] = [];
  18. @property({ tooltip: "品质背景", type: Sprite })
  19. public campBg: Sprite;
  20. @property({ tooltip: "所有品质背景", type: [SpriteFrame] })
  21. public campBgList: SpriteFrame[] = [];
  22. @property({ tooltip: "阵营图标", type: Sprite })
  23. public campIcon: Sprite;
  24. @property({ tooltip: "所有阵营图标", type: [SpriteFrame] })
  25. public campIconList: SpriteFrame[] = [];
  26. @property({ tooltip: "品质框", type: Sprite })
  27. public qualityBorder: Sprite;
  28. @property({ tooltip: "所有品质框", type: [SpriteFrame] })
  29. public qualityBorderList: SpriteFrame[] = [];
  30. @property({ tooltip: "武将原画", type: Sprite })
  31. public body: Sprite;
  32. @property({ tooltip: "星级", type: BitmapFont })
  33. public starBitmapLabel: BitmapFont;
  34. @property({ type: Node, tooltip: "头像组" }) headGroup: Node;
  35. @property({ tooltip: "头像", type: Sprite }) head: Sprite;
  36. private generalConfig: any;
  37. public async setData(data: PVPCardData) {
  38. this.generalConfig = DataSystem.getData(ConfigData)["general"];
  39. let c = this.generalConfig[data.id];
  40. this.nameLabel.string = c.name;
  41. this.nameBg.spriteFrame = this.nameBgList[parseInt(c.color) - 1];
  42. this.campBg.spriteFrame = this.campBgList[parseInt(c.color) - 1];
  43. this.campIcon.spriteFrame = this.campIconList[parseInt(c.camp) - 1];
  44. this.qualityBorder.spriteFrame = this.qualityBorderList[parseInt(c.color) - 1];
  45. this.body.spriteFrame = await this.getComponent(ResourceLoader).load(`images/general/texture/hero_img/${c.hero_res}/spriteFrame`, SpriteFrame);
  46. let starString = "";
  47. for (let i = 0; i < data.star; i++) {
  48. starString += "0";
  49. }
  50. this.starBitmapLabel.string = starString;
  51. if (!!this.headGroup && !!data.url && ISJSB()) {
  52. let img = await this.res.loadRemote<ImageAsset>(data.url, { ext: ".png" });
  53. this.headGroup.active = true;
  54. const spriteFrame = new SpriteFrame();
  55. const texture = new Texture2D();
  56. texture.image = img;
  57. spriteFrame.texture = texture;
  58. this.head.spriteFrame = spriteFrame;
  59. }
  60. }
  61. }