import { ui } from "../ui/layaMaxUI";
import { PlayerManager } from "../Manager/PlayerManager";
import { AccountManager } from "../NetWork/AccountManager";
import { DispatcherManager, StageState } from "../GameUtils/EventManager";
export class InGameView extends ui.InGameViewUI{
    private static ins:InGameView;
    constructor(){
        super();
        InGameView.ins = this;
    }
    public static get Instance():InGameView{
        if(InGameView.ins == null){
            return new InGameView();
        }
        return InGameView.ins;
    }
    OnShow(){
        console.log("游戏界面");
        this.on(Laya.Event.MOUSE_DOWN,this,this.ClickStart);
        this.RefreshUI();
        this.height = Laya.stage.height;
        Laya.stage.on(Laya.Event.RESIZE,this,()=>
        {
            this.height = Laya.stage.height;
        })
        DispatcherManager.StageOn(StageState.RefreshPro,this,this.SetProValue);
        DispatcherManager.StageOn(StageState.ShowGuide1,this,this.ShowGuide1);
        DispatcherManager.StageOn(StageState.HideGuide1,this,this.HideGuide1);
        DispatcherManager.StageOn(StageState.ShowGuide2,this,this.ShowGuide2);
        DispatcherManager.StageOn(StageState.HideGuide2,this,this.HideGuide2);
    }
    ClickStart(){
        this.off(Laya.Event.MOUSE_DOWN,this,this.ClickStart);
    }
    RefreshUI(){
        let stage = Number(AccountManager.Instance.curplayerData.GainAccount("stage")) +1;
        this.NowLevelNum.text = stage + "";
    }
    SetProValue(data){
        this.jindupro.value = data["pre"];
        this.CountTxt.text = "小人数量：" + (Number(data["count"]) + 1);
    }
    ShowGuide1(){
        this.GuideBox1.visible = true;
        Laya.stage.on(Laya.Event.MOUSE_DOWN,this,this.HideGuide1);
    }
    HideGuide1(){
        this.GuideBox1.visible = false;
        Laya.stage.off(Laya.Event.MOUSE_DOWN,this,this.HideGuide1);
        PlayerManager.Instance.Resume();
        PlayerManager.Instance.ListenOn();
    }
    ShowGuide2(){
        this.GuideBox2.visible = true;
        this.guideclick1.play(null,true);
    }
    HideGuide2(){
        this.GuideBox2.visible = false;
        this.guideclick1.stop();
    }
    OnHide(){
        DispatcherManager.StageOff(StageState.RefreshPro,this,this.SetProValue);
        DispatcherManager.StageOff(StageState.ShowGuide1,this,this.ShowGuide1);
        DispatcherManager.StageOff(StageState.HideGuide1,this,this.HideGuide1);
        DispatcherManager.StageOff(StageState.ShowGuide2,this,this.ShowGuide2);
        DispatcherManager.StageOff(StageState.HideGuide2,this,this.HideGuide2);
    }
}