83d18db8-0205-42f1-9e94-45d2d02a9ac2.js 8.15 KB
"use strict";
cc._RF.push(module, '83d1824AgVC8Z6URdLQKprC', 'UIManager');
// scripts/ui/UIManager.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UIManager = void 0;
var UIBase_1 = require("./UIBase");
var UIManager = /** @class */ (function () {
    function UIManager() {
        this._cache = new Map();
        // playResFlyEffect
    }
    Object.defineProperty(UIManager, "ins", {
        get: function () {
            if (this._ins == null) {
                this._ins = new UIManager();
            }
            return this._ins;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(UIManager.prototype, "uiLayer", {
        get: function () { return this._uiLayer; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(UIManager.prototype, "widgetLayer", {
        get: function () { return this._widgetLayer; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(UIManager.prototype, "loadingLayer", {
        get: function () { return this._loadingLayer; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(UIManager.prototype, "adLayer", {
        get: function () { return this._adLayer; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(UIManager.prototype, "cache", {
        get: function () { return this._cache; },
        enumerable: false,
        configurable: true
    });
    // setLoadingNode(node: Node): void {
    //     this._loadingNode = node;
    // }
    // setAdNode(node: cc.Node) {
    //     this._adRoot = node;
    // }
    UIManager.prototype.init = function (uiRoot) {
        //已经进入了GameMain场景
        this._uiRoot = uiRoot;
        this._uiLayer = this._uiRoot.getChildByName("uiLayer");
        this._windowLockLayer = this._uiRoot.getChildByName("windowBlcok");
        this._windowLockLayer.active = false;
        // this._windowLockLayer.getComponent(Widget).updateAlignment();
        this._windowLayer = this._uiRoot.getChildByName("windowLayer");
        this._widgetLayer = this._uiRoot.getChildByName("widgetLayer");
        this._loadingLayer = this._uiRoot.getChildByName("loadingLayer");
        this._loadingLayer.active = false;
        this._tipsLayer = this._uiRoot.getChildByName("tipsLayer");
        this._adLayer = this._uiRoot.getChildByName("adLayer");
        // if (this._loadingNode) {
        //     // this._loadingNode.removeFromParent(); 
        //     this._loadingLayer.addChild(this._loadingNode);
        //     this._loadingNode.getChildByName("type1").active = false;
        //     this._loadingNode.getChildByName("type2").active = true;
        //     this._loadingNode.active = false;
        // }
        // uiRoot.addChild(this._adRoot);//添加广告节点
    };
    // static get adRoot() {
    //     let _scene: any = cc.director.getScene();
    //     let _adRoot = _scene.getChildByName('Canvas').getChildByName('adLayer') as cc.Node;
    //     if (_adRoot == null) {
    //         _adRoot = new cc.Node();
    //         _adRoot.name = 'adLayer';
    //         _adRoot.parent = _scene.getChildByName('Canvas');
    //         _adRoot.x = 0;
    //         _adRoot.y = 0;
    //         _adRoot.width = cc.winSize.width;
    //         _adRoot.height = cc.winSize.height;
    //         _adRoot.setSiblingIndex(999);
    //     }
    //     return _adRoot;
    // }
    UIManager.prototype.openScene = function (name) {
        var _this = this;
        this._loadingLayer.active = true;
        this._loadingLayer.getChildByName('sceneNode').active = true;
        this._loadingLayer.getChildByName('windowNode').active = false;
        cc.resources.loadScene('scenes/' + name, function (finish, total) {
            var prg = finish / total;
            _this._loadingLayer.getChildByName('sceneNode').getComponentInChildren(cc.ProgressBar).progress = prg;
        }, function (error, scene) {
            _this._loadingLayer.active = false;
            cc.director.runScene(scene);
        });
        // cc.director.scene
    };
    /**
     *
     * @param type
     * @param callBack 参数 view:cc.Node
     */
    UIManager.prototype.loadWindow = function (type, callBack) {
        var _this = this;
        if (this._cache.has(type)) {
            callBack(this._cache.get(type));
        }
        else {
            this._loadingLayer.active = true;
            this._loadingLayer.getChildByName('sceneNode').active = false;
            this._loadingLayer.getChildByName('windowNode').active = true;
            cc.resources.load(type, cc.Prefab, function (error, prefab) {
                _this._loadingLayer.active = false;
                if (!error) {
                    if (!_this._cache.has(type)) {
                        var view = cc.instantiate(prefab);
                        _this._cache.set(type, view);
                        callBack(view);
                    }
                }
            });
        }
    };
    UIManager.prototype.openWindow = function (type, openParam) {
        var _this = this;
        if (openParam === void 0) { openParam = null; }
        if (this._cache.has(type)) {
            this.doOpenWindow(this._cache.get(type), openParam);
        }
        else {
            // this._loadingLayer.active = true;
            // this._loadingLayer.getChildByName('sceneNode').active = false;
            // this._loadingLayer.getChildByName('windowNode').active = true;
            // cc.resources.load(type, cc.Prefab,
            //     (finished, total) => {
            //         let prg = finished / total;
            //     },
            //     (error, prefab: cc.Prefab) => {
            //         //finish
            //         if (!this._cache.has(type)) {
            //             let view = cc.instantiate(prefab);
            //             this._cache.set(type, view);
            //             this._loadingLayer.active = false;
            //             this.doOpenWindow(view, openParam);
            //         }
            //     });
            this.loadWindow(type, function (view) {
                _this.doOpenWindow(view, openParam);
            });
        }
    };
    UIManager.prototype.doOpenWindow = function (view, param) {
        if (!view.parent) {
            !this._windowLockLayer.active && (this._windowLockLayer.active = true);
            var base = view.getComponent(UIBase_1.UIBase);
            base && (base.enableParam = param);
            this._windowLayer.addChild(view);
            view.active = true;
            base && base.onPopUpEffect();
        }
    };
    UIManager.prototype.closeWindow = function (type, callback) {
        var _this = this;
        if (callback === void 0) { callback = null; }
        if (this._cache.has(type)) {
            var view_1 = this._cache.get(type);
            // view.active = false;
            var base = view_1.getComponent(UIBase_1.UIBase);
            base && base.onBeforeClose();
            base.onCloseEffect(function () {
                var isOnWindowLayer = (view_1.isValid && view_1.parent === _this._windowLayer);
                if (isOnWindowLayer) {
                    view_1.removeFromParent();
                    view_1.active = false;
                }
                if (isOnWindowLayer && _this._windowLayer.children.length == 0) {
                    _this._windowLockLayer.active = false;
                }
                callback && callback();
            }, this);
        }
    };
    UIManager.prototype.getWidgetNode = function (type) {
        return this._widgetLayer.getChildByName('widget' + type.toString());
    };
    UIManager.prototype.showTips = function (str) {
        // let node = this._tipsLayer.getChildByName('TipsNode');
        // node.active = true;
        // node.getComponentInChildren(Label).string = str;
        // Tween.stopAllByTarget(node);
        // tween(node).delay(3).call(this.closeTips.bind(this)).start()
    };
    UIManager.prototype.closeTips = function () {
        var node = this._tipsLayer.getChildByName('TipsNode');
        node.active = false;
    };
    UIManager._ins = null;
    return UIManager;
}());
exports.UIManager = UIManager;

cc._RF.pop();