|
@@ -10,7 +10,13 @@ const { ccclass, property } = cc._decorator;
|
|
|
* @author 薛鸿潇
|
|
* @author 薛鸿潇
|
|
|
*/
|
|
*/
|
|
|
@ccclass
|
|
@ccclass
|
|
|
-export default class TableViewUtils extends cc.Component {
|
|
|
|
|
|
|
+export default class TableView extends cc.Component {
|
|
|
|
|
+
|
|
|
|
|
+ @property({ type: [cc.Prefab] })
|
|
|
|
|
+ private pre_item: cc.Prefab[] = [];
|
|
|
|
|
+ /** 间距 */
|
|
|
|
|
+ @property({ displayName: '间距' })
|
|
|
|
|
+ private itemInterval: number = 0;
|
|
|
|
|
|
|
|
/** 数据 */
|
|
/** 数据 */
|
|
|
private itemData: any = null;
|
|
private itemData: any = null;
|
|
@@ -18,8 +24,6 @@ export default class TableViewUtils extends cc.Component {
|
|
|
private scrollView: cc.ScrollView = null;
|
|
private scrollView: cc.ScrollView = null;
|
|
|
/** item预制体组 */
|
|
/** item预制体组 */
|
|
|
private item: Array<any> = null;
|
|
private item: Array<any> = null;
|
|
|
- /** 间隔 */
|
|
|
|
|
- private itemInterval: number = 0;
|
|
|
|
|
/** 滑动列表的内容节点 */
|
|
/** 滑动列表的内容节点 */
|
|
|
private content: any = null;
|
|
private content: any = null;
|
|
|
/** 列表高 */
|
|
/** 列表高 */
|
|
@@ -36,6 +40,27 @@ export default class TableViewUtils extends cc.Component {
|
|
|
private count: number = 0;
|
|
private count: number = 0;
|
|
|
private itemCanMoveDown: boolean = null;
|
|
private itemCanMoveDown: boolean = null;
|
|
|
private itemCanMoveUp: boolean = null;
|
|
private itemCanMoveUp: boolean = null;
|
|
|
|
|
+ onLoad() {
|
|
|
|
|
+ this.initPro();
|
|
|
|
|
+ let itemData = [];
|
|
|
|
|
+ for (let i = 0; i < 20; i++) {
|
|
|
|
|
+ let test_data = {
|
|
|
|
|
+ pfbType: 0,
|
|
|
|
|
+ }
|
|
|
|
|
+ itemData.push(test_data);
|
|
|
|
|
+ }
|
|
|
|
|
+ this.init(itemData);
|
|
|
|
|
+ }
|
|
|
|
|
+ private initPro() {
|
|
|
|
|
+ this.scrollView = this.node.getComponent(cc.ScrollView);
|
|
|
|
|
+ this.content = this.scrollView.content;
|
|
|
|
|
+ this.item = this.pre_item;
|
|
|
|
|
+ this.layerHeight = this.node.height;
|
|
|
|
|
+ for (let i = 0; i < this.item.length; i++) {
|
|
|
|
|
+ this.itemNode[i] = cc.instantiate(this.item[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+ this.node.on('srollview-init', this.init, this);
|
|
|
|
|
+ }
|
|
|
//itemData是item数据,itemPosMap是滚动条滚动时要用到的item位置数据.
|
|
//itemData是item数据,itemPosMap是滚动条滚动时要用到的item位置数据.
|
|
|
/**
|
|
/**
|
|
|
* @param itemData 列表数据
|
|
* @param itemData 列表数据
|
|
@@ -45,31 +70,31 @@ export default class TableViewUtils extends cc.Component {
|
|
|
* @param isSkipInit 跳过初始化
|
|
* @param isSkipInit 跳过初始化
|
|
|
* @returns
|
|
* @returns
|
|
|
*/
|
|
*/
|
|
|
- public init(itemData: Array<any>, scrollView: cc.ScrollView, item: Array<cc.Prefab>, itemInterval: number, isSkipInit) {
|
|
|
|
|
- if (!arguments[0]) {
|
|
|
|
|
|
|
+ public init(itemData: Array<any>, isSkipInit: boolean = false) {
|
|
|
|
|
+ if (!itemData[0]) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
this.itemData = itemData; //item数据
|
|
this.itemData = itemData; //item数据
|
|
|
- this.scrollView = scrollView;
|
|
|
|
|
- this.item = item;
|
|
|
|
|
- this.itemInterval = itemInterval || 0; //间距
|
|
|
|
|
- //初始化各类属性
|
|
|
|
|
- this.content = this.scrollView.content;
|
|
|
|
|
- this.layerHeight = this.scrollView.node.height;
|
|
|
|
|
|
|
+ // this.scrollView = scrollView;
|
|
|
|
|
+ // this.item = item;
|
|
|
|
|
+ // this.itemInterval = itemInterval || 0; //间距
|
|
|
|
|
+ // 初始化各类属性
|
|
|
|
|
+ // this.content = this.scrollView.content;
|
|
|
|
|
+ // this.layerHeight = this.scrollView.node.height;
|
|
|
this.firstItemIndex = 0;
|
|
this.firstItemIndex = 0;
|
|
|
this.lastItemIndex = 0;
|
|
this.lastItemIndex = 0;
|
|
|
this.firstItemData = {};
|
|
this.firstItemData = {};
|
|
|
this.lastItemData = {};
|
|
this.lastItemData = {};
|
|
|
this.itemArr = [];
|
|
this.itemArr = [];
|
|
|
- this.itemNode = [];
|
|
|
|
|
this.itemPosMap = new Map();
|
|
this.itemPosMap = new Map();
|
|
|
this.initItemData = true;
|
|
this.initItemData = true;
|
|
|
this.count = 0;
|
|
this.count = 0;
|
|
|
if (isSkipInit) return;
|
|
if (isSkipInit) return;
|
|
|
- for (let i = 0; i < this.item.length; i++) {
|
|
|
|
|
- this.itemNode[i] = cc.instantiate(this.item[i]);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // this.itemNode = [];
|
|
|
|
|
+ // for (let i = 0; i < this.item.length; i++) {
|
|
|
|
|
+ // this.itemNode[i] = cc.instantiate(this.item[i]);
|
|
|
|
|
+ // }
|
|
|
// cc.log(this.testTime(0));// 消耗计时
|
|
// cc.log(this.testTime(0));// 消耗计时
|
|
|
this.initItem();
|
|
this.initItem();
|
|
|
this.getItemPos(0);
|
|
this.getItemPos(0);
|