import { _decorator, Component, Node, Size, tween, UITransform, Vec2, Vec3 } from 'cc';
import { cheyin_manager } from './cheyin_manager';
import { Util } from '../../util';
const { ccclass, property } = _decorator;

@ccclass('cheyin_item')
export class cheyin_item extends Component {
    private isCanUse:boolean = true

    public init(){
        this.isCanUse = true
        this.hide()
    }
    public IsCanUse(){
        return this.isCanUse
    }

    public show(){
        this.node.active = true
        let old = this.node.parent.getComponent(cheyin_manager).getOldPos()
        let n = this.node.parent.getComponent(cheyin_manager).getCarPos()
        this.node.getComponent(UITransform).contentSize = new Size(Math.abs(old.x-n.x),40)
        this.node.position = old
        this.isCanUse = false
        if(old.x>n.x){
            this.node.getComponent(UITransform).anchorX = 1
        }else{
            this.node.getComponent(UITransform).anchorX = 0
        }
        tween(this.node).delay(5).call(()=>{
            this.hide()
        }).start()
        let angle = Util.getAngle(new Vec2(old.x,old.y),new Vec2(n.x,n.y))
        this.node.angle = angle
    }

    public hide(){
        this.isCanUse = true
        this.node.active = false
    }
}


