123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- /**
- * 界面相关的工具
- */
- require("UIInfo")
- const Proxy = require('Proxy');
- const ViewBase = require('ViewBase');
- /**
- * 登录数据管理
- */
- let UIMgr = {
- //* ************* 初始化 ************* *//
- /**
- * 初始化
- *
- */
- init () {
- if (CC_EDITOR) {
- return;
- }
- // 常亮定义
- this.defaultUIPath = 'edt_prefab/';
- this.uiRoots = {
- [JMC.Proxy.Main]:"Main",
- [JMC.Proxy.Navigation]:"Navigation",
- [JMC.Proxy.Toast]:"Toast",
- [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 = this.defaultUIPath + JMC.UIPath[type];
- this.showUI(prefabPath, param)
- },
- showUI(prefabPath, param, cb, cache = false) {
- G.LogUtils.warn('showAlert', prefabPath);
- let self = this;
- cc.loader.loadRes(prefabPath, cc.Prefab, (completedCount, totalCount, item) => {
- }, (err, prefab) => {
- 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 == JMC.Proxy.Main)
- }
- let ret = self.safeAddChild(uiRoot, node);
- if (!ret) {
- return;
- }
- let viewBase = node.getComponent(ViewBase);
- if (viewBase) {
- viewBase.init(param)
- }
- if (!cache) {
- cc.loader.releaseRes(prefabPath);
- }
- });
- },
- safeAddChild(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;
|