|
@@ -0,0 +1,97 @@
|
|
1
|
+/**
|
|
2
|
+ * 界面相关的工具
|
|
3
|
+ */
|
|
4
|
+
|
|
5
|
+require("UIInfo")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+/**
|
|
9
|
+ * 登录数据管理
|
|
10
|
+ */
|
|
11
|
+let UIMgr = {
|
|
12
|
+ //* ************* 初始化 ************* *//
|
|
13
|
+ /**
|
|
14
|
+ * 初始化
|
|
15
|
+ *
|
|
16
|
+ */
|
|
17
|
+ init () {
|
|
18
|
+ if (CC_EDITOR) {
|
|
19
|
+ return;
|
|
20
|
+ }
|
|
21
|
+ },
|
|
22
|
+
|
|
23
|
+ getUIRoot () {
|
|
24
|
+ return cc.director.getScene().getChildByName('Root');
|
|
25
|
+ },
|
|
26
|
+
|
|
27
|
+ open(type, param) {
|
|
28
|
+ // edt_prefab/ctrl/prefab_normal_alert
|
|
29
|
+ let prefabPath = 'edt_prefab/ctrl/' + window.JMC.UIPath[type];
|
|
30
|
+ this.showUI(prefabPath, param)
|
|
31
|
+ },
|
|
32
|
+
|
|
33
|
+ showUI (prefabPath, alertData, cb, cache = false) {
|
|
34
|
+ G.LogUtils.warn('showAlert', prefabPath);
|
|
35
|
+
|
|
36
|
+ let temp = undefined;
|
|
37
|
+ cc.loader.loadRes(prefabPath, cc.Prefab, (completedCount, totalCount, item)=>{
|
|
38
|
+ temp = G.AppUtils.getLoadProgressInfo(temp, completedCount, totalCount);
|
|
39
|
+ G.AppUtils.getSceneCtrl().updateLoadingProgress(temp.precent * 100, 100, item);
|
|
40
|
+ }, (err, prefab) => {
|
|
41
|
+ G.AppUtils.getSceneCtrl().updateLoadingProgress(100, 100, undefined);
|
|
42
|
+
|
|
43
|
+ if (err) {
|
|
44
|
+ G.AppUtils.getSceneCtrl().addToast('网络异常!');
|
|
45
|
+ G.LogUtils.error('[showAlert]', err);
|
|
46
|
+ if (cb) {
|
|
47
|
+ cb(undefined, 'error', err);
|
|
48
|
+ }
|
|
49
|
+ return;
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ let node = cc.instantiate(prefab);
|
|
53
|
+ let alert = node.getComponent('JMAlertBase');
|
|
54
|
+ if (cb) {
|
|
55
|
+ cb(alert, 'willShow', undefined);
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ let uiRoot = this.getUIRoot();
|
|
59
|
+ let ret = this.pushUI(uiRoot, alert);
|
|
60
|
+ if (!ret) {
|
|
61
|
+ return;
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ // 因为reloadData如果出错会导致游戏闪屏,所以加上try catch
|
|
65
|
+ try {
|
|
66
|
+ alert.reloadData(alertData, cb);
|
|
67
|
+ } catch (error) {
|
|
68
|
+ G.LogUtils.error('AlertCtrl showAlert error:', error);
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ if (!cache) {
|
|
72
|
+ cc.loader.releaseRes(prefabPath);
|
|
73
|
+ }
|
|
74
|
+ });
|
|
75
|
+ },
|
|
76
|
+
|
|
77
|
+ /**
|
|
78
|
+ * 弹出指定弹框
|
|
79
|
+ *
|
|
80
|
+ * @author Pyden
|
|
81
|
+ * @date 2019-03-22
|
|
82
|
+ * @param {JMAlertBase} alert 弹框
|
|
83
|
+ */
|
|
84
|
+ pushUI (alert) {
|
|
85
|
+ if (!cc.isValid(alert) || !cc.isValid(uiRoot)) {
|
|
86
|
+ return false;
|
|
87
|
+ }
|
|
88
|
+
|
|
89
|
+ let zIndex = alert.alertZIndex;
|
|
90
|
+ uiRoot.addChild(alert.node, zIndex);
|
|
91
|
+
|
|
92
|
+ cc.game.emit('e_ui_push_alert', {alert: alert});
|
|
93
|
+ return true;
|
|
94
|
+ },
|
|
95
|
+}
|
|
96
|
+
|
|
97
|
+module.exports = UIMgr;
|