difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
"use strict";
cc._RF.push(module, '33e04WhYdJMibSyfyrdHE6F', 'common_scrollview');
// Scripts/common/common_scrollview.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: shiraho@syg.com(必填, 创建模块的人员)
// @description:
//      无线滚动容器,子对象必须是锚点0.5,0.5, 而且一定要继承 basepanel
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
var LoaderManager = require("loadermanager");
 
var PathTool = require("pathtool");
 
var CommonScrollView = cc.Class({
  "extends": BaseClass,
  ctor: function ctor() {
    this.initConfig();
  },
  initConfig: function initConfig() {
    this.parent = null;
    this.prefabPath = PathTool.getPrefabPath("common", "common_scroll_view");
    this.pos = cc.v2(0, 0);
    this.dir = ScrollViewDir.vertical;
    this.start_pos = ScrollViewStartPos.top;
    this.size = cc.size(100, 100);
    this.ap = cc.v2(0, 0);
    this.cache_item_list = []; // 当前显示的对象
 
    this.cache_item_pool = []; // 缓存中是剩余的对象
 
    this.item_click_callback = null;
    this.extend = null; //扩展参数
 
    this.cur_item_class = null; //当前显示的对象
 
    this.is_radian = false;
    this.is_scrolling = false;
    this.cur_min_index = 0;
    this.bounceEnabled = true; //是否回弹
 
    this.clickEnabled = true; //是否可点击
  },
 
  /**
   * 创建
   * @param {*} parent 所在父节点
   * @param {*} pos 滑动组件位置
   * @param {*} dir 滑动对齐方式
   * @param {*} start_pos 滑动列表开始位置
   * @param {*} size 滑动框大小
   * @param {*} setting 设置信息
   * @param {*} ap 锚点
   */
  createScroll: function createScroll(parent, pos, dir, start_pos, size, setting, ap) {
    this.parent = parent;
    this.pos = pos || cc.v2(0, 0);
    this.dir = dir || ScrollViewDir.vertical;
    this.start_pos = start_pos || ScrollViewStartPos.top;
    this.size = size || cc.size(100, 100);
    this.ap = ap || cc.v2(0, 0);
    this.analysisSetting(setting);
    LoaderManager.getInstance().loadRes(this.prefabPath, function (res_object) {
      if (this.parent == null || this.parent && this.parent.isValid) {
        this.root_wnd = res_object;
        this.createRootWnd(this.root_wnd);
      }
    }.bind(this));
  },
  // 初始化创建对象
  createRootWnd: function createRootWnd(scroll) {
    if (this.root_wnd == null) return;
    this.root_wnd = scroll;
    this.scroll_view = scroll.getChildByName("ScrollView");
    this.scroll_view_mask = this.scroll_view.getChildByName("view");
    this.container = this.scroll_view_mask.getChildByName("content");
    this.mask = this.scroll_view.getChildByName("mask");
    this.root_wnd.setContentSize(this.size);
    this.root_wnd.setAnchorPoint(this.ap.x, this.ap.y);
    this.root_wnd.setPosition(this.pos);
    this.scroll_view.setContentSize(this.size);
    this.scroll_view_mask.setContentSize(this.size);
    this.container.setContentSize(this.size); // 滚动组建
 
    this.scroll_view_compend = this.scroll_view.getComponent(cc.ScrollView);
 
    if (this.dir == ScrollViewDir.vertical) {
      this.scroll_view_compend.vertical = true;
    } else {
      this.scroll_view_compend.horizontal = true;
    }
 
    if (this.scroll_state != null) {
      this.setScrollState(this.scroll_state);
    }
 
    if (this.parent) {
      this.parent.addChild(scroll);
    }
 
    this.setBounceEnabled(this.bounceEnabled);
    this.setClickEnabled(this.clickEnabled); // 监听事件
 
    this.setInnerContainer();
    this.registerEvent();
  },
  registerEvent: function registerEvent() {
    if (this.need_dynamic == true) {
      if (this.dir == ScrollViewDir.vertical) {
        this.scroll_view_compend.node.on('scrolling', this.checkRectIntersectsRect, this);
      }
    }
  },
  //移动的过程中盘点是否不再可视范围,不再的时候移除掉,放到对象池,并且准备下一次创建
  checkRectIntersectsRect: function checkRectIntersectsRect(event) {
    if (this.need_dynamic == false) {
      return;
    }
 
    if (this.dir == ScrollViewDir.vertical) {
      this.checkOverShowByVertical();
    }
  },
  //竖直方向的监测判断
  checkOverShowByVertical: function checkOverShowByVertical() {
    if (this.cur_item_class == null) {
      return;
    }
 
    if (this.data_list == null || Utils.next(this.data_list) == null) {
      return;
    }
 
    var item_list = this.cache_item_list;
    var pool_list = this.cache_item_pool;
 
    if (item_list == null) {
      return;
    }
 
    var container_y = this.container.y;
 
    if (this.last_pos_y == null) {
      this.last_pos_y = container_y;
    }
 
    var item = null;
    var container_y_abs = Math.abs(container_y); //先移除不在可视的
 
    for (var index = item_list.length - 1; index >= 0; index--) {
      var _item = item_list[index];
 
      if (_item.y == null) {
        Log.error(_item);
      }
 
      var item_y = _item.y;
      var need_clear = false;
 
      if (container_y > 0) {
        if (item_y > this.size.height - container_y + this.item_height) {
          need_clear = true;
        }
      } else {
        if (item_y < container_y_abs - this.item_height) {
          need_clear = true;
        } else if (item_y > container_y_abs + this.size.height + this.item_height) {
          need_clear = true;
        }
      }
 
      if (need_clear == true) {
        if (_item && _item.suspendAllActions != null) {
          _item.suspendAllActions();
 
          _item.cur_visible = false;
 
          _item.setVisible(false, this.dir);
        }
 
        pool_list.push(_item);
        item_list.splice(index, 1);
      }
    }
 
    this.supplementItemList(item_list, this.last_pos_y, container_y);
    this.last_pos_y = container_y;
  },
  //补充需要创建的
  supplementItemList: function supplementItemList(item_list, last_y, cur_y) {
    if (item_list == null || item_list.length == 0) {
      return;
    }
 
    var cur_table_num = item_list.length;
 
    if (cur_table_num < this.max_sum) {
      var min_index = item_list[0].tmp_index;
      var max_index = item_list[0].tmp_index;
 
      for (var index = 0; index < item_list.length; index++) {
        var item = item_list[index];
 
        if (min_index >= item.tmp_index) {
          min_index = Number(item.tmp_index);
        }
 
        if (max_index <= item.tmp_index) {
          max_index = Number(item.tmp_index);
        }
      }
 
      if (cur_y > last_y) {
        //向上,那么就创建到下面
        for (var _index = 0; _index < this.max_sum - cur_table_num; _index++) {
          this.createList(this.data_list[max_index + _index + 1]);
        }
      } else {
        for (var _index2 = 0; _index2 < this.max_sum - cur_table_num; _index2++) {
          if (min_index - _index2 > 0) {
            this.createList(this.data_list[min_index - _index2 - 1]);
          }
        }
      }
    }
  },
  setSwallowTouches: function setSwallowTouches(status) {
    this.scroll_view.setSwallowTouches(status);
  },
  setBounceEnabled: function setBounceEnabled(status) {
    this.bounceEnabled = status;
    if (!this.scroll_view_compend) return;
    this.scroll_view_compend.elastic = status;
  },
  // 设置 scrollview 是否可点
  setClickEnabled: function setClickEnabled(status) {
    this.clickEnabled = status;
    if (!this.scroll_view_compend) return;
 
    if (status) {
      this.scroll_view_compend.node.on(cc.Node.EventType.TOUCH_START, this.scroll_view_compend._onTouchBegan, this.scroll_view_compend, true);
      this.scroll_view_compend.node.on(cc.Node.EventType.TOUCH_MOVE, this.scroll_view_compend._onTouchMoved, this.scroll_view_compend, true);
      this.scroll_view_compend.node.on(cc.Node.EventType.TOUCH_END, this.scroll_view_compend._onTouchEnded, this.scroll_view_compend, true);
      this.scroll_view_compend.node.on(cc.Node.EventType.TOUCH_CANCEL, this.scroll_view_compend._onTouchCancelled, this.scroll_view_compend, true);
    } else {
      this.scroll_view_compend.node.off(cc.Node.EventType.TOUCH_START, this.scroll_view_compend._onTouchBegan, this.scroll_view_compend, true);
      this.scroll_view_compend.node.off(cc.Node.EventType.TOUCH_MOVE, this.scroll_view_compend._onTouchMoved, this.scroll_view_compend, true);
      this.scroll_view_compend.node.off(cc.Node.EventType.TOUCH_END, this.scroll_view_compend._onTouchEnded, this.scroll_view_compend, true);
      this.scroll_view_compend.node.off(cc.Node.EventType.TOUCH_CANCEL, this.scroll_view_compend._onTouchCancelled, this.scroll_view_compend, true);
    }
  },
  //滚动容器移动到指定位置
  updateMove: function updateMove(pos) {
    var target_pos = this.checkPosition(pos.x, pos.y);
    var move_to = cc.moveTo(0.1, target_pos.x, target_pos.y).easing(cc.easeBackOut());
    this.container.runAction(move_to);
  },
  //跳转指定位置
  jumpToMove: function jumpToMove(pos, time, callback) {
    var target_pos = this.checkPosition(pos.x, pos.y);
    time = time == null ? 1 : time;
    var move_to = cc.moveTo(time, cc.v2(target_pos.x, target_pos.y));
    this.container.runAction(cc.sequence(move_to, cc.callFunc(function () {
      if (callback) {
        callback();
      }
    }))); //该方法在滚动的时候并不能触发scroll自己的监听,来更新数据,注释掉
  },
  jumpToMove_2: function jumpToMove_2(pos, time, callback) {
    var target_pos = this.checkPosition(pos.x, pos.y);
    time = time == null ? 1 : time;
    var move_to = cc.moveTo(time, cc.v2(target_pos.x, target_pos.y));
    this.container.runAction(cc.sequence(move_to, cc.callFunc(function () {
      if (callback) {
        callback();
      }
    }))); //该方法在滚动的时候并不能触发scroll自己的监听,来更新数据,注释掉
    // var size = this.container.getContentSize();
    // this.scroll_view_compend.scrollTo(cc.v2(target_pos.x / size.width, target_pos.y / size.height), time);
    // this.container.runAction(cc.sequence(cc.delayTime(0),cc.callFunc(function () {
    //     if (callback) {
    //         callback();
    //     }
    // })))
  },
  getCurContainerPosY: function getCurContainerPosY() {
    if (this.container) {
      return this.container.y;
    }
  },
  getCurContainerPosX: function getCurContainerPosX() {
    if (this.container) {
      return this.container.x;
    }
  },
  //监测目标点位置
  checkPosition: function checkPosition(x, y) {
    if (this.root_wnd == null) {
      return cc.v2(0, 0);
    }
 
    var _x = this.container.x;
    var _y = this.container.y;
 
    if (this.dir == ScrollViewDir.horizontal) {
      _x = _x + x;
    } else if (this.dir == ScrollViewDir.vertical) {
      _y = _y + y;
    }
 
    if (_x > 0) {
      _x = 0;
    } else if (_x < this.size.width - this.container_size.width) {
      _x = this.size.width - this.container_size.width;
    }
 
    if (_y > 0) {
      _y = 0;
    } else if (_y < this.size.height - this.container_size.height) {
      _y = this.size.height - this.container_size.height;
    }
 
    return cc.v2(_x, _y);
  },
  //设置滚动容器的大小
  setInnerContainer: function setInnerContainer() {
    var size = 0;
 
    if (this.data_list) {
      size = this.data_list.length;
    }
 
    var container_width = this.size.width;
    var container_height = this.size.height;
    var num = 0;
 
    if (this.dir == ScrollViewDir.horizontal) {
      num = Math.ceil(size / this.row);
      container_width = num * this.item_width + 2 * this.start_x + (num - 1) * this.space_x;
    } else {
      num = Math.ceil(size / this.col);
 
      if (!this.is_change) {
        container_height = num * this.item_height + 2 * this.start_y + (num - 1) * this.space_y;
      } else {
        container_height = num * this.item_height + 2 * this.start_y + num * this.space_y;
      }
    }
 
    container_width = Math.max(container_width, this.size.width);
    container_height = Math.max(container_height, this.size.height);
    this.container_size = cc.size(container_width, container_height);
 
    if (this.container) {
      this.container.setContentSize(this.container_size.width, this.container_size.height + this.bottom);
    }
 
    if (this.scroll_view_compend) {
      this.scroll_view_compend.stopAutoScroll();
 
      if (this.dir == ScrollViewDir.vertical) {
        if (this.start_pos == ScrollViewStartPos.top) {
          this.scroll_view_compend.scrollToTop(0);
        } else if (this.start_pos == ScrollViewStartPos.bottom) {
          this.scroll_view_compend.scrollToBottom(0);
        }
      } else if (this.dir == ScrollViewDir.horizontal) {
        if (this.start_pos == ScrollViewStartPos.top) {
          this.scroll_view_compend.scrollToLeft(0);
        } else if (this.start_pos == ScrollViewStartPos.bottom) {
          this.scroll_view_compend.scrollToRight(0);
        }
      }
    }
  },
  //设置数据
  setData: function setData(data_list, click_callback, extend) {
    this.clearCacheList();
 
    if (data_list == null || Utils.next(data_list) == null) {
      return;
    } // 转换一下存储,保证不改变原数据
 
 
    var switchList = [];
 
    for (var _index3 = 0; _index3 < data_list.length; _index3++) {
      var element = data_list[_index3];
      switchList.push({
        data: element,
        index: _index3
      });
    }
 
    this.item_click_callback = click_callback;
    this.data_list = switchList;
    this.extend = extend;
    this.cur_item_class = this.item_class; //设置内部滚动容器的尺寸
 
    this.setInnerContainer();
    var index = 0;
    var once_num = this.once_num || 1; //如果需要动态创建的话
 
    var size = this.data_list.length;
 
    if (this.need_dynamic == true) {
      size = this.max_sum - 1; //因为js从0开始,实际个数单位减少1
    } //判断这边是否已经创建过的,如果创建过的就不需要分帧创建了,直接add吧
 
 
    if (this.cur_item_class && this.cache_item_pool.length > 0) {
      for (var i = 0; i < size; i++) {
        var data = this.data_list[i];
 
        if (data != null) {
          this.createList(data);
        }
 
        if (i == size - 1) {
          if (this.end_callBack) {
            this.end_callBack();
          }
        }
      }
    } else {
      if (this.time_ticket == null && Utils.next(this.data_list || {}) != null) {
        this.time_ticket = gcore.Timer.set(function () {
          if (this.container) {
            if (this.data_list == null) {
              if (this.end_callBack) {
                this.end_callBack();
              }
 
              this.clearTimeTicket();
            } else {
              for (var i = index; i < index + once_num; i++) {
                var switch_data = this.data_list[i];
 
                if (switch_data != null) {
                  this.createList(switch_data);
                }
              }
 
              index = index + once_num;
 
              if (index > size) {
                if (this.end_callBack) {
                  this.end_callBack();
                }
 
                this.clearTimeTicket();
              }
            }
          } else {}
        }.bind(this), this.delay * 10, -1);
      }
    }
  },
  updateItemData: function updateItemData(index, new_data) {
    var new_item_data = {
      data: new_data,
      index: index
    };
    this.data_list[index] = new_item_data;
    var item = this.getItem(index);
 
    if (item) {
      item.setData(new_data);
    }
  },
  setStartX: function setStartX(x) {
    this.start_x = x;
  },
  setSpaceY: function setSpaceY(space_y, is_change) {
    this.space_y = space_y;
    this.is_change = is_change;
  },
  clearTimeTicket: function clearTimeTicket() {
    if (this.time_ticket != null) {
      gcore.Timer.del(this.time_ticket);
      this.time_ticket = null;
    }
  },
  //重设滚动区域大小
  resetSize: function resetSize(size, pos) {
    if (size == null) return;
    if (size.width == this.size.width && size.height == this.size.height) return;
    this.size = size;
    if (this.root_wnd) this.root_wnd.setContentSize(size);
    if (this.scroll_view) this.scroll_view.setContentSize(size);
    if (this.scroll_view_mask) this.scroll_view_mask.setContentSize(size);
    if (this.root_wnd && pos) this.root_wnd.setPosition(pos);
    this.calculationMaxSum();
  },
 
  /**
   * 暂停计时器,以及回收掉之前创建的对象
   */
  clearCacheList: function clearCacheList() {
    this.clearTimeTicket();
 
    for (var index = 0; index < this.cache_item_list.length; index++) {
      var element = this.cache_item_list[index];
 
      if (element && element.suspendAllActions) {
        element.suspendAllActions();
      }
 
      this.cache_item_pool.push(element);
    }
 
    for (var _index4 = 0; _index4 < this.cache_item_pool.length; _index4++) {
      var _element = this.cache_item_pool[_index4];
 
      if (_element && _element.setVisible) {
        _element.cur_visible = false;
 
        _element.setVisible(false, this.dir); // element.setPosVisible();
 
      }
    }
 
    this.cache_item_list = [];
  },
  addEndCallBack: function addEndCallBack(call_back) {
    this.end_callBack = call_back;
  },
 
  /**
   * 创建具体事例
   * @param {*} data 这个数据是转换之后的数据,因为为了不改变数据结构,所以转换了 包含 data 和 index,其中data才是真实数据
   */
  createList: function createList(switch_data) {
    if (switch_data == null || switch_data.data == null || switch_data.index == null) return;
    if (this.cur_item_class == null) return; // if (this.cache_item_list[switch_data.index]) {
    //     var item = this.cache_item_list[switch_data.index]
    //     item.setVisible(true)
    //     return
    // }
 
    var item = null;
 
    if (this.cache_item_pool.length == 0) {
      if (typeof this.item_class == "string") {
        item = ItemsPool.getInstance().getItem(this.item_class);
      } else {
        item = new this.item_class(this.item_obj);
      }
 
      item.setParent(this.container);
      if (item.show) item.show();
 
      if (item.setScale) {
        item.setScale(this.scale);
      }
 
      if (this.isZIndex) {
        if (this.isZIndex == 1) {
          if (item.setZIndex) {
            item.setZIndex(switch_data.index);
          }
        } else if (this.isZIndex == 2) {
          if (item.setZIndex && this.data_list) {
            item.setZIndex(this.data_list.length - switch_data.index);
          }
        }
      }
    } else {
      item = this.cache_item_pool.shift();
 
      if (item.setVisible) {
        item.setVisible(true, this.dir);
      } else {
        Log.error("没有设置显示接口啊!!!");
      }
    } //临时使用
 
 
    item.tmp_index = switch_data.index;
    this.cache_item_list.push(item); //由于array数组的性质,有empty数据也算作一个长度,所以用push方法
    //拓展参数
 
    if (this.extend != null && item.setExtendData) {
      item.setExtendData(this.extend);
    } // 设置位置
 
 
    this.setItemPosition(item, switch_data.index); // 回调方法
 
    if (this.item_click_callback != null) {
      if (item.addCallBack) {
        item.addCallBack(this.item_click_callback);
      }
    }
 
    item.setData(switch_data.data, this.is_hide_effect);
    this.cur_min_index = switch_data.index;
  },
  //设置当前对象的位置,根据数据的临时_index去确定
  setItemPosition: function setItemPosition(item, index) {
    var cur_item_index = Number(index);
    var anchor_point = {};
    anchor_point.x = 0.5;
    anchor_point.y = 0.5;
    var _x = 0;
    var _y = 0; //父容器的相对锚点为(0,1)
 
    if (this.dir == ScrollViewDir.horizontal) {
      _x = this.start_x + this.item_width * anchor_point.x + (this.item_width + this.space_x) * Math.floor(cur_item_index / this.row);
      _y = this.container_size.height - (this.start_y + this.item_height * (1 - anchor_point.y) + cur_item_index % this.row * (this.item_height + this.space_y));
    } else {
      if (this.start_pos == ScrollViewStartPos.top) {
        _x = this.start_x + this.item_width * anchor_point.x + (this.item_width + this.space_x) * (cur_item_index % this.col);
        _y = this.container_size.height - (this.start_y + this.item_height * (1 - anchor_point.y) + Math.floor(cur_item_index / this.col) * (this.item_height + this.space_y));
      } else {
        _x = this.start_x + this.item_width * anchor_point.x + (this.item_width + this.space_x) * (cur_item_index % this.col);
        _y = this.start_y + this.item_height * anchor_point.y + Math.floor(cur_item_index / this.col) * (this.item_height + this.space_y);
      }
    }
 
    item.setPosition(_x, _y + this.bottom);
  },
  resetCurrentItems: function resetCurrentItems() {
    for (var index = 0; index < this.cache_item_list.length; index++) {
      if (this.cache_item_list[index] && this.cache_item_list[index].setData) {
        var cur_data = this.data_list[this.cache_item_list[index].tmp_index];
        this.cache_item_list[index].setData(cur_data.data);
      }
    }
  },
  //获取已创建的全部对象
  getItemList: function getItemList() {
    var item_list = [];
 
    for (var index = 0; index < this.cache_item_list.length; index++) {
      var element = this.cache_item_list[index];
      item_list.push(element);
    }
 
    return item_list;
  },
  getItem: function getItem(tmp_index) {
    for (var item_i in this.cache_item_list) {
      var item = this.cache_item_list[item_i];
 
      if (item.tmp_index == tmp_index) {
        return item;
      }
    }
 
    return null;
  },
  setRootVisible: function setRootVisible(bool) {
    if (this.root_wnd) {
      this.root_wnd.active = bool;
    }
  },
  //用于增减的时候操作,需要传去最新的List
  resetAddPosition: function resetAddPosition(list, sort_fun) {
    if (list == null || Utils.next(list) == null) return;
 
    if (sort_fun != null) {
      list.sort(sort_fun);
    }
 
    var swich_list = [];
 
    for (var index = 0; index < list.length; index++) {
      var element = list[index];
      swich_list.push({
        data: element,
        index: index
      });
    }
 
    this.data_list = swich_list;
    if (this.cache_item_list == null || Utils.next(this.cache_item_list) == null) return;
 
    for (var _index5 = 0; _index5 < this.cache_item_list.length; _index5++) {
      var item = this.cache_item_list[_index5]; // 对象
 
      var switch_data = swich_list[item.tmp_index]; // 数据对象
 
      if (switch_data && item.setData && switch_data.data) {
        item.setData(switch_data.data);
        item.setVisible(true, this.dir);
        item.tmp_index = switch_data.index;
      } else {
        item.cur_visible = false;
        item.setVisible(false, this.dir);
        this.cache_item_pool.push(item); // 移除掉
 
        this.cache_item_list.splice(_index5, 1);
      }
    }
  },
  //对当前创建对象做排序,同时对缓存数据做排序
  resetPosition: function resetPosition(sort_fun, is_clear) {
    if (this.data_list == null || Utils.next(this.data_list) == null) return;
 
    if (sort_fun != null) {
      this.data_list.sort(sort_fun);
    }
 
    for (var index = 0; index < this.data_list.length; index++) {
      var element = this.data_list[index];
      element.index = index;
    }
 
    if (this.cache_item_list == null || Utils.next(this.cache_item_list) == null) return;
 
    for (var _index6 = 0; _index6 < this.cache_item_list.length; _index6++) {
      var item = this.cache_item_list[_index6];
 
      if (item.tmp_index) {
        var switch_data = this.data_list[item.tmp_index];
 
        if (switch_data && item.setData && switch_data.data) {
          item.setData(switch_data.data);
          item.setVisible(true, this.dir);
          item.tmp_index = switch_data.index;
        }
      }
    }
  },
  //解析数据
  analysisSetting: function analysisSetting(setting) {
    this.setting = setting || {};
    this.item_class = this.setting.item_class;
    this.start_x = this.setting.start_x || 0; //第一个单元的起点X
 
    this.space_x = this.setting.space_x || 3; // 横向间隔空间
 
    this.start_y = this.setting.start_y || 0; // 第一个单元的起点Y
 
    this.space_y = this.setting.space_y || 3; // 竖向间隔空间
 
    this.item_width = this.setting.item_width || 115; // 单元的宽度
 
    this.item_height = this.setting.item_height || 115; // 单元的高度
 
    this.is_radian = this.setting.is_radian || false; //是否要弧度
 
    this.row = this.setting.row || 5; // 行数,作用于水平方向的滚动
 
    this.col = this.setting.col || 5; // 列数,作用于垂直方向的滚动
 
    this.delay = this.setting.delay || 1; // 创建延迟时间
 
    this.once_num = this.setting.once_num || 1; // 每次创建的数量
 
    this.scale = this.setting.scale || 1; //缩放值
 
    this.need_dynamic = this.setting.need_dynamic || false; // 是否需要动态创建的 
 
    this.is_hide_effect = this.setting.is_hide_effect || false;
    this.item_obj = this.setting.item_obj; //给item_class传入默认参数
 
    this.bottom = this.setting.bottom || 0; //底部间距
 
    this.calculationMaxSum();
  },
  //计算一下一屏最多创建的个数
  calculationMaxSum: function calculationMaxSum() {
    var max_sum;
 
    if (this.dir == ScrollViewDir.horizontal) {
      max_sum = (Math.ceil(this.size.width / (this.item_width + this.space_x)) + 1) * this.row;
    } else {
      max_sum = (Math.ceil(this.size.height / (this.item_height + this.space_y)) + 1) * this.col;
    }
 
    this.max_sum = max_sum;
  },
  getMaxSize: function getMaxSize() {
    return this.container_size;
  },
  getContainer: function getContainer() {
    return this.container;
  },
  deleteMe: function deleteMe() {
    this.DeleteMe();
  },
  //设置滚动状态,false取消滚动,true恢复原来的滚动方向
  setScrollState: function setScrollState(bool) {
    if (this.scroll_view_compend) {
      if (!bool) {
        this.scroll_view_compend.vertical = false;
        this.scroll_view_compend.horizontal = false;
      } else {
        if (this.dir == ScrollViewDir.vertical) {
          this.scroll_view_compend.vertical = true;
        } else {
          this.scroll_view_compend.horizontal = true;
        }
      }
    } else {
      this.scroll_state = bool;
    }
  },
  setVisible: function setVisible(bool) {
    if (this.root_wnd && bool != null) {
      this.root_wnd.active = bool;
    }
  },
 
  /**
   * 是否设置item层次排序
   * type:   1:正向  2:反向
   */
  setItemZIndexByType: function setItemZIndexByType(type) {
    this.isZIndex = type;
  },
  //移除对象
  DeleteMe: function DeleteMe() {
    // doStopAllActions(self.container);    //不清楚H5还需不需要安全判断,先注释掉
    this.clearTimeTicket();
    this.setClickEnabled(false);
 
    for (var index = 0; index < this.cache_item_list.length; index++) {
      var element = this.cache_item_list[index];
 
      if (element.deleteMe) {
        element.deleteMe();
        element = null;
      }
    }
 
    for (var _index7 = 0; _index7 < this.cache_item_pool.length; _index7++) {
      var element = this.cache_item_pool[_index7];
 
      if (element.deleteMe) {
        element.deleteMe();
        element = null;
      }
    }
 
    this.cache_item_list = null;
    this.cache_item_pool = null;
 
    if (this.root_wnd) {
      this.root_wnd.destroy();
      this.root_wnd = null;
    }
 
    LoaderManager.getInstance().releasePrefab(this.prefabPath);
  }
});
 
cc._RF.pop();