Exemplo n.º 1
0
Arquivo: Node.cs Projeto: xxy1991/cozy
 /// <summary>
 /// Get all the children recursive and flattens it into the given list.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="listToFill">The list to fill.</param>
 private void FlattenChildren(Node parent, ref NodeCollection listToFill)
 {
     listToFill.Add(parent);
     foreach (var child in parent.Children)
     {
         this.FlattenChildren(child, ref listToFill);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// walk trough every node recursive , and if a node is a control , then initialize it.
        /// Use this method to query for any required services, and load any non-graphics resources. 
        /// </summary>
        /// <param name="rootNode">The node where we start to initialize recursive.</param>
        private void InitializeRecursive(Node rootNode)
        {
            var control = rootNode as Control;
            if (control != null)
            {
                control.Manager = this.Manager;
                control.Initialize();
            }

            // Update children recursively
            for (var i = 0; i < rootNode.Children.Count; i++)
            {
                this.InitializeRecursive(rootNode.Children[i]);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Utility function to create a default menu.
        /// </summary>
        /// <param name="node">The node.</param>
        private void ConnectEventToButtons(Node node)
        {
            var btn = node as MenuItemButton;
            if (btn != null)
            {
                btn.MouseClicked += this.OnButtonClicked;
            }

            foreach (var child in node.Children)
            {
                this.ConnectEventToButtons(child);
            }
        }
Exemplo n.º 4
0
        /// <summary>Call the UpdateCall on each node recursively
        /// Called when the game has determined that game logic needs to be processed. 
        /// This might include the management of the game state, the processing of user input, or the updating of simulation data. 
        /// Use this method with game-specific logic.</summary>
        /// <param name="time">The time used for updating animated objects thanks to time differences.</param>
        /// <param name="currentNode">The current Node to update.</param>
        /// <param name="updateIndex">The update Index , used for height calculations.</param>
        private void UpdateRecursive(GameTime time, Node currentNode, ref int updateIndex)
        {
            // Update node
            var currentControl = currentNode as Control;
            if (currentControl != null)
            {
                if (currentControl.DrawMeAndMyChildren)
                {
                    // lazy initialization
                    if (currentControl.IsLoaded == false)
                    {
                        Debug.WriteLine("Loading : " + currentControl.Name);
                        if (currentControl.Manager == null)
                        {
                            currentControl.Manager = this.Manager;
                        }

                        currentControl.LoadContent();
                        currentControl.IsLoaded = true;
                    }

                    // do the monogame version of update
                    currentControl.Update(time);

                    // Set update index, for height calculations
                    updateIndex++;
                    currentControl.State.UpdateIndex = updateIndex;
                }
            }

            // Update children recursively
            for (var i = 0; i < currentNode.Children.Count; i++)
            {
                if (currentControl != null && currentControl.DrawMeAndMyChildren == false)
                {
                    if (currentNode.Children[i] is Control)
                    {
                        continue;
                    }
                }

                this.UpdateRecursive(time, currentNode.Children[i], ref updateIndex);
            }
        }
Exemplo n.º 5
0
        /// <summary>Tells each control to unload content recursive.</summary>
        /// <param name="currentNode">The current Node to unload.</param>
        private void UnloadContentRecursive(Node currentNode)
        {
            var currentControl = currentNode as Control;
            if (currentControl != null)
            {
                currentControl.UnloadContent();
            }

            // Update children recursively
            for (var i = 0; i < currentNode.Children.Count; i++)
            {
                this.UnloadContentRecursive(currentNode.Children[i]);
            }
        }
Exemplo n.º 6
0
        /// <summary>Draws each node recursive. But does not draw it is not visible.
        /// Your code now already knows where the draw and how to draw each control , thanks to your update implementation.</summary>
        /// <param name="gameTime">The game Time. Used by objects to change  what they draw , because time  is changed.</param>
        /// <param name="currentNode">The current Node to draw.</param>
        // ReSharper disable once UnusedParameter.Local
        private void DrawRecursive(GameTime gameTime, Node currentNode)
        {
            // if current node is drawable
            var currentControl = currentNode as Control;
            if (currentControl != null)
            {
                // and if "me and my children should be drawn" (like tab-sheets)
                if (currentControl.DrawMeAndMyChildren)
                {
                    // and if i should be drawn
                    if (currentControl.Config.Visible)
                    {
                        currentControl.DrawMyData();
                    }
                }
            }

            // and go recursive
            for (var i = 0; i < currentNode.Children.Count; i++)
            {
                var currentChildNode = currentNode.Children[i];

                // if currentControl is not null, then we are a Control. 
                // if  currentControl is a Control, then maybe we should not draw her or its children
                if (currentControl != null && currentControl.DrawMeAndMyChildren == false)
                {
                    if (currentChildNode is Control)
                    {
                        continue;
                    }
                }

                // draw my child
                this.DrawRecursive(gameTime, currentChildNode);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the given node by name , by crawling recursive trough the tree.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="treeNodeName">Name of the tree node.</param>
        /// <returns>The tree-node with given name.</returns>
        /// <exception cref="System.ArgumentNullException">Node can not be null.</exception>
        public TreeViewNode GetNodeRecursive(Node node, string treeNodeName)
        {
#if DEBUG
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
#endif

            TreeViewNode nodeToReturn = null;
            foreach (var child in node.Children)
            {
                var treeviewchild = child as TreeViewNode;
                if (treeviewchild != null)
                {
                    if (treeviewchild.Name.Equals(treeNodeName))
                    {
                        nodeToReturn = treeviewchild;
                        break;
                    }
                }

                var recursedNode = this.GetNodeRecursive(child, treeNodeName);
                if (recursedNode != null)
                {
                    return recursedNode;
                }
            }

            return nodeToReturn;
        }