// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
//点击
import Common5 from "../../../Platform/th/Common5";

const {ccclass, property} = cc._decorator;

@ccclass
export default class GZNodeTouchEndScript extends cc.Component {
    @property(
      {
        type: cc.Node,
        displayName: "注册触摸节点",
      }
    )
    emitTarget:cc.Node = null

    @property(
        {
            type: cc.Node,
            displayName: "触发的节点",
        }
    )
    tiggerNode:cc.Node = null

    
    @property(cc.String)
    spineAnim:string = ''

    @property(    {
        type: cc.Node,
        displayName: "spine动画节点",
    })
    spineNode:cc.Node = null

    @property(cc.Boolean)
    isSpineNodeHide:boolean = false
    
    // LIFE-CYCLE CALLBACKS:
    touchStartPosi = null
    onLoad () {
        if(!this.emitTarget){
            this.emitTarget = this.node
        }
        this.openTouchEvent(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
        let posi = event.getLocation()//世界坐标

        console.log('touchStartNode')

        
    }

    

    initTouchEvent(node,checkNode){
        var attrs = {
            checkNode:checkNode, 
            recoveposi:node.getPosition(),//初始位置
    
        };
		node.attr(attrs);
        this.openTouchEvent(node)
    }

    touchMoveNode(event){

    }

    touchEndNode(event){
        let target = event.target
        target.active = false

        if(this.tiggerNode){
            this.tiggerNode.active = true
        }
        if(this.spineNode){
            this.spineNode.active = true
            this.spineNode.getComponent(sp.Skeleton).setAnimation(0, this.spineAnim, false)

        }
    
        //
    }
}