123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /**
- * 界面相关的工具
- */
- require("UIInfo")
- const Proxy = require('Proxy');
- /**
- * 登录数据管理
- */
- let UIMgr = {
- //* ************* 初始化 ************* *//
- /**
- * 初始化
- *
- */
- init () {
- if (CC_EDITOR) {
- return;
- }
- this.UIRoots = {
- [window.JMC.Proxy.Main]:"Main",
- [window.JMC.Proxy.Navigation]:"Navigation",
- [window.JMC.Proxy.Toast]:"Toast",
- [window.JMC.Proxy.UI]:"UI",
- };
- },
- getUIRoot () {
- let curScene = cc.director.getScene();
- let root = curScene.getChildByName('Canvas').getChildByName("Root").getChildByName("UIRoot");
- return root;
- },
- open(type, param) {
- let prefabPath = 'edt_prefab/' + window.JMC.UIPath[type];
- this.showUI(prefabPath, param)
- },
- showUI(prefabPath, alertData, cb, cache = false) {
- G.LogUtils.warn('showAlert', prefabPath);
- let self = this;
- let temp = undefined;
- cc.loader.loadRes(prefabPath, cc.Prefab, (completedCount, totalCount, item)=>{
- temp = G.AppUtils.getLoadProgressInfo(temp, completedCount, totalCount);
- G.AppUtils.getSceneCtrl().updateLoadingProgress(temp.precent * 100, 100, item);
- }, (err, prefab) => {
- G.AppUtils.getSceneCtrl().updateLoadingProgress(100, 100, undefined);
- if (err) {
- G.AppUtils.getSceneCtrl().addToast('网络异常!');
- G.LogUtils.error('[showAlert]', err);
- if (cb) {
- cb(undefined, 'error', err);
- }
- return;
- }
- let node = cc.instantiate(prefab);
- if (cb) {
- cb(alert, 'willShow', undefined);
- }
- let uiRoot = self.getUIRoot();
- let proxy = node.getComponent(Proxy);
- if (proxy){
- uiRoot = uiRoot.getChildByName(self.UIRoots[proxy.type])
- self.clearUIType(proxy.type, proxy.type == window.JMC.Proxy.Main)
- }
-
- // let uiRoot = this.getUIRoot();
- // .getChildByName(this.UIRoots[type])
- let ret = self.pushUI(uiRoot, node);
- if (!ret) {
- return;
- }
- if (!cache) {
- cc.loader.releaseRes(prefabPath);
- }
- });
- },
- /**
- * 弹出指定弹框
- *
- * @author Pyden
- * @date 2019-03-22
- * @param {JMAlertBase} alert 弹框
- */
- pushUI (uiRoot, node) {
- if (!cc.isValid(node) || !cc.isValid(uiRoot)) {
- return false;
- }
- uiRoot.addChild(node);
- cc.game.emit('e_ui_push_alert', {node});
- return true;
- },
- clearUIType(type, isClear) {
- if (!isClear) {
- return
- }
- let uiRoot = this.getUIRoot();
- let typeRoot = uiRoot.getChildByName(this.UIRoots[type]);
- typeRoot.removeAllChildren();
- }
- }
- module.exports = UIMgr;
|