"use strict"; cc._RF.push(module, 'f360cY0CBZGAJubplExXuPs', 'cmp.main.popups'); // Scripts/mod/mainui/cmp/cmp.main.popups.js "use strict"; /****************************************************************** * Copyright(C) 2019 - 2020 Nx Studio * * 主界面 --- 弹窗队列辅助 * * ******************************************************************/ var BridgeComponent = require("bridge.component"); var _require = require("define"), SCENE_TAG = _require.SCENE_TAG; cc.Class({ "extends": BridgeComponent, properties: {}, // 显示 onEnable: function onEnable() { // 弹窗队列 this.cur = null; this.queue = []; this.pushs = []; // 弹窗层 this.popRoot = nx.bridge.ui.getSceneNode(SCENE_TAG.popup); if (!this.popRoot) { nx.error("$Popups:辅助失败,缺少弹窗层popup_tag!"); return; } // 监听 this.popRoot.on("child-removed", this.onRemoveChild.bind(this)); // 全局支持 nx.bridge.popups = this; }, // 关闭 onDisable: function onDisable() { // 监听解除 this.popRoot.off("child-removed", this.onRemoveChild.bind(this)); // 全局支持 nx.bridge.popups = null; }, // 子节点移除 onRemoveChild: function onRemoveChild() { if (!this.popRoot) { return; } // 当前清理 this.cur = null; // 引导事件 if (nx.bridge.plot && this.queue.length == 0 && this.pushs.length == 0 && this.popRoot.childrenCount == 0) { // 发布引导事件 nx.bridge.plot.postKey("popups_clean"); // 如果当前不在引导中,尝试触发引导(比如:升级) var cur = nx.bridge.plot.vget("id"); if (nx.dt.strEmpty(cur)) { nx.bridge.mainui.tryPlot(); return; } } // 下一个 this.tryPopup(); }, // 添加弹窗 push: function push(_wname, _params, _cfgs) { nx.debug("$Popups:添加弹窗:", _wname); if (_cfgs && _cfgs.push) { this.pushs.push({ wid: _wname, args: _params || {} }); } else { this.queue.push({ wid: _wname, args: _params || {} }); } this.tryPopup(); }, // 清空弹窗 clean: function clean(_deep) { if (_deep === void 0) { _deep = false; } nx.debug("$Popups:清空弹窗队列"); this.queue = []; this.cur = null; var chds = this.popRoot.children; for (var i in chds) { var cmp = chds[i].getComponent("bridge.window"); if (cmp) { cmp.close(); } } // 深度清理 if (_deep) { this.pushs = []; } }, // 尝试弹出 tryPopup: function tryPopup() { var _this = this; // 空队列/节点非空 if (nx.dt.arrEmpty(this.queue) || this.popRoot.childrenCount > 0) { this.tryPush(); return; } // 加载中 if (this.cur) { nx.warn("Popups:载入中:", this.cur._wname); return; } this.cur = this.queue.shift(); nx.bridge.ui.openWindow(this.cur.wid, this.cur.args, function (_ret, _params) { if (!_ret) { nx.error("$Popups:加载失败:", _this.cur._wname); _this.cur = null; _this.tryPopup(); return; } _this.cur = null; }, true); }, // 尝试推送 tryPush: function tryPush() { var _this2 = this; // 空队列/节点非空 if (nx.dt.arrEmpty(this.pushs) || this.popRoot.childrenCount > 0) { return; } // 引导阶段不弹出 if (nx.bridge.plot) { var cur = nx.bridge.plot.vget("id"); if (nx.dt.strNEmpty(cur)) { return; } } // 加载中 if (this.cur) { nx.warn("Popups:载入中:", this.cur._wname); return; } this.cur = this.pushs.shift(); nx.bridge.ui.openWindow(this.cur.wid, this.cur.args, function (_ret, _params) { if (!_ret) { nx.error("$Popups:加载失败:", _this2.cur._wname); _this2.cur = null; _this2.tryPush(); return; } _this2.cur = null; }, true); } }); cc._RF.pop();