|
@@ -26,6 +26,7 @@ cc.Class({
|
26
|
26
|
default: undefined,
|
27
|
27
|
type: RegisterPanel,
|
28
|
28
|
},
|
|
29
|
+ loadProgressBar: JMLoadProgressBar,
|
29
|
30
|
},
|
30
|
31
|
|
31
|
32
|
|
|
@@ -36,6 +37,14 @@ cc.Class({
|
36
|
37
|
// 进行授权、登录、注册等操作
|
37
|
38
|
this.initAuth();
|
38
|
39
|
this.initUI();
|
|
40
|
+
|
|
41
|
+ cc.game.on('e_socket_on_logined', this._handleSocketOnLogined, this);
|
|
42
|
+ cc.game.on('e_socket_on_closed', this._handleSocketOnClosed, this);
|
|
43
|
+ },
|
|
44
|
+
|
|
45
|
+ onDestroy () {
|
|
46
|
+ cc.game.targetOff(this);
|
|
47
|
+ this._super();
|
39
|
48
|
},
|
40
|
49
|
|
41
|
50
|
initAuth () {
|
|
@@ -52,11 +61,107 @@ cc.Class({
|
52
|
61
|
this.registerPanel.reloadData(()=> {
|
53
|
62
|
this.showpanel(TagType.LOGIN);
|
54
|
63
|
});
|
|
64
|
+
|
|
65
|
+ // 隐藏进度
|
|
66
|
+ this.showDownloadProgress(false);
|
|
67
|
+ },
|
|
68
|
+
|
|
69
|
+ /**
|
|
70
|
+ * 是否显示下载进度。不显示下载进度时,展示授权按钮
|
|
71
|
+ *
|
|
72
|
+ * @param {Boolean} isShow
|
|
73
|
+ */
|
|
74
|
+ showDownloadProgress (isShow) {
|
|
75
|
+ // 更新布局
|
|
76
|
+ this.loadProgressBar.node.active = isShow;
|
|
77
|
+
|
|
78
|
+ if (isShow) {
|
|
79
|
+ this.loadProgressBar.progressBar.progress = 0;
|
|
80
|
+ this.loadProgressBar.setProgress(15, 1);
|
|
81
|
+ }
|
55
|
82
|
},
|
56
|
83
|
|
57
|
84
|
showpanel (tagType) {
|
58
|
85
|
this._tagType = tagType;
|
59
|
86
|
this.loginPanel.node.active = tagType == TagType.LOGIN;
|
60
|
87
|
this.registerPanel.node.active = tagType == TagType.REGISTER;
|
61
|
|
- }
|
|
88
|
+ },
|
|
89
|
+
|
|
90
|
+ /**
|
|
91
|
+ * 登录成功
|
|
92
|
+ *
|
|
93
|
+ */
|
|
94
|
+ _handleSocketOnLogined () {
|
|
95
|
+ this.didLoginSuccessful();
|
|
96
|
+ },
|
|
97
|
+
|
|
98
|
+ /**
|
|
99
|
+ * 登录成功
|
|
100
|
+ *
|
|
101
|
+ */
|
|
102
|
+ _handleSocketOnClosed () {
|
|
103
|
+ this.didLoginFailed();
|
|
104
|
+ },
|
|
105
|
+
|
|
106
|
+ /**
|
|
107
|
+ * 登录成功
|
|
108
|
+ *
|
|
109
|
+ */
|
|
110
|
+ didLoginSuccessful () {
|
|
111
|
+ G.LogUtils.log('didLoginSuccessful');
|
|
112
|
+ this.enterMainScene();
|
|
113
|
+ },
|
|
114
|
+
|
|
115
|
+ /**
|
|
116
|
+ * 登录失败
|
|
117
|
+ *
|
|
118
|
+ */
|
|
119
|
+ didLoginFailed () {
|
|
120
|
+ G.LogUtils.log('didLoginFailed');
|
|
121
|
+ },
|
|
122
|
+
|
|
123
|
+ // 进入主界面
|
|
124
|
+ enterMainScene () {
|
|
125
|
+ // 避免反复进入
|
|
126
|
+ if (this._alreadyEnterScene)
|
|
127
|
+ return;
|
|
128
|
+
|
|
129
|
+ // 提前预加载大厅场景
|
|
130
|
+ if (!this.didLoadMainScene) {
|
|
131
|
+ this.preLoadMainScene();
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ this._alreadyEnterScene = true;
|
|
135
|
+ this.scheduleOnce(() => {
|
|
136
|
+ G.AppUtils.runScene('scene_main');
|
|
137
|
+ }, 0.1);
|
|
138
|
+
|
|
139
|
+ this.showDownloadProgress(true);
|
|
140
|
+ this.loadProgressBar.setProgress(0.1, 1);
|
|
141
|
+ },
|
|
142
|
+
|
|
143
|
+ // 预加载主界面
|
|
144
|
+ preLoadMainScene () {
|
|
145
|
+ // 加载中、或者加载成功时,不再加载
|
|
146
|
+ if (this.isPreLoading || this.didLoadHomeScene) {
|
|
147
|
+ return;
|
|
148
|
+ }
|
|
149
|
+ this.isPreLoading = true;
|
|
150
|
+
|
|
151
|
+ // 开始预加载资源
|
|
152
|
+ let temp = undefined;
|
|
153
|
+ cc.director.preloadScene('scene_main', (completedCount, totalCount, item)=>{
|
|
154
|
+ temp = G.AppUtils.getLoadProgressInfo(temp, completedCount, totalCount);
|
|
155
|
+ this.downloadPercent = Math.floor(temp.precent * 100);
|
|
156
|
+ }, (error, asset) => {
|
|
157
|
+ this.isPreLoading = false;
|
|
158
|
+ if (error) {
|
|
159
|
+ this.addToast('网络异常!场景加载失败');
|
|
160
|
+ return;
|
|
161
|
+ }
|
|
162
|
+
|
|
163
|
+ this.didLoadMainScene = true;
|
|
164
|
+ this.enterMainScene();
|
|
165
|
+ });
|
|
166
|
+ },
|
62
|
167
|
});
|