Exemple #1
0
        public void SetSelectedItem(CTreeNode node)
        {
            CTreeNodeData nodeData = node.data;

            if (node.type == CTreeNode.NodeType.Leaf)
            {
                _openBranchIndex   = _dataProvider.IndexOf(nodeData.parent);
                _selectedLeafIndex = nodeData.parent.child.IndexOf(nodeData);
            }
            else
            {
                int tempIndex = _dataProvider.IndexOf(nodeData);
                if (tempIndex != _openBranchIndex)
                {
                    _selectedLeafIndex = autoSelectFirstLeaf ? 0 : -1;
                    node.isOpen        = true;
                    if (openBranch != null && onlyOneOpen)
                    {
                        openBranch.isOpen = false;
                    }
                    openBranch = node;
                }
                else if (openBranch != null)
                {
                    openBranch.isOpen = !openBranch.isOpen;
                }
                _openBranchIndex = tempIndex;
                ResetItems();
            }
        }
Exemple #2
0
 protected void OnItemPress(GameObject go, bool isPressed, bool needEvent)
 {
     if (isPressed)
     {
         CTreeNode c = go.GetDisplayObj() as CTreeNode;
         SelectedItem = c;
         if (OnItemSelect != null && needEvent)
         {
             if (_leafUsedList.Count == 0)
             {
                 return;
             }
             CTreeNode l = autoSelectFirstLeaf ? _leafUsedList[_selectedLeafIndex] : c;
             if (openLeaf != null)
             {
                 openLeaf.isOpen = false;
             }
             if (autoSelectFirstLeaf || c.type == CTreeNode.NodeType.Leaf)
             {
                 openLeaf        = l;
                 openLeaf.isOpen = true;
             }
             OnItemSelect(l);
             SetSelSp(l);
         }
     }
 }
Exemple #3
0
 private void SetSelSp(CTreeNode node)
 {
     if (node.type == CTreeNode.NodeType.Branch)
     {
         spSelected.transform.localPosition = new Vector3(PaddingLeft, spSelected.height + 100, 0);
     }
     else
     {
         spSelected.transform.localPosition = node.tran.localPosition;
     }
 }
Exemple #4
0
        public void RollTo(CTreeNode node)
        {
            float y = -node.y;

            if (TotalHeight > this.height && y > TotalHeight - this.height)
            {
                y = TotalHeight - this.height;
            }
            //contentPos.y = y;
            //maskOffset.y = -y;
            Bar.value = y / (TotalHeight - this.height);
        }
Exemple #5
0
 protected void OnItemHover(object go, bool isOver)
 {
     if (isOver)
     {
         CTreeNode node = ((GameObject)go).GetDisplayObj() as CTreeNode;
         if (node.type == CTreeNode.NodeType.Branch)
         {
             Overlay.SetDimensions(branchWidth, branchHeight);
         }
         else
         {
             Overlay.SetDimensions(leafWidth, leafHeight);
         }
         Overlay.transform.localPosition = ((GameObject)go).transform.localPosition;
     }
     else
     {
         Overlay.transform.localPosition = new Vector3(PaddingLeft, Overlay.height + 100, 0);
     }
 }
Exemple #6
0
        protected virtual void ResetItems()
        {
            CTreeNode branchItem;

            TotalHeight = 0;
            bool clearAllLeaf = true;
            int  chlidLen     = 0;

            if (_branchUsedList == null)
            {
                return;
            }
            for (int i = 0; i < _branchUsedList.Count; i++)
            {
                branchItem      = _branchUsedList[i];
                branchItem.name = "Item" + i;
                branchItem.data = _dataProvider[i];

                float itemY;
                itemY = -TotalHeight;
                branchItem.tran.localPosition = new Vector3(0, itemY, 0);
                EventUtil.AddHover(branchItem.go, OnItemHover);
                EventUtil.AddPress(branchItem.go, OnItemHover);
                UIEventListener listener = UIEventListener.Get(branchItem.go);
                listener.onHover = OnItemHover;
                listener.onPress = OnItemPress;
                TotalHeight     += branchHeight + branchGapU;
                if (branchItem.isOpen)
                {
                    int startIndex = chlidLen;
                    if (branchItem.data.child != null)
                    {
                        chlidLen += branchItem.data.child.Count;
                    }
                    if (chlidLen > 0)
                    {
                        clearAllLeaf = false;
                    }
                    for (int n = 0; (n + startIndex) < chlidLen; n++)
                    {
                        CTreeNode child;
                        if ((n + startIndex) < _leafUsedList.Count)
                        {
                            child = _leafUsedList[n + startIndex];
                        }
                        else
                        {
                            child = GetLeaf();
                        }
                        child.name = "Item" + i;
                        child.SetParent(Content.transform);
                        child.SetActive(true);
                        child.data = branchItem.data.child[n];

                        float childY;
                        childY = -TotalHeight;
                        child.tran.localPosition = new Vector3(0, childY, 0);

                        UIEventListener childListener = UIEventListener.Get(child.go);
                        childListener.onHover = OnItemHover;
                        childListener.onPress = OnItemPress;
                        TotalHeight          += _leafHeight + leafGapU;
                    }
                }
            }

            if (chlidLen < _leafUsedList.Count)
            {
                for (int j = _leafUsedList.Count - 1; j >= chlidLen; j--)
                {
                    CTreeNode temp = _leafUsedList[j];
                    temp.SetParent(Recycle);
                    _leafPool.Add(temp);
                    _leafUsedList.Remove(temp);
                }
            }
            if (clearAllLeaf)
            {
                for (int j = _leafUsedList.Count - 1; j >= 0; j--)
                {
                    CTreeNode temp = _leafUsedList[j];
                    temp.SetParent(Recycle);
                    _leafPool.Add(temp);
                    _leafUsedList.Remove(temp);
                }
            }
            spSelected.gameObject.SetActive(!clearAllLeaf);
            //if (_dataProvider == null) {
            //    TotalHeight = 0;
            //} else {
            //    float itemH = _branchHeight * _dataProvider.Count / float.Parse(ColNum.ToString());
            //        TotalHeight = PaddingTop + Mathf.CeilToInt(itemH) + PaddingBottom;
            //}

            //Bar.gameObject.SetActive(TotalHeight > height);
            //if (Bar.gameObject.activeSelf == true) {
            //    Bar.BarSize = (float)this.height / TotalHeight;
            //}
            CalculateHeight(TotalHeight);
            int barWidth = 0;

            if (Bar.gameObject.activeSelf == true)
            {
                barWidth = Bar.width;
            }
            Overlay.width          = this.width - barWidth;
            spSelected.width       = this.width - barWidth;
            Content.baseClipRegion = new Vector4((this.width - barWidth) / 2, -this.height / 2, this.width - barWidth, this.height);
        }