Просмотр исходного кода

Merge branch 'master' of http://git.mokasz.com/zouyong/mk_framework

薛鸿潇 5 лет назад
Родитель
Сommit
d065509a57

+ 12 - 0
mk_framework/assets/resources/prefab/uiItem.meta

@@ -0,0 +1,12 @@
+{
+  "ver": "1.1.2",
+  "uuid": "2fdc9c29-4a46-40ba-bba3-61adbae081f9",
+  "isBundle": false,
+  "bundleName": "",
+  "priority": 1,
+  "compressionType": {},
+  "optimizeHotUpdate": {},
+  "inlineSpriteFrames": {},
+  "isRemoteBundle": {},
+  "subMetas": {}
+}

+ 28 - 0
mk_framework/assets/resources/prefab/uiItem/1.ts

@@ -0,0 +1,28 @@
+// Learn TypeScript:
+//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
+// Learn Attribute:
+//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
+// Learn life-cycle callbacks:
+//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
+
+const {ccclass, property} = cc._decorator;
+
+@ccclass
+export default class NewClass extends cc.Component {
+
+    @property(cc.Label)
+    label: cc.Label = null;
+
+    @property
+    text: string = 'hello';
+
+    // LIFE-CYCLE CALLBACKS:
+
+    // onLoad () {}
+
+    start () {
+
+    }
+
+    // update (dt) {}
+}

+ 9 - 0
mk_framework/assets/resources/prefab/uiItem/1.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "221a271a-4349-4582-9004-a89635b59f5a",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 28 - 0
mk_framework/assets/resources/prefab/uiPanel/2.ts

@@ -0,0 +1,28 @@
+// Learn TypeScript:
+//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
+// Learn Attribute:
+//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
+// Learn life-cycle callbacks:
+//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
+
+const {ccclass, property} = cc._decorator;
+
+@ccclass
+export default class NewClass extends cc.Component {
+
+    @property(cc.Label)
+    label: cc.Label = null;
+
+    @property
+    text: string = 'hello';
+
+    // LIFE-CYCLE CALLBACKS:
+
+    // onLoad () {}
+
+    start () {
+
+    }
+
+    // update (dt) {}
+}

+ 9 - 0
mk_framework/assets/resources/prefab/uiPanel/2.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "63235b10-da18-4188-b3a6-b0db180fa7ac",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

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

@@ -1,4 +1,3 @@
-
 /**
  * UI管理类
  * @author 冯聪
@@ -22,10 +21,9 @@ export default class UISystem {
     /**
      * 打开panel界面
      * @param panelName  界面名称
-     * @param callBack   打开之后的回调
      * @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)) {
             return;
@@ -33,39 +31,49 @@ export default class UISystem {
 
         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);
+                })
+        });
     }
 
     /**