diff --git a/ListViewV2Demo/assets/Prefab/ListviewItem.prefab b/ListViewV2Demo/assets/Prefab/ListviewItem.prefab index 4f7f6fa..332408f 100644 --- a/ListViewV2Demo/assets/Prefab/ListviewItem.prefab +++ b/ListViewV2Demo/assets/Prefab/ListviewItem.prefab @@ -246,17 +246,16 @@ "sync": false }, { - "__type__": "a1b5dhqiGxCkqZ/KM1XymD/", + "__type__": "4d730hKafhH86WjXm0jYqWj", "_name": "", "_objFlags": 0, "node": { "__id__": 1 }, "_enabled": true, - "level": { + "label": { "__id__": 6 - }, - "_data": null + } }, { "__type__": "cc.PrefabInfo", diff --git a/ListViewV2Demo/assets/Scene/helloworldJs.fire b/ListViewV2Demo/assets/Scene/helloworldJs.fire deleted file mode 100644 index 5a1ec1d..0000000 --- a/ListViewV2Demo/assets/Scene/helloworldJs.fire +++ /dev/null @@ -1,481 +0,0 @@ -[ - { - "__type__": "cc.SceneAsset", - "_name": "", - "_objFlags": 0, - "_rawFiles": null, - "scene": { - "__id__": 1 - } - }, - { - "__type__": "cc.Scene", - "_objFlags": 0, - "_parent": null, - "_children": [ - { - "__id__": 2 - } - ], - "_tag": -1, - "_active": true, - "_components": [], - "_prefab": null, - "_id": "2d2f792f-a40c-49bb-a189-ed176a246e49", - "_opacity": 255, - "_color": { - "__type__": "cc.Color", - "r": 255, - "g": 255, - "b": 255, - "a": 255 - }, - "_cascadeOpacityEnabled": true, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 0, - "height": 0 - }, - "_localZOrder": 0, - "_globalZOrder": 0, - "_opacityModifyRGB": false, - "groupIndex": 0, - "autoReleaseAssets": false - }, - { - "__type__": "cc.Node", - "_name": "Canvas", - "_objFlags": 0, - "_parent": { - "__id__": 1 - }, - "_children": [ - { - "__id__": 3 - }, - { - "__id__": 6 - } - ], - "_tag": -1, - "_active": true, - "_components": [ - { - "__id__": 13 - } - ], - "_prefab": null, - "_id": "a286bbGknJLZpRpxROV6M94", - "_opacity": 255, - "_color": { - "__type__": "cc.Color", - "r": 252, - "g": 252, - "b": 252, - "a": 255 - }, - "_cascadeOpacityEnabled": true, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.5, - "y": 0.5 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 960, - "height": 640 - }, - "_rotationX": 0, - "_rotationY": 0, - "_scaleX": 1, - "_scaleY": 1, - "_position": { - "__type__": "cc.Vec2", - "x": 480, - "y": 320 - }, - "_skewX": 0, - "_skewY": 0, - "_localZOrder": 0, - "_globalZOrder": 0, - "_opacityModifyRGB": false, - "groupIndex": 0 - }, - { - "__type__": "cc.Node", - "_name": "background", - "_objFlags": 0, - "_parent": { - "__id__": 2 - }, - "_children": [], - "_tag": -1, - "_active": true, - "_components": [ - { - "__id__": 4 - }, - { - "__id__": 5 - } - ], - "_prefab": null, - "_id": "e2e0crkOLxGrpMxpbC4iQg1", - "_opacity": 255, - "_color": { - "__type__": "cc.Color", - "r": 27, - "g": 38, - "b": 46, - "a": 255 - }, - "_cascadeOpacityEnabled": true, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.5, - "y": 0.5 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 960, - "height": 640 - }, - "_rotationX": 0, - "_rotationY": 0, - "_scaleX": 1, - "_scaleY": 1, - "_position": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_skewX": 0, - "_skewY": 0, - "_localZOrder": 0, - "_globalZOrder": 0, - "_opacityModifyRGB": false, - "groupIndex": 0 - }, - { - "__type__": "cc.Widget", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 3 - }, - "_enabled": true, - "isAlignOnce": true, - "_target": null, - "_alignFlags": 45, - "_left": 0, - "_right": 0, - "_top": 0, - "_bottom": 0, - "_verticalCenter": 0, - "_horizontalCenter": 0, - "_isAbsLeft": true, - "_isAbsRight": true, - "_isAbsTop": true, - "_isAbsBottom": true, - "_isAbsHorizontalCenter": true, - "_isAbsVerticalCenter": true, - "_originalWidth": 200, - "_originalHeight": 150 - }, - { - "__type__": "cc.Sprite", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 3 - }, - "_enabled": true, - "_spriteFrame": { - "__uuid__": "410fb916-8721-4663-bab8-34397391ace7" - }, - "_type": 1, - "_sizeMode": 0, - "_fillType": 0, - "_fillCenter": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_fillStart": 0, - "_fillRange": 0, - "_isTrimmedMode": true, - "_srcBlendFactor": 770, - "_dstBlendFactor": 771, - "_atlas": null - }, - { - "__type__": "cc.Node", - "_name": "ScrollView", - "_objFlags": 0, - "_parent": { - "__id__": 2 - }, - "_children": [ - { - "__id__": 7 - } - ], - "_tag": -1, - "_active": true, - "_components": [ - { - "__id__": 10 - }, - { - "__id__": 11 - }, - { - "__id__": 12 - } - ], - "_prefab": null, - "_id": "92lL5sUpRLp4ACxwVgYY3A", - "_opacity": 255, - "_color": { - "__type__": "cc.Color", - "r": 184, - "g": 184, - "b": 184, - "a": 255 - }, - "_cascadeOpacityEnabled": true, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.5, - "y": 0.5 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 400, - "height": 600 - }, - "_rotationX": 0, - "_rotationY": 0, - "_scaleX": 1, - "_scaleY": 1, - "_position": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_skewX": 0, - "_skewY": 0, - "_localZOrder": 0, - "_globalZOrder": 0, - "_opacityModifyRGB": false, - "groupIndex": 0 - }, - { - "__type__": "cc.Node", - "_name": "view", - "_objFlags": 0, - "_parent": { - "__id__": 6 - }, - "_children": [ - { - "__id__": 8 - } - ], - "_tag": -1, - "_active": true, - "_components": [ - { - "__id__": 9 - } - ], - "_prefab": null, - "_id": "05kf/Rkl1BiLiCJB9Ad22Z", - "_opacity": 255, - "_color": { - "__type__": "cc.Color", - "r": 255, - "g": 255, - "b": 255, - "a": 255 - }, - "_cascadeOpacityEnabled": true, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.5, - "y": 1 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 400, - "height": 600 - }, - "_rotationX": 0, - "_rotationY": 0, - "_scaleX": 1, - "_scaleY": 1, - "_position": { - "__type__": "cc.Vec2", - "x": 0, - "y": 300 - }, - "_skewX": 0, - "_skewY": 0, - "_localZOrder": 0, - "_globalZOrder": 0, - "_opacityModifyRGB": false, - "groupIndex": 0 - }, - { - "__type__": "cc.Node", - "_name": "content", - "_objFlags": 0, - "_parent": { - "__id__": 7 - }, - "_children": [], - "_tag": -1, - "_active": true, - "_components": [], - "_prefab": null, - "_id": "79OIFfXElLr4eQ/hGJLNpN", - "_opacity": 255, - "_color": { - "__type__": "cc.Color", - "r": 255, - "g": 255, - "b": 255, - "a": 255 - }, - "_cascadeOpacityEnabled": true, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0, - "y": 1 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 400, - "height": 600 - }, - "_rotationX": 0, - "_rotationY": 0, - "_scaleX": 1, - "_scaleY": 1, - "_position": { - "__type__": "cc.Vec2", - "x": -200, - "y": 0 - }, - "_skewX": 0, - "_skewY": 0, - "_localZOrder": 0, - "_globalZOrder": 0, - "_opacityModifyRGB": false, - "groupIndex": 0 - }, - { - "__type__": "cc.Mask", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 7 - }, - "_enabled": true, - "_type": 0, - "_segements": 64, - "_N$spriteFrame": null, - "_N$alphaThreshold": 1, - "_N$inverted": false - }, - { - "__type__": "cc.Sprite", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 6 - }, - "_enabled": true, - "_spriteFrame": { - "__uuid__": "9bbda31e-ad49-43c9-aaf2-f7d9896bac69" - }, - "_type": 1, - "_sizeMode": 0, - "_fillType": 0, - "_fillCenter": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_fillStart": 0, - "_fillRange": 0, - "_isTrimmedMode": true, - "_srcBlendFactor": 770, - "_dstBlendFactor": 771, - "_atlas": null - }, - { - "__type__": "cc.ScrollView", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 6 - }, - "_enabled": true, - "content": { - "__id__": 8 - }, - "horizontal": false, - "vertical": true, - "inertia": true, - "brake": 0.75, - "elastic": true, - "bounceDuration": 0.23, - "scrollEvents": [], - "cancelInnerEvents": true, - "_N$horizontalScrollBar": null, - "_N$verticalScrollBar": null - }, - { - "__type__": "86872n9U6tCEobIPwudn2h/", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 6 - }, - "_enabled": true, - "scrollview": { - "__id__": 11 - }, - "prefab": { - "__uuid__": "10c60cf0-420d-41d3-b409-ae1ebad07af7" - }, - "content": { - "__id__": 8 - }, - "mask": { - "__id__": 9 - } - }, - { - "__type__": "cc.Canvas", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 2 - }, - "_enabled": true, - "_designResolution": { - "__type__": "cc.Size", - "width": 960, - "height": 640 - }, - "_fitWidth": false, - "_fitHeight": true - } -] \ No newline at end of file diff --git a/ListViewV2Demo/assets/Scene/helloworldJs.fire.meta b/ListViewV2Demo/assets/Scene/helloworldJs.fire.meta deleted file mode 100644 index cd42bc6..0000000 --- a/ListViewV2Demo/assets/Scene/helloworldJs.fire.meta +++ /dev/null @@ -1,7 +0,0 @@ -{ - "ver": "0.9.0", - "uuid": "2d2f792f-a40c-49bb-a189-ed176a246e49", - "asyncLoadAssets": false, - "autoReleaseAssets": false, - "subMetas": {} -} \ No newline at end of file diff --git a/ListViewV2Demo/assets/Scene/helloworldTs.fire b/ListViewV2Demo/assets/Scene/helloworldTs.fire index 8034ab2..9b8a106 100644 --- a/ListViewV2Demo/assets/Scene/helloworldTs.fire +++ b/ListViewV2Demo/assets/Scene/helloworldTs.fire @@ -67,6 +67,9 @@ "_components": [ { "__id__": 13 + }, + { + "__id__": 14 } ], "_prefab": null, @@ -239,7 +242,7 @@ } ], "_prefab": null, - "_id": "92lL5sUpRLp4ACxwVgYY3A", + "_id": "89bR5zdlpDKYOUS2c9rA+O", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -256,8 +259,8 @@ }, "_contentSize": { "__type__": "cc.Size", - "width": 400, - "height": 600 + "width": 700, + "height": 270 }, "_rotationX": 0, "_rotationY": 0, @@ -295,7 +298,7 @@ } ], "_prefab": null, - "_id": "05kf/Rkl1BiLiCJB9Ad22Z", + "_id": "ddrOAdUPBCQbRM5qnQEGWd", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -307,13 +310,13 @@ "_cascadeOpacityEnabled": true, "_anchorPoint": { "__type__": "cc.Vec2", - "x": 0.5, - "y": 1 + "x": 0, + "y": 0.5 }, "_contentSize": { "__type__": "cc.Size", - "width": 400, - "height": 600 + "width": 700, + "height": 270 }, "_rotationX": 0, "_rotationY": 0, @@ -321,8 +324,8 @@ "_scaleY": 1, "_position": { "__type__": "cc.Vec2", - "x": 0, - "y": 300 + "x": -350, + "y": 0 }, "_skewX": 0, "_skewY": 0, @@ -343,7 +346,7 @@ "_active": true, "_components": [], "_prefab": null, - "_id": "79OIFfXElLr4eQ/hGJLNpN", + "_id": "87Sso0FflMT6bAmboLNq5m", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -360,8 +363,8 @@ }, "_contentSize": { "__type__": "cc.Size", - "width": 400, - "height": 600 + "width": 220, + "height": 270 }, "_rotationX": 0, "_rotationY": 0, @@ -369,8 +372,8 @@ "_scaleY": 1, "_position": { "__type__": "cc.Vec2", - "x": -200, - "y": 0 + "x": 0, + "y": 135 }, "_skewX": 0, "_skewY": 0, @@ -442,7 +445,7 @@ "_N$verticalScrollBar": null }, { - "__type__": "93ce6/0kVBB4b8cNGqV0EYe", + "__type__": "2a2daZ0TLRFQpPMCVCCA6kF", "_name": "", "_objFlags": 0, "node": { @@ -452,15 +455,21 @@ "scrollview": { "__id__": 11 }, - "prefab": { - "__uuid__": "10c60cf0-420d-41d3-b409-ae1ebad07af7" - }, "content": { "__id__": 8 }, "mask": { "__id__": 9 - } + }, + "prefab": { + "__uuid__": "10c60cf0-420d-41d3-b409-ae1ebad07af7" + }, + "PrefabClass": "TestListViewItem", + "direction": 2, + "row": 1, + "column": 1, + "gap_x": 0, + "gap_y": 0 }, { "__type__": "cc.Canvas", @@ -477,5 +486,17 @@ }, "_fitWidth": false, "_fitHeight": true + }, + { + "__type__": "280c3rsZJJKnZ9RqbALVwtK", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 2 + }, + "_enabled": true, + "listViewNode": { + "__id__": 6 + } } ] \ No newline at end of file diff --git a/ListViewV2Demo/assets/Scene/helloworldTs.fire.meta b/ListViewV2Demo/assets/Scene/helloworldTs.fire.meta index 6eb6e0d..615a57c 100644 --- a/ListViewV2Demo/assets/Scene/helloworldTs.fire.meta +++ b/ListViewV2Demo/assets/Scene/helloworldTs.fire.meta @@ -1,5 +1,5 @@ { - "ver": "0.9.0", + "ver": "1.0.0", "uuid": "3955e774-48e8-4785-9050-195165faa0ce", "asyncLoadAssets": false, "autoReleaseAssets": false, diff --git a/ListViewV2Demo/assets/Script/HelloWorld.js b/ListViewV2Demo/assets/Script/HelloWorld.js index b8d80cc..e2787ef 100644 --- a/ListViewV2Demo/assets/Script/HelloWorld.js +++ b/ListViewV2Demo/assets/Script/HelloWorld.js @@ -2,17 +2,13 @@ cc.Class({ extends: cc.Component, properties: { - label: { - default: null, - type: cc.Label - }, - // defaults, set visually when attaching this script to the Canvas - text: 'Hello, World!' + + listViewNode: cc.Node }, - // use this for initialization - onLoad: function () { - this.label.string = this.text; + start() { + let script = this.listViewNode.getComponent('ListViewFactory'); + script.init([1, 2, 3, 4, 5, 6, 7, 8, 9]); }, // called every frame diff --git a/ListViewV2Demo/assets/Script/ListViewFactory.ts b/ListViewV2Demo/assets/Script/ListViewFactory.ts new file mode 100644 index 0000000..65747e2 --- /dev/null +++ b/ListViewV2Demo/assets/Script/ListViewFactory.ts @@ -0,0 +1,63 @@ +import { ListViewTs } from "./Listview/listview"; + +const { ccclass, property } = cc._decorator; + + +export enum ListViewDir { + Vertical = 1, + Horizontal = 2, +} +export let CListViewDir = { type: cc.Enum(ListViewDir) } + +@ccclass +export default class ListViewFactory extends cc.Component { + + @property(cc.ScrollView) + scrollview: cc.ScrollView = null; + @property(cc.Node) + content: cc.Node = null; + @property(cc.Mask) + mask: cc.Mask = null; + @property(cc.Prefab) + prefab: cc.Prefab = null; + @property(String) + PrefabClass: string = ''; + + @property(CListViewDir) + direction: ListViewDir = ListViewDir.Horizontal + @property(Number) + row: number = 1; + @property(Number) + column: number = 1; + @property(Number) + gap_x: number = 0; + @property(Number) + gap_y: number = 0; + + listView: ListViewTs; + + init(data) { + //初始化 + let item = cc.instantiate(this.prefab); + this.listView = new ListViewTs({ + scrollview: this.scrollview, + mask: this.mask, + content: this.content, + item_tpl: item, + item_class: this.PrefabClass, + direction: this.direction, + row: this.row, + column: this.column, + gap_x: this.gap_x, + gap_y: this.gap_y + }); + //显示 + this.listView.set_data(data); + } + + update(dt) { + if (this.listView) { + this.listView.onUpdate(); + } + } +} diff --git a/ListViewV2Demo/assets/Script/Listview-js/layout_utils.js.meta b/ListViewV2Demo/assets/Script/ListViewFactory.ts.meta similarity index 74% rename from ListViewV2Demo/assets/Script/Listview-js/layout_utils.js.meta rename to ListViewV2Demo/assets/Script/ListViewFactory.ts.meta index 32792cc..154757a 100644 --- a/ListViewV2Demo/assets/Script/Listview-js/layout_utils.js.meta +++ b/ListViewV2Demo/assets/Script/ListViewFactory.ts.meta @@ -1,6 +1,6 @@ { "ver": "1.0.5", - "uuid": "ded623b9-8cae-4b6b-b1cf-82747026c50e", + "uuid": "2a2da674-4cb4-4542-93cc-09508203a905", "isPlugin": false, "loadPluginInWeb": true, "loadPluginInNative": true, diff --git a/ListViewV2Demo/assets/Script/Listview-js.meta b/ListViewV2Demo/assets/Script/Listview-js.meta deleted file mode 100644 index c9530d6..0000000 --- a/ListViewV2Demo/assets/Script/Listview-js.meta +++ /dev/null @@ -1,5 +0,0 @@ -{ - "ver": "1.0.1", - "uuid": "e15db58e-2ca5-416a-be41-75b225cc342d", - "subMetas": {} -} \ No newline at end of file diff --git a/ListViewV2Demo/assets/Script/Listview-js/layout_utils.js b/ListViewV2Demo/assets/Script/Listview-js/layout_utils.js deleted file mode 100644 index 4f6b9ae..0000000 --- a/ListViewV2Demo/assets/Script/Listview-js/layout_utils.js +++ /dev/null @@ -1,46 +0,0 @@ -var LayoutUtil = /** @class */ (function () { - function LayoutUtil() { - } - LayoutUtil.vertical_layout = function (index, item_width, item_height, column, gap_x, gap_y, padding_left, padding_top) { - if (column === void 0) { column = 1; } - if (gap_x === void 0) { gap_x = 0; } - if (gap_y === void 0) { gap_y = 0; } - if (padding_left === void 0) { padding_left = 0; } - if (padding_top === void 0) { padding_top = 0; } - var x = (index % column) * (item_width + gap_x) + padding_left; - var y = -Math.floor(index / column) * (item_height + gap_y) - padding_top; - return [x, y]; - }; - LayoutUtil.horizontal_layout = function (index, item_width, item_height, row, gap_x, gap_y, padding_left, padding_top) { - if (row === void 0) { row = 1; } - if (gap_x === void 0) { gap_x = 0; } - if (gap_y === void 0) { gap_y = 0; } - if (padding_left === void 0) { padding_left = 0; } - if (padding_top === void 0) { padding_top = 0; } - var x = Math.floor(index / row) * (item_width + gap_x) + padding_left; - var y = -(index % row) * (item_height + gap_y) - padding_top; - return [x, y]; - }; - LayoutUtil.set_pivot_smart = function (node, ax, ay, recursive) { - if (recursive === void 0) { recursive = false; } - var deltaAx = ax - node.anchorX; - var deltaAy = ay - node.anchorY; - node.anchorX = ax; - node.anchorY = ay; - //改变节点锚点,位置值相对锚点不变。需要调整节点至新位置才能保持一致视觉效果 - var deltaX = deltaAx * node.width; - var deltaY = deltaAy * node.height; - node.x += deltaX; - node.y += deltaY; - node.children.forEach(function (child) { - //父节点锚点改变,子节点相对父节点位置值不变,需要调整子节点至新位置才能保持一致视觉效果 - child.x -= deltaX; - child.y -= deltaY; - if (recursive) { - LayoutUtil.set_pivot_smart(child, ax, ay); - } - }); - }; - return LayoutUtil; -}()); -exports.LayoutUtil = LayoutUtil; \ No newline at end of file diff --git a/ListViewV2Demo/assets/Script/Listview-js/listview.js b/ListViewV2Demo/assets/Script/Listview-js/listview.js deleted file mode 100644 index 4d36981..0000000 --- a/ListViewV2Demo/assets/Script/Listview-js/listview.js +++ /dev/null @@ -1,763 +0,0 @@ -var layout_utils_1 = require("layout_utils"); -var ListView = /** @class */ (function () { - function ListView(params) { - this._selected_index = -1; - this.scrollview = params.scrollview; - this.mask = params.mask; - this.content = params.content; - this.item_tpl = params.item_tpl; - this.item_tpl.active = false; - this.item_width = this.item_tpl.width; - this.item_height = this.item_tpl.height; - this.dir = params.direction || ListViewDir.Vertical; - this.width = params.width || this.scrollview.node.width; - this.height = params.height || this.scrollview.node.height; - this.gap_x = params.gap_x || 0; - this.gap_y = params.gap_y || 0; - this.padding_left = params.padding_left || 0; - this.padding_right = params.padding_right || 0; - this.padding_top = params.padding_top || 0; - this.padding_bottom = params.padding_bottom || 0; - this.item_anchorX = params.item_anchorX != null ? params.item_anchorX : 0; - this.item_anchorY = params.item_anchorY != null ? params.item_anchorY : 1; - this.row = params.row || 1; - this.col = params.column || 1; - this.cb_host = params.cb_host; - this.scroll_to_end_cb = params.scroll_to_end_cb; - this.item_class = params.item_class; - this.auto_scrolling = params.auto_scrolling || false; - this.item_pool = []; - if (this.dir == ListViewDir.Vertical) { - var content_width = (this.item_width + this.gap_x) * this.col - this.gap_x + this.padding_left + this.padding_right; - if (content_width > this.width) { - cc.log("content_width > width, resize listview to content_width,", this.width, "->", content_width); - this.width = content_width; - } - this.set_content_size(this.width, 0); - } - else { - var content_height = (this.item_height + this.gap_y) * this.row - this.gap_y + this.padding_top + this.padding_bottom; - if (content_height > this.height) { - cc.log("content_height > height, resize listview to content_height,", this.height, "->", content_height); - this.height = content_height; - } - this.set_content_size(0, this.height); - } - this.original_width = this.width; - this.original_height = this.height; - this.mask.node.setContentSize(this.width, this.height); - this.scrollview.node.setContentSize(this.width, this.height); - this.scrollview.vertical = this.dir == ListViewDir.Vertical; - this.scrollview.horizontal = this.dir == ListViewDir.Horizontal; - this.scrollview.inertia = true; - this.scrollview.node.on("scrolling", this.on_scrolling, this); - this.scrollview.node.on("scroll-to-bottom", this.on_scroll_to_end, this); - this.scrollview.node.on("scroll-to-right", this.on_scroll_to_end, this); - this.scrollview.node.on(cc.Node.EventType.TOUCH_START, this.on_scroll_touch_start, this); - this.scrollview.node.on(cc.Node.EventType.TOUCH_END, this.on_scroll_touch_end, this); - this.scrollview.node.on(cc.Node.EventType.TOUCH_CANCEL, this.on_scroll_touch_cancel, this); - } - ListView.prototype.on_scroll_touch_start = function (event) { - this._touchBeganPosition = cc.v2(event.touch.getLocation().x, event.touch.getLocation().y); - }; - ListView.prototype.on_scroll_touch_cancel = function (event) { - this._touchEndPosition = event.touch.getLocation(); - this.handle_release_logic(); - }; - ListView.prototype.on_scroll_touch_end = function (event) { - this._touchEndPosition = event.touch.getLocation(); - this.handle_release_logic(); - }; - ListView.prototype.handle_release_logic = function () { - var touchPos = this._touchEndPosition; - var moveOffset = this._touchBeganPosition.sub(this._touchEndPosition); - var dragDirection = this.get_drag_direction(moveOffset); - if (dragDirection != 0) { - return; - } - if (!this.packItems || !this.packItems.length) { - return; - } - //无滑动的情况下点击 - var touchPosInContent = this.content.convertToNodeSpaceAR(touchPos); - for (var i = this.start_index; i <= this.stop_index; i++) { - var packItem = this.packItems[i]; - if (packItem && packItem.item && packItem.item.node.getBoundingBox().contains(touchPosInContent)) { - packItem.item.onTouchEnd(packItem.item.node.convertToNodeSpaceAR(touchPos), packItem.data, i); - break; - } - } - }; - ListView.prototype.get_drag_direction = function (moveOffset) { - if (this.dir === ListViewDir.Horizontal) { - if (Math.abs(moveOffset.x) < 3) { - return 0; - } - return (moveOffset.x > 0 ? 1 : -1); - } - else if (this.dir === ListViewDir.Vertical) { - // 由于滚动 Y 轴的原点在在右上角所以应该是小于 0 - if (Math.abs(moveOffset.y) < 3) { - return 0; - } - return (moveOffset.y < 0 ? 1 : -1); - } - }; - ListView.prototype.on_scroll_to_end = function () { - if (this.scroll_to_end_cb) { - this.scroll_to_end_cb.call(this.cb_host); - } - }; - ListView.prototype.on_scrolling = function () { - var pos; - var threshold; - if (this.dir == ListViewDir.Vertical) { - pos = this.content.y; - threshold = this.item_height; - } - else { - pos = this.content.x; - threshold = this.item_width; - } - if (this.last_content_pos != null && Math.abs(pos - this.last_content_pos) < threshold) { - return; - } - this.last_content_pos = pos; - this.render(); - }; - ListView.prototype.render = function () { - if (!this.packItems || !this.packItems.length) { - return; - } - if (this.dir == ListViewDir.Vertical) { - var posy = this.content.y; - // cc.log("onscrolling, content posy=", posy); - if (posy < 0) { - posy = 0; - } - else if (posy > this.content_height - this.height) { - posy = this.content_height - this.height; - } - var viewport_start = -posy; - var viewport_stop = viewport_start - this.height; - // while(this.packItems[start].y - this.item_height > viewport_start) - // { - // start++; - // } - // while(this.packItems[stop].y < viewport_stop) - // { - // stop--; - // } - var start = this.indexFromOffset(viewport_start); - var stop = this.indexFromOffset(viewport_stop); - //expand viewport for better experience - start = Math.max(start - this.col, 0); - stop = Math.min(this.packItems.length - 1, stop + this.col); - if (start != this.start_index) { - this.start_index = start; - this.renderDirty = true; - } - if (stop != this.stop_index) { - this.stop_index = stop; - this.renderDirty = true; - } - } - else { - var posx = this.content.x; - // cc.log("onscrolling, content posx=", posx); - if (posx > 0) { - posx = 0; - } - else if (posx < this.width - this.content_width) { - posx = this.width - this.content_width; - } - var viewport_start = -posx; - var viewport_stop = viewport_start + this.width; - // while(this.packItems[start].x + this.item_width < viewport_start) - // { - // start++; - // } - // while(this.packItems[stop].x > viewport_stop) - // { - // stop--; - // } - var start = this.indexFromOffset(viewport_start); - var stop = this.indexFromOffset(viewport_stop); - //expand viewport for better experience - start = Math.max(start - this.row, 0); - stop = Math.min(this.packItems.length - 1, stop + this.row); - if (start != this.start_index) { - this.start_index = start; - this.renderDirty = true; - } - if (stop != this.stop_index) { - this.stop_index = stop; - this.renderDirty = true; - } - } - }; - ListView.prototype.onUpdate = function () { - if (this.renderDirty && cc.isValid(this.scrollview.node)) { - // cc.log("listView, render_from:", this.start_index, this.stop_index); - this.render_items(); - - this.renderDirty = false; - } - }; - //不支持多行多列 - ListView.prototype.indexFromOffset = function (offset) { - var low = 0; - var high = 0; - var max_idx = 0; - high = max_idx = this.packItems.length - 1; - if (this.dir == ListViewDir.Vertical) { - while (high >= low) { - var index = low + Math.floor((high - low) / 2); - var itemStart = this.packItems[index].y; - var itemStop = index < max_idx ? this.packItems[index + 1].y : -this.content_height; - if (offset <= itemStart && offset >= itemStop) { - return index; - } - else if (offset > itemStart) { - high = index - 1; - } - else { - low = index + 1; - } - } - } - else { - while (high >= low) { - var index = low + Math.floor((high - low) / 2); - var itemStart = this.packItems[index].x; - var itemStop = index < max_idx ? this.packItems[index + 1].x : this.content_width; - if (offset >= itemStart && offset <= itemStop) { - return index; - } - else if (offset > itemStart) { - low = index + 1; - } - else { - high = index - 1; - } - } - } - return -1; - }; - ListView.prototype.select_data = function (data) { - var idx = this.packItems.findIndex(function (item) { return item.data == data; }); - if (idx != -1) { - this.select_item(idx); - } - }; - ListView.prototype.select_item = function (index) { - if (index == this._selected_index) { - return; - } - if (this._selected_index != -1) { - this.inner_select_item(this._selected_index, false); - } - this._selected_index = index; - this.inner_select_item(index, true); - }; - ListView.prototype.inner_select_item = function (index, is_select) { - var packItem = this.packItems[index]; - if (!packItem) { - cc.warn("inner_select_item index is out of range{", 0, this.packItems.length - 1, "}", index); - return; - } - packItem.is_select = is_select; - if (packItem.item) { - packItem.item.onSetSelect(is_select, index); - if (is_select) { - packItem.item.onSelected(packItem.data, index); - } - } - }; - ListView.prototype.spawn_item = function (index) { - var item = this.item_pool.pop(); - if (!item) { - item = cc.instantiate(this.item_tpl).getComponent(this.item_class); - item.node.active = true; - //仅仅改变父节点锚点,子元素位置不会随之变化 - // item.node.setAnchorPoint(this.item_anchorX, this.item_anchorY); - layout_utils_1.LayoutUtil.set_pivot_smart(item.node, this.item_anchorX, this.item_anchorY); - item.onInit(); - // cc.log("spawn_item", index); - } - item.node.parent = this.content; - return item; - }; - ListView.prototype.recycle_item = function (packItem) { - var item = packItem.item; - if (item && cc.isValid(item.node)) { - item.onRecycle(packItem.data); - item.node.removeFromParent(); - this.item_pool.push(item); - packItem.item = null; - } - }; - ListView.prototype.clear_items = function () { - var _this = this; - if (this.packItems) { - this.packItems.forEach(function (packItem) { - _this.recycle_item(packItem); - }); - } - }; - ListView.prototype.render_items = function () { - var packItem; - for (var i = 0; i < this.start_index; i++) { - packItem = this.packItems[i]; - if (packItem.item) { - // cc.log("recycle_item", i); - this.recycle_item(packItem); - } - } - for (var i = this.packItems.length - 1; i > this.stop_index; i--) { - packItem = this.packItems[i]; - if (packItem.item) { - // cc.log("recycle_item", i); - this.recycle_item(packItem); - } - } - for (var i = this.start_index; i <= this.stop_index; i++) { - packItem = this.packItems[i]; - if (!packItem.item) { - // cc.log("render_item", i); - packItem.item = this.spawn_item(i); - packItem.item.onSetData(packItem.data, i); - packItem.item.onSetSelect(packItem.is_select, i); - if (packItem.is_select) { - packItem.item.onSelected(packItem.data, i); - } - } - //列表添加与删除时item位置会变化,因此每次render_items都要执行 - // packItem.item.node.setPosition(packItem.x, packItem.y); - packItem.item.setLeftTop(packItem.x, packItem.y); - } - }; - ListView.prototype.pack_item = function (data) { - return { x: 0, y: 0, data: data, item: null, is_select: false }; - }; - ListView.prototype.layout_items = function (start) { - // cc.log("layout_items, start=", start); - for (var index = start, stop = this.packItems.length; index < stop; index++) { - var packItem = this.packItems[index]; - if (this.dir == ListViewDir.Vertical) { - _a = layout_utils_1.LayoutUtil.vertical_layout(index, this.item_width, this.item_height, this.col, this.gap_x, this.gap_y, this.padding_left, this.padding_top), packItem.x = _a[0], packItem.y = _a[1]; - } - else { - _b = layout_utils_1.LayoutUtil.horizontal_layout(index, this.item_width, this.item_height, this.row, this.gap_x, this.gap_y, this.padding_left, this.padding_top), packItem.x = _b[0], packItem.y = _b[1]; - } - } - var _a, _b; - }; - ListView.prototype.adjust_content = function () { - if (this.packItems.length <= 0) { - this.set_content_size(0, 0); - return; - } - var last_packItem = this.packItems[this.packItems.length - 1]; - if (this.dir == ListViewDir.Vertical) { - var height = Math.max(this.height, this.item_height - last_packItem.y + this.padding_bottom); - this.set_content_size(this.content_width, height); - } - else { - var width = Math.max(this.width, last_packItem.x + this.item_width + this.padding_right); - this.set_content_size(width, this.content_height); - } - }; - ListView.prototype.set_content_size = function (width, height) { - if (this.content_width != width) { - this.content_width = width; - this.content.width = width; - } - if (this.content_height != height) { - this.content_height = height; - this.content.height = height; - } - // cc.log("ListView, set_content_size", width, height, this.content.width, this.content.height); - }; - ListView.prototype.set_viewport = function (width, height) { - if (width == null) { - width = this.width; - } - else if (width > this.content_width) { - width = this.content_width; - } - if (height == null) { - height = this.height; - } - else if (height > this.content_height) { - height = this.content_height; - } - //设置遮罩区域尺寸 - this.width = width; - this.height = height; - this.mask.node.setContentSize(width, height); - this.scrollview.node.setContentSize(width, height); - this.render(); - }; - ListView.prototype.renderAll = function (value) { - var width; - var height; - if (value) { - width = this.content_width; - height = this.content_height; - } - else { - width = this.original_width; - height = this.original_height; - } - this.set_viewport(width, height); - }; - ListView.prototype.set_data = function (datas) { - var _this = this; - if (this.packItems) { - this.clear_items(); - this.packItems.length = 0; - } - else { - this.packItems = []; - } - datas.forEach(function (data) { - var packItem = _this.pack_item(data); - _this.packItems.push(packItem); - }); - this.layout_items(0); - this.adjust_content(); - this.start_index = -1; - this.stop_index = -1; - if (this.dir == ListViewDir.Vertical) { - this.content.y = 0; - } - else { - this.content.x = 0; - } - if (this.packItems.length > 0) { - this.render(); - } - }; - ListView.prototype.insert_data = function (index) { - var _this = this; - var datas = []; - for (var _i = 1; _i < arguments.length; _i++) { - datas[_i - 1] = arguments[_i]; - } - if (datas.length == 0) { - cc.log("nothing to insert"); - return; - } - if (!this.packItems) { - this.packItems = []; - } - if (index < 0 || index > this.packItems.length) { - cc.warn("insert_data, invalid index", index); - return; - } - var is_append = index == this.packItems.length; - var packItems = []; - datas.forEach(function (data) { - var packItem = _this.pack_item(data); - packItems.push(packItem); - }); - (_a = this.packItems).splice.apply(_a, [index, 0].concat(packItems)); - this.layout_items(index); - this.adjust_content(); - this.start_index = -1; - this.stop_index = -1; - if (this.auto_scrolling && is_append) { - this.scroll_to_end(); - } - this.render(); - var _a; - }; - ListView.prototype.remove_data = function (index, count) { - var _this = this; - if (count === void 0) { count = 1; } - if (!this.packItems) { - cc.log("call set_data before call this method"); - return; - } - if (index < 0 || index >= this.packItems.length) { - cc.warn("remove_data, invalid index", index); - return; - } - if (count < 1) { - cc.log("nothing to remove"); - return; - } - var old_length = this.packItems.length; - var del_items = this.packItems.splice(index, count); - //回收node - del_items.forEach(function (packItem) { - _this.recycle_item(packItem); - }); - //重新排序index后面的 - if (index + count < old_length) { - this.layout_items(index); - } - this.adjust_content(); - if (this.packItems.length > 0) { - this.start_index = -1; - this.stop_index = -1; - this.render(); - } - }; - ListView.prototype.append_data = function () { - var datas = []; - for (var _i = 0; _i < arguments.length; _i++) { - datas[_i] = arguments[_i]; - } - if (!this.packItems) { - this.packItems = []; - } - this.insert_data.apply(this, [this.packItems.length].concat(datas)); - }; - ListView.prototype.scroll_to = function (index, time) { - if (time === void 0) { time = 0; } - if (!this.packItems) { - return; - } - var packItem = this.packItems[index]; - if (!packItem) { - cc.log("scroll_to, index out of range"); - return; - } - if (this.dir == ListViewDir.Vertical) { - var min_y = this.height - this.content_height; - if (min_y >= 0) { - cc.log("no need to scroll"); - return; - } - var y = packItem.y; - if (y < min_y) { - y = min_y; - cc.log("content reach bottom"); - } - var x = this.content.x; - if (time == 0) { - this.scrollview.setContentPosition(cc.v2(x, -y)); - } - else { - this.scrollview.scrollToOffset(cc.v2(x, -y), time); - } - this.render(); - } - else { - var max_x = this.content_width - this.width; - if (max_x <= 0) { - cc.log("no need to scroll"); - return; - } - var x = packItem.x; - if (x > max_x) { - x = max_x; - cc.log("content reach right"); - } - var y = this.content.y; - if (time == 0) { - this.scrollview.setContentPosition(cc.v2(-x, y)); - } - else { - this.scrollview.scrollToOffset(cc.v2(-x, y), time); - } - this.render(); - } - }; - ListView.prototype.get_scroll_offset = function () { - var offset = this.scrollview.getScrollOffset(); - if (this.dir == ListViewDir.Vertical) { - return offset.y; - } - else { - return offset.x; - } - }; - ListView.prototype.scroll_to_offset = function (value, time) { - if (time === void 0) { time = 0; } - if (this.dir == ListViewDir.Vertical) { - var x = this.content.x; - if (time == 0) { - this.scrollview.setContentPosition(cc.v2(x, value)); - } - else { - this.scrollview.scrollToOffset(cc.v2(x, value), time); - } - this.render(); - } - else { - var y = this.content.y; - if (time == 0) { - this.scrollview.setContentPosition(cc.v2(value, y)); - } - else { - this.scrollview.scrollToOffset(cc.v2(value, y), time); - } - this.render(); - } - }; - ListView.prototype.scroll_to_end = function () { - if (this.dir == ListViewDir.Vertical) { - this.scrollview.scrollToBottom(); - } - else { - this.scrollview.scrollToRight(); - } - }; - ListView.prototype.refresh_item = function (index, data) { - var packItem = this.get_pack_item(index); - if (!packItem) { - return; - } - var oldData = packItem.data; - packItem.data = data; - if (packItem.item) { - packItem.item.onRecycle(oldData); - packItem.item.onSetData(data, index); - } - }; - ListView.prototype.reload_item = function (index) { - var packItem = this.get_pack_item(index); - if (packItem && packItem.item) { - packItem.item.onRecycle(packItem.data); - packItem.item.onSetData(packItem.data, index); - } - }; - ListView.prototype.get_pack_item = function (index) { - if (!this.packItems) { - cc.log("call set_data before call this method"); - return null; - } - if (index < 0 || index >= this.packItems.length) { - cc.warn("get_pack_item, invalid index", index); - return null; - } - return this.packItems[index]; - }; - ListView.prototype.get_item = function (index) { - var packItem = this.get_pack_item(index); - return packItem ? packItem.item : null; - }; - ListView.prototype.get_data = function (index) { - var packItem = this.get_pack_item(index); - return packItem ? packItem.data : null; - }; - ListView.prototype.find_item = function (predicate) { - if (!this.packItems || !this.packItems.length) { - cc.log("call set_data before call this method"); - return null; - } - for (var i = this.start_index; i <= this.stop_index; i++) { - var packItem = this.packItems[i]; - if (predicate(packItem.data)) { - return packItem.item; - } - } - return null; - }; - ListView.prototype.find_index = function (predicate) { - if (!this.packItems || !this.packItems.length) { - cc.log("call set_data before call this method"); - return -1; - } - return this.packItems.findIndex(function (packItem) { - return predicate(packItem.data); - }); - }; - Object.defineProperty(ListView.prototype, "renderedItems", { - get: function () { - var items = []; - for (var i = this.start_index; i <= this.stop_index; i++) { - var packItem = this.packItems[i]; - if (packItem && packItem.item) { - items.push(packItem.item); - } - } - return items; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ListView.prototype, "length", { - get: function () { - if (!this.packItems) { - cc.log("call set_data before call this method"); - return 0; - } - return this.packItems.length; - }, - enumerable: true, - configurable: true - }); - ListView.prototype.destroy = function () { - this.clear_items(); - this.item_pool.forEach(function (item) { - item.onUnInit(); - item.node.destroy(); - }); - this.item_pool = null; - this.packItems = null; - this.renderDirty = null; - if (cc.isValid(this.scrollview.node)) { - this.scrollview.node.off("scrolling", this.on_scrolling, this); - this.scrollview.node.off("scroll-to-bottom", this.on_scroll_to_end, this); - this.scrollview.node.off("scroll-to-right", this.on_scroll_to_end, this); - this.scrollview.node.off(cc.Node.EventType.TOUCH_START, this.on_scroll_touch_start, this); - this.scrollview.node.off(cc.Node.EventType.TOUCH_END, this.on_scroll_touch_end, this); - this.scrollview.node.off(cc.Node.EventType.TOUCH_CANCEL, this.on_scroll_touch_cancel, this); - } - }; - Object.defineProperty(ListView.prototype, "selected_index", { - get: function () { - return this._selected_index; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ListView.prototype, "selected_data", { - get: function () { - var packItem = this.packItems[this._selected_index]; - if (packItem) { - return packItem.data; - } - return null; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ListView.prototype, "scrollable", { - set: function (value) { - if (this.dir == ListViewDir.Vertical) { - this.scrollview.vertical = value; - } - else { - this.scrollview.horizontal = value; - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ListView.prototype, "startIndex", { - get: function () { - return this.start_index; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ListView.prototype, "stopIndex", { - get: function () { - return this.stop_index; - }, - enumerable: true, - configurable: true - }); - return ListView; -}()); -exports.ListView = ListView; -var ListViewDir; -(function (ListViewDir) { - ListViewDir[ListViewDir["Vertical"] = 1] = "Vertical"; - ListViewDir[ListViewDir["Horizontal"] = 2] = "Horizontal"; -})(ListViewDir = exports.ListViewDir || (exports.ListViewDir = {})); \ No newline at end of file diff --git a/ListViewV2Demo/assets/Script/Listview-js/listview.js.meta b/ListViewV2Demo/assets/Script/Listview-js/listview.js.meta deleted file mode 100644 index 43863d4..0000000 --- a/ListViewV2Demo/assets/Script/Listview-js/listview.js.meta +++ /dev/null @@ -1,9 +0,0 @@ -{ - "ver": "1.0.5", - "uuid": "f4394ca7-5f81-4fbc-8a29-4361e05d601f", - "isPlugin": false, - "loadPluginInWeb": true, - "loadPluginInNative": true, - "loadPluginInEditor": false, - "subMetas": {} -} \ No newline at end of file diff --git a/ListViewV2Demo/assets/Script/Listview-js/listviewitem.js b/ListViewV2Demo/assets/Script/Listview-js/listviewitem.js deleted file mode 100644 index 4ece796..0000000 --- a/ListViewV2Demo/assets/Script/Listview-js/listviewitem.js +++ /dev/null @@ -1,44 +0,0 @@ -var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; -var ListViewItem = /** @class */ (function (_super) { - __extends(ListViewItem, _super); - function ListViewItem() { - return _super !== null && _super.apply(this, arguments) || this; - } - // constructor() - // { - // super(); - // } - ListViewItem.prototype.onInit = function () { - // cc.log("item初如化"); - }; - ListViewItem.prototype.onUnInit = function () { - // cc.log("item析构"); - }; - ListViewItem.prototype.onSetData = function (data, index) { - // cc.log("item设置数据"); - }; - ListViewItem.prototype.onSetSelect = function (is_select, index) { - // cc.log("item选中状态改变"); - }; - ListViewItem.prototype.onRecycle = function (data) { - // cc.log("item被回收"); - }; - ListViewItem.prototype.onSelected = function (data, index) { - // cc.log("item被选中"); - }; - ListViewItem.prototype.onTouchEnd = function (touchPos, data, index) { - // cc.log("item非滑动状态下被点击"); - }; - ListViewItem.prototype.onBecameInvisible = function () { - // cc.log("item从父节点移除或不可见"); - }; - ListViewItem.prototype.setLeftTop = function (left, top) { - this.node.x = left + this.node.anchorX * this.node.width; - this.node.y = top - (1 - this.node.anchorY) * this.node.height; - }; - ListViewItem = __decorate([ - ccclass - ], ListViewItem); - return ListViewItem; -}(cc.Component)); -exports.ListViewItem = ListViewItem; \ No newline at end of file diff --git a/ListViewV2Demo/assets/Script/Listview-js/listviewitem.js.meta b/ListViewV2Demo/assets/Script/Listview-js/listviewitem.js.meta deleted file mode 100644 index 65b05e5..0000000 --- a/ListViewV2Demo/assets/Script/Listview-js/listviewitem.js.meta +++ /dev/null @@ -1,9 +0,0 @@ -{ - "ver": "1.0.5", - "uuid": "3cccd937-6bcc-49a5-bbc2-0e8ab9160951", - "isPlugin": false, - "loadPluginInWeb": true, - "loadPluginInNative": true, - "loadPluginInEditor": false, - "subMetas": {} -} \ No newline at end of file diff --git a/ListViewV2Demo/assets/Script/Listview-ts.meta b/ListViewV2Demo/assets/Script/Listview.meta similarity index 100% rename from ListViewV2Demo/assets/Script/Listview-ts.meta rename to ListViewV2Demo/assets/Script/Listview.meta diff --git a/ListViewV2Demo/assets/Script/Listview-ts/ListViewTs.ts b/ListViewV2Demo/assets/Script/Listview/ListView.ts similarity index 97% rename from ListViewV2Demo/assets/Script/Listview-ts/ListViewTs.ts rename to ListViewV2Demo/assets/Script/Listview/ListView.ts index 39201a8..7edd263 100644 --- a/ListViewV2Demo/assets/Script/Listview-ts/ListViewTs.ts +++ b/ListViewV2Demo/assets/Script/Listview/ListView.ts @@ -1,12 +1,12 @@ -import { LayoutUtilTs } from "./layout_utilsTs" -import { ListViewItemTs } from "./ListViewItemTs"; +import { LayoutUtil } from "./layout_utils" +import { ListViewItem } from "./ListViewItem"; export class ListViewTs { private scrollview: cc.ScrollView; private mask: cc.Mask; private content: cc.Node; private item_tpl: cc.Node; - private item_pool: ListViewItemTs[]; + private item_pool: ListViewItem[]; private dir: number; private width: number; @@ -326,14 +326,14 @@ export class ListViewTs { } } - private spawn_item(index: number): ListViewItemTs { - let item: ListViewItemTs = this.item_pool.pop(); + private spawn_item(index: number): ListViewItem { + let item: ListViewItem = this.item_pool.pop(); if (!item) { - item = cc.instantiate(this.item_tpl).getComponent(this.item_class) as ListViewItemTs; + item = cc.instantiate(this.item_tpl).getComponent(this.item_class) as ListViewItem; item.node.active = true; //仅仅改变父节点锚点,子元素位置不会随之变化 // item.node.setAnchorPoint(this.item_anchorX, this.item_anchorY); - LayoutUtilTs.set_pivot_smart(item.node, this.item_anchorX, this.item_anchorY); + LayoutUtil.set_pivot_smart(item.node, this.item_anchorX, this.item_anchorY); item.onInit(); // cc.log("spawn_item", index); } @@ -401,10 +401,10 @@ export class ListViewTs { for (let index = start, stop = this.packItems.length; index < stop; index++) { const packItem = this.packItems[index]; if (this.dir == ListViewDir.Vertical) { - [packItem.x, packItem.y] = LayoutUtilTs.vertical_layout(index, this.item_width, this.item_height, this.col, this.gap_x, this.gap_y, this.padding_left, this.padding_top); + [packItem.x, packItem.y] = LayoutUtil.vertical_layout(index, this.item_width, this.item_height, this.col, this.gap_x, this.gap_y, this.padding_left, this.padding_top); } else { - [packItem.x, packItem.y] = LayoutUtilTs.horizontal_layout(index, this.item_width, this.item_height, this.row, this.gap_x, this.gap_y, this.padding_left, this.padding_top); + [packItem.x, packItem.y] = LayoutUtil.horizontal_layout(index, this.item_width, this.item_height, this.row, this.gap_x, this.gap_y, this.padding_left, this.padding_top); } } } @@ -730,7 +730,7 @@ export class ListViewTs { } get renderedItems() { - const items: ListViewItemTs[] = []; + const items: ListViewItem[] = []; for (let i = this.start_index; i <= this.stop_index; i++) { const packItem = this.packItems[i]; if (packItem && packItem.item) { @@ -833,5 +833,5 @@ type PackItem = { y: number; data: any; is_select: boolean; - item: ListViewItemTs; + item: ListViewItem; } \ No newline at end of file diff --git a/ListViewV2Demo/assets/Script/Listview-ts/ListViewTs.ts.meta b/ListViewV2Demo/assets/Script/Listview/ListView.ts.meta similarity index 100% rename from ListViewV2Demo/assets/Script/Listview-ts/ListViewTs.ts.meta rename to ListViewV2Demo/assets/Script/Listview/ListView.ts.meta diff --git a/ListViewV2Demo/assets/Script/Listview-ts/ListViewItemTs.ts b/ListViewV2Demo/assets/Script/Listview/ListViewItem.ts similarity index 95% rename from ListViewV2Demo/assets/Script/Listview-ts/ListViewItemTs.ts rename to ListViewV2Demo/assets/Script/Listview/ListViewItem.ts index fbca19c..ab24168 100644 --- a/ListViewV2Demo/assets/Script/Listview-ts/ListViewItemTs.ts +++ b/ListViewV2Demo/assets/Script/Listview/ListViewItem.ts @@ -1,6 +1,6 @@ const {ccclass, property} = cc._decorator; @ccclass -export class ListViewItemTs extends cc.Component +export class ListViewItem extends cc.Component { // constructor() // { diff --git a/ListViewV2Demo/assets/Script/Listview-ts/ListViewItemTs.ts.meta b/ListViewV2Demo/assets/Script/Listview/ListViewItem.ts.meta similarity index 100% rename from ListViewV2Demo/assets/Script/Listview-ts/ListViewItemTs.ts.meta rename to ListViewV2Demo/assets/Script/Listview/ListViewItem.ts.meta diff --git a/ListViewV2Demo/assets/Script/Listview-ts/layout_utilsTs.ts b/ListViewV2Demo/assets/Script/Listview/layout_utils.ts similarity index 98% rename from ListViewV2Demo/assets/Script/Listview-ts/layout_utilsTs.ts rename to ListViewV2Demo/assets/Script/Listview/layout_utils.ts index f1836b6..dd9e73e 100644 --- a/ListViewV2Demo/assets/Script/Listview-ts/layout_utilsTs.ts +++ b/ListViewV2Demo/assets/Script/Listview/layout_utils.ts @@ -1,5 +1,5 @@ //item及父节点锚点都为(0,1) -export class LayoutUtilTs +export class LayoutUtil { static vertical_layout(index:number, item_width:number, item_height:number, column = 1, gap_x = 0, gap_y = 0, padding_left = 0, padding_top = 0):[number, number] { diff --git a/ListViewV2Demo/assets/Script/Listview-ts/layout_utilsTs.ts.meta b/ListViewV2Demo/assets/Script/Listview/layout_utils.ts.meta similarity index 100% rename from ListViewV2Demo/assets/Script/Listview-ts/layout_utilsTs.ts.meta rename to ListViewV2Demo/assets/Script/Listview/layout_utils.ts.meta diff --git a/ListViewV2Demo/assets/Script/TestListView-js.js b/ListViewV2Demo/assets/Script/TestListView-js.js deleted file mode 100644 index 94f5487..0000000 --- a/ListViewV2Demo/assets/Script/TestListView-js.js +++ /dev/null @@ -1,63 +0,0 @@ -const ListView = require("listview").ListView; -cc.Class({ - extends: cc.Component, - - properties: { - scrollview: cc.ScrollView, - prefab: cc.Prefab, - content: cc.Node, - mask: cc.Mask, - }, - - onLoad() { - let data = []; - for (let i = 0; i < 100; i++) { - data.push(i); - } - this.init(data); - }, - - registerEvent() { - - }, - - init(data) { - let item = cc.instantiate(this.prefab); - //初始化 - this.listView = new ListView({ - scrollview: this.scrollview, - mask: this.mask, - content: this.content, - item_tpl: item, - item_class: 'TestListViewItem-js', - column: 2, - gap_y: 5, - gap_x: 5, - }); - //显示 - this.listView.set_data(data); - }, - - update(dt) { - //刷新 - if (this.listView) { - this.listView.onUpdate(); - } - }, - - onEnable() { - this.registerEvent(); - }, - - onDisable() { - this.offEvent(); - }, - - offEvent() { - // - }, - - onDestroy() { - - } -}); \ No newline at end of file diff --git a/ListViewV2Demo/assets/Script/TestListView-js.js.meta b/ListViewV2Demo/assets/Script/TestListView-js.js.meta deleted file mode 100644 index e2bdd06..0000000 --- a/ListViewV2Demo/assets/Script/TestListView-js.js.meta +++ /dev/null @@ -1,9 +0,0 @@ -{ - "ver": "1.0.5", - "uuid": "868729fd-53ab-4212-86c8-3f0b9d9f687f", - "isPlugin": false, - "loadPluginInWeb": true, - "loadPluginInNative": true, - "loadPluginInEditor": false, - "subMetas": {} -} \ No newline at end of file diff --git a/ListViewV2Demo/assets/Script/TestListView-ts.ts b/ListViewV2Demo/assets/Script/TestListView-ts.ts deleted file mode 100644 index aaacfab..0000000 --- a/ListViewV2Demo/assets/Script/TestListView-ts.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { ListViewTs } from "./Listview-ts/listviewTs"; - -const { ccclass, property } = cc._decorator; - -@ccclass -export default class NewClass extends cc.Component { - - @property(cc.ScrollView) - scrollview: cc.ScrollView = null; - @property(cc.Prefab) - prefab: cc.Prefab = null; - @property(cc.Node) - content: cc.Node = null; - @property(cc.Mask) - mask: cc.Mask = null; - listView: ListViewTs - - onLoad() { - console.log('abc'); - - let data = []; - for (let i = 0; i < 100; i++) { - data.push(i); - } - this.init(data); - } - - start() { - - } - - init(data) { - let item = cc.instantiate(this.prefab); - //初始化 - this.listView = new ListViewTs({ - scrollview: this.scrollview, - mask: this.mask, - content: this.content, - item_tpl: item, - item_class: 'TestListViewItem-js', - column: 2, - gap_y: 5, - gap_x: 5, - }); - //显示 - this.listView.set_data(data); - } - - update(dt) { - if (this.listView) { - this.listView.onUpdate(); - } - } -} diff --git a/ListViewV2Demo/assets/Script/TestListView-ts.ts.meta b/ListViewV2Demo/assets/Script/TestListView-ts.ts.meta deleted file mode 100644 index f3f0cc1..0000000 --- a/ListViewV2Demo/assets/Script/TestListView-ts.ts.meta +++ /dev/null @@ -1,9 +0,0 @@ -{ - "ver": "1.0.5", - "uuid": "93ce6ff4-9150-41e1-bf1c-346a95d0461e", - "isPlugin": false, - "loadPluginInWeb": true, - "loadPluginInNative": true, - "loadPluginInEditor": false, - "subMetas": {} -} \ No newline at end of file diff --git a/ListViewV2Demo/assets/Script/TestListViewItem-js.js b/ListViewV2Demo/assets/Script/TestListViewItem-js.js deleted file mode 100644 index 652ccbf..0000000 --- a/ListViewV2Demo/assets/Script/TestListViewItem-js.js +++ /dev/null @@ -1,55 +0,0 @@ -const ListViewItem = require("listviewitem").ListViewItem; -cc.Class({ - extends: ListViewItem, - - properties: { - level: cc.Label, - _data: null - }, - - onLoad() { - - }, - - onInit() { - // cc.log("item初如化"); - }, - - onUnInit() { - // cc.log("item析构"); - }, - - onSetData(data, index) { - cc.log("item设置数据"); - this._data = data; - this.level.string = `data=${data}/index=${index}`; - }, - - onSetSelect(is_select, index) { - // cc.log("item选中状态改变"); - }, - - onRecycle(data) { - // cc.log("item被回收"); - }, - - onSelected(data, index) { - // cc.log("item被选中"); - }, - - onTouchEnd(touchPos/** : cc.Vec2*/, data, index) { - // cc.log("item非滑动状态下被点击"); - - }, - - onBecameInvisible() { - // cc.log("item从父节点移除或不可见"); - }, - - setLeftTop(left, top) { - this.node.x = left + this.node.anchorX * this.node.width; - this.node.y = top - (1 - this.node.anchorY) * this.node.height; - }, - - -}); \ No newline at end of file diff --git a/ListViewV2Demo/assets/Script/TestListViewItem-js.js.meta b/ListViewV2Demo/assets/Script/TestListViewItem-js.js.meta deleted file mode 100644 index b1a8a4d..0000000 --- a/ListViewV2Demo/assets/Script/TestListViewItem-js.js.meta +++ /dev/null @@ -1,9 +0,0 @@ -{ - "ver": "1.0.5", - "uuid": "a1b5d86a-886c-4292-a67f-28cd57ca60ff", - "isPlugin": false, - "loadPluginInWeb": true, - "loadPluginInNative": true, - "loadPluginInEditor": false, - "subMetas": {} -} \ No newline at end of file diff --git a/ListViewV2Demo/assets/Script/TestListViewItem-ts.ts b/ListViewV2Demo/assets/Script/TestListViewItem.ts similarity index 75% rename from ListViewV2Demo/assets/Script/TestListViewItem-ts.ts rename to ListViewV2Demo/assets/Script/TestListViewItem.ts index a6c50e7..39e2922 100644 --- a/ListViewV2Demo/assets/Script/TestListViewItem-ts.ts +++ b/ListViewV2Demo/assets/Script/TestListViewItem.ts @@ -1,9 +1,9 @@ -import { ListViewItemTs } from "./Listview-ts/ListViewItemTs"; +import { ListViewItem } from "./Listview/ListViewItem"; const { ccclass, property } = cc._decorator; @ccclass -export default class TestListView extends ListViewItemTs { +export default class TestListViewItems extends ListViewItem { @property(cc.Label) label: cc.Label = null; diff --git a/ListViewV2Demo/assets/Script/TestListViewItem-ts.ts.meta b/ListViewV2Demo/assets/Script/TestListViewItem.ts.meta similarity index 100% rename from ListViewV2Demo/assets/Script/TestListViewItem-ts.ts.meta rename to ListViewV2Demo/assets/Script/TestListViewItem.ts.meta diff --git a/ListViewV2Demo/assets/Texture/HelloWorld.png.meta b/ListViewV2Demo/assets/Texture/HelloWorld.png.meta index efdbc77..9c52a59 100644 --- a/ListViewV2Demo/assets/Texture/HelloWorld.png.meta +++ b/ListViewV2Demo/assets/Texture/HelloWorld.png.meta @@ -1,10 +1,9 @@ { - "ver": "2.2.0", + "ver": "1.0.0", "uuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4", "type": "sprite", "wrapMode": "clamp", "filterMode": "bilinear", - "premultiplyAlpha": false, "subMetas": { "HelloWorld": { "ver": "1.0.3", diff --git a/ListViewV2Demo/assets/Texture/singleColor.png.meta b/ListViewV2Demo/assets/Texture/singleColor.png.meta index e3a0a2b..89cdf74 100644 --- a/ListViewV2Demo/assets/Texture/singleColor.png.meta +++ b/ListViewV2Demo/assets/Texture/singleColor.png.meta @@ -1,10 +1,9 @@ { - "ver": "2.2.0", + "ver": "1.0.0", "uuid": "a8027877-d8d6-4645-97a0-52d4a0123dba", "type": "sprite", "wrapMode": "clamp", "filterMode": "bilinear", - "premultiplyAlpha": false, "subMetas": { "singleColor": { "ver": "1.0.3", diff --git a/ListViewV2Demo/settings/project.json b/ListViewV2Demo/settings/project.json index eff1f74..ac399c6 100644 --- a/ListViewV2Demo/settings/project.json +++ b/ListViewV2Demo/settings/project.json @@ -20,15 +20,9 @@ "width": 960, "height": 640 }, - "last-module-event-record-time": 0, - "facebook": { + "cocos-analytics": { "enable": false, - "appID": "", - "live": { - "enable": false - }, - "audience": { - "enable": false - } + "appID": "13798", + "appSecret": "959b3ac0037d0f3c2fdce94f8421a9b2" } } \ No newline at end of file