英雄上阵选择 基本完成
This commit is contained in:
77
assets/script/game/hero/HeroSelectComp.ts
Normal file
77
assets/script/game/hero/HeroSelectComp.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { _decorator, Label } 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 { MissionHomeComp } from "../map/MissionHomeComp";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('HeroSelectComp')
|
||||
@ecs.register('HeroSelectComp', false)
|
||||
export class HeroSelectComp extends CCComp {
|
||||
mhc_home: MissionHomeComp = null!;
|
||||
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() {
|
||||
|
||||
this.mhc_home=this.node.parent.parent.parent.parent.getComponent(MissionHomeComp);
|
||||
if(smc.vmdata.fight_heros.indexOf(this.h_uuid)>=0){
|
||||
this.show_bg(true)
|
||||
}else{
|
||||
this.show_bg(false)
|
||||
}
|
||||
}
|
||||
select(){
|
||||
if(smc.vmdata.fight_heros.indexOf(this.h_uuid)>=0){
|
||||
smc.vmdata.fight_heros.splice(smc.vmdata.fight_heros.indexOf(this.h_uuid),1)
|
||||
this.show_bg(false)
|
||||
this.mhc_home.cancel_hero(this.h_uuid)
|
||||
return
|
||||
}
|
||||
if(smc.vmdata.fight_heros.length>= 5){
|
||||
oops.gui.toast("英雄数量不能超过5个")
|
||||
return
|
||||
}
|
||||
smc.vmdata.fight_heros.push(this.h_uuid)
|
||||
this.mhc_home.select_hero(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(event: string, args: any){
|
||||
if(args.uuid!=this.h_uuid) return
|
||||
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>=1) {slv.getChildByName("s1").active=true} else {slv.getChildByName("s1").active=false};
|
||||
if(smc.heros[this.h_uuid].slv>=2) {slv.getChildByName("s2").active=true} else {slv.getChildByName("s2").active=false};
|
||||
if(smc.heros[this.h_uuid].slv>=3) {slv.getChildByName("s3").active=true} else {slv.getChildByName("s3").active=false};
|
||||
if(smc.heros[this.h_uuid].slv>=4) {slv.getChildByName("s4").active=true} else {slv.getChildByName("s4").active=false};
|
||||
if(smc.heros[this.h_uuid].slv>=5) {slv.getChildByName("s5").active=true} else {slv.getChildByName("s5").active=false};
|
||||
}
|
||||
/** 全局消息逻辑处理 */
|
||||
// private onHandler(event: string, args: any) {
|
||||
// switch (event) {
|
||||
// case ModuleEvent.Cmd:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user