Class.js
18.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
var Common = require('Common');
var Network = require('Network');
var TVFocus = require('TVFocus');
var FocusInfo = require('FocusInfo');
var TVCanvas = require('TVCanvas');
var TVScrollParameter = require('TVScrollParameter');
var ListView = require('ListView');
var ListCell = require('ListCell');
cc.Class({
extends: TVCanvas,
properties: {
_aNavId: [],
spriteGrowup: cc.Sprite,
spriteGrade: cc.Sprite,
spriteCustom: cc.Sprite,
spriteMain: cc.Sprite,
PFB_NAV: {
default: null,
type: cc.Prefab
},
PFB_CATEGORY: {
default: null,
type: cc.Prefab
},
},
onLoad: function () {
this._super();
this._oSceneContext = {};
this._oSceneContext._iCurrentNavIndex = 0;
this.spriteGrowup.spriteFrame.setRect(cc.rect(0, 0, 173, 62));
this.spriteGrade.spriteFrame.setRect(cc.rect(0, 0, 173, 62));
this.spriteCustom.spriteFrame.setRect(cc.rect(0, 0, 173, 62));
this.spriteMain.spriteFrame.setRect(cc.rect(0, 0, 137, 65));
this._nodeNavListWrapper = cc.find('NavListArea/NavListWrapper', this.node);//
this._nodeNavList = cc.find('NavList', this._nodeNavListWrapper);
this._nodeNavList.addComponent(TVScrollParameter);
//右分类框框
this._nodeCategoryList = cc.find("CategoryList", this.node);
let lvCategoryList = this._nodeCategoryList.addComponent(ListView);
lvCategoryList.init(this, 3, 1, 3, 4, 'ClassCategoryListCell',
-415, 110, //起始位置
0, 138, 40, 0, //margin
1, 1,
function () {
// this.getDefaultCollection();
this.getNavList();
}
);
this.initPrefab();
// this.getNavList();
},
initPrefab: function () {
let aTheme = ["SHBK", "ZRZS", "YSQM", "YYSJ", "ZJYZ", "GSGX", "MSSG"];
for (let i = 0; i < 7; i++) {
// cc.log("加载预制...");
let nodeNavListCell = cc.instantiate(this.PFB_NAV);
nodeNavListCell.getChildByName("Theme").getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, 121, 44));
nodeNavListCell.getChildByName("Week").getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, 121, 44));
nodeNavListCell.x = nodeNavListCell.width / 2 + i * ((nodeNavListCell.width) + 40);
this._nodeNavList.addChild(nodeNavListCell, 10, "nav_cell_" + i);
cc.loader.loadRes('class/' + aTheme[i], cc.Texture2D, function (err, texture) { //背景框
nodeNavListCell.getChildByName("Theme").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 121, 44));
// spriteFrame._calculateUV();
});
cc.loader.loadRes('class/' + i, cc.Texture2D, function (err, texture) { //背景框
nodeNavListCell.getChildByName("Week").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 121, 44));
// spriteFrame._calculateUV();
});
//准备焦点坐标
let fiCategoryBlock = nodeNavListCell.addComponent(FocusInfo);
fiCategoryBlock.init(
'',
true, null, null, 1.0
);
nodeNavListCell.active = true; //在初始化时已经实现,这里只是为了避免一闪而过的背景
// nodeCategoryListCell.getComponent(FocusInfo).setEnable(false);
this._aFocusTargets[0]['nav_list_cell_' + i] = nodeNavListCell;
}
},
getNavList: function () {
let oTypeRequestParameters = {
"view": "json",
"limit": 7,
"sortField": "date_time",
"sortDirection": "asc",
"token": Common.TEST_API_TOKEN_EDU,
};
Network.ajax('GET', Common.TOPDRAW_API_SERVER_EDU + "ClassSchedule/ListCurrentWeek", null, oTypeRequestParameters,
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == 'success') {
if (oJSONResult.resultSet.length > 0) {
for (var i = 0; i < oJSONResult.resultSet.length; i++) {
this._aNavId.push(oJSONResult.resultSet[i].id);
//恢复上下文带过来的位置
// if (this._oSceneContext.requestedTypeId && this._oSceneContext.requestedTypeId == oJSONResult.resultSet[i].id) {
// this._iCurrentTypeIndex = i;
// }
// let nodeTypeListCell = cc.instantiate(this.PFB_TYPE);
// nodeTypeListCell.y = -nodeTypeListCell.height / 2 - i * (nodeTypeListCell.height + 27) - 10;
// this._nodeTypeList.addChild(nodeTypeListCell, 10, "TypeListCell" + i);
// //准备焦点坐标
// let fiTypeBlock = nodeTypeListCell.addComponent(FocusInfo);
// fiTypeBlock.init(
// '',
// true, null, null, 1.15
// );
// this._aFocusTargets[0]['type_list_cell_' + i] = nodeTypeListCell;
// if (oJSONResult.resultSet[i].image[0]) {
// let width = oJSONResult.resultSet[i].image[0].width;
// let height = oJSONResult.resultSet[i].image[0].height / 2;
// nodeTypeListCell.width = width;
// nodeTypeListCell.height = height;
// this._nodeTypeHeight = height;
// if (this._oSceneContext._iCurrentTypeIndex == i) {
// Network.loadImageInNativeRuntime(
// Common.TOPDRAW_IMAGE_SERVER + oJSONResult.resultSet[i].image[0].fileUrl,
// function (texture) {
// cc.find('Bg', nodeTypeListCell).getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, height, width, height));
// }, null, this
// );
// } else {
// Network.loadImageInNativeRuntime(
// Common.TOPDRAW_IMAGE_SERVER + oJSONResult.resultSet[i].image[0].fileUrl,
// function (texture) {
// cc.find('Bg', nodeTypeListCell).getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, width, height));
// }, null, this
// );
// }
// }
}
this._oSceneContext.requestedNavId = this._aNavId[this._oSceneContext._iCurrentNavIndex];
this.getCategoryList();
// this._bInitTypeListSuccess = true;
// this.checkDataReadyAndInitFocus(); //初始化焦点放到这里
} else {
this._oSceneContext.focusPath = "app";
}
cc.log("Success GET TYPE LIST...");
} else {
cc.log("Error GET TYPE LIST..." + oJSONResult.description);
}
} catch (error) {
cc.log("Exception GET TYPE LIST..." + error);
}
},
function (strResponse) {
cc.log("Communication Error : Get Type List Information..." + strResponse + "\r\n");
}, this, "uuid"
);
},
getCategoryList: function () {
var self = this;
let lvCategoryList = this._nodeCategoryList.getComponent(ListView);
let oCategoryRequestParameters = {
"view": "json",
"classScheduleId": this._aNavId[this._oSceneContext._iCurrentNavIndex],
"isVIP": 0,
};
let iStart1 = 0;
if (null != this._oSceneContext.categoryRecordIndexOfFirstCell) {
iStart1 = this._oSceneContext.categoryRecordIndexOfFirstCell;
}
lvCategoryList.setDataSource(
"GET",
Common.TOPDRAW_API_SERVER_EDU + "ClassSchedule/ListMedia",
oCategoryRequestParameters,
iStart1, (lvCategoryList.getShowCellRows() + lvCategoryList.getAlphaCellRows()) * lvCategoryList.getCellCountEachRow(),
"", ""
);
lvCategoryList.loadData(
function (strResponse) {
// var oJSONResult = JSON.parse(strResponse);
// if (oJSONResult.resultSet.length <= 0) { //没有数据就显示占位图
// cc.find('BlankIcon', this.node).opacity = 255
// } else {
// cc.find('BlankIcon', this.node).opacity = 0
// }
lvCategoryList.renderInitData(strResponse, function () {
this._bIsCategoryListDataInit = true;
// this._oSceneContext.categoryRecordIndexOfFirstCell = lvCategoryList.getRecordIndexOfFirstCellInPage();
this.checkDataReadyAndInitFocus();
// this.changeEditorStatus();
});
},
null,
this
);
},
checkDataReadyAndInitFocus: function (bInitSuccess) {
if (!this._bIsFocusInit) {
this.scheduleOnce(() => { //指定0让回调函数在下一帧立即执行
this.initFocus();
}, 0);
this._bIsFocusInit = true;
}
},
initFocus: function () {
var fiGrowup = this.spriteGrowup.addComponent(FocusInfo);
this._aFocusTargets[0]['to_growup_index'] = this.spriteGrowup;
fiGrowup.init(null, true);
var fiGrade = this.spriteGrade.addComponent(FocusInfo);
this._aFocusTargets[0]['to_grade_index'] = this.spriteGrade;
fiGrade.init(null, true);
var fiCustom = this.spriteCustom.addComponent(FocusInfo);
this._aFocusTargets[0]['to_custom_index'] = this.spriteCustom;
fiCustom.init(null, true);
var fiMain = this.spriteMain.addComponent(FocusInfo);
this._aFocusTargets[0]['to_main_index'] = this.spriteMain;
fiMain.init('{"click": [{"action": "ChangeScene","parameters": {"sceneName":"sceneRecommend"}}]}', true);
this._oSceneContext.focusPath = "nav_cell_0"; //---------------------先写死
var nodeInitFocus = cc.find(this._oSceneContext.focusPath, this._nodeNavList);
// cc.log("回退界面:" + this._oSceneContext.focusPath);
var nodeFocus = new cc.Node('nodeFocus');
this.node.addChild(nodeFocus, 0);
this._cFocus = this.node.getChildByName('nodeFocus').addComponent(TVFocus);
this._cFocus.init('focusContainer', this,
nodeInitFocus.getComponent(FocusInfo),
Common.SCREEN_WIDTH, Common.SCREEN_HEIGHT, 0, 0, 1.0, true);//暂且认定这几个参数控制焦点大小
},
keyDownDirection: function (Direct) {
var fiFocusTarget = null;
var fiCurrentFocus = this._fiCurrentFocus;
var oScrollParameter = null;
let aCheckResult;
fiFocusTarget = this._cFocus.findTarget(fiCurrentFocus, this._aFocusTargets, 0, Direct);
if (!fiFocusTarget) { return; }
aCheckResult = this.checkFocusTarget(fiFocusTarget, oScrollParameter);
fiFocusTarget = aCheckResult[0];
oScrollParameter = aCheckResult[1];
this.scheduleOnce(() => { //指定0让回调函数在下一帧立即执行(推荐位初始化图片后,需等待下一帧操作)
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Direct, null, oScrollParameter);
}, 0);
},
checkFocusTarget: function (fiFocusTarget, oScrollParameter) {
return [fiFocusTarget, oScrollParameter];
},
onKeyDown: function (event) {
this._super(event);
//TODO:给ListView传值,使其可以让滑块跟随滚动
let lvCategoryList = this.node.getChildByName('CategoryList').getComponent(ListView);
if (lvCategoryList) {
lvCategoryList.setCurrentFocus(this._fiCurrentFocus);
}
switch (event.keyCode) {
case cc.macro.KEY.up:
case Common.ANDROID_KEY.up:
if (0 == this._fiCurrentFocus.node.getName().indexOf('CategoryOtherListCell')) {
var index = parseInt(this._fiCurrentFocus.node.getName().replace('CategoryOtherListCell', ''));
// cc.log("当前时多少条目:"+index);
let lvCategoryList = this.node.getChildByName('CategoryList').getComponent(ListView);
if (lvCategoryList.scrollARowUp(index)) {
return;
}
}
this.keyDownDirection(Common.MOVE_DIRECTION_UP);
break;
case cc.macro.KEY.right:
case Common.ANDROID_KEY.right:
// this.scheduleOnce(() => { //指定0让回调函数在下一帧立即执行
// this.initFocus();
// }, 0);
this.keyDownDirection(Common.MOVE_DIRECTION_RIGHT);
break;
case cc.macro.KEY.down:
case Common.ANDROID_KEY.down:
if (0 == this._fiCurrentFocus.node.getName().indexOf('CategoryOtherListCell')) {
var index = parseInt(this._fiCurrentFocus.node.getName().replace('CategoryOtherListCell', ''));
let lvCategoryList = this.node.getChildByName('CategoryList').getComponent(ListView);
if (lvCategoryList.scrollARowDown(null, index)) {
return;
}
}
this.keyDownDirection(Common.MOVE_DIRECTION_DOWN);
break;
case cc.macro.KEY.left:
case Common.ANDROID_KEY.left:
this.keyDownDirection(Common.MOVE_DIRECTION_LEFT);
break;
case cc.macro.KEY.enter:
case cc.macro.KEY.space:
case Common.ANDROID_KEY.enter:
if (0 == this._fiCurrentFocus.node.getName().indexOf('MainSprite')) {
this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
} else {
this.commonTip("敬请期待", 1);
}
break;
case cc.macro.KEY.backspace:
case Common.ANDROID_KEY.back:
this.backAScene();
break;
}
},
onBeforeFocusChange: function (event) {
let fiFrom = event.detail.from;
let fiTo = event.detail.to;
if (0 == fiFrom.node.getName().indexOf('GrowupSprite')) {
cc.loader.loadRes('class/growup_button', cc.Texture2D, function (err, texture) {
fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 173, 62));
});
}
if (0 == fiFrom.node.getName().indexOf('GradeSprite')) {
cc.loader.loadRes('class/grade_button', cc.Texture2D, function (err, texture) {
fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 174, 62));
});
}
if (0 == fiFrom.node.getName().indexOf('CustomSprite')) {
cc.loader.loadRes('class/customizedCourses_button', cc.Texture2D, function (err, texture) {
fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 176, 62));
});
}
if (0 == fiFrom.node.getName().indexOf('MainSprite')) {
cc.loader.loadRes('button/home_button', cc.Texture2D, function (err, texture) {
fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 137, 63));
});
}
if (0 == fiFrom.node.getName().indexOf('nav_cell_')) {
fiFrom.node.getChildByName("Bg").getChildByName("active").active = false;
fiFrom.node.getChildByName("Star").getChildByName("active").active = false;
}
},
onAfterFocusChange: function (event) {
let fiTo = event.detail.to;
if (0 == fiTo.node.getName().indexOf('GrowupSprite')) {
cc.loader.loadRes('class/growup_button', cc.Texture2D, function (err, texture) {
fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 62, 173, 62));
});
}
if (0 == fiTo.node.getName().indexOf('GradeSprite')) {
cc.loader.loadRes('class/grade_button', cc.Texture2D, function (err, texture) {
fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 62, 174, 62));
});
}
if (0 == fiTo.node.getName().indexOf('CustomSprite')) {
cc.loader.loadRes('class/customizedCourses_button', cc.Texture2D, function (err, texture) {
fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 62, 176, 62));
});
}
if (0 == fiTo.node.getName().indexOf('MainSprite')) {
cc.loader.loadRes('button/home_button', cc.Texture2D, function (err, texture) {
fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 63, 137, 63));
});
}
if (0 == fiTo.node.getName().indexOf('nav_cell_')) {
fiTo.node.getChildByName("Bg").getChildByName("active").active = true;
fiTo.node.getChildByName("Star").getChildByName("active").active = true;
}
},
doCurrentFocusTVLinkAction: function (strAction) {
let strTVLink = this._fiCurrentFocus.getTVLink();
var joTVLink = null;
try {
joTVLink = JSON.parse(strTVLink);
let jaOperationList = joTVLink.click;
for (let i = 0; i < jaOperationList.length; i++) {
switch (jaOperationList[i].action) {
default:
this.doTVLinkAction(jaOperationList[i]);
break;
}
}
} catch (error) {
cc.log("runTVLinkAction Exception..." + error);
}
},
});