
export class faafssfafsa
{
    constructor(_message:string,_pos:Laya.Vector2,_size:Laya.Vector2,_fontSize:number,_color:string = null)
    {
        this.size = new Laya.Vector2(_size.x,_size.y);
        this.fontSize = _fontSize;
        this.color = _color;
        this.message = _message;
        this.pos = _pos;
    }
    size:Laya.Vector2;
    fontSize = 30;
    color:string;
    message = "";
    pos:Laya.Vector2;
}
export  class GameTools  {
    private static ins:GameTools;
    constructor() {
        GameTools.ins = this; 
     }
    /**单例*/
    public static get Instance():GameTools{
        if(GameTools.ins){
            return GameTools.ins;
        }
        else{
            return new GameTools();
        }
    }
    
    /**插值方法*/
    public  lerp(form:number, to:number, t:number){
        if (t <= 0) {
            return form;
        }else if (t >= 1) {
            return to;
        }
        var a = t * to + (1 - t) * form
        return a;
     }
    /**设置碰撞器*/
    SetCollider(setNode: Laya.Node, CollisionGroup: number) {
        var numchild = setNode.numChildren;
        for (var i = 0; i < setNode.numChildren; i++) {
            var numchild2 = setNode.getChildAt(i).numChildren;
            if (numchild2 > 1) {
                this.SetCollider(setNode.getChildAt(i), CollisionGroup);
            }
            var physicsCollider = setNode.getChildAt(i).getComponent(Laya.PhysicsCollider) as Laya.PhysicsCollider;
            if (physicsCollider) {
                physicsCollider.collisionGroup = CollisionGroup;
            }
        }
    }
    //随机一个浮点数
    public static RandomNumber(from:number,to:number):number
    {
        if(from >= to)
        {
            return 0;
        }
        var size = to - from;
        var curNumber = Math.random()*size + from;
        return curNumber;
    }
    //随机一个int值
    public static RandomANumber(from:number,to:number):number
    {
        if(from >= to)
        {
            return 0;
        }
        var size = to - from;
        var curNumber = Math.random()*size + from;
        return Math.floor(curNumber);
    }

    //签到领取金币Tween动画
    public static GetMoney(_num:number,_pos:Laya.Vector2 = null,_completeHandle:Laya.Handler = null)
    {
        if(_num == 0)return;
        var fafaafsfa = new Laya.Box;
        fafaafsfa.width = 400;
        fafaafsfa.height = 100;
        fafaafsfa.pivotX = fafaafsfa.width/2;
        fafaafsfa.pivotY = fafaafsfa.height/2;
        if(_pos == null)
        {
            _pos = new Laya.Vector2(Laya.stage.width/2,Laya.stage.height/2);
        }
        fafaafsfa.pos(_pos.x,_pos.y);

        var aafafaffa = new Laya.Image;
        aafafaffa.skin = "game/qiandao_1_7.png";
        aafafaffa.width = 60;
        aafafaffa.height = 60;
        aafafaffa.left = 50;
        aafafaffa.y = 10;
        fafaafsfa.addChild(aafafaffa);

        var faasfafsafs = new Laya.Text;
        faasfafsafs.width = 300;
        faasfafsafs.height = 50;
        
        faasfafsafs.align = "center";
        faasfafsafs.valign = "middle";
        faasfafsafs.font = "Microsoft YaHei";
        faasfafsafs.fontSize = 40;
        faasfafsafs.color = "#FFFFFF";
        faasfafsafs.bold = true;
        faasfafsafs.font = "Microsoft YaHei";
        faasfafsafs.text = "金币 +" + _num;
        faasfafsafs.x = 60;
        faasfafsafs.y = 10;
        fafaafsfa.addChild(faasfafsafs);
        
        
        Laya.stage.addChild(fafaafsfa);

        var faasfsaf = Laya.Tween.to(fafaafsfa,{y:fafaafsfa.y - 200},1500,Laya.Ease.expoInOut,Laya.Handler.create(this,()=>
        {
            faasfsaf.clear();
            fafaafsfa.destroy();
            if(_completeHandle)
            {
                _completeHandle.run();
            }
        }),100);

    }
    //文字Tween动画
    public static TweenText(faafssfafsa:faafssfafsa,_hight:number,_completeHandle:Laya.Handler = null,hide = true,_duration:number = 500):Laya.Text
    {
        var afasafsafsfa = new Laya.Text();
        
        afasafsafsfa.width = faafssfafsa.size.x;
        afasafsafsfa.height = faafssfafsa.size.y;
        afasafsafsfa.align = "center";
        afasafsafsfa.valign = "middle";
        afasafsafsfa.font = "Microsoft YaHei";
        afasafsafsfa.fontSize = faafssfafsa.fontSize;
        afasafsafsfa.pivotX = afasafsafsfa.width/2;
        afasafsafsfa.pivotY =  afasafsafsfa.height/2;
        afasafsafsfa.color = "#5ad122";
        afasafsafsfa.bold = true;
        afasafsafsfa.stroke = 5;
        afasafsafsfa.strokeColor = "#ffffff";
        if(faafssfafsa.color)
        {
            faafssfafsa.color = faafssfafsa.color;
        }
        afasafsafsfa.text = faafssfafsa.message;
        afasafsafsfa.zOrder = 1;
        Laya.stage.addChildAt(afasafsafsfa,Laya.stage.numChildren - 1);
        afasafsafsfa.pos(faafssfafsa.pos.x,faafssfafsa.pos.y);
        var tween = Laya.Tween.to(afasafsafsfa,{y:afasafsafsfa.y - _hight,update:new Laya.Handler(this,function()
            {

            })},_duration,Laya.Ease.expoInOut,Laya.Handler.create(this,function()
        {
            tween.clear();
            if(hide)
            {
                afasafsafsfa.destroy();
            }
            if(_completeHandle)
            {
                _completeHandle.run();
            }
        }));
        if(hide)
        {
            Laya.Tween.to(afasafsafsfa,{alpha:0.4},500);
        }
        return afasafsafsfa;
    }

        //文字Tween动画
        public static StationTweenText(faafssfafsa:faafssfafsa,_hight:number,_completeHandle:Laya.Handler = null,hide = true,_duration:number = 500):Laya.Text
        {
            var afasafsafsfa = new Laya.Text();
            
            afasafsafsfa.width = faafssfafsa.size.x;
            afasafsafsfa.height = faafssfafsa.size.y;
            afasafsafsfa.align = "center";
            afasafsafsfa.valign = "middle";
            afasafsafsfa.font = "Microsoft YaHei";
            afasafsafsfa.fontSize = 50;
            afasafsafsfa.pivotX = afasafsafsfa.width/2;
            afasafsafsfa.pivotY =  afasafsafsfa.height/2;
            afasafsafsfa.color = "#5ad122";
            afasafsafsfa.bold = true;
            afasafsafsfa.stroke = 5;
            afasafsafsfa.strokeColor = "#ffffff";
            if(faafssfafsa.color)
            {
                faafssfafsa.color = faafssfafsa.color;
            }
            afasafsafsfa.text = faafssfafsa.message;
            afasafsafsfa.zOrder = 1;
            Laya.stage.addChildAt(afasafsafsfa,Laya.stage.numChildren - 1);
            afasafsafsfa.pos(faafssfafsa.pos.x,faafssfafsa.pos.y);
            var tween = Laya.Tween.to(afasafsafsfa,{y:afasafsafsfa.y - _hight,update:new Laya.Handler(this,function()
                {
    
                })},_duration,Laya.Ease.expoInOut,Laya.Handler.create(this,function()
            {
                tween.clear();
                if(hide)
                {
                    afasafsafsfa.destroy();
                }
                if(_completeHandle)
                {
                    _completeHandle.run();
                }
            }));
            if(hide)
            {
                Laya.Tween.to(afasafsafsfa,{alpha:0.4},10000);
            }
            return afasafsafsfa;
        }

    static tweenMove(transform: Laya.Transform3D, targPos: Laya.Vector3, delay: number, ease: Function, complete: Laya.Handler): Laya.Tween {
        let curPos = transform.position.clone();
        return Laya.Tween.to(curPos, {
            x: targPos.x,
            y: targPos.y,
            z: targPos.z,
            update: new Laya.Handler(this, () => {
                transform.position = curPos.clone();
            })
        }, delay, ease, complete);
    }

    static tweenRotate(transform: Laya.Transform3D, targEuler: Laya.Vector3, delay: number, ease: Function, complete: Laya.Handler): Laya.Tween {
        let curEuler = transform.rotationEuler.clone();
        return Laya.Tween.to(curEuler, {
            x: targEuler.x,
            y: targEuler.y,
            z: targEuler.z,
            update: new Laya.Handler(this, () => {
                transform.rotationEuler = curEuler.clone();
            })
        }, delay, ease, complete);
    }
    
}