78 lines
2.8 KiB
TypeScript
78 lines
2.8 KiB
TypeScript
import { _decorator, Label, Node, ProgressBar } 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 { GameEvent } from "../common/config/GameEvent";
|
|
import { HeroViewComp } from "../hero/HeroViewComp";
|
|
import { HeroModelComp } from "../hero/HeroModelComp";
|
|
import { MasterModelComp } from "../hero/MasterModel";
|
|
import { FriendModelComp } from "../hero/FriendModel";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('BarCompComp')
|
|
@ecs.register('BarComp', false)
|
|
export class BarCompComp extends CCComp {
|
|
hero_bar:Node = null;
|
|
friend_bar:Node = null;
|
|
boss_bar:Node = null;
|
|
hero:HeroViewComp = null;
|
|
friend:HeroViewComp = null;
|
|
boss:HeroViewComp = null;
|
|
/** 视图层逻辑代码分离演示 */
|
|
protected onLoad(): void {
|
|
this.on(GameEvent.FightReady,this.readay,this)
|
|
}
|
|
start() {
|
|
// this.hero_bar = this.node.getChildByName("bar");
|
|
// this.friend_bar = this.node.getChildByName("fbar");
|
|
// this.boss_bar = this.node.getChildByName("bar");
|
|
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
|
// this.on(ModuleEvent.Cmd, this.onHandler, this);
|
|
}
|
|
private readay(){
|
|
this.hero_bar.active = this.get_hero()
|
|
this.friend_bar.active = this.get_friend()
|
|
}
|
|
|
|
private get_hero(){
|
|
let heros = ecs.query(ecs.allOf(MasterModelComp))
|
|
if(heros.length > 0){
|
|
this.hero = heros[0].get(HeroViewComp)
|
|
return true
|
|
}else{
|
|
this.hero = null
|
|
return false
|
|
}
|
|
}
|
|
private get_friend(){
|
|
let friend = ecs.query(ecs.allOf(FriendModelComp))
|
|
if(friend.length > 0){
|
|
this.friend = friend[0].get(HeroViewComp)
|
|
return true
|
|
}else{
|
|
this.friend = null
|
|
return false
|
|
}
|
|
}
|
|
update_bar(){
|
|
if(!this.get_hero()) return
|
|
let hp_bar = this.hero_bar.getChildByName("hp").getChildByName("bar").getComponent(ProgressBar)
|
|
let ap_bar = this.hero_bar.getChildByName("ap").getChildByName("val").getComponent(Label)
|
|
let ap =this.hero.ap+"("+this.hero.ap_ur+")"
|
|
hp_bar.progress = this.hero.hp/this.hero.hp_max
|
|
ap_bar.string = ap.toString()
|
|
}
|
|
/** 全局消息逻辑处理 */
|
|
// private onHandler(event: string, args: any) {
|
|
// switch (event) {
|
|
// case ModuleEvent.Cmd:
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |