Пример #1
0
        void UpdateAllTreeItemDataIndex()
        {
            if (mIsDirty == false)
            {
                return;
            }
            mLastQueryResult = null;
            mIsDirty         = false;
            int count = mTreeItemDataList.Count;

            if (count == 0)
            {
                return;
            }
            TreeViewItemCountData data0 = mTreeItemDataList[0];

            data0.mBeginIndex = 0;
            data0.mEndIndex   = (data0.mIsExpand ? data0.mChildCount : 0);
            int curEnd = data0.mEndIndex;

            for (int i = 1; i < count; ++i)
            {
                TreeViewItemCountData data = mTreeItemDataList[i];
                data.mBeginIndex = curEnd + 1;
                data.mEndIndex   = data.mBeginIndex + (data.mIsExpand ? data.mChildCount : 0);
                curEnd           = data.mEndIndex;
            }
        }
Пример #2
0
        void OnAddNewBtnClicked()
        {
            int itemIndex  = 0;
            int childIndex = 0;

            if (int.TryParse(mAddNewInputItem.text, out itemIndex) == false)
            {
                return;
            }
            if (int.TryParse(mAddNewInputChild.text, out childIndex) == false)
            {
                childIndex = 0;
            }
            if (childIndex < 0)
            {
                childIndex = 0;
            }
            TreeViewItemCountData itemCountData = mTreeItemCountMgr.GetTreeItem(itemIndex);

            if (itemCountData == null)
            {
                return;
            }
            TreeViewDataSourceMgr.Get.AddNewItemChildForTest(itemIndex, childIndex);
            int childCount = itemCountData.mChildCount;

            mTreeItemCountMgr.SetItemChildCount(itemIndex, childCount + 1);
            mLoopListView.SetListItemCount(mTreeItemCountMgr.GetTotalItemAndChildCount(), false);
            mLoopListView.RefreshAllShownItem();
        }
        private void UpdateAllTreeItemDataIndex()
        {
            if (!this.mIsDirty)
            {
                return;
            }
            this.mLastQueryResult = (TreeViewItemCountData)null;
            this.mIsDirty         = false;
            int count = this.mTreeItemDataList.Count;

            if (count == 0)
            {
                return;
            }
            TreeViewItemCountData mTreeItemData1 = this.mTreeItemDataList[0];

            mTreeItemData1.mBeginIndex = 0;
            mTreeItemData1.mEndIndex   = !mTreeItemData1.mIsExpand ? 0 : mTreeItemData1.mChildCount;
            int mEndIndex = mTreeItemData1.mEndIndex;

            for (int index = 1; index < count; ++index)
            {
                TreeViewItemCountData mTreeItemData2 = this.mTreeItemDataList[index];
                mTreeItemData2.mBeginIndex = mEndIndex + 1;
                mTreeItemData2.mEndIndex   = mTreeItemData2.mBeginIndex + (!mTreeItemData2.mIsExpand ? 0 : mTreeItemData2.mChildCount);
                mEndIndex = mTreeItemData2.mEndIndex;
            }
        }
Пример #4
0
        public bool IsTreeItemExpand(int treeIndex)
        {
            TreeViewItemCountData data = GetTreeItem(treeIndex);

            if (data == null)
            {
                return(false);
            }
            return(data.mIsExpand);
        }
Пример #5
0
        public void AddTreeItem(int count, bool isExpand)
        {
            TreeViewItemCountData data = new TreeViewItemCountData();

            data.mTreeItemIndex = mTreeItemDataList.Count;
            data.mChildCount    = count;
            data.mIsExpand      = isExpand;
            mTreeItemDataList.Add(data);
            mIsDirty = true;
        }
Пример #6
0
        public void SetItemChildCount(int treeIndex, int count)
        {
            if (treeIndex < 0 || treeIndex >= mTreeItemDataList.Count)
            {
                return;
            }
            mIsDirty = true;
            TreeViewItemCountData data = mTreeItemDataList[treeIndex];

            data.mChildCount = count;
        }
Пример #7
0
        public void ToggleItemExpand(int treeIndex)
        {
            if (treeIndex < 0 || treeIndex >= mTreeItemDataList.Count)
            {
                return;
            }
            mIsDirty = true;
            TreeViewItemCountData data = mTreeItemDataList[treeIndex];

            data.mIsExpand = !data.mIsExpand;
        }
        LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index)
        {
            if (index < 0)
            {
                return(null);
            }

            TreeViewItemCountData countData = mTreeItemCountMgr.QueryTreeItemByTotalIndex(index);

            if (countData == null)
            {
                return(null);
            }
            int treeItemIndex = countData.mTreeItemIndex;
            TreeViewItemData treeViewItemData = TreeViewDataSourceMgr.Get.GetItemDataByIndex(treeItemIndex);

            if (index == countData.mBeginIndex)
            {
                LoopListViewItem2 item       = listView.NewListViewItem("ItemPrefab1");
                ListItem12        itemScript = item.GetComponent <ListItem12>();
                if (item.IsInitHandlerCalled == false)
                {
                    item.IsInitHandlerCalled = true;
                    itemScript.Init();
                    itemScript.SetClickCallBack(this.OnExpandClicked);
                }
                item.UserIntData1     = treeItemIndex;
                item.UserIntData2     = 0;
                itemScript.mText.text = treeViewItemData.mName;
                itemScript.SetItemData(treeItemIndex, countData.mIsExpand);
                return(item);
            }
            else
            {
                int      childIndex = index - countData.mBeginIndex - 1;
                ItemData itemData   = treeViewItemData.GetChild(childIndex);
                if (itemData == null)
                {
                    return(null);
                }
                LoopListViewItem2 item       = listView.NewListViewItem("ItemPrefab2");
                ListItem13        itemScript = item.GetComponent <ListItem13>();
                if (item.IsInitHandlerCalled == false)
                {
                    item.IsInitHandlerCalled = true;
                    itemScript.Init();
                }
                item.UserIntData1 = treeItemIndex;
                item.UserIntData2 = childIndex;
                itemScript.SetItemData(itemData, treeItemIndex, childIndex);
                return(item);
            }
        }
        private LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index)
        {
            if (index < 0)
            {
                return((LoopListViewItem2)null);
            }
            TreeViewItemCountData viewItemCountData = this.mTreeItemCountMgr.QueryTreeItemByTotalIndex(index);

            if (viewItemCountData == null)
            {
                return((LoopListViewItem2)null);
            }
            int mTreeItemIndex = viewItemCountData.mTreeItemIndex;
            TreeViewItemData itemDataByIndex = TreeViewDataSourceMgr.Get.GetItemDataByIndex(mTreeItemIndex);

            if (!viewItemCountData.IsChild(index))
            {
                LoopListViewItem2 loopListViewItem2 = listView.NewListViewItem("ItemPrefab1");
                ListItem12        component         = (ListItem12)((Component)loopListViewItem2).GetComponent <ListItem12>();
                if (!loopListViewItem2.IsInitHandlerCalled)
                {
                    loopListViewItem2.IsInitHandlerCalled = true;
                    component.Init();
                    component.SetClickCallBack(new Action <int>(this.OnExpandClicked));
                }
                loopListViewItem2.UserIntData1 = mTreeItemIndex;
                loopListViewItem2.UserIntData2 = 0;
                component.mText.set_text(itemDataByIndex.mName);
                component.SetItemData(mTreeItemIndex, viewItemCountData.mIsExpand);
                return(loopListViewItem2);
            }
            int      childIndex = viewItemCountData.GetChildIndex(index);
            ItemData child      = itemDataByIndex.GetChild(childIndex);

            if (child == null)
            {
                return((LoopListViewItem2)null);
            }
            LoopListViewItem2 loopListViewItem2_1 = listView.NewListViewItem("ItemPrefab2");
            ListItem13        component1          = (ListItem13)((Component)loopListViewItem2_1).GetComponent <ListItem13>();

            if (!loopListViewItem2_1.IsInitHandlerCalled)
            {
                loopListViewItem2_1.IsInitHandlerCalled = true;
                component1.Init();
            }
            loopListViewItem2_1.UserIntData1 = mTreeItemIndex;
            loopListViewItem2_1.UserIntData2 = childIndex;
            component1.SetItemData(child, mTreeItemIndex, childIndex);
            return(loopListViewItem2_1);
        }
Пример #10
0
        public TreeViewItemCountData QueryTreeItemByTotalIndex(int totalIndex)
        {
            if (totalIndex < 0)
            {
                return(null);
            }
            int count = mTreeItemDataList.Count;

            if (count == 0)
            {
                return(null);
            }
            UpdateAllTreeItemDataIndex();
            if (mLastQueryResult != null)
            {
                if (mLastQueryResult.mBeginIndex <= totalIndex && mLastQueryResult.mEndIndex >= totalIndex)
                {
                    return(mLastQueryResult);
                }
            }
            int low  = 0;
            int high = count - 1;
            TreeViewItemCountData data = null;

            while (low <= high)
            {
                int mid = (low + high) / 2;
                data = mTreeItemDataList[mid];
                if (data.mBeginIndex <= totalIndex && data.mEndIndex >= totalIndex)
                {
                    mLastQueryResult = data;
                    return(data);
                }
                else if (totalIndex > data.mEndIndex)
                {
                    low = mid + 1;
                }
                else
                {
                    high = mid - 1;
                }
            }
            return(null);
        }
Пример #11
0
        private void OnJumpBtnClicked()
        {
            int result1 = 0;
            int result2 = 0;

            if (!int.TryParse(this.mScrollToInputItem.get_text(), out result1))
            {
                return;
            }
            if (!int.TryParse(this.mScrollToInputChild.get_text(), out result2))
            {
                result2 = 0;
            }
            if (result2 < 0)
            {
                result2 = 0;
            }
            TreeViewItemCountData treeItem = this.mTreeItemCountMgr.GetTreeItem(result1);

            if (treeItem == null)
            {
                return;
            }
            int mChildCount = treeItem.mChildCount;
            int itemIndex;

            if (!treeItem.mIsExpand || mChildCount == 0 || result2 == 0)
            {
                itemIndex = treeItem.mBeginIndex;
            }
            else
            {
                if (result2 > mChildCount)
                {
                    result2 = mChildCount;
                }
                if (result2 < 1)
                {
                    result2 = 1;
                }
                itemIndex = treeItem.mBeginIndex + result2;
            }
            this.mLoopListView.MovePanelToItemIndex(itemIndex, 0.0f);
        }
Пример #12
0
        void OnJumpBtnClicked()
        {
            int itemIndex  = 0;
            int childIndex = 0;
            int finalIndex = 0;

            if (int.TryParse(mScrollToInputItem.text, out itemIndex) == false)
            {
                return;
            }
            if (int.TryParse(mScrollToInputChild.text, out childIndex) == false)
            {
                childIndex = 0;
            }
            if (childIndex < 0)
            {
                childIndex = 0;
            }
            TreeViewItemCountData itemCountData = mTreeItemCountMgr.GetTreeItem(itemIndex);

            if (itemCountData == null)
            {
                return;
            }
            int childCount = itemCountData.mChildCount;

            if (itemCountData.mIsExpand == false || childCount == 0 || childIndex == 0)
            {
                finalIndex = itemCountData.mBeginIndex;
            }
            else
            {
                if (childIndex > childCount)
                {
                    childIndex = childCount;
                }
                if (childIndex < 1)
                {
                    childIndex = 1;
                }
                finalIndex = itemCountData.mBeginIndex + childIndex;
            }
            mLoopListView.MovePanelToItemIndex(finalIndex, 0);
        }
        public TreeViewItemCountData QueryTreeItemByTotalIndex(int totalIndex)
        {
            if (totalIndex < 0)
            {
                return((TreeViewItemCountData)null);
            }
            int count = this.mTreeItemDataList.Count;

            if (count == 0)
            {
                return((TreeViewItemCountData)null);
            }
            this.UpdateAllTreeItemDataIndex();
            if (this.mLastQueryResult != null && this.mLastQueryResult.mBeginIndex <= totalIndex && this.mLastQueryResult.mEndIndex >= totalIndex)
            {
                return(this.mLastQueryResult);
            }
            int num1 = 0;
            int num2 = count - 1;

            while (num1 <= num2)
            {
                int index = (num1 + num2) / 2;
                TreeViewItemCountData mTreeItemData = this.mTreeItemDataList[index];
                if (mTreeItemData.mBeginIndex <= totalIndex && mTreeItemData.mEndIndex >= totalIndex)
                {
                    this.mLastQueryResult = mTreeItemData;
                    return(mTreeItemData);
                }
                if (totalIndex > mTreeItemData.mEndIndex)
                {
                    num1 = index + 1;
                }
                else
                {
                    num2 = index - 1;
                }
            }
            return((TreeViewItemCountData)null);
        }
Пример #14
0
        //when a TreeItem or TreeChildItem is getting in the scrollrect viewport,
        //this method will be called with the item’ index as a parameter,
        //to let you create the item and update its content.
        LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index)
        {
            if (index < 0)
            {
                return(null);
            }

            /*to check the index'th item is a TreeItem or a TreeChildItem.for example,
             *
             * 0  TreeItem0
             * 1      TreeChildItem0_0
             * 2      TreeChildItem0_1
             * 3      TreeChildItem0_2
             * 4      TreeChildItem0_3
             * 5  TreeItem1
             * 6      TreeChildItem1_0
             * 7      TreeChildItem1_1
             * 8      TreeChildItem1_2
             * 9  TreeItem2
             * 10     TreeChildItem2_0
             * 11     TreeChildItem2_1
             * 12     TreeChildItem2_2
             *
             * the first column value is the param 'index', for example, if index is 1,
             * then we should return TreeChildItem0_0 to SuperScrollView, and if index is 5,
             * then we should return TreeItem1 to SuperScrollView
             */

            TreeViewItemCountData countData = mTreeItemCountMgr.QueryTreeItemByTotalIndex(index);

            if (countData == null)
            {
                return(null);
            }
            int treeItemIndex = countData.mTreeItemIndex;
            TreeViewItemData treeViewItemData = TreeViewDataSourceMgr.Get.GetItemDataByIndex(treeItemIndex);

            if (countData.IsChild(index) == false)// if is a TreeItem
            {
                //get a new TreeItem
                LoopListViewItem2 item       = listView.NewListViewItem("ItemPrefab1");
                ListItem12        itemScript = item.GetComponent <ListItem12>();
                if (item.IsInitHandlerCalled == false)
                {
                    item.IsInitHandlerCalled = true;
                    itemScript.Init();
                    itemScript.SetClickCallBack(this.OnExpandClicked);
                }
                //update the TreeItem's content
                itemScript.mText.text = treeViewItemData.mName;
                itemScript.SetItemData(treeItemIndex, countData.mIsExpand);
                return(item);
            }
            else // if is a TreeChildItem
            {
                //childIndex is from 0 to ChildCount.
                //for example, TreeChildItem0_0 is the 0'th child of TreeItem0
                //and TreeChildItem1_2 is the 2'th child of TreeItem1
                int      childIndex = countData.GetChildIndex(index);
                ItemData itemData   = treeViewItemData.GetChild(childIndex);
                if (itemData == null)
                {
                    return(null);
                }
                //get a new TreeChildItem
                LoopListViewItem2 item       = listView.NewListViewItem("ItemPrefab2");
                ListItem13        itemScript = item.GetComponent <ListItem13>();
                if (item.IsInitHandlerCalled == false)
                {
                    item.IsInitHandlerCalled = true;
                    itemScript.Init();
                }
                //update the TreeChildItem's content
                itemScript.SetItemData(itemData, treeItemIndex, childIndex);
                return(item);
            }
        }
        public bool IsTreeItemExpand(int treeIndex)
        {
            TreeViewItemCountData treeItem = this.GetTreeItem(treeIndex);

            return(treeItem != null && treeItem.mIsExpand);
        }
Пример #16
0
        void UpdateStickeyHeadPos()
        {
            bool isHeadItemVisible = mStickeyHeadItem.gameObject.activeSelf;
            int  count             = mLoopListView.ShownItemCount;

            if (count == 0)
            {
                if (isHeadItemVisible)
                {
                    mStickeyHeadItem.gameObject.SetActive(false);
                }
                return;
            }
            LoopListViewItem2 item0   = mLoopListView.GetShownItemByIndex(0);
            Vector3           topPos0 = mLoopListView.GetItemCornerPosInViewPort(item0, ItemCornerEnum.LeftTop);

            LoopListViewItem2 targetItem = null;
            float             start      = topPos0.y;
            float             end        = start - item0.ItemSizeWithPadding;
            int targetItemShownIndex     = -1;

            if (start <= 0)
            {
                if (isHeadItemVisible)
                {
                    mStickeyHeadItem.gameObject.SetActive(false);
                }
                return;
            }
            if (end < 0)
            {
                targetItem           = item0;
                targetItemShownIndex = 0;
            }
            else
            {
                for (int i = 1; i < count; ++i)
                {
                    LoopListViewItem2 item = mLoopListView.GetShownItemByIndexWithoutCheck(i);
                    start = end;
                    end   = start - item.ItemSizeWithPadding;
                    if (start >= 0 && end <= 0)
                    {
                        targetItem           = item;
                        targetItemShownIndex = i;
                        break;
                    }
                }
            }
            if (targetItem == null)
            {
                if (isHeadItemVisible)
                {
                    mStickeyHeadItem.gameObject.SetActive(false);
                }
                return;
            }
            int itemIndex  = targetItem.UserIntData1;
            int childIndex = targetItem.UserIntData2;
            TreeViewItemCountData countData = mTreeItemCountMgr.GetTreeItem(itemIndex);

            if (countData == null)
            {
                if (isHeadItemVisible)
                {
                    mStickeyHeadItem.gameObject.SetActive(false);
                }
                return;
            }
            if (countData.mIsExpand == false || countData.mChildCount == 0)
            {
                if (isHeadItemVisible)
                {
                    mStickeyHeadItem.gameObject.SetActive(false);
                }
                return;
            }
            if (isHeadItemVisible == false)
            {
                mStickeyHeadItem.gameObject.SetActive(true);
            }
            if (mStickeyHeadItem.TreeItemIndex != itemIndex)
            {
                TreeViewItemData treeViewItemData = TreeViewDataSourceMgr.Get.GetItemDataByIndex(itemIndex);
                mStickeyHeadItem.mText.text = treeViewItemData.mName;
                mStickeyHeadItem.SetItemData(itemIndex, countData.mIsExpand);
            }
            mStickeyHeadItem.gameObject.transform.localPosition = Vector3.zero;
            float lastChildPosAbs = -end;
            float lastPadding     = targetItem.Padding;

            if (lastChildPosAbs - lastPadding >= mStickeyHeadItemHeight)
            {
                return;
            }
            for (int i = targetItemShownIndex + 1; i < count; ++i)
            {
                LoopListViewItem2 item = mLoopListView.GetShownItemByIndexWithoutCheck(i);
                if (item.UserIntData1 != itemIndex)
                {
                    break;
                }
                lastChildPosAbs += item.ItemSizeWithPadding;
                lastPadding      = item.Padding;
                if (lastChildPosAbs - lastPadding >= mStickeyHeadItemHeight)
                {
                    return;
                }
            }
            float y = mStickeyHeadItemHeight - (lastChildPosAbs - lastPadding);

            mStickeyHeadItemRf.anchoredPosition3D = new Vector3(0, y, 0);
        }
        private void UpdateStickeyHeadPos()
        {
            bool activeSelf     = ((Component)this.mStickeyHeadItem).get_gameObject().get_activeSelf();
            int  shownItemCount = this.mLoopListView.ShownItemCount;

            if (shownItemCount == 0)
            {
                if (!activeSelf)
                {
                    return;
                }
                ((Component)this.mStickeyHeadItem).get_gameObject().SetActive(false);
            }
            else
            {
                LoopListViewItem2 shownItemByIndex    = this.mLoopListView.GetShownItemByIndex(0);
                Vector3           cornerPosInViewPort = this.mLoopListView.GetItemCornerPosInViewPort(shownItemByIndex, ItemCornerEnum.LeftTop);
                LoopListViewItem2 loopListViewItem2   = (LoopListViewItem2)null;
                float             y    = (float)cornerPosInViewPort.y;
                float             num1 = y - shownItemByIndex.ItemSizeWithPadding;
                int num2 = -1;
                if ((double)y <= 0.0)
                {
                    if (!activeSelf)
                    {
                        return;
                    }
                    ((Component)this.mStickeyHeadItem).get_gameObject().SetActive(false);
                }
                else
                {
                    if ((double)num1 < 0.0)
                    {
                        loopListViewItem2 = shownItemByIndex;
                        num2 = 0;
                    }
                    else
                    {
                        for (int index = 1; index < shownItemCount; ++index)
                        {
                            LoopListViewItem2 indexWithoutCheck = this.mLoopListView.GetShownItemByIndexWithoutCheck(index);
                            float             num3 = num1;
                            num1 = num3 - indexWithoutCheck.ItemSizeWithPadding;
                            if ((double)num3 >= 0.0 && (double)num1 <= 0.0)
                            {
                                loopListViewItem2 = indexWithoutCheck;
                                num2 = index;
                                break;
                            }
                        }
                    }
                    if (Object.op_Equality((Object)loopListViewItem2, (Object)null))
                    {
                        if (!activeSelf)
                        {
                            return;
                        }
                        ((Component)this.mStickeyHeadItem).get_gameObject().SetActive(false);
                    }
                    else
                    {
                        int userIntData1 = loopListViewItem2.UserIntData1;
                        int userIntData2 = loopListViewItem2.UserIntData2;
                        TreeViewItemCountData treeItem = this.mTreeItemCountMgr.GetTreeItem(userIntData1);
                        if (treeItem == null)
                        {
                            if (!activeSelf)
                            {
                                return;
                            }
                            ((Component)this.mStickeyHeadItem).get_gameObject().SetActive(false);
                        }
                        else if (!treeItem.mIsExpand || treeItem.mChildCount == 0)
                        {
                            if (!activeSelf)
                            {
                                return;
                            }
                            ((Component)this.mStickeyHeadItem).get_gameObject().SetActive(false);
                        }
                        else
                        {
                            if (!activeSelf)
                            {
                                ((Component)this.mStickeyHeadItem).get_gameObject().SetActive(true);
                            }
                            if (this.mStickeyHeadItem.TreeItemIndex != userIntData1)
                            {
                                this.mStickeyHeadItem.mText.set_text(TreeViewDataSourceMgr.Get.GetItemDataByIndex(userIntData1).mName);
                                this.mStickeyHeadItem.SetItemData(userIntData1, treeItem.mIsExpand);
                            }
                            ((Component)this.mStickeyHeadItem).get_gameObject().get_transform().set_localPosition(Vector3.get_zero());
                            float num3    = -num1;
                            float padding = loopListViewItem2.Padding;
                            if ((double)num3 - (double)padding >= (double)this.mStickeyHeadItemHeight)
                            {
                                return;
                            }
                            for (int index = num2 + 1; index < shownItemCount; ++index)
                            {
                                LoopListViewItem2 indexWithoutCheck = this.mLoopListView.GetShownItemByIndexWithoutCheck(index);
                                if (indexWithoutCheck.UserIntData1 == userIntData1)
                                {
                                    num3   += indexWithoutCheck.ItemSizeWithPadding;
                                    padding = indexWithoutCheck.Padding;
                                    if ((double)num3 - (double)padding >= (double)this.mStickeyHeadItemHeight)
                                    {
                                        return;
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                            this.mStickeyHeadItemRf.set_anchoredPosition3D(new Vector3(0.0f, this.mStickeyHeadItemHeight - (num3 - padding), 0.0f));
                        }
                    }
                }
            }
        }
 public void Clear()
 {
     this.mTreeItemDataList.Clear();
     this.mLastQueryResult = (TreeViewItemCountData)null;
     this.mIsDirty         = true;
 }
Пример #19
0
 public void Clear()
 {
     mTreeItemDataList.Clear();
     mLastQueryResult = null;
     mIsDirty         = true;
 }