61 lines
2.6 KiB
TypeScript
61 lines
2.6 KiB
TypeScript
import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,ProgressBar,resources,Sprite,SpriteAtlas,UITransform,v3 } 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 { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
|
|
import { HeroModelComp } from "../hero/HeroModelComp";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('HCardComp')
|
|
@ecs.register('HCardComp', false)
|
|
export class HCardComp extends CCComp {
|
|
hi: number = 0;
|
|
heros:any = []
|
|
icon:any=[]
|
|
hc_name:any=[]
|
|
ap:any=[]
|
|
hp:any=[]
|
|
life:any=[]
|
|
pw:any=[]
|
|
is_dead:boolean=false
|
|
protected onLoad(): void {
|
|
|
|
|
|
}
|
|
start() {
|
|
this.heros= ecs.query(ecs.allOf(HeroModelComp));
|
|
this.hc_name=this.node.getChildByName("name").getComponent(Label)!
|
|
// this.icon=this.node.getChildByName("icon").getComponent(Sprite)!
|
|
this.hp=this.node.getChildByName("hp").getChildByName("num").getComponent(Label)!
|
|
this.ap=this.node.getChildByName("ap").getChildByName("num").getComponent(Label)!
|
|
this.life=this.node.getChildByName("life").getComponent(ProgressBar)!
|
|
this.pw=this.node.getChildByName("pow").getComponent(ProgressBar)!
|
|
this.hc_name.string= this.heros[this.hi].HeroView.hero_name
|
|
console.log("hcard start")
|
|
}
|
|
protected update(dt: number): void {
|
|
if(this.is_dead) return
|
|
if(this.heros[this.hi].HeroView.is_dead){
|
|
this.node.getChildByName("dead").active=true
|
|
this.node.getChildByName("bg").getComponent(Sprite).grayscale=true
|
|
this.is_dead=true
|
|
}else{
|
|
this.node.getChildByName("dead").active=false
|
|
this.node.getChildByName("bg").getComponent(Sprite).grayscale=false
|
|
this.is_dead=false
|
|
}
|
|
this.hp.string=this.heros[this.hi].HeroView.hp_max
|
|
this.ap.string=this.heros[this.hi].HeroView.ap
|
|
this.life.progress=this.heros[this.hi].HeroView.hp/this.heros[this.hi].HeroView.hp_max
|
|
this.pw.progress=this.heros[this.hi].HeroView.pw/this.heros[this.hi].HeroView.pwm
|
|
|
|
}
|
|
/** 视图对象通过 ecs.Entity.remove(ControllerComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
console.log("hcard reset");
|
|
this.node.destroy();
|
|
}
|
|
} |