Game.js
22.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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
//游戏探索界面
//ListView在显示只有1列的列表时,加载不到下一页信息,待排查!
var Common = require('Common');
var Network = require('Network');
var TVFocus = require('TVFocus');
var FocusInfo = require('FocusInfo');
var TVCanvas = require('TVCanvas');
var Utils = require('Utils');
var BusinessParameter = require('BusinessParameter');
var ListView = require('ListView');
var ListCell = require('ListCell');
var GameLobbyCategoryJson = require('GameLobbyCategoryJson');
var GlobalValue = require('GlobalValue');
cc.Class({
extends: TVCanvas,
properties: {
activitySprite: cc.Sprite,
roleSprite: cc.Sprite,
taskSprite: cc.Sprite,
achievementSprite: cc.Sprite,
shopSprite: cc.Sprite,
closeTaskSprite: cc.Sprite,
closeAchievementSprite: cc.Sprite,
closeActivitySprite: cc.Sprite,
roleAnim: dragonBones.ArmatureDisplay,
pointer: cc.Sprite, //大转盘指针
pointerButton: cc.Sprite, //大转盘按钮
PFB_GAME_TASKITEM: {
default: null,
type: cc.Prefab
},
PFB_POP: {
default: null,
type: cc.Prefab
},
},
onLoad: function () {
this._super();
this._aFocusTargets[1] = []; //任务弹窗焦点
this._aFocusTargets[2] = []; //成就弹窗焦点
this._aFocusTargets[3] = []; //活动大转盘弹窗
this._iSceneStatus = 0; //焦点层级
this.roleAnim.node.zIndex = 40;
this.initFocus();
cc.find("bgScrollView", this.node).getComponent(cc.ScrollView).scrollToLeft();
//右分类框框
this._nodeCategoryList = cc.find("task/task_panel/CategoryList", this.node);
let lvCategoryList = this._nodeCategoryList.addComponent(ListView);
lvCategoryList.init(this, 3, 1, 3, 1, 'pfbGameTaskItemCell',
0, 100, //起始位置
0, 0, 0, 0, //margin
1, 1,
function () {
this.getTaskCategoryList();
}
);
this._nodeAchievementList = cc.find("achievement/task_panel/CategoryList", this.node);
let lvNodeAchievementList = this._nodeAchievementList.addComponent(ListView);
lvNodeAchievementList.init(this, 2, 1, 2, 3, 'GameAchievementCell',
-140, 80,//起始位置
0, 0, 10, 0, //margin
1, 1,
function () {
this.getAchievementList();
}
);
},
getTaskCategoryList: function () {
let lvCategoryList = this._nodeCategoryList.getComponent(ListView);
//请求列表
let oMediaParas = {};
oMediaParas.categoryId = 9;//
oMediaParas.appId = "";
let iStart1 = 0;
if (null != this._oSceneContext.categoryRecordIndexOfFirstCell) {
iStart1 = this._oSceneContext.categoryRecordIndexOfFirstCell;
}
lvCategoryList.setDataSource(
"GET",
Common.TOPDRAW_API_SERVER_EDU + "Media/List",
oMediaParas,
iStart1, (lvCategoryList.getShowCellRows() + lvCategoryList.getAlphaCellRows()) * lvCategoryList.getCellCountEachRow(),
null, null
);
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
// }
// strResponse = GameLobbyCategoryJson.gameCategory; //暂时采用假数据
// lvCategoryList.renderInitData(JSON.stringify(strResponse)); //将假数据转成字符串在给过去
// this._bIsCategoryListDataInit = true;
// this._oSceneContext.categoryRecordIndexOfFirstCell = lvCategoryList.getRecordIndexOfFirstCellInPage();
// this.checkDataReadyAndInitFocus();
lvCategoryList.renderInitData(strResponse, function () {
this._bIsCategoryListDataInit = true;
this._oSceneContext.categoryRecordIndexOfFirstCell = lvCategoryList.getRecordIndexOfFirstCellInPage();
// this.checkDataReadyAndInitFocus();
});
},
null,
this
);
},
getAchievementList: function () {
let lvCategoryList = this._nodeAchievementList.getComponent(ListView);
//请求列表
let oMediaParas = {};
oMediaParas.categoryId = 9;//
oMediaParas.appId = "";
let iStart = 0;
// //滚行:上翻-4,下翻+4,
// //滚页:上翻-8,下翻+8
// if (null != this._oSceneContext.categoryRecordIndexOfFirstCell && this._oSceneContext.categoryRecordIndexOfFirstCell != 0) {
// //TODO:回退界面返回原来焦点框位置
// iStart = this._oSceneContext.categoryRecordIndexOfFirstCell + this._oSceneContext.iRecordKeyDownOperation;
// }
if (null != this._oSceneContext.categoryRecordIndexOfFirstCell) {
iStart = this._oSceneContext.categoryRecordIndexOfFirstCell;
}
lvCategoryList.setDataSource(
"GET",
Common.TOPDRAW_API_SERVER_EDU + "Media/List",
oMediaParas,
iStart, (lvCategoryList.getShowCellRows() + lvCategoryList.getAlphaCellRows()) * lvCategoryList.getCellCountEachRow(),
null, null
);
lvCategoryList.loadData(
function (strResponse) {
// strResponse = GameLobbyCategoryJson.gameCategory; //暂时采用假数据
// cc.log("网络列表:" + JSON.stringify(strResponse));
lvCategoryList.renderInitData(strResponse); //将假数据转成字符串在给过去
this._bIsCategoryListDataInit = true;
this._oSceneContext.categoryRecordIndexOfFirstCell = lvCategoryList.getRecordIndexOfFirstCellInPage();
// this.checkDataReadyAndInitFocus();
},
null,
this
);
},
initFocus: function () {
//弄各个小岛焦点
for (let i = 1; i < 4; i++) {
let fiIslandSprite = cc.find("bgScrollView/viewport/content/island_" + i, this.node).addComponent(FocusInfo);//
this._aFocusTargets[0]['to_island' + i] = cc.find("bgScrollView/viewport/content/island_" + i, this.node);
fiIslandSprite.init(
'{"click": [{"action": "ChangeScene","parameters": {"sceneName":"sceneExploreNew","order":"'+ i +'"}}]}',
true, null, null, 1
);
//弄小岛下方的进度信息
if(cc.find("scrollViewBg/scrollViewBar",fiIslandSprite.node) && cc.find("progress",fiIslandSprite.node)){
this.totalTask = GlobalValue.ISLAND_CONFIG[i-1].PROGRESS_BAR_VALUE;
cc.find("scrollViewBg/scrollViewBar",fiIslandSprite.node).width=GlobalValue.ISLAND_CONFIG[i-1].PROGRESS_BAR_VALUE * 200;
cc.find("progress",fiIslandSprite.node).getComponent(cc.Label).string=GlobalValue.ISLAND_CONFIG[i-1].PROGRESS_LABEL_VALUE;
}
if (i == 1) {
fiIslandSprite.setTVLink("");
}
if (i == 3) { //这里是测试时使用数据,保证角色在第二个小岛上
this.roleAnim.node.x = fiIslandSprite.node.x;
this.roleAnim.node.y = fiIslandSprite.node.y;
}
}
var fiActivitySprite = this.activitySprite.addComponent(FocusInfo);//
this._aFocusTargets[0]['to_activity'] = this.activitySprite;
fiActivitySprite.init(
null, true
);
var fiRoleSprite = this.roleSprite.addComponent(FocusInfo);//
this._aFocusTargets[0]['to_role'] = this.roleSprite;
fiRoleSprite.init(
null, true
);
var fiTaskSprite = this.taskSprite.addComponent(FocusInfo);//
this._aFocusTargets[0]['to_task'] = this.taskSprite;
fiTaskSprite.init(
null, true
);
var fiAchievementSprite = this.achievementSprite.addComponent(FocusInfo);//
this._aFocusTargets[0]['to_achievement'] = this.achievementSprite;
fiAchievementSprite.init(
null, true
);
var fiShopSprite = this.shopSprite.addComponent(FocusInfo);//
this._aFocusTargets[0]['to_shop'] = this.shopSprite;
fiShopSprite.init(
null, true
);
var fiPointerButton = this.pointerButton.addComponent(FocusInfo);//
this._aFocusTargets[3]['to_pointer_button'] = this.pointerButton;
fiPointerButton.init(
null, true
);
var fiCloseTaskSprite = this.closeTaskSprite.addComponent(FocusInfo);//
this._aFocusTargets[1]['to_close_task'] = this.closeTaskSprite;
fiCloseTaskSprite.init(
null, true
);
var fiCloseAchievementSprite = this.closeAchievementSprite.addComponent(FocusInfo);//
this._aFocusTargets[2]['to_close_achievement'] = this.closeAchievementSprite;
fiCloseAchievementSprite.init(
null, true
);
var fiCloseActivitySprite = this.closeActivitySprite.addComponent(FocusInfo);//
this._aFocusTargets[3]['to_close_activity'] = this.closeActivitySprite;
fiCloseActivitySprite.init(
null, true
);
var nodeFocus = new cc.Node('nodeFocus');
this.node.addChild(nodeFocus, 10);
this._cFocus = this.node.getChildByName('nodeFocus').addComponent(TVFocus);
this._cFocus.init('focusContainer', this,
this.activitySprite.getComponent(FocusInfo),
Common.SCREEN_WIDTH, Common.SCREEN_HEIGHT, 6, 4, 1.0);
// this._cFocus.hide(); //所有焦点都是隐藏的
},
keyDownDirection: function (Direct) {
var fiFocusTarget = null;
var fiCurrentFocus = this._fiCurrentFocus;
var oScrollParameter = null;
fiFocusTarget = this._cFocus.findTarget(fiCurrentFocus, this._aFocusTargets, this._iSceneStatus, Direct);
fiFocusTarget = this.checkFocusTarget(fiFocusTarget);
if (!fiFocusTarget) { return; }
//小岛之间跳转需要处理ScrollView
if (0 == fiFocusTarget.node.name.indexOf("island_")) {
this._cFocus.hide();
this.roleAnim.playAnimation("Animation1");
} else {
this._cFocus.show();
this.roleAnim._armature.animation.stop();
}
if (0 == this._fiCurrentFocus.node.name.indexOf("island_") && 0 == fiFocusTarget.node.name.indexOf("island_")) {
let index = fiFocusTarget.node.name.replace("island_", "");
this.node.getChildByName("bgScrollView").getComponent(cc.ScrollView).scrollToPercentHorizontal(0.01 * 25 * (index - 1), 0.1);
// this._cFocus.hide();
this.scheduleOnce(() => {
// this._cFocus.show();
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Direct, null, oScrollParameter);
}, 0.1);
} else {
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Direct, null, oScrollParameter);
}
},
checkFocusTarget: function (fiFocusTarget) {
return fiFocusTarget;
},
onKeyDown: function (event) {
this._super(event);
switch (event.keyCode) {
case cc.macro.KEY.up:
case Common.ANDROID_KEY.up:
if (this._bIsSongListMoving) {
return;
}
if (0 == this._fiCurrentFocus.node.getName().indexOf('GameTaskItemCell')) {
var index = parseInt(this._fiCurrentFocus.node.getName().replace('GameTaskItemCell', ''));
// cc.log("当前时多少条目:"+index);
let lvCategoryList = this._nodeCategoryList.getComponent(ListView);
if (lvCategoryList.scrollARowUp(index)) {
return;
}
}
if (0 == this._fiCurrentFocus.node.getName().indexOf('StarListCell')) {
var index = parseInt(this._fiCurrentFocus.node.getName().replace('StarListCell', ''));
// cc.log("当前时多少条目:"+index);
let lvCategoryList = this._nodeAchievementList.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.keyDownDirection(Common.MOVE_DIRECTION_RIGHT);
break;
case cc.macro.KEY.down:
case Common.ANDROID_KEY.down:
if (this._bIsSongListMoving) {
return;
}
if (0 == this._fiCurrentFocus.node.getName().indexOf('GameTaskItemCell')) {
var index = parseInt(this._fiCurrentFocus.node.getName().replace('GameTaskItemCell', ''));
// cc.log("当前时多少条目:"+index);
let lvCategoryList = this._nodeCategoryList.getComponent(ListView);
lvCategoryList.setStatusInScene(this._iSceneStatus);
if (lvCategoryList.scrollARowDown(null, index)) {
return;
}
}
if (0 == this._fiCurrentFocus.node.getName().indexOf('StarListCell')) {
var index = parseInt(this._fiCurrentFocus.node.getName().replace('StarListCell', ''));
// cc.log("当前时多少条目:"+index);
let lvCategoryList = this._nodeAchievementList.getComponent(ListView);
lvCategoryList.setStatusInScene(this._iSceneStatus);
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('spriteTask')) { //任务
cc.find("task", this.node).active = true;
this._iSceneStatus = 1;
var fiFocusTarget = this._cFocus.findTarget(this._fiCurrentFocus, this._aFocusTargets, this._iSceneStatus, Common.MOVE_DIRECTION_LEFT);
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_LEFT, null, null);
cc.find("task", this.node).zIndex = 10;
this.activitySprite.node.zIndex = 0; //这几个总是另类凸显出来
this.roleSprite.node.zIndex = 0;
this.taskSprite.node.zIndex = 0;
this.achievementSprite.node.zIndex = 0;
this.shopSprite.node.zIndex = 0;
} else if (0 == this._fiCurrentFocus.node.getName().indexOf('spriteAchievement')) { //成就
cc.find("achievement", this.node).active = true;
this._iSceneStatus = 2;
var fiFocusTarget = this._cFocus.findTarget(this._fiCurrentFocus, this._aFocusTargets, this._iSceneStatus, Common.MOVE_DIRECTION_LEFT);
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_LEFT, null, null);
cc.find("achievement", this.node).zIndex = 10;
this.activitySprite.node.zIndex = 0; //这几个总是另类凸显出来
this.roleSprite.node.zIndex = 0;
this.taskSprite.node.zIndex = 0;
this.achievementSprite.node.zIndex = 0;
this.shopSprite.node.zIndex = 0;
} else if (0 == this._fiCurrentFocus.node.getName().indexOf('spriteActivity')) { //活动
cc.find("activity", this.node).active = true;
this._iSceneStatus = 3;
var fiFocusTarget = this._cFocus.findTarget(this._fiCurrentFocus, this._aFocusTargets, this._iSceneStatus, Common.MOVE_DIRECTION_DOWN);
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_LEFT, null, null);
cc.find("activity", this.node).zIndex = 10;
this.activitySprite.node.zIndex = 0; //这几个总是另类凸显出来
this.roleSprite.node.zIndex = 0;
this.taskSprite.node.zIndex = 0;
this.achievementSprite.node.zIndex = 0;
this.shopSprite.node.zIndex = 0;
}
else if (0 == this._fiCurrentFocus.node.getName().indexOf('close')) {
cc.find("task", this.node).active = false;
this._iSceneStatus = 0;
var fiFocusTarget = this.taskSprite.getComponent(FocusInfo);
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_UP, null, null);
} else if (0 == this._fiCurrentFocus.node.getName().indexOf('achievementClose')) {
cc.find("achievement", this.node).active = false;
this._iSceneStatus = 0;
var fiFocusTarget = this.achievementSprite.getComponent(FocusInfo);
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_UP, null, null);
} else if (0 == this._fiCurrentFocus.node.getName().indexOf('activityClose')) {
cc.find("activity", this.node).active = false;
this._iSceneStatus = 0;
var fiFocusTarget = this.activitySprite.getComponent(FocusInfo);
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_UP, null, null);
} else if (0 == this._fiCurrentFocus.node.getName().indexOf('PointerButton')) {
if (!GlobalValue.ACTIVITY_IS_TURN)
this.pointerButtonStartControl();
} else
this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
break;
case cc.macro.KEY.backspace:
case Common.ANDROID_KEY.back:
this.backAScene();
break;
}
},
pointerButtonStartControl: function () {
var _this = this;
var clickTimes = 6; //设置转盘指针转动多长时间
var rounds = 10; //设置转盘指针转动多少圈
var awardAngleArr = {
1: { angle: parseInt(Math.random() * 35 + 5) },
2: { angle: parseInt(Math.random() * 35 + 42) },
3: { angle: parseInt(Math.random() * 35 + 82) },
4: { angle: parseInt(Math.random() * 35 + 122) },
5: { angle: parseInt(Math.random() * 35 + 162) },
6: { angle: parseInt(Math.random() * 35 + 202) },
7: { angle: parseInt(Math.random() * 35 + 242) },
8: { angle: parseInt(Math.random() * 35 + 282) },
9: { angle: parseInt(Math.random() * 35 + 322) },
};
var adValue = 9; //这里应该灵活获取角度
var self = this;
function infoDelayShow() {
_this.scheduleOnce(function () {
cc.log("转盘转动结束,可以处理一些逻辑啦。。。");
GlobalValue.ACTIVITY_IS_TURN = true;
this.pointerButton.getComponent(FocusInfo).setEnable(false);
cc.loader.loadRes("game/main/turntable_tomorrow", cc.Texture2D, function (err, texture) {
self.pointerButton.spriteFrame = new cc.SpriteFrame(texture);
});
var fiFocusTarget = this._cFocus.findTarget(this._fiCurrentFocus, this._aFocusTargets, this._iSceneStatus, Common.MOVE_DIRECTION_LEFT);
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_LEFT, null, null);
let popItem = cc.instantiate(this.PFB_POP);
this.node.addChild(popItem, 100);
this.node.anchorX = 0; //解决飘窗显示位置不在屏幕中央的问题
this.node.anchorY = 0;
function fadeOutBack() {
popItem.destroy(); //用完就销毁
cc.log("处理飘窗彻底消失后的逻辑。。。。。。");
};
let fadeOut = cc.fadeOut(1.0);
let moveBy = cc.moveBy(1, cc.v2(0, 200));
popItem.runAction(moveBy);
popItem.runAction(cc.sequence(fadeOut, cc.callFunc(fadeOutBack)));
}, clickTimes + 0.5);
};
var rotateBy = cc.rotateBy(clickTimes, awardAngleArr[adValue].angle + 360 * rounds);
_this.pointer.node.runAction(rotateBy).easing(cc.easeCubicActionOut(clickTimes));
// _this.pointerButton.destroy();
infoDelayShow();
},
onBeforeFocusChange: function (event) {
this._super(event);
var self = this;
let fiFrom = event.detail.from;
if (0 == fiFrom.node.name.indexOf('sprite')) {
fiFrom.node.getChildByName("active").active = false;
}
},
onAfterFocusChange: function (event) {
this._super(event);
var self = this;
let fiTo = event.detail.to;
if (0 == fiTo.node.name.indexOf('sprite')) {
fiTo.node.getChildByName("active").active = true;
}
if (0 == fiTo.node.name.indexOf('island')) {
this.roleAnim.node.x = fiTo.node.x;
this.roleAnim.node.y = fiTo.node.y;
}
},
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);
}
},
onListScrollStart: function () {
this._bIsSongListMoving = true;
// cc.log("scroll start");
},
onListScrollEnd: function () {
this._bIsSongListMoving = false;
// cc.log("scroll completed");
},
});