/************************************************************************************ * FileName : HeroItem.ts * Description : * Version : v1.0.0 * CreateTime : 2024-10-22 09:55:13 * Author : * Copyright (c) since 2024 * ============================================================== * Method Description: * * ============================================================== ************************************************************************************/ import { _decorator, Component, Node, Label, Prefab, instantiate, v3, sp } from 'cc'; import {resLoader} from "db://assets/core_tgx/base/utils/ResLoader"; import {ModuleDef} from "db://assets/scripts/ModuleDef"; import {IServerHeroData} from "db://assets/module_basic/shared/protocols/public/arean/AreanTypeDef"; import {areanMgr} from "db://assets/module_arean/scripts/AreanManager"; import {UserMgr} from "db://assets/module_basic/scripts/UserMgr"; import {tgxAudioMgr} from "db://assets/core_tgx/tgx"; import { EMusicDefine } from '../../module_basic/scripts/MusicDefine'; import { IHeroCfg } from '../../module_basic/shared/configs/interface/IHeroCfg'; const { ccclass, property } = _decorator; @ccclass('HeroItem') export class HeroItem extends Component { // 英雄图像 @property(Node) heroIcon: Node = null; @property(Label) heroName: Label = null; @property(Node) heroType: Node = null; @property(Node) frame: Node = null; @property(Node) choose: Node = null; @property(Node) mask: Node = null; // 英雄唯一标识 private _heroId : number = null; private _fun : Function = null; private _heroData : IHeroCfg = null; public get heroData() : IHeroCfg{ return this._heroData; } public initData(data: IHeroCfg,isHave : IServerHeroData,callBack : Function,chooseHeroId : number,heroId : number) : void{ this._heroId = heroId; if(this._heroId !== -1){ this._heroData = data; this._fun = callBack; this._initIcon(data.id); this._initName(data.name); this._updateMask(isHave); this._updateKaung(chooseHeroId === data.id); } } private _updateMask(isHave : IServerHeroData) : void{ this.mask.active = !isHave; } private _initIcon(id : number) : void{ // let res = `res/heroImg/${id}`; // let sp : SpriteFrame = resLoader.getSpriteFrame(res,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; let self = this; resLoader.load(ModuleDef.Arean,`res/Prefebs/heroSpine/${skinId}`,(err: Error, prefab: Prefab) => { if(err){ console.error(err); return; }else { let spineNode = instantiate(prefab); self.heroIcon.destroyAllChildren(); self.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(name : string) : void { // let skinData = CommonFun.getInstance().checkHeroDefaultSkin(this._heroData); this.heroName.string = this._heroData.name; } public clickHero() : void{ if(this._heroId !== -1){ tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_CLICK); this._fun && this._fun(this._heroId); this._updateKaung(true); } } private _updateKaung(isChoose : boolean) : void{ this.node.getChildByName("kuang").active = isChoose; } }