Files
heros/assets/script/game/hero/HeroCardComp.ts

78 lines
3.4 KiB
TypeScript

import { _decorator, Color, instantiate, Label, Prefab, ProgressBar, Sprite } 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 { HeroHomeComp } from "../map/HeroHomeComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { smc } from "../common/SingletonModuleComp";
import { HeroInfo } from "../common/config/heroSet";
import { ColorSet } from "../common/config/BoxSet";
import { getUpChipByLv, SlvUp } from "../common/config/RoleSet";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('HeroCardComp')
@ecs.register('HeroCardComp', false)
export class HeroCardComp extends CCComp {
hcc_home: HeroHomeComp = null!;
h_uuid: number = 0;
onLoad() {
oops.message.on("hero_card_show_info", this.check_show, this);
oops.message.on("hero_card_update_info", this.update_data, this);
}
/** 视图层逻辑代码分离演示 */
start() {
this.hcc_home=this.node.parent.parent.parent.parent.getComponent(HeroHomeComp);
// console.log("hero_card hcc_home",this.hcc_home)
}
show_info(){
this.hcc_home.hero_show(this.h_uuid)
oops.message.dispatchEvent("hero_card_show_info",{uuid:this.h_uuid})
}
check_show(event: string, args: any){
// console.log("hero_card check_show",args)
this.show_bg(false)
if(args.uuid==this.h_uuid){
this.show_bg(true)
}
}
show_bg(val:boolean){
// this.node.getChildByName("show").active=val
}
update_data(){
let slv = this.node.getChildByName("slv")
this.node.getChildByName("lv").getComponent(Label).string=smc.heros[this.h_uuid].lv.toString()+"级"
// if(smc.heros[this.h_uuid].slv==0){
// this.node.getChildByName("lock").active=true
// slv.active=false
// }else{
// slv.active=true
// this.node.getChildByName("lock").active=false
// slv.getChildByName("slv").getComponent(Label).string=smc.heros[this.h_uuid].slv.toString()
// }
let lvneed=(getUpChipByLv(smc.heros[this.h_uuid].lv)-HeroInfo[this.h_uuid].lvexp)*smc.heros[this.h_uuid].lv
let lvnum=smc.heros[this.h_uuid].num
this.node.getChildByName("up").active=lvnum>=lvneed
this.node.getChildByName("need").getComponent(Label).string = lvneed.toString()
this.node.getChildByName("num").getComponent(Label).string = lvnum.toString()
this.node.getChildByName("bar").getComponent(ProgressBar).progress = lvnum/lvneed
this.node.getChildByName("g1").active=HeroInfo[this.h_uuid].quality==1
this.node.getChildByName("g2").active=HeroInfo[this.h_uuid].quality==2
this.node.getChildByName("g3").active=HeroInfo[this.h_uuid].quality==3
}
call_hero(uuid:number){
var path = "game/heros/uiheros/"+HeroInfo[uuid].path;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = this.node.getChildByName("Mask")
}
clear_hero(){
this.node.getChildByName("Mask").destroyAllChildren()
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}