Beispiel #1
0
        public void ReflushAllCreatedGroup()
        {
            int curIndex = 0;

            if (mArrangeType == ListItemArrangeType.TopToBottom)
            {
                float curY = Mathf.Clamp(mContainerTrans.localPosition.y, 0, mMaxLocalPosition.y);
                curIndex = Mathf.FloorToInt(curY / mItemPaddingHeight);
            }
            else if (mArrangeType == ListItemArrangeType.BottomToTop)
            {
                float curY = Mathf.Clamp(-mContainerTrans.localPosition.y, 0, mMaxLocalPosition.y);
                curIndex = Mathf.FloorToInt(curY / mItemPaddingHeight);
            }
            else if (mArrangeType == ListItemArrangeType.RightToLeft)
            {
                float curX = Mathf.Clamp(mContainerTrans.localPosition.x, 0, mMaxLocalPosition.x);
                curIndex = Mathf.FloorToInt(curX / mItemPaddingWidth);
            }
            else if (mArrangeType == ListItemArrangeType.LeftToRight)
            {
                float curX = Mathf.Clamp(-mContainerTrans.localPosition.x, 0, mMaxLocalPosition.x);
                curIndex = Mathf.FloorToInt(curX / mItemPaddingWidth);
            }
            int count = mItemGroupList.Count;

            for (int i = 0; i < count; ++i)
            {
                LoopListItemGroup it = mItemGroupList[i];
                it.GroupIndex = i + curIndex;
                ResetGroupItemPos(it);
                UpdateGroupItems(it);
            }
        }
Beispiel #2
0
 void RecycleGroupItem(LoopListItemGroup group)
 {
     foreach (LoopListViewItem item in group.mItemList)
     {
         mItemPoolMgr.RecycleItem(item);
     }
     group.mItemList.Clear();
 }
Beispiel #3
0
        void ReflushAllCreatedGroup(int realHeadIndex)
        {
            if (realHeadIndex < 0)
            {
                realHeadIndex = 0;
            }
            int count = mItemGroupList.Count;

            for (int i = 0; i < count; ++i)
            {
                LoopListItemGroup it = mItemGroupList[i];
                it.GroupIndex = i + realHeadIndex;
                ResetGroupItemPos(it);
                UpdateGroupItems(it);
            }
        }
Beispiel #4
0
        void CreateItemGroup(int groupIndex)
        {
            LoopListItemGroup tGroup = new LoopListItemGroup();

            mItemGroupList.Add(tGroup);
            for (int i = 0; i < mItemCountPerGroup; ++i)
            {
                LoopListViewItem tViewItem = mItemPoolMgr.GetItem();
                RectTransform    rf        = tViewItem.GetComponent <RectTransform>();
                rf.SetParent(mContainerTrans);
                rf.localScale            = Vector3.one;
                rf.localPosition         = Vector3.zero;
                rf.rotation              = Quaternion.identity;
                tViewItem.ParentListView = this;
                tGroup.mItemList.Add(tViewItem);
            }
            tGroup.GroupIndex = groupIndex;
        }
Beispiel #5
0
        void OnGroupCreated(LoopListItemGroup group)
        {
            if (mOnItemCreated == null)
            {
                return;
            }
            int count = group.mItemList.Count;

            for (int i = 0; i < count; ++i)
            {
                LoopListViewItem tItem = group.mItemList[i];
                if (tItem.CreatedHandlerCalled == false)
                {
                    tItem.CreatedHandlerCalled = true;
                    mOnItemCreated(tItem);
                }
            }
        }
Beispiel #6
0
        void ResetGroupItemPos(LoopListItemGroup group)
        {
            int index = group.GroupIndex;
            int count = group.mItemList.Count;

            if (mIsVertList)
            {
                float y = (mArrangeType == ListItemArrangeType.TopToBottom)?(-index * mItemPaddingHeight) : (index * mItemPaddingHeight);
                for (int i = 0; i < count; ++i)
                {
                    group.mItemList[i].transform.localPosition = new Vector3(i * mItemPaddingWidth, y, 0.0f);
                }
            }
            else
            {
                float x = (mArrangeType == ListItemArrangeType.LeftToRight)?(index * mItemPaddingWidth) :(-index * mItemPaddingWidth);
                for (int i = 0; i < count; ++i)
                {
                    group.mItemList[i].transform.localPosition = new Vector3(x, -i * mItemPaddingHeight, 0.0f);
                }
            }
        }
Beispiel #7
0
        void UpdateGroupItems(LoopListItemGroup group)
        {
            if (mOnItemIndexUpdated == null)
            {
                return;
            }
            int count = group.mItemList.Count;

            for (int i = 0; i < count; ++i)
            {
                LoopListViewItem tViewItem = group.mItemList[i];
                if (tViewItem.ItemIndex >= mItemTotalCount)
                {
                    tViewItem.gameObject.SetActive(false);
                }
                else
                {
                    tViewItem.gameObject.SetActive(true);
                    mOnItemIndexUpdated(tViewItem);
                }
            }
        }
Beispiel #8
0
        void UpdateForVertList()
        {
            bool isUpScroll = mContainerTrans.localPosition.y > mLastPosY;

            mLastPosY = mContainerTrans.localPosition.y;
            if (mArrangeType == ListItemArrangeType.TopToBottom)
            {
                float curY     = Mathf.Clamp(mContainerTrans.localPosition.y, 0, mMaxLocalPosition.y);
                int   curIndex = Mathf.FloorToInt(curY / mItemPaddingHeight);
                if (mLastHeadGroupIndex == curIndex)
                {
                    return;
                }
                mLastHeadGroupIndex = curIndex;
                int count         = mItemGroupList.Count;
                int realHeadIndex = curIndex;
                if (isUpScroll)
                {
                    if (mItemGroupList[mItemGroupList.Count - 1].GroupIndex == mTotalItemGroupCount - 1)
                    {
                        return;
                    }
                    int indexDelta = realHeadIndex - mItemGroupList[0].GroupIndex;
                    if (indexDelta == 0)
                    {
                        return;
                    }
                    if (indexDelta > 0 && indexDelta <= mMoreCreateValue)
                    {
                        for (int i = 1; i < count; ++i)
                        {
                            LoopListItemGroup it = mItemGroupList[i];
                            if (it.GroupIndex != i + realHeadIndex - indexDelta)
                            {
                                ReflushAllCreatedGroup(realHeadIndex);
                                return;
                            }
                        }
                        for (int i = 1; i <= indexDelta; ++i)
                        {
                            LoopListItemGroup it0 = mItemGroupList[0];
                            if (it0.GroupIndex + count >= mTotalItemGroupCount)
                            {
                                break;
                            }
                            it0.GroupIndex = it0.GroupIndex + count;
                            mItemGroupList.RemoveAt(0);
                            mItemGroupList.Add(it0);
                            ResetGroupItemPos(it0);
                            UpdateGroupItems(it0);
                        }
                    }
                    else
                    {
                        ReflushAllCreatedGroup(realHeadIndex);
                    }
                }
                else
                {
                    if (mItemGroupList[0].GroupIndex == 0)
                    {
                        return;
                    }
                    float dist          = mContentSize.y - mListViewPortSize.y - curY;
                    int   index2        = Mathf.FloorToInt(dist / mItemPaddingHeight);
                    int   realTailIndex = mTotalItemGroupCount - index2 - 1;
                    int   indexDelta    = mItemGroupList[count - 1].GroupIndex - realTailIndex;
                    if (indexDelta == 0)
                    {
                        return;
                    }
                    if (indexDelta > 0 && indexDelta <= mMoreCreateValue)
                    {
                        for (int i = 1; i < count; ++i)
                        {
                            LoopListItemGroup it = mItemGroupList[count - i - 1];
                            if (it.GroupIndex != realTailIndex + indexDelta - i)
                            {
                                ReflushAllCreatedGroup(realTailIndex - count + 1);
                                return;
                            }
                        }

                        for (int i = 1; i <= indexDelta; ++i)
                        {
                            LoopListItemGroup it0 = mItemGroupList[count - 1];
                            if (it0.GroupIndex - count < 0)
                            {
                                break;
                            }
                            it0.GroupIndex = it0.GroupIndex - count;
                            mItemGroupList.RemoveAt(count - 1);
                            mItemGroupList.Insert(0, it0);
                            ResetGroupItemPos(it0);
                            UpdateGroupItems(it0);
                        }
                    }
                    else
                    {
                        ReflushAllCreatedGroup(realTailIndex - count + 1);
                    }
                }
            }
            else
            {
                float curY     = Mathf.Clamp(-mContainerTrans.localPosition.y, 0, mMaxLocalPosition.y);
                int   curIndex = Mathf.FloorToInt(curY / mItemPaddingHeight);
                if (mLastHeadGroupIndex == curIndex)
                {
                    return;
                }
                mLastHeadGroupIndex = curIndex;
                int count         = mItemGroupList.Count;
                int realHeadIndex = curIndex;
                if (!isUpScroll)
                {
                    if (mItemGroupList[mItemGroupList.Count - 1].GroupIndex == mTotalItemGroupCount - 1)
                    {
                        return;
                    }
                    int indexDelta = realHeadIndex - mItemGroupList[0].GroupIndex;
                    if (indexDelta == 0)
                    {
                        return;
                    }
                    if (indexDelta > 0 && indexDelta <= mMoreCreateValue)
                    {
                        for (int i = 1; i < count; ++i)
                        {
                            LoopListItemGroup it = mItemGroupList[i];
                            if (it.GroupIndex != i + realHeadIndex - indexDelta)
                            {
                                ReflushAllCreatedGroup(realHeadIndex);
                                return;
                            }
                        }
                        for (int i = 1; i <= indexDelta; ++i)
                        {
                            LoopListItemGroup it0 = mItemGroupList[0];
                            if (it0.GroupIndex + count >= mTotalItemGroupCount)
                            {
                                break;
                            }
                            it0.GroupIndex = it0.GroupIndex + count;
                            mItemGroupList.RemoveAt(0);
                            mItemGroupList.Add(it0);
                            ResetGroupItemPos(it0);
                            UpdateGroupItems(it0);
                        }
                    }
                    else
                    {
                        ReflushAllCreatedGroup(realHeadIndex);
                    }
                }
                else
                {
                    if (mItemGroupList[0].GroupIndex == 0)
                    {
                        return;
                    }
                    float dist          = mContentSize.y - mListViewPortSize.y - curY;
                    int   index2        = Mathf.FloorToInt(dist / mItemPaddingHeight);
                    int   realTailIndex = mTotalItemGroupCount - index2 - 1;
                    int   indexDelta    = mItemGroupList[count - 1].GroupIndex - realTailIndex;
                    if (indexDelta == 0)
                    {
                        return;
                    }
                    if (indexDelta > 0 && indexDelta <= mMoreCreateValue)
                    {
                        for (int i = 1; i < count; ++i)
                        {
                            LoopListItemGroup it = mItemGroupList[count - i - 1];
                            if (it.GroupIndex != realTailIndex + indexDelta - i)
                            {
                                ReflushAllCreatedGroup(realTailIndex - count + 1);
                                return;
                            }
                        }

                        for (int i = 1; i <= indexDelta; ++i)
                        {
                            LoopListItemGroup it0 = mItemGroupList[count - 1];
                            if (it0.GroupIndex - count < 0)
                            {
                                break;
                            }
                            it0.GroupIndex = it0.GroupIndex - count;
                            mItemGroupList.RemoveAt(count - 1);
                            mItemGroupList.Insert(0, it0);
                            ResetGroupItemPos(it0);
                            UpdateGroupItems(it0);
                        }
                    }
                    else
                    {
                        ReflushAllCreatedGroup(realTailIndex - count + 1);
                    }
                }
            }
        }