예제 #1
0
        private static void RemoveAllNodesFrom(StyleLoadTreeNode root, List <StyleLoadTreeNode> list)
        {
            if (list.Contains(root))
            {
                list.Remove(root);
            }

            foreach (StyleLoadTreeNode child in root.Children)
            {
                RemoveAllNodesFrom(child, list);
            }
        }
예제 #2
0
        private void BuildStylesInOrder(StyleLoadTreeNode rootNode)
        {
            IGuiStyle parent = null;

            if (rootNode.Parent != null)
            {
                if (rootNode.Parent.Name == BUILTIN_UNITY_STYLE_NAME)
                {
                    throw new GuiConstructionException("Style (" + rootNode.Name + ") cannot be based on (" + BUILTIN_UNITY_STYLE_NAME + ")");
                }
                parent = mStyles[rootNode.Parent.Name];
            }

            IGuiStyle newStyle = BuildStyle(rootNode.Name, rootNode.Xml, parent);

            mStyles[newStyle.Name] = newStyle;

            foreach (StyleLoadTreeNode child in rootNode.Children)
            {
                BuildStylesInOrder(child);
            }
        }
예제 #3
0
        public IEnumerable <IGuiStyle> ConstructAllStyles()
        {
            if (mStyles == null)
            {
                if (mGuiDoc == null)
                {
                    throw new Exception("No XMLDocument Loaded");
                }

                mStyles = new Dictionary <string, IGuiStyle>();

                // Add the default unity style (null)
                mStyles.Add(BUILTIN_UNITY_STYLE_NAME, null);

                List <StyleLoadTreeNode> allUnconstructedNodes = new List <StyleLoadTreeNode>();
                List <StyleLoadTreeNode> rootNodes             = new List <StyleLoadTreeNode>();
                List <StyleLoadTreeNode> orphanNodes           = new List <StyleLoadTreeNode>();

                // Styles aren't hierarchical in the XML, so we can just grab them all
                XmlNodeList styleNodes = mGuiDoc.SelectNodes("//Style");
                foreach (XmlNode styleNode in styleNodes)
                {
                    StyleLoadTreeNode newNode = new StyleLoadTreeNode(styleNode);
                    if (styleNode.Attributes["parent"] == null)
                    {
                        rootNodes.Add(newNode);
                    }
                    else
                    {
                        orphanNodes.Add(newNode);
                    }
                    allUnconstructedNodes.Add(newNode);
                }

                foreach (StyleLoadTreeNode orphanNode in orphanNodes)
                {
                    orphanNode.Parent = FindElementByName(allUnconstructedNodes, orphanNode.ParentName);
                    orphanNode.Parent.Children.Add(orphanNode);
                }

                foreach (StyleLoadTreeNode root in rootNodes)
                {
                    RemoveAllNodesFrom(root, orphanNodes);
                }

                if (orphanNodes.Count != 0)
                {
                    StringBuilder realOrphans = new StringBuilder();
                    foreach (StyleLoadTreeNode orphanNode in orphanNodes)
                    {
                        realOrphans.Append(orphanNode.Name);
                        realOrphans.Append(", ");
                    }
                    realOrphans.Remove(realOrphans.Length - ", ".Length, ", ".Length);

                    throw new GuiConstructionException("Cannot find a parent for element(s): " + realOrphans);
                }

                foreach (StyleLoadTreeNode root in rootNodes)
                {
                    BuildStylesInOrder(root);
                }

                // Plus 1 for the built in unity style
                if (mStyles.Count != (styleNodes.Count + 1))
                {
                    throw new GuiConstructionException("Not all the Styles in this factory's XML were constructed.");
                }
            }

            return(mStyles.Values);
        }