| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import { _decorator, Component, Node, Sprite, SpriteFrame, EventHandler } from 'cc';
- import { DataSystem } from '../../core/data/DataSystem';
- import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
- import { Hero_Client } from '../../hero/UserHeroData';
- import { RecruitData } from '../RecruitData';
- const { ccclass, property } = _decorator;
- /**
- * 心愿武将item
- * @author 郑聂华
- */
- @ccclass('WishItem')
- export class WishItem extends Component {
- @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" }) res: ResourceLoader = null;
- @property({ type: Sprite, displayName: "品质框", tooltip: "品质框" }) imgQuality: Sprite = null;
- @property({ type: Sprite, displayName: "头像", tooltip: "头像" }) imgHero: Sprite = null;
- @property({ type: Node, displayName: "星级", tooltip: "星级" }) stars: Node[] = [];
- @property({ type: Sprite, displayName: "阵营", tooltip: "阵营" }) imgCamp: Sprite = null;
- @property({ type: Node, displayName: "已上阵", tooltip: "已上阵" }) hasFormation: Node = null;
- @property({ type: Node, displayName: "选中", tooltip: "选中" }) select: Node = null;
- public selectBack: EventHandler;
- private general_id: number = 0;
- private index: number;
- async init(general: Hero_Client, index: number, isHasFormation: boolean) {
- this.index = index;
- this.general_id = general.id;
- this.hasFormation.active = isHasFormation;
- this.setStar(general.initStar);
- //DataSystem.getData(RecruitData).curWishId == this.general_id && this.selectBack && this.selectBack.emit([this.general_id, this.index, DataSystem.getData(RecruitData).wishHeroRate + ""]);
- this.imgQuality.spriteFrame = await this.res.load<SpriteFrame>("images/general/texture/zy_head" + general.color + "/spriteFrame", SpriteFrame);
- this.imgHero.spriteFrame = await this.res.load<SpriteFrame>("images/general/texture/head_img/" + general.hero_res + "/spriteFrame", SpriteFrame);
- this.imgCamp.spriteFrame = await this.res.load<SpriteFrame>("images/general/texture/icon_camp_" + general.camp + "/spriteFrame", SpriteFrame);
- }
- start() {
- DataSystem.getData(RecruitData).curWishId == this.general_id && this.selectBack && this.selectBack.emit([this.general_id, this.index, DataSystem.getData(RecruitData).wishHeroRate + ""]);
- }
- setStar(starNum: number) {
- for (let i = 0; i < this.stars.length; i++) {
- this.stars[i].active = (i + 1) <= starNum;
- }
- }
- onClickSelectBtn() {
- let rate = DataSystem.getData(RecruitData).curWishId == this.general_id ? DataSystem.getData(RecruitData).wishHeroRate + "" : "";
- this.selectBack && this.selectBack.emit([this.general_id, this.index, rate]);
- }
- }
|