예제 #1
0
                /// <summary>
                /// Used internally quickly register a list of child nodes to a parent.
                /// </summary>
                public static void RegisterNodes <TCon, TNode>(HudParentBase newParent, List <HudNodeBase> children, IReadOnlyList <TCon> nodes, bool canPreload)
                    where TCon : IHudElementContainer <TNode>, new()
                    where TNode : HudNodeBase
                {
                    children.EnsureCapacity(children.Count + nodes.Count);

                    for (int n = 0; n < nodes.Count; n++)
                    {
                        HudNodeBase node = nodes[n].Element;
                        node.Parent        = newParent;
                        node.State        |= HudElementStates.IsRegistered;
                        node.ParentVisible = newParent.Visible;

                        children.Add(node);

                        if (canPreload)
                        {
                            node.State |= HudElementStates.CanPreload;
                        }
                        else
                        {
                            node.State &= ~HudElementStates.CanPreload;
                        }
                    }
                }
예제 #2
0
                /// <summary>
                /// Used internally to quickly unregister child nodes from their parent. Removes the range of nodes
                /// specified in the node list from the child list.
                /// </summary>
                public static void UnregisterNodes <TCon, TNode>(HudParentBase parent, List <HudNodeBase> children, IReadOnlyList <TCon> nodes, int index, int count)
                    where TCon : IHudElementContainer <TNode>, new()
                    where TNode : HudNodeBase
                {
                    if (count > 0)
                    {
                        int conEnd = index + count - 1;

                        if (!(index >= 0 && index < nodes.Count && conEnd <= nodes.Count))
                        {
                            throw new Exception("Specified indices are out of range.");
                        }

                        if (parent == null)
                        {
                            throw new Exception("Parent cannot be null");
                        }

                        for (int i = index; i <= conEnd; i++)
                        {
                            int start = 0;

                            while (start < children.Count && children[start] != nodes[i].Element)
                            {
                                start++;
                            }

                            if (children[start] == nodes[i].Element)
                            {
                                int j = start, end = start;

                                while (j < children.Count && i <= conEnd && children[j] == nodes[i].Element)
                                {
                                    end = j;
                                    i++;
                                    j++;
                                }

                                children.RemoveRange(start, end - start + 1);
                            }
                        }

                        for (int n = index; n < count; n++)
                        {
                            HudNodeBase   node       = nodes[n].Element;
                            HudParentBase nodeParent = node._parent;

                            if (nodeParent != parent)
                            {
                                throw new Exception("The child node specified is not registered to the parent given.");
                            }

                            node.Parent = null;
                            node.State &= ~(HudElementStates.IsRegistered | HudElementStates.WasParentVisible);
                        }
                    }
                }
 /// <summary>
 /// Unregisters the specified node from the parent.
 /// </summary>
 /// <param name="fast">Prevents registration from triggering a draw list
 /// update. Meant to be used in conjunction with pooled elements being
 /// unregistered/reregistered to the same parent.</param>
 public virtual bool RemoveChild(HudNodeBase child)
 {
     if (child.Parent == this)
     {
         return(child.Unregister());
     }
     else if (child.Parent == null)
     {
         return(children.Remove(child));
     }
     else
     {
         return(false);
     }
 }
 /// <summary>
 /// Registers a child node to the object.
 /// </summary>
 /// <param name="preregister">Adds the element to the update tree without registering.</param>
 public virtual bool RegisterChild(HudNodeBase child)
 {
     if (child.Parent == this && !child.Registered)
     {
         children.Add(child);
         return(true);
     }
     else if (child.Parent == null)
     {
         return(child.Register(this));
     }
     else
     {
         return(false);
     }
 }
예제 #5
0
            public override bool RemoveChild(HudNodeBase child)
            {
                if (child.Parent == this)
                {
                    bool success = child.Unregister();

                    if (success)
                    {
                        RemoveChild(child);
                    }

                    return(success);
                }
                else if (child.Parent == null && children.Remove(child))
                {
                    if (!skipCollectionRemove)
                    {
                        for (int n = 0; n < hudCollectionList.Count; n++)
                        {
                            if (hudCollectionList[n].Element == child)
                            {
                                hudCollectionList.RemoveAt(n);
                                break;
                            }
                        }
                    }
                    else
                    {
                        skipCollectionRemove = false;
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }