1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327 |
- var t = require;
- var e = module;
- var i = exports;
- var s,
- o,
- u,
- e =
- (this && this.__decorate) ||
- function(t, e, i, s) {
- var o,
- a = arguments.length,
- n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
- if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
- else
- for (var r = t.length - 1; 0 <= r; r--)
- (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
- return 3 < a && n && Object.defineProperty(e, i, n), n;
- };
- Object.defineProperty(i, "__esModule", { value: !0 });
- const { ccclass: a, property: n, disallowMultiple: r, menu: l, executionOrder: h, requireComponent: c } = cc._decorator,
- p = t("ListItem");
- ((t = s = s || {})[(t.NODE = 1)] = "NODE"),
- (t[(t.PREFAB = 2)] = "PREFAB"),
- ((t = o = o || {})[(t.NORMAL = 1)] = "NORMAL"),
- (t[(t.ADHERING = 2)] = "ADHERING"),
- (t[(t.PAGE = 3)] = "PAGE"),
- ((t = u = u || {})[(t.NONE = 0)] = "NONE"),
- (t[(t.SINGLE = 1)] = "SINGLE"),
- (t[(t.MULT = 2)] = "MULT");
- t = class extends cc.Component {
- constructor() {
- super(...arguments),
- (this.templateType = s.NODE),
- (this.tmpNode = null),
- (this.tmpPrefab = null),
- (this._slideMode = o.NORMAL),
- (this.pageDistance = 0.3),
- (this.pageChangeEvent = new cc.Component.EventHandler()),
- (this._virtual = !0),
- (this.cyclic = !1),
- (this.lackCenter = !1),
- (this.lackSlide = !1),
- (this._updateRate = 0),
- (this.frameByFrameRenderNum = 0),
- (this.renderEvent = new cc.Component.EventHandler()),
- (this.selectedMode = u.NONE),
- (this.repeatEventSingle = !1),
- (this.selectedEvent = null),
- (this._selectedId = -1),
- (this._forceUpdate = !1),
- (this._updateDone = !0),
- (this._numItems = 0),
- (this._inited = !1),
- (this._needUpdateWidget = !1),
- (this._aniDelRuning = !1),
- (this._doneAfterUpdate = !1),
- (this.adhering = !1),
- (this._adheringBarrier = !1),
- (this.curPageNum = 0);
- }
- set slideMode(t) {
- this._slideMode = t;
- }
- get slideMode() {
- return this._slideMode;
- }
- set virtual(t) {
- null != t && (this._virtual = t), 0 != this._numItems && this._onScrolling();
- }
- get virtual() {
- return this._virtual;
- }
- set updateRate(t) {
- 0 <= t && t <= 6 && (this._updateRate = t);
- }
- get updateRate() {
- return this._updateRate;
- }
- set selectedId(e) {
- let i,
- s = this;
- switch (s.selectedMode) {
- case u.SINGLE:
- {
- if (!s.repeatEventSingle && e == s._selectedId) return;
- let t;
- if (
- ((i = s.getItemByListId(e)),
- 0 <= s._selectedId ? (s._lastSelectedId = s._selectedId) : (s._lastSelectedId = null),
- (s._selectedId = e),
- i && ((t = i.getComponent(p.default)).selected = !0),
- 0 <= s._lastSelectedId && s._lastSelectedId != s._selectedId)
- ) {
- let t = s.getItemByListId(s._lastSelectedId);
- t && (t.getComponent(p.default).selected = !1);
- }
- s.selectedEvent &&
- cc.Component.EventHandler.emitEvents(
- [s.selectedEvent],
- i,
- e % this._actualNumItems,
- null == s._lastSelectedId ? null : s._lastSelectedId % this._actualNumItems
- );
- break;
- }
- case u.MULT:
- {
- if (!(i = s.getItemByListId(e))) return;
- let t = i.getComponent(p.default);
- 0 <= s._selectedId && (s._lastSelectedId = s._selectedId),
- (s._selectedId = e);
- var o = !t.selected;
- t.selected = o;
- var a = s.multSelected.indexOf(e);
- o && a < 0 ? s.multSelected.push(e) : !o && 0 <= a && s.multSelected.splice(a, 1),
- s.selectedEvent &&
- cc.Component.EventHandler.emitEvents(
- [s.selectedEvent],
- i,
- e % this._actualNumItems,
- null == s._lastSelectedId ? null : s._lastSelectedId % this._actualNumItems,
- o
- );
- break;
- }
- }
- }
- get selectedId() {
- return this._selectedId;
- }
- set numItems(e) {
- var i = this;
- if (i.checkInited(!1))
- if (null == e || e < 0) cc.error("numItems set the wrong::", e);
- else if (((i._actualNumItems = i._numItems = e), (i._forceUpdate = !0), i._virtual))
- i._resizeContent(),
- i.cyclic && (i._numItems = i._cyclicNum * i._numItems),
- i._onScrolling(),
- i.frameByFrameRenderNum || i.slideMode != o.PAGE || (i.curPageNum = i.nearestListId);
- else {
- let t = i.content.getComponent(cc.Layout);
- if ((t && (t.enabled = !0), i._delRedundantItem(), (i.firstListId = 0) < i.frameByFrameRenderNum)) {
- var s = i.frameByFrameRenderNum > i._numItems ? i._numItems : i.frameByFrameRenderNum;
- for (let t = 0; t < s; t++) i._createOrUpdateItem2(t);
- i.frameByFrameRenderNum < i._numItems &&
- ((i._updateCounter = i.frameByFrameRenderNum), (i._updateDone = !1));
- } else {
- for (let t = 0; t < e; t++) i._createOrUpdateItem2(t);
- i.displayItemNum = e;
- }
- }
- }
- get numItems() {
- return this._actualNumItems;
- }
- get scrollView() {
- return this._scrollView;
- }
- onLoad() {
- this._init();
- }
- onDestroy() {
- for (
- this._itemTmp && this._itemTmp.isValid && this._itemTmp.destroy(),
- this.tmpNode && this.tmpNode.isValid && this.tmpNode.destroy(); this._pool.size();
- )
- this._pool.get().destroy();
- }
- onEnable() {
- this._registerEvent(), this._init();
- }
- onDisable() {
- this._unregisterEvent();
- }
- _registerEvent() {
- var t = this;
- t.node.on(cc.Node.EventType.TOUCH_START, t._onTouchStart, t, !0),
- t.node.on("touch-up", t._onTouchUp, t),
- t.node.on(cc.Node.EventType.TOUCH_CANCEL, t._onTouchCancelled, t, !0),
- t.node.on("scroll-began", t._onScrollBegan, t, !0),
- t.node.on("scroll-ended", t._onScrollEnded, t, !0),
- t.node.on("scrolling", t._onScrolling, t, !0),
- t.node.on(cc.Node.EventType.SIZE_CHANGED, t._onSizeChanged, t);
- }
- _unregisterEvent() {
- var t = this;
- t.node.off(cc.Node.EventType.TOUCH_START, t._onTouchStart, t, !0),
- t.node.off("touch-up", t._onTouchUp, t),
- t.node.off(cc.Node.EventType.TOUCH_CANCEL, t._onTouchCancelled, t, !0),
- t.node.off("scroll-began", t._onScrollBegan, t, !0),
- t.node.off("scroll-ended", t._onScrollEnded, t, !0),
- t.node.off("scrolling", t._onScrolling, t, !0),
- t.node.off(cc.Node.EventType.SIZE_CHANGED, t._onSizeChanged, t);
- }
- _init() {
- var t = this;
- if (!t._inited)
- if (
- ((t._scrollView = t.node.getComponent(cc.ScrollView)), (t.content = t._scrollView.content), t.content)
- ) {
- switch (
- ((t._layout = t.content.getComponent(cc.Layout)),
- (t._align = t._layout.type),
- (t._resizeMode = t._layout.resizeMode),
- (t._startAxis = t._layout.startAxis),
- (t._topGap = t._layout.paddingTop),
- (t._rightGap = t._layout.paddingRight),
- (t._bottomGap = t._layout.paddingBottom),
- (t._leftGap = t._layout.paddingLeft),
- (t._columnGap = t._layout.spacingX),
- (t._lineGap = t._layout.spacingY),
- t._colLineNum,
- (t._verticalDir = t._layout.verticalDirection),
- (t._horizontalDir = t._layout.horizontalDirection),
- t.setTemplateItem(cc.instantiate(t.templateType == s.PREFAB ? t.tmpPrefab : t.tmpNode)),
- (t._slideMode != o.ADHERING && t._slideMode != o.PAGE) ||
- ((t._scrollView.inertia = !1), (t._scrollView._onMouseWheel = function() {})),
- t.virtual || (t.lackCenter = !1),
- (t._lastDisplayData = []),
- (t.displayData = []),
- (t._pool = new cc.NodePool()),
- (t._forceUpdate = !1),
- (t._updateCounter = 0),
- (t._updateDone = !0),
- (t.curPageNum = 0),
- t.cyclic &&
- ((t._scrollView._processAutoScrolling = this._processAutoScrolling.bind(t)),
- (t._scrollView._startBounceBackIfNeeded = function() {
- return !1;
- })),
- t._align)
- ) {
- case cc.Layout.Type.HORIZONTAL:
- switch (t._horizontalDir) {
- case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
- t._alignCalcType = 1;
- break;
- case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
- t._alignCalcType = 2;
- }
- break;
- case cc.Layout.Type.VERTICAL:
- switch (t._verticalDir) {
- case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
- t._alignCalcType = 3;
- break;
- case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
- t._alignCalcType = 4;
- }
- break;
- case cc.Layout.Type.GRID:
- switch (t._startAxis) {
- case cc.Layout.AxisDirection.HORIZONTAL:
- switch (t._verticalDir) {
- case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
- t._alignCalcType = 3;
- break;
- case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
- t._alignCalcType = 4;
- }
- break;
- case cc.Layout.AxisDirection.VERTICAL:
- switch (t._horizontalDir) {
- case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
- t._alignCalcType = 1;
- break;
- case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
- t._alignCalcType = 2;
- }
- }
- }
- t.content.removeAllChildren(), (t._inited = !0);
- } else cc.error(t.node.name + "'s cc_ScrollView unset content!");
- }
- _processAutoScrolling(t) {
- this._scrollView._autoScrollAccumulatedTime += +t;
- let e = Math.min(1, this._scrollView._autoScrollAccumulatedTime / this._scrollView._autoScrollTotalTime);
- this._scrollView._autoScrollAttenuate && ((a = e - 1), (e = a * a * a * a * a + 1));
- let i = this._scrollView._autoScrollStartPosition.add(this._scrollView._autoScrollTargetDelta.mul(e)),
- s = this._scrollView.getScrollEndedEventTiming(),
- o = Math.abs(e - 1) <= s;
- Math.abs(e - 1) <= this._scrollView.getScrollEndedEventTiming() &&
- !this._scrollView._isScrollEndedWithThresholdEventFired &&
- (this._scrollView._dispatchEvent("scroll-ended-with-threshold"),
- (this._scrollView._isScrollEndedWithThresholdEventFired = !0)),
- o && (this._scrollView._autoScrolling = !1);
- var a = i.sub(this._scrollView.getContentPosition());
- this._scrollView._moveContent(this._scrollView._clampDelta(a), o),
- this._scrollView._dispatchEvent("scrolling"),
- this._scrollView._autoScrolling ||
- ((this._scrollView._isBouncing = !1),
- (this._scrollView._scrolling = !1),
- this._scrollView._dispatchEvent("scroll-ended"));
- }
- setTemplateItem(i) {
- if (i) {
- var s = this;
- (s._itemTmp = i),
- s._resizeMode == cc.Layout.ResizeMode.CHILDREN ?
- (s._itemSize = s._layout.cellSize) :
- (s._itemSize = cc.size(i.width, i.height));
- let t = i.getComponent(p.default),
- e = t ? !1 : !0;
- switch (
- (e && (s.selectedMode = u.NONE),
- (t = i.getComponent(cc.Widget)) && t.enabled && (s._needUpdateWidget = !0),
- s.selectedMode == u.MULT && (s.multSelected = []),
- s._align)
- ) {
- case cc.Layout.Type.HORIZONTAL:
- (s._colLineNum = 1), (s._sizeType = !1);
- break;
- case cc.Layout.Type.VERTICAL:
- (s._colLineNum = 1), (s._sizeType = !0);
- break;
- case cc.Layout.Type.GRID:
- switch (s._startAxis) {
- case cc.Layout.AxisDirection.HORIZONTAL:
- var o = s.content.width - s._leftGap - s._rightGap;
- (s._colLineNum = Math.floor((o + s._columnGap) / (s._itemSize.width + s._columnGap))),
- (s._sizeType = !0);
- break;
- case cc.Layout.AxisDirection.VERTICAL:
- o = s.content.height - s._topGap - s._bottomGap;
- (s._colLineNum = Math.floor((o + s._lineGap) / (s._itemSize.height + s._lineGap))),
- (s._sizeType = !1);
- }
- }
- }
- }
- checkInited(t = !0) {
- return !!this._inited || (t && cc.error("List initialization not completed!"), !1);
- }
- _resizeContent() {
- let t,
- e = this;
- switch (e._align) {
- case cc.Layout.Type.HORIZONTAL:
- t = e._customSize ?
- ((i = e._getFixedSize(null)),
- e._leftGap +
- i.val +
- e._itemSize.width * (e._numItems - i.count) +
- e._columnGap * (e._numItems - 1) +
- e._rightGap) :
- e._leftGap + e._itemSize.width * e._numItems + e._columnGap * (e._numItems - 1) + e._rightGap;
- break;
- case cc.Layout.Type.VERTICAL:
- var i;
- t = e._customSize ?
- ((i = e._getFixedSize(null)),
- e._topGap +
- i.val +
- e._itemSize.height * (e._numItems - i.count) +
- e._lineGap * (e._numItems - 1) +
- e._bottomGap) :
- e._topGap + e._itemSize.height * e._numItems + e._lineGap * (e._numItems - 1) + e._bottomGap;
- break;
- case cc.Layout.Type.GRID:
- switch ((e.lackCenter && (e.lackCenter = !1), e._startAxis)) {
- case cc.Layout.AxisDirection.HORIZONTAL:
- var s = Math.ceil(e._numItems / e._colLineNum);
- t = e._topGap + e._itemSize.height * s + e._lineGap * (s - 1) + e._bottomGap;
- break;
- case cc.Layout.AxisDirection.VERTICAL:
- s = Math.ceil(e._numItems / e._colLineNum);
- t = e._leftGap + e._itemSize.width * s + e._columnGap * (s - 1) + e._rightGap;
- }
- }
- let o = e.content.getComponent(cc.Layout);
- var a;
- o && (o.enabled = !1),
- (e._allItemSize = t),
- (e._allItemSizeNoEdge =
- e._allItemSize - (e._sizeType ? e._topGap + e._bottomGap : e._leftGap + e._rightGap)),
- e.cyclic &&
- ((a = e._sizeType ? e.node.height : e.node.width),
- (e._cyclicPos1 = 0),
- (a -= e._cyclicPos1),
- (e._cyclicNum = Math.ceil(a / e._allItemSizeNoEdge) + 1),
- (a = e._sizeType ? e._lineGap : e._columnGap),
- (e._cyclicPos2 = e._cyclicPos1 + e._allItemSizeNoEdge + a),
- (e._cyclicAllItemSize =
- e._allItemSize + e._allItemSizeNoEdge * (e._cyclicNum - 1) + a * (e._cyclicNum - 1)),
- (e._cycilcAllItemSizeNoEdge = e._allItemSizeNoEdge * e._cyclicNum),
- (e._cycilcAllItemSizeNoEdge += a * (e._cyclicNum - 1))),
- (e._lack = !e.cyclic && e._allItemSize < (e._sizeType ? e.node.height : e.node.width));
- let n = (e._lack && e.lackCenter) || !e.lackSlide ? 0.1 : 0,
- r = e._lack ?
- (e._sizeType ? e.node.height : e.node.width) - n :
- e.cyclic ?
- e._cyclicAllItemSize :
- e._allItemSize;
- r < 0 && (r = 0), e._sizeType ? (e.content.height = r) : (e.content.width = r);
- }
- _onScrolling(e = null) {
- if (
- (null == this.frameCount && (this.frameCount = this._updateRate), !this._forceUpdate && e && "scroll-ended" != e.type && 0 < this.frameCount)
- )
- this.frameCount--;
- else if (((this.frameCount = this._updateRate), !this._aniDelRuning)) {
- if (this.cyclic) {
- let t = this.content.getPosition();
- t = this._sizeType ? t.y : t.x;
- var e = this._allItemSizeNoEdge + (this._sizeType ? this._lineGap : this._columnGap),
- i = this._sizeType ? cc.v2(0, e) : cc.v2(e, 0);
- switch (this._alignCalcType) {
- case 1:
- t > -this._cyclicPos1 ?
- ((this.content.x = -this._cyclicPos2),
- this._scrollView.isAutoScrolling() &&
- (this._scrollView._autoScrollStartPosition =
- this._scrollView._autoScrollStartPosition.sub(i))) :
- t < -this._cyclicPos2 &&
- ((this.content.x = -this._cyclicPos1),
- this._scrollView.isAutoScrolling() &&
- (this._scrollView._autoScrollStartPosition =
- this._scrollView._autoScrollStartPosition.add(i)));
- break;
- case 2:
- t < this._cyclicPos1 ?
- ((this.content.x = this._cyclicPos2),
- this._scrollView.isAutoScrolling() &&
- (this._scrollView._autoScrollStartPosition =
- this._scrollView._autoScrollStartPosition.add(i))) :
- t > this._cyclicPos2 &&
- ((this.content.x = this._cyclicPos1),
- this._scrollView.isAutoScrolling() &&
- (this._scrollView._autoScrollStartPosition =
- this._scrollView._autoScrollStartPosition.sub(i)));
- break;
- case 3:
- t < this._cyclicPos1 ?
- ((this.content.y = this._cyclicPos2),
- this._scrollView.isAutoScrolling() &&
- (this._scrollView._autoScrollStartPosition =
- this._scrollView._autoScrollStartPosition.add(i))) :
- t > this._cyclicPos2 &&
- ((this.content.y = this._cyclicPos1),
- this._scrollView.isAutoScrolling() &&
- (this._scrollView._autoScrollStartPosition =
- this._scrollView._autoScrollStartPosition.sub(i)));
- break;
- case 4:
- t > -this._cyclicPos1 ?
- ((this.content.y = -this._cyclicPos2),
- this._scrollView.isAutoScrolling() &&
- (this._scrollView._autoScrollStartPosition =
- this._scrollView._autoScrollStartPosition.sub(i))) :
- t < -this._cyclicPos2 &&
- ((this.content.y = -this._cyclicPos1),
- this._scrollView.isAutoScrolling() &&
- (this._scrollView._autoScrollStartPosition =
- this._scrollView._autoScrollStartPosition.add(i)));
- }
- }
- let s, o, a, n;
- if (
- (this._calcViewPos(),
- this._sizeType ?
- ((s = this.viewTop), (a = this.viewBottom)) :
- ((o = this.viewRight), (n = this.viewLeft)),
- this._virtual)
- ) {
- var r;
- this.displayData = [];
- let e = 0,
- i = this._numItems - 1;
- if (this._customSize) {
- let t = !1;
- for (; e <= i && !t; e++)
- switch (((r = this._calcItemPos(e)), this._align)) {
- case cc.Layout.Type.HORIZONTAL:
- r.right >= n && r.left <= o ?
- this.displayData.push(r) :
- 0 != e && 0 < this.displayData.length && (t = !0);
- break;
- case cc.Layout.Type.VERTICAL:
- r.bottom <= s && r.top >= a ?
- this.displayData.push(r) :
- 0 != e && 0 < this.displayData.length && (t = !0);
- break;
- case cc.Layout.Type.GRID:
- switch (this._startAxis) {
- case cc.Layout.AxisDirection.HORIZONTAL:
- r.bottom <= s && r.top >= a ?
- this.displayData.push(r) :
- 0 != e && 0 < this.displayData.length && (t = !0);
- break;
- case cc.Layout.AxisDirection.VERTICAL:
- r.right >= n && r.left <= o ?
- this.displayData.push(r) :
- 0 != e && 0 < this.displayData.length && (t = !0);
- }
- }
- } else {
- var t = this._itemSize.width + this._columnGap,
- l = this._itemSize.height + this._lineGap;
- switch (this._alignCalcType) {
- case 1:
- (e = (n + this._leftGap) / t), (i = (o + this._rightGap) / t);
- break;
- case 2:
- (e = (-o - this._rightGap) / t), (i = (-n - this._leftGap) / t);
- break;
- case 3:
- (e = (-s - this._topGap) / l), (i = (-a - this._bottomGap) / l);
- break;
- case 4:
- (e = (a + this._bottomGap) / l), (i = (s + this._topGap) / l);
- }
- for (
- e = Math.floor(e) * this._colLineNum,
- i = Math.ceil(i) * this._colLineNum,
- e < 0 && (e = 0),
- --i >= this._numItems && (i = this._numItems - 1); e <= i; e++
- )
- this.displayData.push(this._calcItemPos(e));
- }
- if ((this._delRedundantItem(), this.displayData.length <= 0 || !this._numItems))
- this._lastDisplayData = [];
- else {
- (this.firstListId = this.displayData[0].id), (this.displayItemNum = this.displayData.length);
- let t = this._lastDisplayData.length,
- e = this.displayItemNum != t;
- if (
- (e &&
- (0 < this.frameByFrameRenderNum && this._lastDisplayData.sort((t, e) => t - e),
- (e =
- this.firstListId != this._lastDisplayData[0] ||
- this.displayData[this.displayItemNum - 1].id != this._lastDisplayData[t - 1])),
- this._forceUpdate || e)
- )
- if (0 < this.frameByFrameRenderNum)
- 0 < this._numItems ?
- (this._updateDone ? (this._updateCounter = 0) : (this._doneAfterUpdate = !0),
- (this._updateDone = !1)) :
- ((this._updateCounter = 0), (this._updateDone = !0));
- else {
- this._lastDisplayData = [];
- for (let t = 0; t < this.displayItemNum; t++) this._createOrUpdateItem(this.displayData[t]);
- this._forceUpdate = !1;
- }
- this._calcNearestItem();
- }
- }
- }
- }
- _calcViewPos() {
- var t = this.content.getPosition();
- switch (this._alignCalcType) {
- case 1:
- (this.elasticLeft = 0 < t.x ? t.x : 0),
- (this.viewLeft = (t.x < 0 ? -t.x : 0) - this.elasticLeft),
- (this.viewRight = this.viewLeft + this.node.width),
- (this.elasticRight =
- this.viewRight > this.content.width ? Math.abs(this.viewRight - this.content.width) : 0),
- (this.viewRight += this.elasticRight);
- break;
- case 2:
- (this.elasticRight = t.x < 0 ? -t.x : 0),
- (this.viewRight = (0 < t.x ? -t.x : 0) + this.elasticRight),
- (this.viewLeft = this.viewRight - this.node.width),
- (this.elasticLeft =
- this.viewLeft < -this.content.width ? Math.abs(this.viewLeft + this.content.width) : 0),
- (this.viewLeft -= this.elasticLeft);
- break;
- case 3:
- (this.elasticTop = t.y < 0 ? Math.abs(t.y) : 0),
- (this.viewTop = (0 < t.y ? -t.y : 0) + this.elasticTop),
- (this.viewBottom = this.viewTop - this.node.height),
- (this.elasticBottom =
- this.viewBottom < -this.content.height ? Math.abs(this.viewBottom + this.content.height) : 0),
- (this.viewBottom += this.elasticBottom);
- break;
- case 4:
- (this.elasticBottom = 0 < t.y ? Math.abs(t.y) : 0),
- (this.viewBottom = (t.y < 0 ? -t.y : 0) - this.elasticBottom),
- (this.viewTop = this.viewBottom + this.node.height),
- (this.elasticTop =
- this.viewTop > this.content.height ? Math.abs(this.viewTop - this.content.height) : 0),
- (this.viewTop -= this.elasticTop);
- }
- }
- _calcItemPos(t) {
- let e, i, s, o, a, n, r, l;
- switch (this._align) {
- case cc.Layout.Type.HORIZONTAL:
- switch (this._horizontalDir) {
- case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
- var h;
- return (
- (e = this._customSize ?
- ((h = this._getFixedSize(t)),
- (a =
- this._leftGap +
- (this._itemSize.width + this._columnGap) * (t - h.count) +
- (h.val + this._columnGap * h.count)),
- 0 < (h = this._customSize[t]) ? h : this._itemSize.width) :
- ((a = this._leftGap + (this._itemSize.width + this._columnGap) * t),
- this._itemSize.width)),
- (n = a + e),
- this.lackCenter &&
- ((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 }
- );
- case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
- var c;
- return (
- (e = this._customSize ?
- ((c = this._getFixedSize(t)),
- (n = -this._rightGap -
- (this._itemSize.width + this._columnGap) * (t - c.count) -
- (c.val + this._columnGap * c.count)),
- 0 < (c = this._customSize[t]) ? c : this._itemSize.width) :
- ((n = -this._rightGap - (this._itemSize.width + this._columnGap) * t),
- this._itemSize.width)),
- (a = n - e),
- this.lackCenter &&
- ((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 }
- );
- }
- break;
- case cc.Layout.Type.VERTICAL:
- switch (this._verticalDir) {
- case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
- var d;
- return (
- (i = this._customSize ?
- ((d = this._getFixedSize(t)),
- (s = -this._topGap -
- (this._itemSize.height + this._lineGap) * (t - d.count) -
- (d.val + this._lineGap * d.count)),
- 0 < (d = this._customSize[t]) ? d : this._itemSize.height) :
- ((s = -this._topGap - (this._itemSize.height + this._lineGap) * t),
- this._itemSize.height)),
- (o = s - i),
- this.lackCenter &&
- ((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 }
- );
- case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
- var u;
- return (
- (i = this._customSize ?
- ((u = this._getFixedSize(t)),
- (o =
- this._bottomGap +
- (this._itemSize.height + this._lineGap) * (t - u.count) +
- (u.val + this._lineGap * u.count)),
- 0 < (u = this._customSize[t]) ? u : this._itemSize.height) :
- ((o = this._bottomGap + (this._itemSize.height + this._lineGap) * t),
- this._itemSize.height)),
- (s = o + i),
- this.lackCenter &&
- ((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 }
- );
- }
- case cc.Layout.Type.GRID:
- var p = Math.floor(t / this._colLineNum);
- switch (this._startAxis) {
- case cc.Layout.AxisDirection.HORIZONTAL:
- switch (this._verticalDir) {
- case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
- l =
- (o =
- (s = -this._topGap - (this._itemSize.height + this._lineGap) * p) -
- this._itemSize.height) +
- this._itemTmp.anchorY * this._itemSize.height;
- break;
- case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
- (s =
- (o = this._bottomGap + (this._itemSize.height + this._lineGap) * p) +
- this._itemSize.height),
- (l = o + this._itemTmp.anchorY * this._itemSize.height);
- }
- switch (
- ((r = this._leftGap + (t % this._colLineNum) * (this._itemSize.width + this._columnGap)),
- this._horizontalDir)
- ) {
- case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
- (r += this._itemTmp.anchorX * this._itemSize.width),
- (r -= this.content.anchorX * this.content.width);
- break;
- case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
- (r += (1 - this._itemTmp.anchorX) * this._itemSize.width),
- (r -= (1 - this.content.anchorX) * this.content.width),
- (r *= -1);
- }
- return { id: t, top: s, bottom: o, x: r, y: l };
- case cc.Layout.AxisDirection.VERTICAL:
- switch (this._horizontalDir) {
- case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
- (n =
- (a = this._leftGap + (this._itemSize.width + this._columnGap) * p) +
- this._itemSize.width),
- (r = a + this._itemTmp.anchorX * this._itemSize.width),
- (r -= this.content.anchorX * this.content.width);
- break;
- case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
- (r =
- (a =
- (n = -this._rightGap - (this._itemSize.width + this._columnGap) * p) -
- this._itemSize.width) +
- this._itemTmp.anchorX * this._itemSize.width),
- (r += (1 - this.content.anchorX) * this.content.width);
- }
- switch (
- ((l = -this._topGap - (t % this._colLineNum) * (this._itemSize.height + this._lineGap)),
- this._verticalDir)
- ) {
- case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
- (l -= (1 - this._itemTmp.anchorY) * this._itemSize.height),
- (l += (1 - this.content.anchorY) * this.content.height);
- break;
- case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
- (l -= this._itemTmp.anchorY * this._itemSize.height),
- (l += this.content.anchorY * this.content.height),
- (l *= -1);
- }
- return { id: t, left: a, right: n, x: r, y: l };
- }
- }
- }
- _calcExistItemPos(t) {
- var e = this.getItemByListId(t);
- if (!e) return null;
- let i = { id: t, x: e.x, y: e.y };
- return (
- this._sizeType ?
- ((i.top = e.y + e.height * (1 - e.anchorY)), (i.bottom = e.y - e.height * e.anchorY)) :
- ((i.left = e.x - e.width * e.anchorX), (i.right = e.x + e.width * (1 - e.anchorX))),
- i
- );
- }
- getItemPos(t) {
- return this._virtual || this.frameByFrameRenderNum ? this._calcItemPos(t) : this._calcExistItemPos(t);
- }
- _getFixedSize(t) {
- if (!this._customSize) return null;
- null == t && (t = this._numItems);
- let e = 0,
- i = 0;
- for (var s in this._customSize) parseInt(s) < t && ((e += this._customSize[s]), i++);
- return { val: e, count: i };
- }
- _onScrollBegan() {
- this._beganPos = this._sizeType ? this.viewTop : this.viewLeft;
- }
- _onScrollEnded() {
- var e = this;
- if (null != e.scrollToListId) {
- let t = e.getItemByListId(e.scrollToListId);
- (e.scrollToListId = null), t && t.runAction(cc.sequence(cc.scaleTo(0.1, 1.06), cc.scaleTo(0.1, 1)));
- }
- e._onScrolling(),
- e._slideMode != o.ADHERING || e.adhering ?
- e._slideMode == o.PAGE && (null != e._beganPos ? this._pageAdhere() : e.adhere()) :
- e.adhere();
- }
- _onTouchStart(e, t) {
- if (!this._scrollView.hasNestedViewGroup(e, t) &&
- (e.eventPhase !== cc.Event.AT_TARGET || e.target !== this.node)
- ) {
- let t = e.target;
- for (; null == t._listId && t.parent;) t = t.parent;
- this._scrollItem = null != t._listId ? t : e.target;
- }
- }
- _onTouchUp() {
- (this._scrollPos = null),
- this._slideMode == o.ADHERING ?
- (this.adhering && (this._adheringBarrier = !0), this.adhere()) :
- this._slideMode == o.PAGE && (null != this._beganPos ? this._pageAdhere() : this.adhere()),
- (this._scrollItem = null);
- }
- _onTouchCancelled(t, e) {
- var i = this;
- i._scrollView.hasNestedViewGroup(t, e) ||
- t.simulate ||
- ((i._scrollPos = null),
- i._slideMode == o.ADHERING ?
- (i.adhering && (i._adheringBarrier = !0), i.adhere()) :
- i._slideMode == o.PAGE && (null != i._beganPos ? i._pageAdhere() : i.adhere()),
- (this._scrollItem = null));
- }
- _onSizeChanged() {
- this.checkInited(!1) && this._onScrolling();
- }
- _onItemAdaptive(t) {
- var e;
- ((!this._sizeType && t.width != this._itemSize.width) ||
- (this._sizeType && t.height != this._itemSize.height)) &&
- (this._customSize || (this._customSize = {}),
- (e = this._sizeType ? t.height : t.width),
- this._customSize[t._listId] != e &&
- ((this._customSize[t._listId] = e),
- this._resizeContent(),
- this.updateAll(),
- null != this._scrollToListId &&
- ((this._scrollPos = null),
- this.unschedule(this._scrollToSo),
- this.scrollTo(
- this._scrollToListId,
- Math.max(0, this._scrollToEndTime - new Date().getTime() / 1e3)
- ))));
- }
- _pageAdhere() {
- var t = this;
- if (t.cyclic || !(0 < t.elasticTop || 0 < t.elasticRight || 0 < t.elasticBottom || 0 < t.elasticLeft)) {
- var e = t._sizeType ? t.viewTop : t.viewLeft,
- i = (t._sizeType ? t.node.height : t.node.width) * t.pageDistance;
- if (Math.abs(t._beganPos - e) > i)
- switch (t._alignCalcType) {
- case 1:
- case 4:
- t._beganPos > e ? t.prePage(0.5) : t.nextPage(0.5);
- break;
- case 2:
- case 3:
- t._beganPos < e ? t.prePage(0.5) : t.nextPage(0.5);
- }
- else t.elasticTop <= 0 && t.elasticRight <= 0 && t.elasticBottom <= 0 && t.elasticLeft <= 0 && t.adhere();
- t._beganPos = null;
- }
- }
- adhere() {
- var t,
- e = this;
- e.checkInited() &&
- (0 < e.elasticTop ||
- 0 < e.elasticRight ||
- 0 < e.elasticBottom ||
- 0 < e.elasticLeft ||
- ((e.adhering = !0),
- e._calcNearestItem(),
- (t = (e._sizeType ? e._topGap : e._leftGap) / (e._sizeType ? e.node.height : e.node.width)),
- e.scrollTo(e.nearestListId, 0.7, t)));
- }
- update() {
- if (!(this.frameByFrameRenderNum <= 0 || this._updateDone))
- if (this._virtual) {
- var e =
- this._updateCounter + this.frameByFrameRenderNum > this.displayItemNum ?
- this.displayItemNum :
- this._updateCounter + this.frameByFrameRenderNum;
- for (let t = this._updateCounter; t < e; t++) {
- var i = this.displayData[t];
- i && this._createOrUpdateItem(i);
- }
- this._updateCounter >= this.displayItemNum - 1 ?
- this._doneAfterUpdate ?
- ((this._updateCounter = 0), (this._updateDone = !1), (this._doneAfterUpdate = !1)) :
- ((this._updateDone = !0),
- this._delRedundantItem(),
- (this._forceUpdate = !1),
- this._calcNearestItem(),
- this.slideMode == o.PAGE && (this.curPageNum = this.nearestListId)) :
- (this._updateCounter += this.frameByFrameRenderNum);
- } else if (this._updateCounter < this._numItems) {
- var s =
- this._updateCounter + this.frameByFrameRenderNum > this._numItems ?
- this._numItems :
- this._updateCounter + this.frameByFrameRenderNum;
- for (let t = this._updateCounter; t < s; t++) this._createOrUpdateItem2(t);
- this._updateCounter += this.frameByFrameRenderNum;
- } else
- (this._updateDone = !0),
- this._calcNearestItem(),
- this.slideMode == o.PAGE && (this.curPageNum = this.nearestListId);
- }
- _createOrUpdateItem(e) {
- let i = this.getItemByListId(e.id);
- if (i)
- this._forceUpdate &&
- this.renderEvent &&
- (i.setPosition(cc.v2(e.x, e.y)),
- this._resetItemSize(i),
- this.renderEvent &&
- cc.Component.EventHandler.emitEvents([this.renderEvent], i, e.id % this._actualNumItems));
- else {
- var s = 0 < this._pool.size();
- if (
- ((i = s ? this._pool.get() : cc.instantiate(this._itemTmp))._listId != e.id &&
- ((i._listId = e.id), i.setContentSize(this._itemSize)),
- i.setPosition(cc.v2(e.x, e.y)),
- this._resetItemSize(i),
- this.content.addChild(i),
- s && this._needUpdateWidget)
- ) {
- let t = i.getComponent(cc.Widget);
- t && t.updateAlignment();
- }
- i.setSiblingIndex(this.content.childrenCount - 1);
- let t = i.getComponent(p.default);
- (i.listItem = t),
- t && ((t.listId = e.id), (t.list = this), t._registerEvent()),
- this.renderEvent &&
- cc.Component.EventHandler.emitEvents([this.renderEvent], i, e.id % this._actualNumItems);
- }
- this._resetItemSize(i),
- this._updateListItem(i.listItem),
- this._lastDisplayData.indexOf(e.id) < 0 && this._lastDisplayData.push(e.id);
- }
- _createOrUpdateItem2(t) {
- let e,
- i = this.content.children[t];
- i
- ?
- this._forceUpdate &&
- this.renderEvent &&
- ((i._listId = t),
- e && (e.listId = t),
- this.renderEvent && cc.Component.EventHandler.emitEvents([this.renderEvent], i, t)) :
- (((i = cc.instantiate(this._itemTmp))._listId = t),
- this.content.addChild(i),
- (e = i.getComponent(p.default)),
- (i.listItem = e),
- e && ((e.listId = t), (e.list = this), e._registerEvent()),
- this.renderEvent && cc.Component.EventHandler.emitEvents([this.renderEvent], i, t)),
- this._updateListItem(e),
- this._lastDisplayData.indexOf(t) < 0 && this._lastDisplayData.push(t);
- }
- _updateListItem(t) {
- if (t && this.selectedMode > u.NONE) {
- var e = t.node;
- switch (this.selectedMode) {
- case u.SINGLE:
- t.selected = this.selectedId == e._listId;
- break;
- case u.MULT:
- t.selected = 0 <= this.multSelected.indexOf(e._listId);
- }
- }
- }
- _resetItemSize(t) {}
- _updateItemPos(t) {
- let e = isNaN(t) ? t : this.getItemByListId(t),
- i = this.getItemPos(e._listId);
- e.setPosition(i.x, i.y);
- }
- setMultSelected(s, t) {
- if (this.checkInited()) {
- if ((Array.isArray(s) || (s = [s]), null == t)) this.multSelected = s;
- else {
- let e, i;
- if (t)
- for (let t = s.length - 1; 0 <= t; t--)
- (e = s[t]), (i = this.multSelected.indexOf(e)) < 0 && this.multSelected.push(e);
- else
- for (let t = s.length - 1; 0 <= t; t--)
- (e = s[t]), 0 <= (i = this.multSelected.indexOf(e)) && this.multSelected.splice(i, 1);
- }
- (this._forceUpdate = !0), this._onScrolling();
- }
- }
- updateItem(i) {
- if (this.checkInited()) {
- Array.isArray(i) || (i = [i]);
- for (let t = 0, e = i.length; t < e; t++) {
- var s = i[t],
- o = this.getItemByListId(s);
- o && cc.Component.EventHandler.emitEvents([this.renderEvent], o, s % this._actualNumItems);
- }
- }
- }
- updateAll() {
- this.checkInited() && (this.numItems = this.numItems);
- }
- getItemByListId(e) {
- for (let t = this.content.childrenCount - 1; 0 <= t; t--) {
- var i = this.content.children[t];
- if (i._listId == e) return i;
- }
- }
- _getOutsideItem() {
- let e,
- i = [];
- for (let t = this.content.childrenCount - 1; 0 <= t; t--)
- (e = this.content.children[t]), this.displayData.find(t => t.id == e._listId) || i.push(e);
- return i;
- }
- _delRedundantItem() {
- if (this._virtual) {
- var e = this._getOutsideItem();
- for (let t = e.length - 1; 0 <= t; t--) {
- var i = e[t];
- if (!this._scrollItem || i._listId != this._scrollItem._listId) {
- this._pool.put(i);
- for (let t = this._lastDisplayData.length - 1; 0 <= t; t--)
- if (this._lastDisplayData[t] == i._listId) {
- this._lastDisplayData.splice(t, 1);
- break;
- }
- }
- }
- } else
- for (; this.content.childrenCount > this._numItems;)
- this._delSingleItem(this.content.children[this.content.childrenCount - 1]);
- }
- _delSingleItem(t) {
- t.removeFromParent(), t.destroy && t.destroy(), (t = null);
- }
- aniDelItem(l, h, t) {
- let c = this;
- if (!c.checkInited() || c.cyclic || !c._virtual) return cc.error("This function is not allowed to be called!");
- if (c._aniDelRuning) return cc.warn("Please wait for the current deletion to finish!");
- let e,
- d = c.getItemByListId(l);
- if (d) {
- (e = d.getComponent(p.default)), (c._aniDelRuning = !0);
- let n = c.displayData[c.displayData.length - 1].id,
- r = e.selected;
- e.showAni(
- t,
- () => {
- let e, i, s;
- var o;
- if (
- (n < c._numItems - 2 && (e = n + 1),
- null != e ?
- ((t = c._calcItemPos(e)),
- c.displayData.push(t),
- c._virtual ? c._createOrUpdateItem(t) : c._createOrUpdateItem2(e)) :
- c._numItems--,
- c.selectedMode == u.SINGLE)
- )
- r ? (c._selectedId = -1) : 0 <= c._selectedId - 1 && c._selectedId--;
- else if (c.selectedMode == u.MULT && c.multSelected.length) {
- var t = c.multSelected.indexOf(l);
- 0 <= t && c.multSelected.splice(t, 1);
- for (let t = c.multSelected.length - 1; 0 <= t; t--)
- c.multSelected[t] >= l && c.multSelected[t]--;
- }
- if (c._customSize) {
- c._customSize[l] && delete c._customSize[l];
- let t,
- e = {};
- for (var a in c._customSize) {
- t = c._customSize[a];
- a = parseInt(a);
- e[a - (l <= a ? 1 : 0)] = t;
- }
- c._customSize = e;
- }
- for (let t = null != e ? e : n; t >= l + 1; t--)
- (d = c.getItemByListId(t)) &&
- ((o = c._calcItemPos(t - 1)),
- (i = [cc.moveTo(0.2333, cc.v2(o.x, o.y))]),
- t <= l + 1 &&
- ((s = !0),
- i.push(
- cc.callFunc(() => {
- (c._aniDelRuning = !1), h(l);
- })
- )),
- 1 < i.length ? d.runAction(cc.sequence(i)) : d.runAction(i[0]));
- s || ((c._aniDelRuning = !1), h(l));
- }, !0
- );
- } else h(l);
- }
- scrollTo(o, a = 0.5, n = null, r = !1) {
- let l = this;
- if (l.checkInited(!1)) {
- null == a ? (a = 0.5) : a < 0 && (a = 0),
- o < 0 ? (o = 0) : o >= l._numItems && (o = l._numItems - 1), !l._virtual && l._layout && l._layout.enabled && l._layout.updateLayout();
- let t,
- e,
- i = l.getItemPos(o);
- switch (l._alignCalcType) {
- case 1:
- (t = i.left), (t -= null != n ? l.node.width * n : l._leftGap), (i = cc.v2(t, 0));
- break;
- case 2:
- (t = i.right - l.node.width),
- (t += null != n ? l.node.width * n : l._rightGap),
- (i = cc.v2(t + l.content.width, 0));
- break;
- case 3:
- (e = i.top), (e += null != n ? l.node.height * n : l._topGap), (i = cc.v2(0, -e));
- break;
- case 4:
- (e = i.bottom + l.node.height),
- (e -= null != n ? l.node.height * n : l._bottomGap),
- (i = cc.v2(0, -e + l.content.height));
- }
- let s = l.content.getPosition();
- s = Math.abs(l._sizeType ? s.y : s.x);
- var h = l._sizeType ? i.y : i.x;
- 0.5 < Math.abs((null != l._scrollPos ? l._scrollPos : s) - h) &&
- (l._scrollView.scrollToOffset(i, a),
- (l._scrollToListId = o),
- (l._scrollToEndTime = new Date().getTime() / 1e3 + a),
- (l._scrollToSo = l.scheduleOnce(() => {
- if (
- (l._adheringBarrier || (l.adhering = l._adheringBarrier = !1),
- (l._scrollPos = l._scrollToListId = l._scrollToEndTime = l._scrollToSo = null),
- r)
- ) {
- let t = l.getItemByListId(o);
- t && t.runAction(cc.sequence(cc.scaleTo(0.1, 1.05), cc.scaleTo(0.1, 1)));
- }
- }, a + 0.1)),
- a <= 0 && l._onScrolling());
- }
- }
- _calcNearestItem() {
- let e,
- i,
- s,
- o,
- a,
- n,
- r = this;
- (r.nearestListId = null),
- r._virtual && r._calcViewPos(),
- (s = r.viewTop),
- (o = r.viewRight),
- (a = r.viewBottom),
- (n = r.viewLeft);
- let l = !1;
- for (let t = 0; t < r.content.childrenCount && !l; t += r._colLineNum)
- if ((e = r._virtual ? r.displayData[t] : r._calcExistItemPos(t)))
- switch (((i = r._sizeType ? (e.top + e.bottom) / 2 : (e.left + e.right) / 2), r._alignCalcType)) {
- case 1:
- e.right >= n &&
- ((r.nearestListId = e.id), n > i && (r.nearestListId += r._colLineNum), (l = !0));
- break;
- case 2:
- e.left <= o &&
- ((r.nearestListId = e.id), o < i && (r.nearestListId += r._colLineNum), (l = !0));
- break;
- case 3:
- e.bottom <= s &&
- ((r.nearestListId = e.id), s < i && (r.nearestListId += r._colLineNum), (l = !0));
- break;
- case 4:
- e.top >= a && ((r.nearestListId = e.id), a > i && (r.nearestListId += r._colLineNum), (l = !0));
- }
- if (
- (e = r._virtual ? r.displayData[r.displayItemNum - 1] : r._calcExistItemPos(r._numItems - 1)) &&
- e.id == r._numItems - 1
- )
- switch (((i = r._sizeType ? (e.top + e.bottom) / 2 : (e.left + e.right) / 2), r._alignCalcType)) {
- case 1:
- o > i && (r.nearestListId = e.id);
- break;
- case 2:
- n < i && (r.nearestListId = e.id);
- break;
- case 3:
- a < i && (r.nearestListId = e.id);
- break;
- case 4:
- s > i && (r.nearestListId = e.id);
- }
- }
- prePage(t = 0.5) {
- this.checkInited() && this.skipPage(this.curPageNum - 1, t);
- }
- nextPage(t = 0.5) {
- this.checkInited() && this.skipPage(this.curPageNum + 1, t);
- }
- skipPage(t, e) {
- if (this.checkInited())
- return this._slideMode != o.PAGE ?
- cc.error("This function is not allowed to be called, Must SlideMode = PAGE!") :
- void(
- t < 0 ||
- t >= this._numItems ||
- (this.curPageNum != t &&
- ((this.curPageNum = t),
- this.pageChangeEvent && cc.Component.EventHandler.emitEvents([this.pageChangeEvent], t),
- this.scrollTo(t, e)))
- );
- }
- calcCustomSize(i) {
- var s = this;
- if (s.checkInited()) {
- if (!s._itemTmp) return cc.error("Unset template item!");
- if (!s.renderEvent) return cc.error("Unset Render-Event!");
- s._customSize = {};
- let e = cc.instantiate(s._itemTmp);
- s.content.addChild(e);
- for (let t = 0; t < i; t++)
- cc.Component.EventHandler.emitEvents([s.renderEvent], e, t),
- (e.height == s._itemSize.height && e.width == s._itemSize.width) ||
- (s._customSize[t] = s._sizeType ? e.height : e.width);
- return (
- Object.keys(s._customSize).length || (s._customSize = null),
- e.removeFromParent(),
- e.destroy && e.destroy(),
- s._customSize
- );
- }
- }
- };
- e([n({ type: cc.Enum(s) })], t.prototype, "templateType", void 0),
- e(
- [
- n({
- type: cc.Node,
- visible() {
- return this.templateType == s.NODE;
- }
- })
- ],
- t.prototype,
- "tmpNode",
- void 0
- ),
- e(
- [
- n({
- type: cc.Prefab,
- visible() {
- return this.templateType == s.PREFAB;
- }
- })
- ],
- t.prototype,
- "tmpPrefab",
- void 0
- ),
- e([n()], t.prototype, "_slideMode", void 0),
- e([n({ type: cc.Enum(o) })], t.prototype, "slideMode", null),
- e(
- [
- n({
- type: cc.Float,
- range: [0, 1, 0.1],
- slide: !0,
- visible() {
- return this._slideMode == o.PAGE;
- }
- })
- ],
- t.prototype,
- "pageDistance",
- void 0
- ),
- e(
- [
- n({
- type: cc.Component.EventHandler,
- visible() {
- return this._slideMode == o.PAGE;
- }
- })
- ],
- t.prototype,
- "pageChangeEvent",
- void 0
- ),
- e([n()], t.prototype, "_virtual", void 0),
- e([n({ type: cc.Boolean })], t.prototype, "virtual", null),
- e(
- [
- n({
- visible() {
- var t = this.virtual && this.slideMode == o.NORMAL;
- return t || (this.cyclic = !1), t;
- }
- })
- ],
- t.prototype,
- "cyclic",
- void 0
- ),
- e(
- [
- n({
- visible() {
- return this.virtual;
- }
- })
- ],
- t.prototype,
- "lackCenter",
- void 0
- ),
- e(
- [
- n({
- visible() {
- var t = this.virtual && !this.lackCenter;
- return t || (this.lackSlide = !1), t;
- }
- })
- ],
- t.prototype,
- "lackSlide",
- void 0
- ),
- e([n({ type: cc.Integer })], t.prototype, "_updateRate", void 0),
- e([n({ type: cc.Integer, range: [0, 6, 1], slide: !0 })], t.prototype, "updateRate", null),
- e([n({ type: cc.Integer, range: [0, 12, 1], slide: !0 })], t.prototype, "frameByFrameRenderNum", void 0),
- e([n({ type: cc.Component.EventHandler })], t.prototype, "renderEvent", void 0),
- e([n({ type: cc.Enum(u) })], t.prototype, "selectedMode", void 0),
- e(
- [
- n({
- visible() {
- return this.selectedMode == u.SINGLE;
- }
- })
- ],
- t.prototype,
- "repeatEventSingle",
- void 0
- ),
- e(
- [
- n({
- type: cc.Component.EventHandler,
- visible() {
- return this.selectedMode > u.NONE;
- }
- })
- ],
- t.prototype,
- "selectedEvent",
- void 0
- ),
- e([n({ serializable: !1 })], t.prototype, "_numItems", void 0),
- (t = e([a, r(), c(cc.ScrollView), h(-5e3)], t)),
- (i.default = t);
|