Esempio n. 1
0
        public void AddNewItemChildForTest(int itemIndex, int AddToBeforeChildIndex)
        {
            if (itemIndex < 0 || itemIndex >= mItemDataList.Count)
            {
                return;
            }
            TreeViewItemData tData             = mItemDataList[itemIndex];
            List <ItemData>  childItemDataList = tData.mChildItemDataList;
            ItemData         childItemData     = new ItemData();

            childItemData.mName      = "New Added Item" + itemIndex + ":" + AddToBeforeChildIndex;
            childItemData.mDesc      = "Item Desc For " + childItemData.mName;
            childItemData.mIcon      = ResManager.Get.GetSpriteNameByIndex(Random.Range(0, 24));
            childItemData.mStarCount = Random.Range(0, 6);
            childItemData.mFileSize  = Random.Range(20, 999);
            if (AddToBeforeChildIndex < 0)
            {
                childItemDataList.Insert(0, childItemData);
            }
            else if (AddToBeforeChildIndex >= childItemDataList.Count)
            {
                childItemDataList.Add(childItemData);
            }
            else
            {
                childItemDataList.Insert(AddToBeforeChildIndex, childItemData);
            }
        }
Esempio n. 2
0
        public ItemData GetItemChildDataByIndex(int itemIndex, int childIndex)
        {
            TreeViewItemData data = GetItemDataByIndex(itemIndex);

            if (data == null)
            {
                return(null);
            }
            return(data.GetChild(childIndex));
        }
        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);
        }
Esempio n. 5
0
 void DoRefreshDataSource()
 {
     mItemDataList.Clear();
     for (int i = 0; i < mTreeViewItemCount; ++i)
     {
         TreeViewItemData tData = new TreeViewItemData();
         tData.mName = "Item" + i;
         tData.mIcon = ResManager.Get.GetSpriteNameByIndex(Random.Range(0, 24));
         mItemDataList.Add(tData);
         int childCount = mTreeViewChildItemCount;
         for (int j = 1; j <= childCount; ++j)
         {
             ItemData childItemData = new ItemData();
             childItemData.mName      = "Item" + i + ":Child" + j;
             childItemData.mDesc      = "Item Desc For " + childItemData.mName;
             childItemData.mIcon      = ResManager.Get.GetSpriteNameByIndex(Random.Range(0, 24));
             childItemData.mStarCount = Random.Range(0, 6);
             childItemData.mFileSize  = Random.Range(20, 999);
             tData.AddChild(childItemData);
         }
     }
 }
 private void DoRefreshDataSource()
 {
     this.mItemDataList.Clear();
     for (int index1 = 0; index1 < this.mTreeViewItemCount; ++index1)
     {
         TreeViewItemData treeViewItemData = new TreeViewItemData();
         treeViewItemData.mName = "Item" + (object)index1;
         treeViewItemData.mIcon = ResManager.Get.GetSpriteNameByIndex(Random.Range(0, 24));
         this.mItemDataList.Add(treeViewItemData);
         int viewChildItemCount = this.mTreeViewChildItemCount;
         for (int index2 = 1; index2 <= viewChildItemCount; ++index2)
         {
             ItemData data = new ItemData()
             {
                 mName = "Item" + (object)index1 + ":Child" + (object)index2
             };
             data.mDesc      = "Item Desc For " + data.mName;
             data.mIcon      = ResManager.Get.GetSpriteNameByIndex(Random.Range(0, 24));
             data.mStarCount = Random.Range(0, 6);
             data.mFileSize  = Random.Range(20, 999);
             treeViewItemData.AddChild(data);
         }
     }
 }
Esempio n. 7
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);
            }
        }
Esempio n. 8
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);
        }