List.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s,
  5. o,
  6. u,
  7. e =
  8. (this && this.__decorate) ||
  9. function(t, e, i, s) {
  10. var o,
  11. a = arguments.length,
  12. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  13. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  14. else
  15. for (var r = t.length - 1; 0 <= r; r--)
  16. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  17. return 3 < a && n && Object.defineProperty(e, i, n), n;
  18. };
  19. Object.defineProperty(i, "__esModule", { value: !0 });
  20. const { ccclass: a, property: n, disallowMultiple: r, menu: l, executionOrder: h, requireComponent: c } = cc._decorator,
  21. p = t("ListItem");
  22. ((t = s = s || {})[(t.NODE = 1)] = "NODE"),
  23. (t[(t.PREFAB = 2)] = "PREFAB"),
  24. ((t = o = o || {})[(t.NORMAL = 1)] = "NORMAL"),
  25. (t[(t.ADHERING = 2)] = "ADHERING"),
  26. (t[(t.PAGE = 3)] = "PAGE"),
  27. ((t = u = u || {})[(t.NONE = 0)] = "NONE"),
  28. (t[(t.SINGLE = 1)] = "SINGLE"),
  29. (t[(t.MULT = 2)] = "MULT");
  30. t = class extends cc.Component {
  31. constructor() {
  32. super(...arguments),
  33. (this.templateType = s.NODE),
  34. (this.tmpNode = null),
  35. (this.tmpPrefab = null),
  36. (this._slideMode = o.NORMAL),
  37. (this.pageDistance = 0.3),
  38. (this.pageChangeEvent = new cc.Component.EventHandler()),
  39. (this._virtual = !0),
  40. (this.cyclic = !1),
  41. (this.lackCenter = !1),
  42. (this.lackSlide = !1),
  43. (this._updateRate = 0),
  44. (this.frameByFrameRenderNum = 0),
  45. (this.renderEvent = new cc.Component.EventHandler()),
  46. (this.selectedMode = u.NONE),
  47. (this.repeatEventSingle = !1),
  48. (this.selectedEvent = null),
  49. (this._selectedId = -1),
  50. (this._forceUpdate = !1),
  51. (this._updateDone = !0),
  52. (this._numItems = 0),
  53. (this._inited = !1),
  54. (this._needUpdateWidget = !1),
  55. (this._aniDelRuning = !1),
  56. (this._doneAfterUpdate = !1),
  57. (this.adhering = !1),
  58. (this._adheringBarrier = !1),
  59. (this.curPageNum = 0);
  60. }
  61. set slideMode(t) {
  62. this._slideMode = t;
  63. }
  64. get slideMode() {
  65. return this._slideMode;
  66. }
  67. set virtual(t) {
  68. null != t && (this._virtual = t), 0 != this._numItems && this._onScrolling();
  69. }
  70. get virtual() {
  71. return this._virtual;
  72. }
  73. set updateRate(t) {
  74. 0 <= t && t <= 6 && (this._updateRate = t);
  75. }
  76. get updateRate() {
  77. return this._updateRate;
  78. }
  79. set selectedId(e) {
  80. let i,
  81. s = this;
  82. switch (s.selectedMode) {
  83. case u.SINGLE:
  84. {
  85. if (!s.repeatEventSingle && e == s._selectedId) return;
  86. let t;
  87. if (
  88. ((i = s.getItemByListId(e)),
  89. 0 <= s._selectedId ? (s._lastSelectedId = s._selectedId) : (s._lastSelectedId = null),
  90. (s._selectedId = e),
  91. i && ((t = i.getComponent(p.default)).selected = !0),
  92. 0 <= s._lastSelectedId && s._lastSelectedId != s._selectedId)
  93. ) {
  94. let t = s.getItemByListId(s._lastSelectedId);
  95. t && (t.getComponent(p.default).selected = !1);
  96. }
  97. s.selectedEvent &&
  98. cc.Component.EventHandler.emitEvents(
  99. [s.selectedEvent],
  100. i,
  101. e % this._actualNumItems,
  102. null == s._lastSelectedId ? null : s._lastSelectedId % this._actualNumItems
  103. );
  104. break;
  105. }
  106. case u.MULT:
  107. {
  108. if (!(i = s.getItemByListId(e))) return;
  109. let t = i.getComponent(p.default);
  110. 0 <= s._selectedId && (s._lastSelectedId = s._selectedId),
  111. (s._selectedId = e);
  112. var o = !t.selected;
  113. t.selected = o;
  114. var a = s.multSelected.indexOf(e);
  115. o && a < 0 ? s.multSelected.push(e) : !o && 0 <= a && s.multSelected.splice(a, 1),
  116. s.selectedEvent &&
  117. cc.Component.EventHandler.emitEvents(
  118. [s.selectedEvent],
  119. i,
  120. e % this._actualNumItems,
  121. null == s._lastSelectedId ? null : s._lastSelectedId % this._actualNumItems,
  122. o
  123. );
  124. break;
  125. }
  126. }
  127. }
  128. get selectedId() {
  129. return this._selectedId;
  130. }
  131. set numItems(e) {
  132. var i = this;
  133. if (i.checkInited(!1))
  134. if (null == e || e < 0) cc.error("numItems set the wrong::", e);
  135. else if (((i._actualNumItems = i._numItems = e), (i._forceUpdate = !0), i._virtual))
  136. i._resizeContent(),
  137. i.cyclic && (i._numItems = i._cyclicNum * i._numItems),
  138. i._onScrolling(),
  139. i.frameByFrameRenderNum || i.slideMode != o.PAGE || (i.curPageNum = i.nearestListId);
  140. else {
  141. let t = i.content.getComponent(cc.Layout);
  142. if ((t && (t.enabled = !0), i._delRedundantItem(), (i.firstListId = 0) < i.frameByFrameRenderNum)) {
  143. var s = i.frameByFrameRenderNum > i._numItems ? i._numItems : i.frameByFrameRenderNum;
  144. for (let t = 0; t < s; t++) i._createOrUpdateItem2(t);
  145. i.frameByFrameRenderNum < i._numItems &&
  146. ((i._updateCounter = i.frameByFrameRenderNum), (i._updateDone = !1));
  147. } else {
  148. for (let t = 0; t < e; t++) i._createOrUpdateItem2(t);
  149. i.displayItemNum = e;
  150. }
  151. }
  152. }
  153. get numItems() {
  154. return this._actualNumItems;
  155. }
  156. get scrollView() {
  157. return this._scrollView;
  158. }
  159. onLoad() {
  160. this._init();
  161. }
  162. onDestroy() {
  163. for (
  164. this._itemTmp && this._itemTmp.isValid && this._itemTmp.destroy(),
  165. this.tmpNode && this.tmpNode.isValid && this.tmpNode.destroy(); this._pool.size();
  166. )
  167. this._pool.get().destroy();
  168. }
  169. onEnable() {
  170. this._registerEvent(), this._init();
  171. }
  172. onDisable() {
  173. this._unregisterEvent();
  174. }
  175. _registerEvent() {
  176. var t = this;
  177. t.node.on(cc.Node.EventType.TOUCH_START, t._onTouchStart, t, !0),
  178. t.node.on("touch-up", t._onTouchUp, t),
  179. t.node.on(cc.Node.EventType.TOUCH_CANCEL, t._onTouchCancelled, t, !0),
  180. t.node.on("scroll-began", t._onScrollBegan, t, !0),
  181. t.node.on("scroll-ended", t._onScrollEnded, t, !0),
  182. t.node.on("scrolling", t._onScrolling, t, !0),
  183. t.node.on(cc.Node.EventType.SIZE_CHANGED, t._onSizeChanged, t);
  184. }
  185. _unregisterEvent() {
  186. var t = this;
  187. t.node.off(cc.Node.EventType.TOUCH_START, t._onTouchStart, t, !0),
  188. t.node.off("touch-up", t._onTouchUp, t),
  189. t.node.off(cc.Node.EventType.TOUCH_CANCEL, t._onTouchCancelled, t, !0),
  190. t.node.off("scroll-began", t._onScrollBegan, t, !0),
  191. t.node.off("scroll-ended", t._onScrollEnded, t, !0),
  192. t.node.off("scrolling", t._onScrolling, t, !0),
  193. t.node.off(cc.Node.EventType.SIZE_CHANGED, t._onSizeChanged, t);
  194. }
  195. _init() {
  196. var t = this;
  197. if (!t._inited)
  198. if (
  199. ((t._scrollView = t.node.getComponent(cc.ScrollView)), (t.content = t._scrollView.content), t.content)
  200. ) {
  201. switch (
  202. ((t._layout = t.content.getComponent(cc.Layout)),
  203. (t._align = t._layout.type),
  204. (t._resizeMode = t._layout.resizeMode),
  205. (t._startAxis = t._layout.startAxis),
  206. (t._topGap = t._layout.paddingTop),
  207. (t._rightGap = t._layout.paddingRight),
  208. (t._bottomGap = t._layout.paddingBottom),
  209. (t._leftGap = t._layout.paddingLeft),
  210. (t._columnGap = t._layout.spacingX),
  211. (t._lineGap = t._layout.spacingY),
  212. t._colLineNum,
  213. (t._verticalDir = t._layout.verticalDirection),
  214. (t._horizontalDir = t._layout.horizontalDirection),
  215. t.setTemplateItem(cc.instantiate(t.templateType == s.PREFAB ? t.tmpPrefab : t.tmpNode)),
  216. (t._slideMode != o.ADHERING && t._slideMode != o.PAGE) ||
  217. ((t._scrollView.inertia = !1), (t._scrollView._onMouseWheel = function() {})),
  218. t.virtual || (t.lackCenter = !1),
  219. (t._lastDisplayData = []),
  220. (t.displayData = []),
  221. (t._pool = new cc.NodePool()),
  222. (t._forceUpdate = !1),
  223. (t._updateCounter = 0),
  224. (t._updateDone = !0),
  225. (t.curPageNum = 0),
  226. t.cyclic &&
  227. ((t._scrollView._processAutoScrolling = this._processAutoScrolling.bind(t)),
  228. (t._scrollView._startBounceBackIfNeeded = function() {
  229. return !1;
  230. })),
  231. t._align)
  232. ) {
  233. case cc.Layout.Type.HORIZONTAL:
  234. switch (t._horizontalDir) {
  235. case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
  236. t._alignCalcType = 1;
  237. break;
  238. case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
  239. t._alignCalcType = 2;
  240. }
  241. break;
  242. case cc.Layout.Type.VERTICAL:
  243. switch (t._verticalDir) {
  244. case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
  245. t._alignCalcType = 3;
  246. break;
  247. case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
  248. t._alignCalcType = 4;
  249. }
  250. break;
  251. case cc.Layout.Type.GRID:
  252. switch (t._startAxis) {
  253. case cc.Layout.AxisDirection.HORIZONTAL:
  254. switch (t._verticalDir) {
  255. case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
  256. t._alignCalcType = 3;
  257. break;
  258. case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
  259. t._alignCalcType = 4;
  260. }
  261. break;
  262. case cc.Layout.AxisDirection.VERTICAL:
  263. switch (t._horizontalDir) {
  264. case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
  265. t._alignCalcType = 1;
  266. break;
  267. case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
  268. t._alignCalcType = 2;
  269. }
  270. }
  271. }
  272. t.content.removeAllChildren(), (t._inited = !0);
  273. } else cc.error(t.node.name + "'s cc_ScrollView unset content!");
  274. }
  275. _processAutoScrolling(t) {
  276. this._scrollView._autoScrollAccumulatedTime += +t;
  277. let e = Math.min(1, this._scrollView._autoScrollAccumulatedTime / this._scrollView._autoScrollTotalTime);
  278. this._scrollView._autoScrollAttenuate && ((a = e - 1), (e = a * a * a * a * a + 1));
  279. let i = this._scrollView._autoScrollStartPosition.add(this._scrollView._autoScrollTargetDelta.mul(e)),
  280. s = this._scrollView.getScrollEndedEventTiming(),
  281. o = Math.abs(e - 1) <= s;
  282. Math.abs(e - 1) <= this._scrollView.getScrollEndedEventTiming() &&
  283. !this._scrollView._isScrollEndedWithThresholdEventFired &&
  284. (this._scrollView._dispatchEvent("scroll-ended-with-threshold"),
  285. (this._scrollView._isScrollEndedWithThresholdEventFired = !0)),
  286. o && (this._scrollView._autoScrolling = !1);
  287. var a = i.sub(this._scrollView.getContentPosition());
  288. this._scrollView._moveContent(this._scrollView._clampDelta(a), o),
  289. this._scrollView._dispatchEvent("scrolling"),
  290. this._scrollView._autoScrolling ||
  291. ((this._scrollView._isBouncing = !1),
  292. (this._scrollView._scrolling = !1),
  293. this._scrollView._dispatchEvent("scroll-ended"));
  294. }
  295. setTemplateItem(i) {
  296. if (i) {
  297. var s = this;
  298. (s._itemTmp = i),
  299. s._resizeMode == cc.Layout.ResizeMode.CHILDREN ?
  300. (s._itemSize = s._layout.cellSize) :
  301. (s._itemSize = cc.size(i.width, i.height));
  302. let t = i.getComponent(p.default),
  303. e = t ? !1 : !0;
  304. switch (
  305. (e && (s.selectedMode = u.NONE),
  306. (t = i.getComponent(cc.Widget)) && t.enabled && (s._needUpdateWidget = !0),
  307. s.selectedMode == u.MULT && (s.multSelected = []),
  308. s._align)
  309. ) {
  310. case cc.Layout.Type.HORIZONTAL:
  311. (s._colLineNum = 1), (s._sizeType = !1);
  312. break;
  313. case cc.Layout.Type.VERTICAL:
  314. (s._colLineNum = 1), (s._sizeType = !0);
  315. break;
  316. case cc.Layout.Type.GRID:
  317. switch (s._startAxis) {
  318. case cc.Layout.AxisDirection.HORIZONTAL:
  319. var o = s.content.width - s._leftGap - s._rightGap;
  320. (s._colLineNum = Math.floor((o + s._columnGap) / (s._itemSize.width + s._columnGap))),
  321. (s._sizeType = !0);
  322. break;
  323. case cc.Layout.AxisDirection.VERTICAL:
  324. o = s.content.height - s._topGap - s._bottomGap;
  325. (s._colLineNum = Math.floor((o + s._lineGap) / (s._itemSize.height + s._lineGap))),
  326. (s._sizeType = !1);
  327. }
  328. }
  329. }
  330. }
  331. checkInited(t = !0) {
  332. return !!this._inited || (t && cc.error("List initialization not completed!"), !1);
  333. }
  334. _resizeContent() {
  335. let t,
  336. e = this;
  337. switch (e._align) {
  338. case cc.Layout.Type.HORIZONTAL:
  339. t = e._customSize ?
  340. ((i = e._getFixedSize(null)),
  341. e._leftGap +
  342. i.val +
  343. e._itemSize.width * (e._numItems - i.count) +
  344. e._columnGap * (e._numItems - 1) +
  345. e._rightGap) :
  346. e._leftGap + e._itemSize.width * e._numItems + e._columnGap * (e._numItems - 1) + e._rightGap;
  347. break;
  348. case cc.Layout.Type.VERTICAL:
  349. var i;
  350. t = e._customSize ?
  351. ((i = e._getFixedSize(null)),
  352. e._topGap +
  353. i.val +
  354. e._itemSize.height * (e._numItems - i.count) +
  355. e._lineGap * (e._numItems - 1) +
  356. e._bottomGap) :
  357. e._topGap + e._itemSize.height * e._numItems + e._lineGap * (e._numItems - 1) + e._bottomGap;
  358. break;
  359. case cc.Layout.Type.GRID:
  360. switch ((e.lackCenter && (e.lackCenter = !1), e._startAxis)) {
  361. case cc.Layout.AxisDirection.HORIZONTAL:
  362. var s = Math.ceil(e._numItems / e._colLineNum);
  363. t = e._topGap + e._itemSize.height * s + e._lineGap * (s - 1) + e._bottomGap;
  364. break;
  365. case cc.Layout.AxisDirection.VERTICAL:
  366. s = Math.ceil(e._numItems / e._colLineNum);
  367. t = e._leftGap + e._itemSize.width * s + e._columnGap * (s - 1) + e._rightGap;
  368. }
  369. }
  370. let o = e.content.getComponent(cc.Layout);
  371. var a;
  372. o && (o.enabled = !1),
  373. (e._allItemSize = t),
  374. (e._allItemSizeNoEdge =
  375. e._allItemSize - (e._sizeType ? e._topGap + e._bottomGap : e._leftGap + e._rightGap)),
  376. e.cyclic &&
  377. ((a = e._sizeType ? e.node.height : e.node.width),
  378. (e._cyclicPos1 = 0),
  379. (a -= e._cyclicPos1),
  380. (e._cyclicNum = Math.ceil(a / e._allItemSizeNoEdge) + 1),
  381. (a = e._sizeType ? e._lineGap : e._columnGap),
  382. (e._cyclicPos2 = e._cyclicPos1 + e._allItemSizeNoEdge + a),
  383. (e._cyclicAllItemSize =
  384. e._allItemSize + e._allItemSizeNoEdge * (e._cyclicNum - 1) + a * (e._cyclicNum - 1)),
  385. (e._cycilcAllItemSizeNoEdge = e._allItemSizeNoEdge * e._cyclicNum),
  386. (e._cycilcAllItemSizeNoEdge += a * (e._cyclicNum - 1))),
  387. (e._lack = !e.cyclic && e._allItemSize < (e._sizeType ? e.node.height : e.node.width));
  388. let n = (e._lack && e.lackCenter) || !e.lackSlide ? 0.1 : 0,
  389. r = e._lack ?
  390. (e._sizeType ? e.node.height : e.node.width) - n :
  391. e.cyclic ?
  392. e._cyclicAllItemSize :
  393. e._allItemSize;
  394. r < 0 && (r = 0), e._sizeType ? (e.content.height = r) : (e.content.width = r);
  395. }
  396. _onScrolling(e = null) {
  397. if (
  398. (null == this.frameCount && (this.frameCount = this._updateRate), !this._forceUpdate && e && "scroll-ended" != e.type && 0 < this.frameCount)
  399. )
  400. this.frameCount--;
  401. else if (((this.frameCount = this._updateRate), !this._aniDelRuning)) {
  402. if (this.cyclic) {
  403. let t = this.content.getPosition();
  404. t = this._sizeType ? t.y : t.x;
  405. var e = this._allItemSizeNoEdge + (this._sizeType ? this._lineGap : this._columnGap),
  406. i = this._sizeType ? cc.v2(0, e) : cc.v2(e, 0);
  407. switch (this._alignCalcType) {
  408. case 1:
  409. t > -this._cyclicPos1 ?
  410. ((this.content.x = -this._cyclicPos2),
  411. this._scrollView.isAutoScrolling() &&
  412. (this._scrollView._autoScrollStartPosition =
  413. this._scrollView._autoScrollStartPosition.sub(i))) :
  414. t < -this._cyclicPos2 &&
  415. ((this.content.x = -this._cyclicPos1),
  416. this._scrollView.isAutoScrolling() &&
  417. (this._scrollView._autoScrollStartPosition =
  418. this._scrollView._autoScrollStartPosition.add(i)));
  419. break;
  420. case 2:
  421. t < this._cyclicPos1 ?
  422. ((this.content.x = this._cyclicPos2),
  423. this._scrollView.isAutoScrolling() &&
  424. (this._scrollView._autoScrollStartPosition =
  425. this._scrollView._autoScrollStartPosition.add(i))) :
  426. t > this._cyclicPos2 &&
  427. ((this.content.x = this._cyclicPos1),
  428. this._scrollView.isAutoScrolling() &&
  429. (this._scrollView._autoScrollStartPosition =
  430. this._scrollView._autoScrollStartPosition.sub(i)));
  431. break;
  432. case 3:
  433. t < this._cyclicPos1 ?
  434. ((this.content.y = this._cyclicPos2),
  435. this._scrollView.isAutoScrolling() &&
  436. (this._scrollView._autoScrollStartPosition =
  437. this._scrollView._autoScrollStartPosition.add(i))) :
  438. t > this._cyclicPos2 &&
  439. ((this.content.y = this._cyclicPos1),
  440. this._scrollView.isAutoScrolling() &&
  441. (this._scrollView._autoScrollStartPosition =
  442. this._scrollView._autoScrollStartPosition.sub(i)));
  443. break;
  444. case 4:
  445. t > -this._cyclicPos1 ?
  446. ((this.content.y = -this._cyclicPos2),
  447. this._scrollView.isAutoScrolling() &&
  448. (this._scrollView._autoScrollStartPosition =
  449. this._scrollView._autoScrollStartPosition.sub(i))) :
  450. t < -this._cyclicPos2 &&
  451. ((this.content.y = -this._cyclicPos1),
  452. this._scrollView.isAutoScrolling() &&
  453. (this._scrollView._autoScrollStartPosition =
  454. this._scrollView._autoScrollStartPosition.add(i)));
  455. }
  456. }
  457. let s, o, a, n;
  458. if (
  459. (this._calcViewPos(),
  460. this._sizeType ?
  461. ((s = this.viewTop), (a = this.viewBottom)) :
  462. ((o = this.viewRight), (n = this.viewLeft)),
  463. this._virtual)
  464. ) {
  465. var r;
  466. this.displayData = [];
  467. let e = 0,
  468. i = this._numItems - 1;
  469. if (this._customSize) {
  470. let t = !1;
  471. for (; e <= i && !t; e++)
  472. switch (((r = this._calcItemPos(e)), this._align)) {
  473. case cc.Layout.Type.HORIZONTAL:
  474. r.right >= n && r.left <= o ?
  475. this.displayData.push(r) :
  476. 0 != e && 0 < this.displayData.length && (t = !0);
  477. break;
  478. case cc.Layout.Type.VERTICAL:
  479. r.bottom <= s && r.top >= a ?
  480. this.displayData.push(r) :
  481. 0 != e && 0 < this.displayData.length && (t = !0);
  482. break;
  483. case cc.Layout.Type.GRID:
  484. switch (this._startAxis) {
  485. case cc.Layout.AxisDirection.HORIZONTAL:
  486. r.bottom <= s && r.top >= a ?
  487. this.displayData.push(r) :
  488. 0 != e && 0 < this.displayData.length && (t = !0);
  489. break;
  490. case cc.Layout.AxisDirection.VERTICAL:
  491. r.right >= n && r.left <= o ?
  492. this.displayData.push(r) :
  493. 0 != e && 0 < this.displayData.length && (t = !0);
  494. }
  495. }
  496. } else {
  497. var t = this._itemSize.width + this._columnGap,
  498. l = this._itemSize.height + this._lineGap;
  499. switch (this._alignCalcType) {
  500. case 1:
  501. (e = (n + this._leftGap) / t), (i = (o + this._rightGap) / t);
  502. break;
  503. case 2:
  504. (e = (-o - this._rightGap) / t), (i = (-n - this._leftGap) / t);
  505. break;
  506. case 3:
  507. (e = (-s - this._topGap) / l), (i = (-a - this._bottomGap) / l);
  508. break;
  509. case 4:
  510. (e = (a + this._bottomGap) / l), (i = (s + this._topGap) / l);
  511. }
  512. for (
  513. e = Math.floor(e) * this._colLineNum,
  514. i = Math.ceil(i) * this._colLineNum,
  515. e < 0 && (e = 0),
  516. --i >= this._numItems && (i = this._numItems - 1); e <= i; e++
  517. )
  518. this.displayData.push(this._calcItemPos(e));
  519. }
  520. if ((this._delRedundantItem(), this.displayData.length <= 0 || !this._numItems))
  521. this._lastDisplayData = [];
  522. else {
  523. (this.firstListId = this.displayData[0].id), (this.displayItemNum = this.displayData.length);
  524. let t = this._lastDisplayData.length,
  525. e = this.displayItemNum != t;
  526. if (
  527. (e &&
  528. (0 < this.frameByFrameRenderNum && this._lastDisplayData.sort((t, e) => t - e),
  529. (e =
  530. this.firstListId != this._lastDisplayData[0] ||
  531. this.displayData[this.displayItemNum - 1].id != this._lastDisplayData[t - 1])),
  532. this._forceUpdate || e)
  533. )
  534. if (0 < this.frameByFrameRenderNum)
  535. 0 < this._numItems ?
  536. (this._updateDone ? (this._updateCounter = 0) : (this._doneAfterUpdate = !0),
  537. (this._updateDone = !1)) :
  538. ((this._updateCounter = 0), (this._updateDone = !0));
  539. else {
  540. this._lastDisplayData = [];
  541. for (let t = 0; t < this.displayItemNum; t++) this._createOrUpdateItem(this.displayData[t]);
  542. this._forceUpdate = !1;
  543. }
  544. this._calcNearestItem();
  545. }
  546. }
  547. }
  548. }
  549. _calcViewPos() {
  550. var t = this.content.getPosition();
  551. switch (this._alignCalcType) {
  552. case 1:
  553. (this.elasticLeft = 0 < t.x ? t.x : 0),
  554. (this.viewLeft = (t.x < 0 ? -t.x : 0) - this.elasticLeft),
  555. (this.viewRight = this.viewLeft + this.node.width),
  556. (this.elasticRight =
  557. this.viewRight > this.content.width ? Math.abs(this.viewRight - this.content.width) : 0),
  558. (this.viewRight += this.elasticRight);
  559. break;
  560. case 2:
  561. (this.elasticRight = t.x < 0 ? -t.x : 0),
  562. (this.viewRight = (0 < t.x ? -t.x : 0) + this.elasticRight),
  563. (this.viewLeft = this.viewRight - this.node.width),
  564. (this.elasticLeft =
  565. this.viewLeft < -this.content.width ? Math.abs(this.viewLeft + this.content.width) : 0),
  566. (this.viewLeft -= this.elasticLeft);
  567. break;
  568. case 3:
  569. (this.elasticTop = t.y < 0 ? Math.abs(t.y) : 0),
  570. (this.viewTop = (0 < t.y ? -t.y : 0) + this.elasticTop),
  571. (this.viewBottom = this.viewTop - this.node.height),
  572. (this.elasticBottom =
  573. this.viewBottom < -this.content.height ? Math.abs(this.viewBottom + this.content.height) : 0),
  574. (this.viewBottom += this.elasticBottom);
  575. break;
  576. case 4:
  577. (this.elasticBottom = 0 < t.y ? Math.abs(t.y) : 0),
  578. (this.viewBottom = (t.y < 0 ? -t.y : 0) - this.elasticBottom),
  579. (this.viewTop = this.viewBottom + this.node.height),
  580. (this.elasticTop =
  581. this.viewTop > this.content.height ? Math.abs(this.viewTop - this.content.height) : 0),
  582. (this.viewTop -= this.elasticTop);
  583. }
  584. }
  585. _calcItemPos(t) {
  586. let e, i, s, o, a, n, r, l;
  587. switch (this._align) {
  588. case cc.Layout.Type.HORIZONTAL:
  589. switch (this._horizontalDir) {
  590. case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
  591. var h;
  592. return (
  593. (e = this._customSize ?
  594. ((h = this._getFixedSize(t)),
  595. (a =
  596. this._leftGap +
  597. (this._itemSize.width + this._columnGap) * (t - h.count) +
  598. (h.val + this._columnGap * h.count)),
  599. 0 < (h = this._customSize[t]) ? h : this._itemSize.width) :
  600. ((a = this._leftGap + (this._itemSize.width + this._columnGap) * t),
  601. this._itemSize.width)),
  602. (n = a + e),
  603. this.lackCenter &&
  604. ((h = this.content.width / 2 - this._allItemSizeNoEdge / 2), (a += h), (n += h)), { id: t, left: a, right: n, x: a + this._itemTmp.anchorX * e, y: this._itemTmp.y }
  605. );
  606. case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
  607. var c;
  608. return (
  609. (e = this._customSize ?
  610. ((c = this._getFixedSize(t)),
  611. (n = -this._rightGap -
  612. (this._itemSize.width + this._columnGap) * (t - c.count) -
  613. (c.val + this._columnGap * c.count)),
  614. 0 < (c = this._customSize[t]) ? c : this._itemSize.width) :
  615. ((n = -this._rightGap - (this._itemSize.width + this._columnGap) * t),
  616. this._itemSize.width)),
  617. (a = n - e),
  618. this.lackCenter &&
  619. ((c = this.content.width / 2 - this._allItemSizeNoEdge / 2), (a -= c), (n -= c)), { id: t, right: n, left: a, x: a + this._itemTmp.anchorX * e, y: this._itemTmp.y }
  620. );
  621. }
  622. break;
  623. case cc.Layout.Type.VERTICAL:
  624. switch (this._verticalDir) {
  625. case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
  626. var d;
  627. return (
  628. (i = this._customSize ?
  629. ((d = this._getFixedSize(t)),
  630. (s = -this._topGap -
  631. (this._itemSize.height + this._lineGap) * (t - d.count) -
  632. (d.val + this._lineGap * d.count)),
  633. 0 < (d = this._customSize[t]) ? d : this._itemSize.height) :
  634. ((s = -this._topGap - (this._itemSize.height + this._lineGap) * t),
  635. this._itemSize.height)),
  636. (o = s - i),
  637. this.lackCenter &&
  638. ((d = this.content.height / 2 - this._allItemSizeNoEdge / 2), (s -= d), (o -= d)), { id: t, top: s, bottom: o, x: this._itemTmp.x, y: o + this._itemTmp.anchorY * i }
  639. );
  640. case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
  641. var u;
  642. return (
  643. (i = this._customSize ?
  644. ((u = this._getFixedSize(t)),
  645. (o =
  646. this._bottomGap +
  647. (this._itemSize.height + this._lineGap) * (t - u.count) +
  648. (u.val + this._lineGap * u.count)),
  649. 0 < (u = this._customSize[t]) ? u : this._itemSize.height) :
  650. ((o = this._bottomGap + (this._itemSize.height + this._lineGap) * t),
  651. this._itemSize.height)),
  652. (s = o + i),
  653. this.lackCenter &&
  654. ((u = this.content.height / 2 - this._allItemSizeNoEdge / 2), (s += u), (o += u)), { id: t, top: s, bottom: o, x: this._itemTmp.x, y: o + this._itemTmp.anchorY * i }
  655. );
  656. }
  657. case cc.Layout.Type.GRID:
  658. var p = Math.floor(t / this._colLineNum);
  659. switch (this._startAxis) {
  660. case cc.Layout.AxisDirection.HORIZONTAL:
  661. switch (this._verticalDir) {
  662. case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
  663. l =
  664. (o =
  665. (s = -this._topGap - (this._itemSize.height + this._lineGap) * p) -
  666. this._itemSize.height) +
  667. this._itemTmp.anchorY * this._itemSize.height;
  668. break;
  669. case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
  670. (s =
  671. (o = this._bottomGap + (this._itemSize.height + this._lineGap) * p) +
  672. this._itemSize.height),
  673. (l = o + this._itemTmp.anchorY * this._itemSize.height);
  674. }
  675. switch (
  676. ((r = this._leftGap + (t % this._colLineNum) * (this._itemSize.width + this._columnGap)),
  677. this._horizontalDir)
  678. ) {
  679. case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
  680. (r += this._itemTmp.anchorX * this._itemSize.width),
  681. (r -= this.content.anchorX * this.content.width);
  682. break;
  683. case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
  684. (r += (1 - this._itemTmp.anchorX) * this._itemSize.width),
  685. (r -= (1 - this.content.anchorX) * this.content.width),
  686. (r *= -1);
  687. }
  688. return { id: t, top: s, bottom: o, x: r, y: l };
  689. case cc.Layout.AxisDirection.VERTICAL:
  690. switch (this._horizontalDir) {
  691. case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
  692. (n =
  693. (a = this._leftGap + (this._itemSize.width + this._columnGap) * p) +
  694. this._itemSize.width),
  695. (r = a + this._itemTmp.anchorX * this._itemSize.width),
  696. (r -= this.content.anchorX * this.content.width);
  697. break;
  698. case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
  699. (r =
  700. (a =
  701. (n = -this._rightGap - (this._itemSize.width + this._columnGap) * p) -
  702. this._itemSize.width) +
  703. this._itemTmp.anchorX * this._itemSize.width),
  704. (r += (1 - this.content.anchorX) * this.content.width);
  705. }
  706. switch (
  707. ((l = -this._topGap - (t % this._colLineNum) * (this._itemSize.height + this._lineGap)),
  708. this._verticalDir)
  709. ) {
  710. case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
  711. (l -= (1 - this._itemTmp.anchorY) * this._itemSize.height),
  712. (l += (1 - this.content.anchorY) * this.content.height);
  713. break;
  714. case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
  715. (l -= this._itemTmp.anchorY * this._itemSize.height),
  716. (l += this.content.anchorY * this.content.height),
  717. (l *= -1);
  718. }
  719. return { id: t, left: a, right: n, x: r, y: l };
  720. }
  721. }
  722. }
  723. _calcExistItemPos(t) {
  724. var e = this.getItemByListId(t);
  725. if (!e) return null;
  726. let i = { id: t, x: e.x, y: e.y };
  727. return (
  728. this._sizeType ?
  729. ((i.top = e.y + e.height * (1 - e.anchorY)), (i.bottom = e.y - e.height * e.anchorY)) :
  730. ((i.left = e.x - e.width * e.anchorX), (i.right = e.x + e.width * (1 - e.anchorX))),
  731. i
  732. );
  733. }
  734. getItemPos(t) {
  735. return this._virtual || this.frameByFrameRenderNum ? this._calcItemPos(t) : this._calcExistItemPos(t);
  736. }
  737. _getFixedSize(t) {
  738. if (!this._customSize) return null;
  739. null == t && (t = this._numItems);
  740. let e = 0,
  741. i = 0;
  742. for (var s in this._customSize) parseInt(s) < t && ((e += this._customSize[s]), i++);
  743. return { val: e, count: i };
  744. }
  745. _onScrollBegan() {
  746. this._beganPos = this._sizeType ? this.viewTop : this.viewLeft;
  747. }
  748. _onScrollEnded() {
  749. var e = this;
  750. if (null != e.scrollToListId) {
  751. let t = e.getItemByListId(e.scrollToListId);
  752. (e.scrollToListId = null), t && t.runAction(cc.sequence(cc.scaleTo(0.1, 1.06), cc.scaleTo(0.1, 1)));
  753. }
  754. e._onScrolling(),
  755. e._slideMode != o.ADHERING || e.adhering ?
  756. e._slideMode == o.PAGE && (null != e._beganPos ? this._pageAdhere() : e.adhere()) :
  757. e.adhere();
  758. }
  759. _onTouchStart(e, t) {
  760. if (!this._scrollView.hasNestedViewGroup(e, t) &&
  761. (e.eventPhase !== cc.Event.AT_TARGET || e.target !== this.node)
  762. ) {
  763. let t = e.target;
  764. for (; null == t._listId && t.parent;) t = t.parent;
  765. this._scrollItem = null != t._listId ? t : e.target;
  766. }
  767. }
  768. _onTouchUp() {
  769. (this._scrollPos = null),
  770. this._slideMode == o.ADHERING ?
  771. (this.adhering && (this._adheringBarrier = !0), this.adhere()) :
  772. this._slideMode == o.PAGE && (null != this._beganPos ? this._pageAdhere() : this.adhere()),
  773. (this._scrollItem = null);
  774. }
  775. _onTouchCancelled(t, e) {
  776. var i = this;
  777. i._scrollView.hasNestedViewGroup(t, e) ||
  778. t.simulate ||
  779. ((i._scrollPos = null),
  780. i._slideMode == o.ADHERING ?
  781. (i.adhering && (i._adheringBarrier = !0), i.adhere()) :
  782. i._slideMode == o.PAGE && (null != i._beganPos ? i._pageAdhere() : i.adhere()),
  783. (this._scrollItem = null));
  784. }
  785. _onSizeChanged() {
  786. this.checkInited(!1) && this._onScrolling();
  787. }
  788. _onItemAdaptive(t) {
  789. var e;
  790. ((!this._sizeType && t.width != this._itemSize.width) ||
  791. (this._sizeType && t.height != this._itemSize.height)) &&
  792. (this._customSize || (this._customSize = {}),
  793. (e = this._sizeType ? t.height : t.width),
  794. this._customSize[t._listId] != e &&
  795. ((this._customSize[t._listId] = e),
  796. this._resizeContent(),
  797. this.updateAll(),
  798. null != this._scrollToListId &&
  799. ((this._scrollPos = null),
  800. this.unschedule(this._scrollToSo),
  801. this.scrollTo(
  802. this._scrollToListId,
  803. Math.max(0, this._scrollToEndTime - new Date().getTime() / 1e3)
  804. ))));
  805. }
  806. _pageAdhere() {
  807. var t = this;
  808. if (t.cyclic || !(0 < t.elasticTop || 0 < t.elasticRight || 0 < t.elasticBottom || 0 < t.elasticLeft)) {
  809. var e = t._sizeType ? t.viewTop : t.viewLeft,
  810. i = (t._sizeType ? t.node.height : t.node.width) * t.pageDistance;
  811. if (Math.abs(t._beganPos - e) > i)
  812. switch (t._alignCalcType) {
  813. case 1:
  814. case 4:
  815. t._beganPos > e ? t.prePage(0.5) : t.nextPage(0.5);
  816. break;
  817. case 2:
  818. case 3:
  819. t._beganPos < e ? t.prePage(0.5) : t.nextPage(0.5);
  820. }
  821. else t.elasticTop <= 0 && t.elasticRight <= 0 && t.elasticBottom <= 0 && t.elasticLeft <= 0 && t.adhere();
  822. t._beganPos = null;
  823. }
  824. }
  825. adhere() {
  826. var t,
  827. e = this;
  828. e.checkInited() &&
  829. (0 < e.elasticTop ||
  830. 0 < e.elasticRight ||
  831. 0 < e.elasticBottom ||
  832. 0 < e.elasticLeft ||
  833. ((e.adhering = !0),
  834. e._calcNearestItem(),
  835. (t = (e._sizeType ? e._topGap : e._leftGap) / (e._sizeType ? e.node.height : e.node.width)),
  836. e.scrollTo(e.nearestListId, 0.7, t)));
  837. }
  838. update() {
  839. if (!(this.frameByFrameRenderNum <= 0 || this._updateDone))
  840. if (this._virtual) {
  841. var e =
  842. this._updateCounter + this.frameByFrameRenderNum > this.displayItemNum ?
  843. this.displayItemNum :
  844. this._updateCounter + this.frameByFrameRenderNum;
  845. for (let t = this._updateCounter; t < e; t++) {
  846. var i = this.displayData[t];
  847. i && this._createOrUpdateItem(i);
  848. }
  849. this._updateCounter >= this.displayItemNum - 1 ?
  850. this._doneAfterUpdate ?
  851. ((this._updateCounter = 0), (this._updateDone = !1), (this._doneAfterUpdate = !1)) :
  852. ((this._updateDone = !0),
  853. this._delRedundantItem(),
  854. (this._forceUpdate = !1),
  855. this._calcNearestItem(),
  856. this.slideMode == o.PAGE && (this.curPageNum = this.nearestListId)) :
  857. (this._updateCounter += this.frameByFrameRenderNum);
  858. } else if (this._updateCounter < this._numItems) {
  859. var s =
  860. this._updateCounter + this.frameByFrameRenderNum > this._numItems ?
  861. this._numItems :
  862. this._updateCounter + this.frameByFrameRenderNum;
  863. for (let t = this._updateCounter; t < s; t++) this._createOrUpdateItem2(t);
  864. this._updateCounter += this.frameByFrameRenderNum;
  865. } else
  866. (this._updateDone = !0),
  867. this._calcNearestItem(),
  868. this.slideMode == o.PAGE && (this.curPageNum = this.nearestListId);
  869. }
  870. _createOrUpdateItem(e) {
  871. let i = this.getItemByListId(e.id);
  872. if (i)
  873. this._forceUpdate &&
  874. this.renderEvent &&
  875. (i.setPosition(cc.v2(e.x, e.y)),
  876. this._resetItemSize(i),
  877. this.renderEvent &&
  878. cc.Component.EventHandler.emitEvents([this.renderEvent], i, e.id % this._actualNumItems));
  879. else {
  880. var s = 0 < this._pool.size();
  881. if (
  882. ((i = s ? this._pool.get() : cc.instantiate(this._itemTmp))._listId != e.id &&
  883. ((i._listId = e.id), i.setContentSize(this._itemSize)),
  884. i.setPosition(cc.v2(e.x, e.y)),
  885. this._resetItemSize(i),
  886. this.content.addChild(i),
  887. s && this._needUpdateWidget)
  888. ) {
  889. let t = i.getComponent(cc.Widget);
  890. t && t.updateAlignment();
  891. }
  892. i.setSiblingIndex(this.content.childrenCount - 1);
  893. let t = i.getComponent(p.default);
  894. (i.listItem = t),
  895. t && ((t.listId = e.id), (t.list = this), t._registerEvent()),
  896. this.renderEvent &&
  897. cc.Component.EventHandler.emitEvents([this.renderEvent], i, e.id % this._actualNumItems);
  898. }
  899. this._resetItemSize(i),
  900. this._updateListItem(i.listItem),
  901. this._lastDisplayData.indexOf(e.id) < 0 && this._lastDisplayData.push(e.id);
  902. }
  903. _createOrUpdateItem2(t) {
  904. let e,
  905. i = this.content.children[t];
  906. i
  907. ?
  908. this._forceUpdate &&
  909. this.renderEvent &&
  910. ((i._listId = t),
  911. e && (e.listId = t),
  912. this.renderEvent && cc.Component.EventHandler.emitEvents([this.renderEvent], i, t)) :
  913. (((i = cc.instantiate(this._itemTmp))._listId = t),
  914. this.content.addChild(i),
  915. (e = i.getComponent(p.default)),
  916. (i.listItem = e),
  917. e && ((e.listId = t), (e.list = this), e._registerEvent()),
  918. this.renderEvent && cc.Component.EventHandler.emitEvents([this.renderEvent], i, t)),
  919. this._updateListItem(e),
  920. this._lastDisplayData.indexOf(t) < 0 && this._lastDisplayData.push(t);
  921. }
  922. _updateListItem(t) {
  923. if (t && this.selectedMode > u.NONE) {
  924. var e = t.node;
  925. switch (this.selectedMode) {
  926. case u.SINGLE:
  927. t.selected = this.selectedId == e._listId;
  928. break;
  929. case u.MULT:
  930. t.selected = 0 <= this.multSelected.indexOf(e._listId);
  931. }
  932. }
  933. }
  934. _resetItemSize(t) {}
  935. _updateItemPos(t) {
  936. let e = isNaN(t) ? t : this.getItemByListId(t),
  937. i = this.getItemPos(e._listId);
  938. e.setPosition(i.x, i.y);
  939. }
  940. setMultSelected(s, t) {
  941. if (this.checkInited()) {
  942. if ((Array.isArray(s) || (s = [s]), null == t)) this.multSelected = s;
  943. else {
  944. let e, i;
  945. if (t)
  946. for (let t = s.length - 1; 0 <= t; t--)
  947. (e = s[t]), (i = this.multSelected.indexOf(e)) < 0 && this.multSelected.push(e);
  948. else
  949. for (let t = s.length - 1; 0 <= t; t--)
  950. (e = s[t]), 0 <= (i = this.multSelected.indexOf(e)) && this.multSelected.splice(i, 1);
  951. }
  952. (this._forceUpdate = !0), this._onScrolling();
  953. }
  954. }
  955. updateItem(i) {
  956. if (this.checkInited()) {
  957. Array.isArray(i) || (i = [i]);
  958. for (let t = 0, e = i.length; t < e; t++) {
  959. var s = i[t],
  960. o = this.getItemByListId(s);
  961. o && cc.Component.EventHandler.emitEvents([this.renderEvent], o, s % this._actualNumItems);
  962. }
  963. }
  964. }
  965. updateAll() {
  966. this.checkInited() && (this.numItems = this.numItems);
  967. }
  968. getItemByListId(e) {
  969. for (let t = this.content.childrenCount - 1; 0 <= t; t--) {
  970. var i = this.content.children[t];
  971. if (i._listId == e) return i;
  972. }
  973. }
  974. _getOutsideItem() {
  975. let e,
  976. i = [];
  977. for (let t = this.content.childrenCount - 1; 0 <= t; t--)
  978. (e = this.content.children[t]), this.displayData.find(t => t.id == e._listId) || i.push(e);
  979. return i;
  980. }
  981. _delRedundantItem() {
  982. if (this._virtual) {
  983. var e = this._getOutsideItem();
  984. for (let t = e.length - 1; 0 <= t; t--) {
  985. var i = e[t];
  986. if (!this._scrollItem || i._listId != this._scrollItem._listId) {
  987. this._pool.put(i);
  988. for (let t = this._lastDisplayData.length - 1; 0 <= t; t--)
  989. if (this._lastDisplayData[t] == i._listId) {
  990. this._lastDisplayData.splice(t, 1);
  991. break;
  992. }
  993. }
  994. }
  995. } else
  996. for (; this.content.childrenCount > this._numItems;)
  997. this._delSingleItem(this.content.children[this.content.childrenCount - 1]);
  998. }
  999. _delSingleItem(t) {
  1000. t.removeFromParent(), t.destroy && t.destroy(), (t = null);
  1001. }
  1002. aniDelItem(l, h, t) {
  1003. let c = this;
  1004. if (!c.checkInited() || c.cyclic || !c._virtual) return cc.error("This function is not allowed to be called!");
  1005. if (c._aniDelRuning) return cc.warn("Please wait for the current deletion to finish!");
  1006. let e,
  1007. d = c.getItemByListId(l);
  1008. if (d) {
  1009. (e = d.getComponent(p.default)), (c._aniDelRuning = !0);
  1010. let n = c.displayData[c.displayData.length - 1].id,
  1011. r = e.selected;
  1012. e.showAni(
  1013. t,
  1014. () => {
  1015. let e, i, s;
  1016. var o;
  1017. if (
  1018. (n < c._numItems - 2 && (e = n + 1),
  1019. null != e ?
  1020. ((t = c._calcItemPos(e)),
  1021. c.displayData.push(t),
  1022. c._virtual ? c._createOrUpdateItem(t) : c._createOrUpdateItem2(e)) :
  1023. c._numItems--,
  1024. c.selectedMode == u.SINGLE)
  1025. )
  1026. r ? (c._selectedId = -1) : 0 <= c._selectedId - 1 && c._selectedId--;
  1027. else if (c.selectedMode == u.MULT && c.multSelected.length) {
  1028. var t = c.multSelected.indexOf(l);
  1029. 0 <= t && c.multSelected.splice(t, 1);
  1030. for (let t = c.multSelected.length - 1; 0 <= t; t--)
  1031. c.multSelected[t] >= l && c.multSelected[t]--;
  1032. }
  1033. if (c._customSize) {
  1034. c._customSize[l] && delete c._customSize[l];
  1035. let t,
  1036. e = {};
  1037. for (var a in c._customSize) {
  1038. t = c._customSize[a];
  1039. a = parseInt(a);
  1040. e[a - (l <= a ? 1 : 0)] = t;
  1041. }
  1042. c._customSize = e;
  1043. }
  1044. for (let t = null != e ? e : n; t >= l + 1; t--)
  1045. (d = c.getItemByListId(t)) &&
  1046. ((o = c._calcItemPos(t - 1)),
  1047. (i = [cc.moveTo(0.2333, cc.v2(o.x, o.y))]),
  1048. t <= l + 1 &&
  1049. ((s = !0),
  1050. i.push(
  1051. cc.callFunc(() => {
  1052. (c._aniDelRuning = !1), h(l);
  1053. })
  1054. )),
  1055. 1 < i.length ? d.runAction(cc.sequence(i)) : d.runAction(i[0]));
  1056. s || ((c._aniDelRuning = !1), h(l));
  1057. }, !0
  1058. );
  1059. } else h(l);
  1060. }
  1061. scrollTo(o, a = 0.5, n = null, r = !1) {
  1062. let l = this;
  1063. if (l.checkInited(!1)) {
  1064. null == a ? (a = 0.5) : a < 0 && (a = 0),
  1065. o < 0 ? (o = 0) : o >= l._numItems && (o = l._numItems - 1), !l._virtual && l._layout && l._layout.enabled && l._layout.updateLayout();
  1066. let t,
  1067. e,
  1068. i = l.getItemPos(o);
  1069. switch (l._alignCalcType) {
  1070. case 1:
  1071. (t = i.left), (t -= null != n ? l.node.width * n : l._leftGap), (i = cc.v2(t, 0));
  1072. break;
  1073. case 2:
  1074. (t = i.right - l.node.width),
  1075. (t += null != n ? l.node.width * n : l._rightGap),
  1076. (i = cc.v2(t + l.content.width, 0));
  1077. break;
  1078. case 3:
  1079. (e = i.top), (e += null != n ? l.node.height * n : l._topGap), (i = cc.v2(0, -e));
  1080. break;
  1081. case 4:
  1082. (e = i.bottom + l.node.height),
  1083. (e -= null != n ? l.node.height * n : l._bottomGap),
  1084. (i = cc.v2(0, -e + l.content.height));
  1085. }
  1086. let s = l.content.getPosition();
  1087. s = Math.abs(l._sizeType ? s.y : s.x);
  1088. var h = l._sizeType ? i.y : i.x;
  1089. 0.5 < Math.abs((null != l._scrollPos ? l._scrollPos : s) - h) &&
  1090. (l._scrollView.scrollToOffset(i, a),
  1091. (l._scrollToListId = o),
  1092. (l._scrollToEndTime = new Date().getTime() / 1e3 + a),
  1093. (l._scrollToSo = l.scheduleOnce(() => {
  1094. if (
  1095. (l._adheringBarrier || (l.adhering = l._adheringBarrier = !1),
  1096. (l._scrollPos = l._scrollToListId = l._scrollToEndTime = l._scrollToSo = null),
  1097. r)
  1098. ) {
  1099. let t = l.getItemByListId(o);
  1100. t && t.runAction(cc.sequence(cc.scaleTo(0.1, 1.05), cc.scaleTo(0.1, 1)));
  1101. }
  1102. }, a + 0.1)),
  1103. a <= 0 && l._onScrolling());
  1104. }
  1105. }
  1106. _calcNearestItem() {
  1107. let e,
  1108. i,
  1109. s,
  1110. o,
  1111. a,
  1112. n,
  1113. r = this;
  1114. (r.nearestListId = null),
  1115. r._virtual && r._calcViewPos(),
  1116. (s = r.viewTop),
  1117. (o = r.viewRight),
  1118. (a = r.viewBottom),
  1119. (n = r.viewLeft);
  1120. let l = !1;
  1121. for (let t = 0; t < r.content.childrenCount && !l; t += r._colLineNum)
  1122. if ((e = r._virtual ? r.displayData[t] : r._calcExistItemPos(t)))
  1123. switch (((i = r._sizeType ? (e.top + e.bottom) / 2 : (e.left + e.right) / 2), r._alignCalcType)) {
  1124. case 1:
  1125. e.right >= n &&
  1126. ((r.nearestListId = e.id), n > i && (r.nearestListId += r._colLineNum), (l = !0));
  1127. break;
  1128. case 2:
  1129. e.left <= o &&
  1130. ((r.nearestListId = e.id), o < i && (r.nearestListId += r._colLineNum), (l = !0));
  1131. break;
  1132. case 3:
  1133. e.bottom <= s &&
  1134. ((r.nearestListId = e.id), s < i && (r.nearestListId += r._colLineNum), (l = !0));
  1135. break;
  1136. case 4:
  1137. e.top >= a && ((r.nearestListId = e.id), a > i && (r.nearestListId += r._colLineNum), (l = !0));
  1138. }
  1139. if (
  1140. (e = r._virtual ? r.displayData[r.displayItemNum - 1] : r._calcExistItemPos(r._numItems - 1)) &&
  1141. e.id == r._numItems - 1
  1142. )
  1143. switch (((i = r._sizeType ? (e.top + e.bottom) / 2 : (e.left + e.right) / 2), r._alignCalcType)) {
  1144. case 1:
  1145. o > i && (r.nearestListId = e.id);
  1146. break;
  1147. case 2:
  1148. n < i && (r.nearestListId = e.id);
  1149. break;
  1150. case 3:
  1151. a < i && (r.nearestListId = e.id);
  1152. break;
  1153. case 4:
  1154. s > i && (r.nearestListId = e.id);
  1155. }
  1156. }
  1157. prePage(t = 0.5) {
  1158. this.checkInited() && this.skipPage(this.curPageNum - 1, t);
  1159. }
  1160. nextPage(t = 0.5) {
  1161. this.checkInited() && this.skipPage(this.curPageNum + 1, t);
  1162. }
  1163. skipPage(t, e) {
  1164. if (this.checkInited())
  1165. return this._slideMode != o.PAGE ?
  1166. cc.error("This function is not allowed to be called, Must SlideMode = PAGE!") :
  1167. void(
  1168. t < 0 ||
  1169. t >= this._numItems ||
  1170. (this.curPageNum != t &&
  1171. ((this.curPageNum = t),
  1172. this.pageChangeEvent && cc.Component.EventHandler.emitEvents([this.pageChangeEvent], t),
  1173. this.scrollTo(t, e)))
  1174. );
  1175. }
  1176. calcCustomSize(i) {
  1177. var s = this;
  1178. if (s.checkInited()) {
  1179. if (!s._itemTmp) return cc.error("Unset template item!");
  1180. if (!s.renderEvent) return cc.error("Unset Render-Event!");
  1181. s._customSize = {};
  1182. let e = cc.instantiate(s._itemTmp);
  1183. s.content.addChild(e);
  1184. for (let t = 0; t < i; t++)
  1185. cc.Component.EventHandler.emitEvents([s.renderEvent], e, t),
  1186. (e.height == s._itemSize.height && e.width == s._itemSize.width) ||
  1187. (s._customSize[t] = s._sizeType ? e.height : e.width);
  1188. return (
  1189. Object.keys(s._customSize).length || (s._customSize = null),
  1190. e.removeFromParent(),
  1191. e.destroy && e.destroy(),
  1192. s._customSize
  1193. );
  1194. }
  1195. }
  1196. };
  1197. e([n({ type: cc.Enum(s) })], t.prototype, "templateType", void 0),
  1198. e(
  1199. [
  1200. n({
  1201. type: cc.Node,
  1202. visible() {
  1203. return this.templateType == s.NODE;
  1204. }
  1205. })
  1206. ],
  1207. t.prototype,
  1208. "tmpNode",
  1209. void 0
  1210. ),
  1211. e(
  1212. [
  1213. n({
  1214. type: cc.Prefab,
  1215. visible() {
  1216. return this.templateType == s.PREFAB;
  1217. }
  1218. })
  1219. ],
  1220. t.prototype,
  1221. "tmpPrefab",
  1222. void 0
  1223. ),
  1224. e([n()], t.prototype, "_slideMode", void 0),
  1225. e([n({ type: cc.Enum(o) })], t.prototype, "slideMode", null),
  1226. e(
  1227. [
  1228. n({
  1229. type: cc.Float,
  1230. range: [0, 1, 0.1],
  1231. slide: !0,
  1232. visible() {
  1233. return this._slideMode == o.PAGE;
  1234. }
  1235. })
  1236. ],
  1237. t.prototype,
  1238. "pageDistance",
  1239. void 0
  1240. ),
  1241. e(
  1242. [
  1243. n({
  1244. type: cc.Component.EventHandler,
  1245. visible() {
  1246. return this._slideMode == o.PAGE;
  1247. }
  1248. })
  1249. ],
  1250. t.prototype,
  1251. "pageChangeEvent",
  1252. void 0
  1253. ),
  1254. e([n()], t.prototype, "_virtual", void 0),
  1255. e([n({ type: cc.Boolean })], t.prototype, "virtual", null),
  1256. e(
  1257. [
  1258. n({
  1259. visible() {
  1260. var t = this.virtual && this.slideMode == o.NORMAL;
  1261. return t || (this.cyclic = !1), t;
  1262. }
  1263. })
  1264. ],
  1265. t.prototype,
  1266. "cyclic",
  1267. void 0
  1268. ),
  1269. e(
  1270. [
  1271. n({
  1272. visible() {
  1273. return this.virtual;
  1274. }
  1275. })
  1276. ],
  1277. t.prototype,
  1278. "lackCenter",
  1279. void 0
  1280. ),
  1281. e(
  1282. [
  1283. n({
  1284. visible() {
  1285. var t = this.virtual && !this.lackCenter;
  1286. return t || (this.lackSlide = !1), t;
  1287. }
  1288. })
  1289. ],
  1290. t.prototype,
  1291. "lackSlide",
  1292. void 0
  1293. ),
  1294. e([n({ type: cc.Integer })], t.prototype, "_updateRate", void 0),
  1295. e([n({ type: cc.Integer, range: [0, 6, 1], slide: !0 })], t.prototype, "updateRate", null),
  1296. e([n({ type: cc.Integer, range: [0, 12, 1], slide: !0 })], t.prototype, "frameByFrameRenderNum", void 0),
  1297. e([n({ type: cc.Component.EventHandler })], t.prototype, "renderEvent", void 0),
  1298. e([n({ type: cc.Enum(u) })], t.prototype, "selectedMode", void 0),
  1299. e(
  1300. [
  1301. n({
  1302. visible() {
  1303. return this.selectedMode == u.SINGLE;
  1304. }
  1305. })
  1306. ],
  1307. t.prototype,
  1308. "repeatEventSingle",
  1309. void 0
  1310. ),
  1311. e(
  1312. [
  1313. n({
  1314. type: cc.Component.EventHandler,
  1315. visible() {
  1316. return this.selectedMode > u.NONE;
  1317. }
  1318. })
  1319. ],
  1320. t.prototype,
  1321. "selectedEvent",
  1322. void 0
  1323. ),
  1324. e([n({ serializable: !1 })], t.prototype, "_numItems", void 0),
  1325. (t = e([a, r(), c(cc.ScrollView), h(-5e3)], t)),
  1326. (i.default = t);