Files
heros/assets/script/game/monster/HeroCardViewComp.ts
2024-08-15 10:53:40 +08:00

76 lines
2.5 KiB
TypeScript

import { _decorator ,Vec2,NodeEventType,EventTouch} 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 { data } from "../data/data";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { smc } from "../common/SingletonModuleComp";
import { CardSet } from "../common/config/CardSet";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('HeroCardViewComp')
@ecs.register('HeroCardView', false)
export class HeroCardViewComp extends CCComp {
card_name:string = "hero_card";
card_type:string = "hero";
card_uid:number = 1000;
protected onLoad(): void {
// this.node.on(NodeEventType.TOUCH_START, this.onTouch, this);
// this.node.on(NodeEventType.TOUCH_MOVE, this.onTouchMove, this);
// this.node.on(NodeEventType.TOUCH_END, this.onTouchEnd, this);
// this.node.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this);
// oops.message.on("active_card_eid", this.do_active_card_eid, this);
}
private do_active_card_eid(event: string, args: any) {
console.log("active_card_eid",args,this.ent.eid)
if(this.ent.eid != args.eid){
this.no_active()
}
}
do_active(){
}
no_active(){
// this.node.getChildByName("active").active=false;
// this.node.getChildByName("use").active=false;
// this.node.getChildByName("bag").active=false;
}
doit(){
// this.do_active()
console.log("doit",this.ent)
smc.vm_data.cards.eid = this.ent.eid;
// oops.message.dispatchEvent("active_card_eid",{eid:this.ent.eid})
}
use_card(){
if(smc.vm_data.gold.min >= CardSet[this.card_uid].level){
oops.message.dispatchEvent("do_add_hero",{uuid:this.card_uid})
this.ent.destroy();
smc.vm_data.gold.min -= CardSet[this.card_uid].level;
}else{
oops.gui.toast("金币不够");
}
}
/** 视图层逻辑代码分离演示 */
start() {
}
/** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) {
// switch (event) {
// case ModuleEvent.Cmd:
// break;
// }
// }
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}