import { _decorator, instantiate, Prefab ,Node, 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"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('LuckHomeCompComp') @ecs.register('LuckHomeComp', false) export class LuckHomeCompComp extends CCComp { @property({ type: Node }) sbn: Node = null; @property({ type: Node }) mbn: Node | null = null; @property({ type: Node }) lbn: Node | null = null; @property({ type: Node }) btnno: Node | null = null; @property({ type: Node }) itmes: Node | null = null; selected: string = ""; /** 视图层逻辑代码分离演示 */ start() { // var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象 // this.on(ModuleEvent.Cmd, this.onHandler, this); this.frist(); } frist(){ if(smc.items[1001].num > 0){this.select_box(null,"sb");} else if(smc.items[1002].num > 0){this.select_box(null,"mb");} else if(smc.items[1003].num > 0){this.select_box(null,"lb");} this.check_num(); } check_num(){ this.sbn.getChildByName("num").getComponent(Label).string = smc.items[1001].num.toString(); this.mbn.getChildByName("num").getComponent(Label).string = smc.items[1002].num.toString(); this.lbn.getChildByName("num").getComponent(Label).string = smc.items[1003].num.toString(); } select_box(e:any, val:string){ this.sbn.setScale(1,1,1); this.mbn.setScale(1,1,1); this.lbn.setScale(1,1,1); switch(val){ case "sb": this.sbn.setScale(1.2,1.2,1); if(smc.items[1001].num > 0){ this.btnno.active = false; this.selected="sb" }else{ this.btnno.active = true } break; case "mb": this.mbn.setScale(1.2,1.2,1); if(smc.items[1002].num > 0){ this.btnno.active = false; this.selected="mb" }else{ this.btnno.active = true } break; case "lb": this.lbn.setScale(1.2,1.2,1); if(smc.items[1003].num > 0){ this.btnno.active = false; this.selected="lb" }else{ this.btnno.active = true } break; default: this.selected=""; break; } } open_sb() { console.log("open_sb"); smc.items[1001].num--; this.show_bbox() this.check_num() } open_mb() { console.log("open_mb"); smc.items[1002].num--; this.show_bbox() this.check_num() } open_lb() { console.log("open_lb"); smc.items[1003].num--; this.show_bbox() this.check_num() } show_bbox() { var parent = this.node.getChildByName("bbox") var path = "game/gui/bbox"; var prefab: Prefab = oops.res.get(path, Prefab)!; let box = instantiate(prefab); box.parent = parent; // parent.getChildByName("light").active = true; this.scheduleOnce(()=>{ parent.getChildByName("light").active = false; }, 0.5) this.scheduleOnce(()=>{ box.destroy(); }, 0.7) } to_open(){ if(this.selected==""){return;} switch(this.selected){ case "sb": if(smc.items[1001].num <=0){oops.gui.toast("宝箱数量不足"); this.btnno.active = true;return;} this.open_sb(); break; case "mb": if(smc.items[1002].num <=0){oops.gui.toast("宝箱数量不足");this.btnno.active = true;return;} this.open_mb(); break; case "lb": if(smc.items[1003].num <=0){oops.gui.toast("宝箱数量不足");this.btnno.active = true;return;} this.open_lb(); break; } } /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ reset() { this.node.destroy(); } }