WishItem.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { _decorator, Component, Node, Sprite, SpriteFrame, EventHandler } from 'cc';
  2. import { DataSystem } from '../../core/data/DataSystem';
  3. import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
  4. import { Hero_Client } from '../../hero/UserHeroData';
  5. import { RecruitData } from '../RecruitData';
  6. const { ccclass, property } = _decorator;
  7. /**
  8. * 心愿武将item
  9. * @author 郑聂华
  10. */
  11. @ccclass('WishItem')
  12. export class WishItem extends Component {
  13. @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" }) res: ResourceLoader = null;
  14. @property({ type: Sprite, displayName: "品质框", tooltip: "品质框" }) imgQuality: Sprite = null;
  15. @property({ type: Sprite, displayName: "头像", tooltip: "头像" }) imgHero: Sprite = null;
  16. @property({ type: Node, displayName: "星级", tooltip: "星级" }) stars: Node[] = [];
  17. @property({ type: Sprite, displayName: "阵营", tooltip: "阵营" }) imgCamp: Sprite = null;
  18. @property({ type: Node, displayName: "已上阵", tooltip: "已上阵" }) hasFormation: Node = null;
  19. @property({ type: Node, displayName: "选中", tooltip: "选中" }) select: Node = null;
  20. public selectBack: EventHandler;
  21. private general_id: number = 0;
  22. private index: number;
  23. async init(general: Hero_Client, index: number, isHasFormation: boolean) {
  24. this.index = index;
  25. this.general_id = general.id;
  26. this.hasFormation.active = isHasFormation;
  27. this.setStar(general.initStar);
  28. //DataSystem.getData(RecruitData).curWishId == this.general_id && this.selectBack && this.selectBack.emit([this.general_id, this.index, DataSystem.getData(RecruitData).wishHeroRate + ""]);
  29. this.imgQuality.spriteFrame = await this.res.load<SpriteFrame>("images/general/texture/zy_head" + general.color + "/spriteFrame", SpriteFrame);
  30. this.imgHero.spriteFrame = await this.res.load<SpriteFrame>("images/general/texture/head_img/" + general.hero_res + "/spriteFrame", SpriteFrame);
  31. this.imgCamp.spriteFrame = await this.res.load<SpriteFrame>("images/general/texture/icon_camp_" + general.camp + "/spriteFrame", SpriteFrame);
  32. }
  33. start() {
  34. DataSystem.getData(RecruitData).curWishId == this.general_id && this.selectBack && this.selectBack.emit([this.general_id, this.index, DataSystem.getData(RecruitData).wishHeroRate + ""]);
  35. }
  36. setStar(starNum: number) {
  37. for (let i = 0; i < this.stars.length; i++) {
  38. this.stars[i].active = (i + 1) <= starNum;
  39. }
  40. }
  41. onClickSelectBtn() {
  42. let rate = DataSystem.getData(RecruitData).curWishId == this.general_id ? DataSystem.getData(RecruitData).wishHeroRate + "" : "";
  43. this.selectBack && this.selectBack.emit([this.general_id, this.index, rate]);
  44. }
  45. }