import Dictionary from "../Util/Dictionary";
import { game_ui } from "../Gameui/game_ui";

export enum ViewType {
    game_ui
}
export default class ViewManager {
    private static instance: ViewManager;
    public static get Instance(): ViewManager {
        return this.instance || (this.instance = new ViewManager());
    }
    constructor() {
        this.init();
    }
    private viewDic = [];
    private curView: any;
    private addViewDic = new Dictionary();
    init() {
        this.viewDic[ViewType.game_ui] = game_ui;
    }
    public OpenView(view: ViewType, data?: any) {
        if (this.curView != null) {
            this.curView.OnClose();
            Laya.stage.removeChild(this.curView);
            //    var  a:Laya.Scene;
            //    a.destroy()
            this.curView.destroy(true);
            this.curView = null;
        }
        this.curView = new this.viewDic[view];

        Laya.stage.addChild(this.curView);
        // this.curView.resizeHander();
        this.curView.OnShow(data);

    }

    public get getCurView(): any {
        return this.curView;
    }
    public AddView(view: ViewType, data?: any) {
        if (this.addViewDic.has(view)) return;
        let t_view = new this.viewDic[view];
        this.addViewDic.set(view, t_view);
        Laya.stage.addChild(t_view);
        t_view.OnShow(data);
    }
    public RemoveView() {
        if (this.curView != null) {
            this.curView.OnClose();
            Laya.stage.removeChild(this.curView);
            this.curView.destroy(true);
            this.curView = null;
        }
    }
    public CloseView(view: ViewType) {
        if (!this.addViewDic.has(view)) return;
        let t_view = this.addViewDic.get(view);
        t_view.OnClose();
        Laya.stage.removeChild(t_view);
        t_view.destroy(true);
        this.addViewDic.delete(view);
    }
    private curMask: any;
    public OpenMask() {
        if (this.curMask != null) {
            return;
        }
        //  this.curMask = new Mask_ui();
        if (!this.curMask) return;
        Laya.stage.addChild(this.curMask);
    }
    public CloseMask() {
        if (this.curMask != null) {
            this.curMask.OnClose();
            Laya.stage.removeChild(this.curMask);
            this.curMask.destroy(true);
            this.curMask = null;
        }
    }

}