ChartBookItem.ts 1006 B

123456789101112131415161718192021222324252627
  1. import { _decorator, Component, Label, Sprite, color, SpriteFrame } from 'cc';
  2. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  3. import { g } from '../Data/g';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('ChartBookItem')
  6. export class ChartBookItem extends Component {
  7. @property({ type: Sprite, tooltip: "神将图片" })
  8. generalSprite: Sprite;
  9. @property({ type: Label, tooltip: "神将等级文本" })
  10. lvLabel: Label;
  11. @property({ type: Label, tooltip: "神将名字文本" })
  12. nameLabel: Label;
  13. public async setData(data: any) {
  14. let img: SpriteFrame = await ResourcesUtils.load("Roles/" + data.lv + "/spriteFrame", SpriteFrame, this.node);
  15. if (img) {
  16. this.generalSprite.spriteFrame = img;
  17. this.lvLabel.string = data.lv;
  18. this.nameLabel.string = data.name;
  19. if (g.userData.lv < data.lv) {
  20. this.generalSprite.color = color(0, 0, 0, 255);
  21. }
  22. }
  23. }
  24. }