import { ui } from "../ui/layaMaxUI";
import { SC, ViewType, ViewManager } from "./ViewManager";
import { AccountManager } from "../Net/AccountManager";
import MainView from "./MainView";
import { ServerManager, BlastToMerge } from "../Net/ServerManager";
import { EventManager, StageMode } from "../Tool/EventManager";

export default class FailureView extends ui.FailureViewUI implements SC{
    private static ins:FailureView;
    constructor(){
        super();
    }
    public static get Instance():FailureView{
        if(FailureView.ins){
            return FailureView.ins
        }
        else{
            return new FailureView();
        }
    }
    Show(){
        this.BackBtn.clickHandler = Laya.Handler.create(this,this.ClickBack);
        this.TryBtn.clickHandler = Laya.Handler.create(this,this.ClickTry);
        this.height = Laya.stage.height; 
        this.BG.height = Laya.stage.height;
        Laya.stage.on(Laya.Event.RESIZE,this,()=>
        {
            this.height = Laya.stage.height;
            this.BG.height = Laya.stage.height;
        })
    }
    Close(){
        
    }
    //返回主界面
    ClickBack(){
        var args = [{"t":AccountManager.Instance.ServerTime.toString()},{"play_id":MainView.Instance.play_id},{"win":"0"}];
        ServerManager.Instance.SendHttp(BlastToMerge.JieShu,args,Laya.Handler.create(this,this.BackMain),null);
    }
    //再来一次
    ClickTry(){
        var args = [{"t":AccountManager.Instance.ServerTime.toString()},{"play_id":MainView.Instance.play_id},{"win":"0"}];
        ServerManager.Instance.SendHttp(BlastToMerge.JieShu,args,Laya.Handler.create(this,this.Try),null);
    }
    BackMain(){
        EventManager.StageTrigger(StageMode.Over);
        ViewManager.Instance.ShowView(ViewType.MainView);
    }
    Try(){
        EventManager.StageTrigger(StageMode.ReStart);
        ViewManager.Instance.ClosePopView(ViewType.FailureView);
    }
    

} 