import { _decorator, Label, resources, Sprite, SpriteAtlas } from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { smc } from "../common/SingletonModuleComp"; import { HeroModelComp } from "./HeroModelComp"; import { HeroViewComp } from "./HeroViewComp"; import { HeroInfo, HeroPos, HeroSet } from "../common/config/heroSet"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('HeroInfoCompComp') @ecs.register('HeroInfoComp', false) export class HeroInfoCompComp extends CCComp { @property c_id:number=0 @property is_Change:boolean=false has_hero:boolean=false /** 视图层逻辑代码分离演示 */ start() { // var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象 // this.on(ModuleEvent.Cmd, this.onHandler, this); this.init() } init(){ this.has_hero=false } update(dt: number): void { if(!smc.mission.play) return this.update_info() } update_info(){ let heros=ecs.query(ecs.allOf(HeroModelComp)) this.has_hero=false this.node.getChildByName("info").getChildByName("ap").getChildByName("num").getComponent(Label).string="" this.node.getChildByName("info").getChildByName("hp").getChildByName("num").getComponent(Label).string="" this.node.getChildByName("name").getComponent(Label).string="无英雄" const sprite = this.node.getChildByName("mask").getChildByName("icon").getComponent(Sprite); // sprite.spriteFrame = //需要添加默认头像 for(let hero of heros){ let info=hero.get(HeroViewComp) if(info.node.position.x==HeroPos[this.c_id].pos.x){ this.has_hero=true this.node.getChildByName("info").getChildByName("ap").getChildByName("num").getComponent(Label).string=info.ap.toString() this.node.getChildByName("info").getChildByName("hp").getChildByName("num").getComponent(Label).string=info.hp.toString() this.node.getChildByName("name").getComponent(Label).string=HeroInfo[info.hero_uuid].name var icon_path = "game/heros/herois" resources.load(icon_path, SpriteAtlas, (err: any, atlas) => { const sprite = this.node.getChildByName("mask").getChildByName("icon").getComponent(Sprite); sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[info.hero_uuid].path); }); } } // if(this.is_Change){ // this.node.getChildByName("change").active=this.has_hero // this.node.getChildByName("select").active=!this.has_hero // } } /** 全局消息逻辑处理 */ // private onHandler(event: string, args: any) { // switch (event) { // case ModuleEvent.Cmd: // break; // } // } /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ reset() { this.node.destroy(); } }