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.
145 lines
4.7 KiB
145 lines
4.7 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 TouchRoleNode extends cc.Component {
|
|
|
|
@property(cc.Node)
|
|
emitTarget: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
checkNode: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
formArray: cc.Node[] = [];
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
isClick = true;
|
|
formIndex = 0;
|
|
correctFormIndex = 0;
|
|
|
|
setFormArray(touchRoleNodeInfo) {
|
|
|
|
let formArray: cc.Node[] = [];
|
|
for (let index = 0; index < touchRoleNodeInfo.roleFormArray.length; index++) {
|
|
let form = this.formArray[index];
|
|
form.active = false;
|
|
Common5.getSpriteFrameFromBundle(touchRoleNodeInfo.bandleName, touchRoleNodeInfo.roleFormArray[index], form.getComponent(cc.Sprite));
|
|
formArray.push(form);
|
|
}
|
|
this.formArray = formArray;
|
|
this.formArray[0].active = true;
|
|
this.formIndex = 0;
|
|
|
|
if (!this.emitTarget) {
|
|
this.emitTarget = this.node;
|
|
}
|
|
this.emitTarget.name = touchRoleNodeInfo.roleName;
|
|
this.correctFormIndex = touchRoleNodeInfo.correctFormIndex;
|
|
this.checkNode = touchRoleNodeInfo.checkNode;
|
|
this.initTouchEvent(this.emitTarget, this.checkNode, touchRoleNodeInfo.roleIndex);
|
|
}
|
|
|
|
initTouchEvent(node, checkNode, roleIndex) {
|
|
var attrs = {
|
|
roleIndex: roleIndex,
|
|
checkNode: checkNode,
|
|
recoveposi: node.getPosition(),//初始位置
|
|
scr: this //脚本
|
|
};
|
|
node.attr(attrs);
|
|
this.openTouchEvent(node)
|
|
}
|
|
|
|
cancelTouchEvent() {
|
|
this.closeTouchEvent(this.emitTarget);
|
|
}
|
|
|
|
|
|
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) {
|
|
Common5.playEffect("点击音效");
|
|
|
|
this.isClick = true;
|
|
this.scheduleOnce(() => {
|
|
this.isClick = false;
|
|
}, 0.2);
|
|
|
|
}
|
|
|
|
touchMoveNode(event) {
|
|
|
|
let posi = event.getLocation()//世界坐标
|
|
let target = event.target
|
|
posi = target.parent.convertToNodeSpaceAR(posi)
|
|
target.setPosition(posi)
|
|
|
|
}
|
|
|
|
touchEndNode(event) {
|
|
let target = event.target;
|
|
let checkNode = target.checkNode as cc.Node;
|
|
|
|
if (this.isClick) {
|
|
if (this.formIndex < this.formArray.length - 1) {
|
|
this.formArray[this.formIndex].active = false;
|
|
this.formIndex++;
|
|
if (Common5.checkContainsNode(checkNode, target) && this.correctFormIndex == this.formIndex) {
|
|
checkNode.active = true;
|
|
target.active = false;
|
|
EventMgr.emitEvent_custom(ryw_Event.roleNodeTouchCheck, { targetNode: target });
|
|
Common5.playEffect('放置成功');
|
|
GameReport.BtnsReport(target.name, Common5.selectGameInfo.titleUrl);
|
|
|
|
|
|
console.log("[GameReport]++++++++++++++++++++++>" + target.name);
|
|
} else {
|
|
this.formArray[this.formIndex].active = true;
|
|
}
|
|
}
|
|
} else {
|
|
|
|
if (Common5.checkContainsNode(checkNode, target) && this.correctFormIndex == this.formIndex) {
|
|
checkNode.active = true;
|
|
target.active = false;
|
|
EventMgr.emitEvent_custom(ryw_Event.roleNodeTouchCheck, { targetNode: target });
|
|
Common5.playEffect('放置成功');
|
|
GameReport.BtnsReport(target.name, Common5.selectGameInfo.titleUrl);
|
|
console.log("[GameReport]++++++++++++++++++++++>" + target.name);
|
|
}
|
|
}
|
|
}
|
|
|
|
nodeMoveToRecovery(node, oldPosi: cc.Vec2, func?: Function) {
|
|
|
|
cc.tween(node)
|
|
.to(0.1, { x: oldPosi.x, y: oldPosi.y })
|
|
.call(() => {
|
|
|
|
if (func) {
|
|
func()
|
|
}
|
|
})
|
|
.start()
|
|
}
|
|
|
|
// update (dt) {}
|
|
}
|
|
|