12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- /**
- * 界面相关的工具
- */
- require("UIInfo")
- /**
- * 登录数据管理
- */
- let UIMgr = {
- //* ************* 初始化 ************* *//
- /**
- * 初始化
- *
- */
- init () {
- if (CC_EDITOR) {
- return;
- }
- },
- getUIRoot () {
- return cc.director.getScene().getChildByName('Root');
- },
- open(type, param) {
- // edt_prefab/ctrl/prefab_normal_alert
- let prefabPath = 'edt_prefab/ctrl/' + window.JMC.UIPath[type];
- this.showUI(prefabPath, param)
- },
- showUI (prefabPath, alertData, cb, cache = false) {
- G.LogUtils.warn('showAlert', prefabPath);
- 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);
- let alert = node.getComponent('JMAlertBase');
- if (cb) {
- cb(alert, 'willShow', undefined);
- }
- let uiRoot = this.getUIRoot();
- let ret = this.pushUI(uiRoot, alert);
- if (!ret) {
- return;
- }
- // 因为reloadData如果出错会导致游戏闪屏,所以加上try catch
- try {
- alert.reloadData(alertData, cb);
- } catch (error) {
- G.LogUtils.error('AlertCtrl showAlert error:', error);
- }
- if (!cache) {
- cc.loader.releaseRes(prefabPath);
- }
- });
- },
- /**
- * 弹出指定弹框
- *
- * @author Pyden
- * @date 2019-03-22
- * @param {JMAlertBase} alert 弹框
- */
- pushUI (alert) {
- if (!cc.isValid(alert) || !cc.isValid(uiRoot)) {
- return false;
- }
- let zIndex = alert.alertZIndex;
- uiRoot.addChild(alert.node, zIndex);
- cc.game.emit('e_ui_push_alert', {alert: alert});
- return true;
- },
- }
- module.exports = UIMgr;
|