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 ItemIconTouchScript extends cc.Component { @property(cc.Node) touchNode: cc.Node = null; @property(cc.Label) touchName: cc.Label = null; @property(cc.Node) checkNode: cc.Node = null; @property(cc.Node) targetNode: cc.Node = null; @property(cc.Node) moveNode: cc.Node = null; @property(cc.ScrollView) scrollView: cc.ScrollView = null; // onLoad() {} setTouchNodeIcon(data_) { Common5.getSpriteFrameFromBundle(data_.bandleName, data_.picPath, this.touchNode.getComponent(cc.Sprite)); if (this.touchName) { this.touchName.string = data_.touchName; } if (data_.touchName) { this.touchNode.name = data_.touchName; } this.onTouchEvent(this.touchNode, data_.iconIndex, data_.checkNode, data_.targetNode); } onTouchEvent(node, iconIndex, checkNode, targetNode) { node.attr({ iconIndex: iconIndex, checkNode: checkNode, targetNode: targetNode, recoveposi: node.getPosition(),//初始位置 recoveparent: this.touchNode.parent,//初始父节点 }); this.openTouchEvent(node) } 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 as cc.Node; this.scrollView.enabled = false; target.parent = this.moveNode; let posi = event.getLocation()//世界坐标 posi = target.parent.convertToNodeSpaceAR(posi) target.setPosition(posi) EventMgr.emitEvent_custom(ryw_Event.openBGMove, { open: false }); } touchMoveNode(event) { let posi = event.getLocation()//世界坐标 let target = event.target posi = target.parent.convertToNodeSpaceAR(posi) target.setPosition(posi) } touchEndNode(event) { let target = event.target; this.scrollView.enabled = true; if (target.checkNode.active && Common5.checkIntersectsBox(target, target.checkNode)) { Common5.playEffect('放置成功'); target.checkNode.active = false; this.node.active = false; if (target.targetNode) { target.targetNode.active = true; } GameReport.BtnsReport(target.name, Common5.selectGameInfo.titleUrl); console.log("[GameReport]++++++++++++++++++++++>" + target.name); EventMgr.emitEvent_custom(ryw_Event.itemIconTouchTrue, { targetNode: target }) } else { Common5.playEffect('放置错误'); EventMgr.emitEvent_custom(ryw_Event.itemIconTouchFalse, { targetNode: target }) } if (target["recoveposi"]) { if (target["recoveparent"]) { this.nodeMoveToRecovery(target, target["recoveposi"], target["recoveparent"]); } else { this.nodeMoveToRecovery(target, target["recoveposi"]); } } EventMgr.emitEvent_custom(ryw_Event.openBGMove, { open: true }); } nodeMoveToRecovery(node, oldPosi: cc.Vec2, oldParent?: cc.Node, func?: Function) { if (!oldParent) { oldParent = node.parent; } cc.tween(node) .set({ parent: oldParent }) .to(0.1, { x: oldPosi.x, y: oldPosi.y }) .call(() => { if (func) { func() } }) .start() } }