import { _decorator, Animation, AnimationClip, Component, instantiate, Label, Node, Prefab, resources, Sprite, SpriteFrame, v3 } from 'cc'; import { oops } from 'db://oops-framework/core/Oops'; import { getHeroList, HeroInfo, HType, HTypeName } from '../common/config/heroSet'; import { smc } from '../common/SingletonModuleComp'; const { ccclass, property } = _decorator; @ccclass('HInfoComp') export class HInfoComp extends Component { h_uuid:number=0 name_node:any=null type_node:any=null ap_node:any=null hp_node:any=null def_node:any=null // 重新定义节点映射,使名称更清晰 // 当前显示的英雄节点数组(7个位置) heroNodes: (Node | null)[] = [null, null, null, null, null, null, null]; // 英雄位置定义 hero_pos:any={ 0:v3(420,-109,0), // 不在屏幕内 1:v3(280,-109,0), 2:v3(140,-109,0), 3:v3(0,-109,0), 4:v3(-140,-109,0), 5:v3(-280,-109,0), 6:v3(-420,-109,0), // 不在屏幕内 } // 位置索引常量 private static center_pos = 3; start() { this.name_node=this.node.getChildByName("hero").getChildByName("hname").getChildByName("name") this.type_node=this.node.getChildByName("hero").getChildByName("hname").getChildByName("type") this.ap_node=this.node.getChildByName("info").getChildByName("base").getChildByName("ap").getChildByName("num") this.hp_node=this.node.getChildByName("info").getChildByName("base").getChildByName("hp").getChildByName("num") this.def_node=this.node.getChildByName("info").getChildByName("base").getChildByName("def").getChildByName("num") this.h_uuid=smc.fight_hero this.update_data(this.h_uuid) } update(deltaTime: number) { } update_data(uuid:number){ this.h_uuid=uuid console.log("[HInfoComp]:update_data",uuid,HeroInfo[uuid],this.node) this.name_node.getComponent(Label).string=HeroInfo[uuid].name this.type_node.getComponent(Label).string=HTypeName[HeroInfo[uuid].type] this.ap_node.getComponent(Label).string=HeroInfo[uuid].ap.toString() this.hp_node.getComponent(Label).string=HeroInfo[uuid].hp.toString() this.def_node.getComponent(Label).string=HeroInfo[uuid].def.toString() this.load_all_hero(uuid) } load_all_hero(uuid:number){ } load_hui(uuid:number,pos_index: number){ var path = "game/heros/"+HeroInfo[uuid].path; var prefab: Prefab = oops.res.get(path, Prefab)!; var node = instantiate(prefab); HeroInfo[uuid] let anm_path=HeroInfo[uuid].path resources.load("game/heros/hero/"+anm_path+"/idle", AnimationClip, (err, clip) => { node.getComponent(Animation).addClip(clip); node.getComponent(Animation).play("idle"); }); node.setPosition(this.hero_pos[pos_index]) } claear_hero(){ for (let i = 0; i < this.heroNodes.length; i++) { if (this.heroNodes[i]) { this.heroNodes[i].destroy(); this.heroNodes[i] = null; } } } next_hero(){ let heros=getHeroList() let index = heros.indexOf(this.h_uuid); index++ if(index==heros.length) index=0 let nextHero = heros[index]; this.update_data(nextHero) } prev_hero(){ let heros=getHeroList() let index = heros.indexOf(this.h_uuid); index-- if(index==-1) index=heros.length-1 let prevHero = heros[index]; this.update_data(prevHero) } close(){ oops.gui.removeByNode(this.node) } reset() { this.node.destroy() } }