78 lines
2.9 KiB
TypeScript
78 lines
2.9 KiB
TypeScript
import { _decorator, Color, Label, 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 { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { ColorSet, GameSet } from "../common/config/BoxSet";
|
|
import { HeroInfo } from "../common/config/heroSet";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('HeroSelectComp')
|
|
@ecs.register('HeroSelectComp', false)
|
|
export class HeroSelectComp extends CCComp {
|
|
h_uuid: number = 0;
|
|
onLoad() {
|
|
oops.message.on("hero_set_select", this.check_show, this);
|
|
oops.message.on("hero_card_update_info", this.update_data, this);
|
|
}
|
|
/** 视图层逻辑代码分离演示 */
|
|
start() {
|
|
if(smc.fight_heros.indexOf(this.h_uuid)>=0){
|
|
this.show_bg(true)
|
|
}else{
|
|
this.show_bg(false)
|
|
}
|
|
}
|
|
select(){
|
|
if(smc.fight_heros.indexOf(this.h_uuid)>=0){
|
|
smc.fight_heros.splice(smc.fight_heros.indexOf(this.h_uuid),1)
|
|
this.show_bg(false)
|
|
oops.message.dispatchEvent("hero_card_cancel_select",{uuid:this.h_uuid})
|
|
return
|
|
}
|
|
if(smc.fight_heros.length>= GameSet.HERO_NUM){
|
|
oops.gui.toast(`英雄数量不能超过 ${GameSet.HERO_NUM} 个`);
|
|
return
|
|
}
|
|
smc.fight_heros.push(this.h_uuid)
|
|
oops.message.dispatchEvent("hero_card_select",{uuid:this.h_uuid})
|
|
this.show_bg(true)
|
|
}
|
|
check_show(event: string, args: any){
|
|
// console.log("hero_set 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){
|
|
// slv.active=false
|
|
// }else{
|
|
// slv.active=true
|
|
// slv.getChildByName("slv").getComponent(Label).string=smc.heros[this.h_uuid].slv.toString()
|
|
// }
|
|
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
|
|
}
|
|
/** 全局消息逻辑处理 */
|
|
// private onHandler(event: string, args: any) {
|
|
// switch (event) {
|
|
// case ModuleEvent.Cmd:
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |