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

export default class WinView extends ui.WinViewUI implements SC{
    private static ins:WinView;
    constructor(){
        super();
    }
    public static get Instance():WinView{
        if(WinView.ins){
            return WinView.ins
        }
        else{
            return new WinView();
        }
    }
    Show(){
        this.BackBtn.clickHandler = Laya.Handler.create(this,this.ClickBack);
        this.NextBtn.clickHandler = new Laya.Handler(this,this.NextLevel);
        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":"1"}];
        ServerManager.Instance.SendHttp(BlastToMerge.JieShu,args,Laya.Handler.create(this,this.BackMain),null);
    }
    //下一关
    ClickNextLevel(){
        var args = [{"t":AccountManager.Instance.ServerTime.toString()},{"play_id":MainView.Instance.play_id},{"win":"1"}];
        ServerManager.Instance.SendHttp(BlastToMerge.JieShu,args,Laya.Handler.create(this,this.NextLevel),null);
    }
    //返回主界面
    BackMain(){
        EventManager.StageTrigger(StageMode.Over);
        ViewManager.Instance.ShowView(ViewType.MainView);
    }
    //下一关
    NextLevel(){
        GameManager.Instance.STAGE = Number(AccountManager.Instance.curplayerData.GainAccount("stage"));
        GamePool.Instance.FreshScore();
        EventManager.StageTrigger(StageMode.ReStart);
        ViewManager.Instance.ClearPopViews();
    }

} 