Browse Source

[FC]:UISystem打开panel更改为promise方式

fengcong 5 years ago
parent
commit
b8719ee32a
1 changed files with 39 additions and 31 deletions
  1. 39 31
      mk_framework/assets/script/mk/system/UISystem.ts

+ 39 - 31
mk_framework/assets/script/mk/system/UISystem.ts

@@ -1,4 +1,3 @@
-
 /**
 /**
  * UI管理类
  * UI管理类
  * @author 冯聪
  * @author 冯聪
@@ -22,10 +21,9 @@ export default class UISystem {
     /**
     /**
      * 打开panel界面
      * 打开panel界面
      * @param panelName  界面名称
      * @param panelName  界面名称
-     * @param callBack   打开之后的回调
      * @param openAction 打开之后的操(需不需要关闭其他界面)
      * @param openAction 打开之后的操(需不需要关闭其他界面)
      */
      */
-    openPanel(panelName: string, callBack: Function = null, openAction: OpenActionType = OpenActionType.normal) {
+    openPanel(panelName: string, openAction: OpenActionType = OpenActionType.normal): Promise<any> {
 
 
         if (this.isPanelOpening || this.getCurOnPanel(panelName)) {
         if (this.isPanelOpening || this.getCurOnPanel(panelName)) {
             return;
             return;
@@ -33,39 +31,49 @@ export default class UISystem {
 
 
         this.isPanelOpening = true;
         this.isPanelOpening = true;
 
 
-        mk.loader.load(`${this.panelPrefanbUrl}` + panelName, cc.Prefab).then((prefab) => {
-
-            this.isPanelOpening = false;
+        return new Promise((resolve, reject) => {
 
 
-            let node_panel = cc.instantiate(prefab);
-            this.curOnPanelDic[panelName] = node_panel;
-            //如果父节点不存在,就默认把该节点定为panel的父节点
-            if (!this.panelParent) {
-                mk.console.log("[UISystem] UI的父节点panelParent为null,需指定UI打开的父节点");
-                return;
-            }
-            this.panelParent.addChild(node_panel);
+            mk.loader.load(`${this.panelPrefanbUrl}` + panelName, cc.Prefab)
+                .then((prefab) => {
 
 
-            callBack && callBack();
+                    this.isPanelOpening = false;
+                    let node_panel = cc.instantiate(prefab);
+                    this.curOnPanelDic[panelName] = node_panel;
 
 
-            switch (openAction) {
-                case OpenActionType.normal:
-                    break;
-                case OpenActionType.closeLast:
-                    if (this.lastOpenPanelName) {
-                        this.closePanel(this.lastOpenPanelName);
+                    //如果父节点不存在,就默认把该节点定为panel的父节点
+                    if (!this.panelParent) {
+                        console.error("[UISystem] UI的父节点panelParent为null,需指定UI打开的父节点");
+                        return;
                     }
                     }
-                    break;
-                case OpenActionType.closeOther:
-                    let keys = Object.keys(this.curOnPanelDic).filter((key) => { key != panelName });
-                    for (var i = 0; i < keys.length; i++) {
-                        let key = keys[i];
-                        this.closePanel(key);
+
+                    this.panelParent.addChild(node_panel);
+
+                    switch (openAction) {
+                        case OpenActionType.normal:
+                            break;
+                        case OpenActionType.closeLast:
+                            if (this.lastOpenPanelName) {
+                                this.closePanel(this.lastOpenPanelName);
+                            }
+                            break;
+                        case OpenActionType.closeOther:
+                            let keys = Object.keys(this.curOnPanelDic).filter((key) => { key != panelName });
+                            for (var i = 0; i < keys.length; i++) {
+                                let key = keys[i];
+                                this.closePanel(key);
+                            }
+                            break;
                     }
                     }
-                    break;
-            }
-            this.lastOpenPanelName = panelName;
-        })
+
+                    this.lastOpenPanelName = panelName;
+
+                    //返回panel
+                    resolve(node_panel);
+                })
+                .catch((err) => {
+                    reject(err);
+                })
+        });
     }
     }
 
 
     /**
     /**