Exemplo n.º 1
0
 private void AddChildrenRecursive(BackendData.Foo foo, int numChildren, bool force)
 {
     if (this.IDCounter <= this.m_MaxItems)
     {
         if (foo.depth < 12)
         {
             if (force || UnityEngine.Random.value >= 0.5f)
             {
                 if (foo.children == null)
                 {
                     foo.children = new List <BackendData.Foo>(numChildren);
                 }
                 for (int i = 0; i < numChildren; i++)
                 {
                     BackendData.Foo foo2 = new BackendData.Foo("Tud" + this.IDCounter, foo.depth + 1, ++this.IDCounter);
                     foo2.parent = foo;
                     foo.children.Add(foo2);
                 }
                 if (this.IDCounter <= this.m_MaxItems)
                 {
                     foreach (BackendData.Foo current in foo.children)
                     {
                         this.AddChildrenRecursive(current, UnityEngine.Random.Range(3, 15), false);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        private HashSet <int> GetParentsBelowRecursive(BackendData.Foo searchFromThis)
        {
            HashSet <int> hashSet = new HashSet <int>();

            BackendData.GetParentsBelowRecursive(searchFromThis, hashSet);
            return(hashSet);
        }
Exemplo n.º 3
0
 public void ReparentSelection(BackendData.Foo parentItem, int insertionIndex, List <BackendData.Foo> draggedItems)
 {
     if (parentItem != null)
     {
         if (insertionIndex > 0)
         {
             insertionIndex -= parentItem.children.GetRange(0, insertionIndex).Count(new Func <BackendData.Foo, bool>(draggedItems.Contains));
         }
         foreach (BackendData.Foo current in draggedItems)
         {
             current.parent.children.Remove(current);
             current.parent = parentItem;
         }
         if (!parentItem.hasChildren)
         {
             parentItem.children = new List <BackendData.Foo>();
         }
         List <BackendData.Foo> list = new List <BackendData.Foo>(parentItem.children);
         if (insertionIndex == -1)
         {
             insertionIndex = 0;
         }
         list.InsertRange(insertionIndex, draggedItems);
         parentItem.children = list;
     }
 }
Exemplo n.º 4
0
 public static BackendData.Foo FindItemRecursive(BackendData.Foo item, int id)
 {
     BackendData.Foo result;
     if (item == null)
     {
         result = null;
     }
     else if (item.id == id)
     {
         result = item;
     }
     else if (item.children == null)
     {
         result = null;
     }
     else
     {
         foreach (BackendData.Foo current in item.children)
         {
             BackendData.Foo foo = BackendData.FindItemRecursive(current, id);
             if (foo != null)
             {
                 result = foo;
                 return(result);
             }
         }
         result = null;
     }
     return(result);
 }
Exemplo n.º 5
0
 public BackendData.Foo FindRecursive(int id, BackendData.Foo parent)
 {
     BackendData.Foo result;
     if (!parent.hasChildren)
     {
         result = null;
     }
     else
     {
         foreach (BackendData.Foo current in parent.children)
         {
             if (current.id == id)
             {
                 result = current;
                 return(result);
             }
             BackendData.Foo foo = this.FindRecursive(id, current);
             if (foo != null)
             {
                 result = foo;
                 return(result);
             }
         }
         result = null;
     }
     return(result);
 }
Exemplo n.º 6
0
 public void GenerateData(int maxNumItems)
 {
     this.m_MaxItems = maxNumItems;
     this.IDCounter  = 1;
     this.m_Root     = new BackendData.Foo("Root", 0, 0);
     for (int i = 0; i < 10; i++)
     {
         this.AddChildrenRecursive(this.m_Root, UnityEngine.Random.Range(3, 15), true);
     }
 }
Exemplo n.º 7
0
 private static void GetParentsBelowRecursive(BackendData.Foo item, HashSet <int> parentIDs)
 {
     if (item.hasChildren)
     {
         parentIDs.Add(item.id);
         foreach (BackendData.Foo current in item.children)
         {
             BackendData.GetParentsBelowRecursive(current, parentIDs);
         }
     }
 }
        protected override HashSet <int> GetParentsAbove(int id)
        {
            HashSet <int> hashSet = new HashSet <int>();

            for (BackendData.Foo foo = BackendData.FindItemRecursive(this.m_Backend.root, id); foo != null; foo = foo.parent)
            {
                if (foo.parent != null)
                {
                    hashSet.Add(foo.parent.id);
                }
            }
            return(hashSet);
        }
Exemplo n.º 9
0
        protected override void GetParentsAbove(int id, HashSet <int> parentsAbove)
        {
            BackendData.Foo target = BackendData.FindItemRecursive(m_Backend.root, id);

            while (target != null)
            {
                if (target.parent != null)
                {
                    parentsAbove.Add(target.parent.id);
                }
                target = target.parent;
            }
        }
 void AddChildrenRecursive(BackendData.Foo source, TreeViewItem dest)
 {
     if (source.hasChildren)
     {
         dest.children = new List <TreeViewItem>(source.children.Count);
         for (int i = 0; i < source.children.Count; ++i)
         {
             BackendData.Foo s = source.children[i];
             dest.children.Add(new FooTreeViewItem(s.id, dest.depth + 1, dest, s.name, s));
             itemCounter++;
             AddChildrenRecursive(s, dest.children[i]);
         }
     }
 }
Exemplo n.º 11
0
 private void AddChildrenRecursive(BackendData.Foo source, TreeViewItem dest)
 {
     if (source.hasChildren)
     {
         dest.children = new List <TreeViewItem>(source.children.Count);
         for (int i = 0; i < source.children.Count; i++)
         {
             BackendData.Foo foo = source.children[i];
             dest.children.Add(new FooTreeViewItem(foo.id, dest.depth + 1, dest, foo.name, foo));
             this.itemCounter++;
             this.AddChildrenRecursive(foo, dest.children[i]);
         }
     }
 }
        protected override HashSet <int> GetParentsAbove(int id)
        {
            HashSet <int> parentsAbove = new HashSet <int>();

            BackendData.Foo target = BackendData.FindItemRecursive(m_Backend.root, id);

            while (target != null)
            {
                if (target.parent != null)
                {
                    parentsAbove.Add(target.parent.id);
                }
                target = target.parent;
            }
            return(parentsAbove);
        }
Exemplo n.º 13
0
 private void AddVisibleChildrenRecursive(BackendData.Foo source, TreeViewItem dest)
 {
     if (this.IsExpanded(source.id))
     {
         if (source.children != null && source.children.Count > 0)
         {
             dest.children = new List <TreeViewItem>(source.children.Count);
             for (int i = 0; i < source.children.Count; i++)
             {
                 BackendData.Foo foo = source.children[i];
                 dest.children.Add(new FooTreeViewItem(foo.id, dest.depth + 1, dest, foo.name, foo));
                 this.itemCounter++;
                 this.AddVisibleChildrenRecursive(foo, dest.children[i]);
             }
         }
     }
     else if (source.hasChildren)
     {
         dest.children = LazyTreeViewDataSource.CreateChildListForCollapsedParent();
     }
 }
Exemplo n.º 14
0
        private HashSet <int> GetParentsBelowStackBased(BackendData.Foo searchFromThis)
        {
            Stack <BackendData.Foo> stack = new Stack <BackendData.Foo>();

            stack.Push(searchFromThis);
            HashSet <int> hashSet = new HashSet <int>();

            while (stack.Count > 0)
            {
                BackendData.Foo foo = stack.Pop();
                if (foo.hasChildren)
                {
                    hashSet.Add(foo.id);
                    foreach (BackendData.Foo current in foo.children)
                    {
                        stack.Push(current);
                    }
                }
            }
            return(hashSet);
        }
Exemplo n.º 15
0
        public HashSet <int> GetParentsBelow(int id)
        {
            BackendData.Foo foo = BackendData.FindItemRecursive(this.root, id);
            HashSet <int>   result;

            if (foo != null)
            {
                if (this.m_RecursiveFindParentsBelow)
                {
                    result = this.GetParentsBelowRecursive(foo);
                }
                else
                {
                    result = this.GetParentsBelowStackBased(foo);
                }
            }
            else
            {
                result = new HashSet <int>();
            }
            return(result);
        }
 void AddVisibleChildrenRecursive(BackendData.Foo source, TreeViewItem dest)
 {
     if (IsExpanded(source.id))
     {
         if (source.children != null && source.children.Count > 0)
         {
             dest.children = new List <TreeViewItem>(source.children.Count);
             for (int i = 0; i < source.children.Count; ++i)
             {
                 BackendData.Foo s = source.children[i];
                 dest.children.Add(new FooTreeViewItem(s.id, dest.depth + 1, dest, s.name, s));
                 ++itemCounter;
                 AddVisibleChildrenRecursive(s, dest.children[i]);
             }
         }
     }
     else
     {
         if (source.hasChildren)
         {
             dest.children = CreateChildListForCollapsedParent(); // ensure we show the collapse arrow (because we do not fetch data for collapsed items)
         }
     }
 }
Exemplo n.º 17
0
 public FooTreeViewItem(int id, int depth, TreeViewItem parent, string displayName, BackendData.Foo foo) : base(id, depth, parent, displayName)
 {
     this.foo = foo;
 }