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


export default class MainView extends ui.MainSceneUI implements SC{
    private static ins:MainView;
    //游戏开始接口返回的游戏id
    public play_id:any;
    //当前关卡数
    public STAGE:number = 0;

    constructor(){
        super();
        new GameControl();
        new GameManager();
        new GamePool();
    }
    public static get Instance():MainView{
        if(MainView.ins){
            return MainView.ins
        }
        else{
            return new MainView();
        }
    }
    Show(){
        let stage = AccountManager.Instance.curplayerData.GainAccount("stage");
        this.STAGE = Number(stage);
        GameManager.Instance.STAGE = this.STAGE;
        this.StartBtn.clickHandler = Laya.Handler.create(this,this.ClickStart);
        this.RankBtn.clickHandler = Laya.Handler.create(this,this.ClickRank);
        this.SignBtn.clickHandler = Laya.Handler.create(this,this.ClickSign);
        this.LotteryBtn.clickHandler = Laya.Handler.create(this,this.ClickLottery);
        this.SetBtn.clickHandler = Laya.Handler.create(this,this.ClickSet);
        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;
        })
    }
    ClickStart(){
        var agrs = [{ "t": AccountManager.Instance.ServerTime.toString() }];
        ServerManager.Instance.SendHttp(BlastToMerge.KaiShi, agrs, Laya.Handler.create(this, this.GameStart), null);
    }
    GameStart(_data:any){
        this.play_id = _data.play_id;
        // ViewManager.Instance.ShowView(ViewType.InGameView);
        EventManager.StageTrigger(StageMode.Start);
    }
    ClickRank(){
        ViewManager.Instance.ShowView(ViewType.RankView);
    }
    ClickLottery(){
        ViewManager.Instance.ShowView(ViewType.LotteryView);
    }
    ClickSign(){
        ViewManager.Instance.ShowView(ViewType.SignView);
    }
    ClickSet(){
        ViewManager.Instance.ShowView(ViewType.SetView);
    }
    Close(){

    }

} 