/************************************************************************************ * FileName : HeroItem.ts * Description : 英雄选择界面英雄item * Version : v1.0.0 * CreateTime : 2024-10-22 09:55:13 * Author : * Copyright (c) since 2024 * ============================================================== * Method Description: * * ============================================================== ************************************************************************************/ import { _decorator, Component, Node, Label, SpriteFrame, Sprite, Prefab, instantiate, v3, sp } from 'cc'; import {resLoader} from "db://assets/core_tgx/base/utils/ResLoader"; import {ModuleDef} from "db://assets/scripts/ModuleDef"; import {areanMgr} from "db://assets/module_arean/scripts/AreanManager"; import {UserMgr} from "db://assets/module_basic/scripts/UserMgr"; import { IHeroCfg } from '../../module_basic/shared/configs/interface/IHeroCfg'; const { ccclass, property } = _decorator; @ccclass('ChooseHeroItem') export class ChooseHeroItem extends Component { // 英雄图像 @property(Node) heroIcon: Node = null; @property(Label) heroName: Label = null; @property(Node) choose: Node = null; // 英雄唯一标识 private _heroId : number = null; private _fun : Function = null; public initData(data: IHeroCfg,callBack : Function) : void{ this._heroId = data.id; this._fun = callBack; this._initIcon(data.id); this._initName(data.name); } private _initIcon(id : number) : void{ // let sp : SpriteFrame = resLoader.getSpriteFrame(`res/heroImg/${id}`,ModuleDef.Arean); // if(sp) this.heroIcon.getComponent(Sprite).spriteFrame = sp; let localHeroData = areanMgr.cfgMgr.HeroDatas.getAllDataMap(); let curHeroData = localHeroData.get(id); if(curHeroData){ let skin = curHeroData.skinRes[0]; let skinId = areanMgr.cfgMgr.SkinData.getData(skin).icon resLoader.load(ModuleDef.Arean,`res/Prefebs/heroSpine/${skinId}`,(err: Error, prefab: Prefab) => { if(err){ console.error(err); return; }else { let spineNode = instantiate(prefab); this.heroIcon.destroyAllChildren(); this.heroIcon.addChild(spineNode); spineNode.scale = v3(0.8,0.8,1); spineNode.position = v3(0,-60,0); spineNode.getComponent(sp.Skeleton).animation = null; } }) }else { console.error(`${UserMgr.inst.userInfo.heroId}英雄数据不存在`); } } private _initName(name1 : string) : void { this.heroName.string = name1; } public updateChooseActive(active : boolean) : void{ this.choose.active = active; } public clickHero() : void{ this._fun && this._fun(this._heroId); this.choose.active = true; } }