98 lines
3.5 KiB
TypeScript
98 lines
3.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;
|
|
/** 方向 */
|
|
private _dir: Vec2 = new Vec2(0, 0);
|
|
public get dir(): Vec2 {
|
|
return this._dir;
|
|
}
|
|
public set dir(value: Vec2) {
|
|
this._dir = value;
|
|
}
|
|
pos_x=0;
|
|
pos_y=0;
|
|
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("destroy hero_card", this.on_destroy_node, this);
|
|
}
|
|
|
|
|
|
private on_destroy_node(event: string, args: any) {
|
|
// if(this.ent.eid == args){
|
|
// this.reset();
|
|
// }
|
|
}
|
|
onTouch(){
|
|
smc.vm_data.cards.eid = this.ent.eid;
|
|
let parent = this.node.parent;
|
|
let active = parent.getChildByName("active");
|
|
active.setPosition(this.pos_x,this.pos_y)
|
|
active.active = true;
|
|
active.setPosition(this.node.position.x+47.5,this.node.position.y+47.5);
|
|
}
|
|
onTouchMove(event: EventTouch) {
|
|
smc.vm_data.cards.eid = this.ent.eid;
|
|
// if(this.ent.eid == smc.vm_data.cards.eid){
|
|
// this.node.getChildByName("active").active = true;
|
|
// }else{
|
|
// this.node.getChildByName("active").active = false;
|
|
// }
|
|
let delta = event.getDelta();
|
|
this.node.setPosition(this.node.position.x+delta.x,this.node.position.y+delta.y);
|
|
}
|
|
onTouchEnd(){
|
|
let parent = this.node.parent;
|
|
let active = parent.getChildByName("active");
|
|
active.setPosition(this.pos_x+47.5,this.pos_y+47.5)
|
|
if(this.node.position.y-this.pos_y > 110){
|
|
active.active = false;
|
|
this.use_card()
|
|
}else{
|
|
this.node.setPosition(this.pos_x,this.pos_y);
|
|
}
|
|
}
|
|
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("金币不够");
|
|
this.node.setPosition(this.pos_x,this.pos_y);
|
|
}
|
|
}
|
|
/** 视图层逻辑代码分离演示 */
|
|
start() {
|
|
this.pos_x=this.node.position.x;
|
|
this.pos_y=this.node.position.y;
|
|
}
|
|
|
|
/** 全局消息逻辑处理 */
|
|
// private onHandler(event: string, args: any) {
|
|
// switch (event) {
|
|
// case ModuleEvent.Cmd:
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |