import { ItemRender } from "../../../../frameWork/fgui/ListUtil";

export class ShowTipsItem extends ItemRender{
    private _tipsLabel:fgui.GLabel;

    private bUsing:boolean;
    private stayTime:number;  // 保持不渐变的时间
    private playAniTime:number; 
    private movePosY:number; 

    protected onConstruct(): void {
        this._tipsLabel = this.getChild("TipsLabel").asLabel;
        this.stayTime = 0.35;
        this.playAniTime = 1;
        this.movePosY = -100;
    }

    setData(data: any, index?: number, param?: any) {
        this.ShowTipsUI(data.tips, data.callback);
    }

    private ShowTipsUI(tips:string, callback:()=>void){
        this.bUsing = true;
        this.node.y = -490;
        this._tipsLabel.text = tips;
        this.visible = true;
  
        cc.tween(this.node).delay(this.stayTime).to(this.playAniTime,{position:cc.v3(this.node.x, this.node.y - this.movePosY,0)})
        .call(()=>{
            this.bUsing = false;
            this.visible = false;
            //改变完成回调
            if (callback){
                callback();
            }
        }).start();
        this.node.opacity = 255;
        cc.tween(this.node).to(this.playAniTime,{opacity:125}).start();
    }

    public IsUsing(){
        return this.bUsing;
    }
    public ResetUI(){
        this.bUsing = false;
        this.visible = false;
    }

}
