我智商爆棚
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

147 lines
4.4 KiB

import { ryw_Event } from "../../../FrameWork/Event/EventEnum";
import EventMgr from "../../../FrameWork/Event/EventMgr";
import GameReport from "../../../FrameWork/Report/ZyZyReport";
import Common5 from "../../../Platform/th/Common5";
const { ccclass, property } = cc._decorator;
@ccclass
export default class ANodeListCheckScript extends cc.Component {
@property(cc.Node)
emitTarget: cc.Node = null;
@property(cc.Node)
checkNodeArray: cc.Node[] = [];
@property(cc.Boolean)
isHideTargetNode: boolean = true;
@property(cc.Boolean)
isHideCheckNode: boolean = true;
@property(cc.Node)
moveNode: cc.Node = null;
@property(cc.Node)
attrNodeArray: cc.Node[] = []
// LIFE-CYCLE CALLBACKS:
touchStartPosi = null
onLoad() {
if (!this.emitTarget) {
this.emitTarget = this.node
}
this.initTouchEvent(this.emitTarget, this.checkNodeArray)
this.node['cancelTouchEvent'] = () => {
this.closeTouchEvent(this.emitTarget);
}
}
start() {
}
openTouchEvent(node) {
node.on(cc.Node.EventType.TOUCH_START, this.touchStartNode, this)
node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this)
node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this)
node.on(cc.Node.EventType.TOUCH_END, this.touchEndNode, this)
}
closeTouchEvent(node: cc.Node) {
node.off(cc.Node.EventType.TOUCH_START, this.touchStartNode, this)
node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this)
node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this)
node.off(cc.Node.EventType.TOUCH_END, this.touchEndNode, this)
}
touchStartNode(event) {
let target = event.target;
target.pauseAllActions();
Common5.playEffect("点击音效");
EventMgr.emitEvent_custom(ryw_Event.openBGMove, { open: false });
target['saveWorldPos'] = target.convertToWorldSpaceAR(cc.Vec2.ZERO);
}
initTouchEvent(node, checkNodeArray) {
var attrs = {
checkNodeArray: checkNodeArray,
recoveposi: node.getPosition(),//初始位置
recoveparent: node.parent,
scr: this //脚本
};
node.attr(attrs);
this.openTouchEvent(node)
}
cancelTouchEvent() {
this.closeTouchEvent(this.emitTarget);
}
touchMoveNode(event) {
let target = event.target
if (this.moveNode) {
target.parent = this.moveNode;
}
let posi = event.getLocation()//世界坐标
posi = target.parent.convertToNodeSpaceAR(posi)
target.setPosition(posi)
}
touchEndNode(event) {
let target = event.target;
let checkNodeArray = target.checkNodeArray as cc.Node[];
let jihuoNode = null;
for (let iterator of checkNodeArray) {
if (iterator.active && Common5.checkIntersectsBox(target, iterator)) {
jihuoNode = iterator;
break;
}
}
if (jihuoNode) {
if (this.isHideTargetNode) {
target.active = false;
}
if (this.isHideCheckNode) {
jihuoNode.active = false;
}
target.attr({
checkNode: jihuoNode,
attrNodeArray: this.attrNodeArray
});
GameReport.BtnsReport(target.name, Common5.selectGameInfo.titleUrl);
console.log("[GameReport]++++++++++++++++++++++>" + target.name);
EventMgr.emitEvent_custom(ryw_Event.NormalTouchMoveCheck, { targetNode: target });
}
if (target["recoveposi"]) {
if (target["recoveparent"]) {
this.nodeMoveToRecovery(target, target["recoveposi"], target["recoveparent"])
} else {
this.nodeMoveToRecovery(target, target["recoveposi"])
}
}
target.resumeAllActions();
EventMgr.emitEvent_custom(ryw_Event.openBGMove, { open: true });
}
nodeMoveToRecovery(node, oldPosi: cc.Vec2, recoveparent?: cc.Node, func?: Function) {
cc.tween(node)
.to(0.1, { position: node.parent.convertToNodeSpaceAR(node['saveWorldPos']) })
.set({ parent: recoveparent, position: oldPosi })
.call(() => {
if (func) {
func()
}
})
.start()
}
// update (dt) {}
}