Exemple #1
0
        internal void Deserialize(XmlTextReader reader)
        {
            bool keepreading = true;
            while (keepreading)
            {
                reader.Read();
                if (reader.Name.Equals("material") && reader.NodeType.Equals(XmlNodeType.Element))
                {
                    VoxMaterial mat = new VoxMaterial();
                    mat.ID = (byte)reader.ReadContentAsInt();
                    mat.Name = reader.ReadContentAsString();
                    mat.Flags = (MatFlags)Enum.Parse(typeof(MatFlags), reader.ReadContentAsString());
                    mat.Density = reader.ReadContentAsFloat();
                    mat.Deposit = (DepositType)Enum.Parse(typeof(DepositType), reader.ReadContentAsString());
                    mat.Texture = UUID.Parse(reader.ReadContentAsString());
                    mat.Type = (MaterialType)Enum.Parse(typeof(MaterialType), reader.ReadContentAsString());

                    if (mat.ID > index)
                    {
                        index = mat.ID;
                        index++;
                    }

                    mMaterials.Add(mat.ID, mat);
                    mName2Byte.Add(mat.Name, mat.ID);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Reads style data from xml file
        /// </summary>
        /// <param name="xmlFile">XML file</param>
        public void FromXMLFile(string xmlFile)
        {
            m_xmlFile = xmlFile;
            XmlTextReader reader = new XmlTextReader(xmlFile);
            reader.WhitespaceHandling = WhitespaceHandling.None;
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "GUI")
                    {
                        // Read in the image file name
                        for (int i = 0; i < reader.AttributeCount; i++)
                        {
                            reader.MoveToAttribute(i);
                            if (reader.Name == "ImageFile")
                            {
                                m_guiTexture = DefaultValues.MediaPath + reader.Value;
                                m_imageInfo = TextureLoader.ImageInformationFromFile(m_guiTexture);
                            }
                            else if (reader.Name == "StyleName")
                            {
                                m_name = reader.Value;
                            }
                            else if (reader.Name == "FntFile")
                            {
                                char[] separator = new char[] { ';' };
                                string[] tokens = reader.Value.Split(separator);
                                foreach (string token in tokens)
                                {
                                    string fntFile = DefaultValues.FontPath + token;
                                    BitmapFont font = GM.FontManager.GetFont(fntFile);
                                    if (font == null)
                                        GM.GeneralLog.Write("Wczytywanie GUIStyle, nie znaleziono czcionki:" + fntFile);
                                    else
                                        m_fontName = font.Name;
                                }

                            }
                        }
                    }
                    else if (reader.Name == "Control")
                    {
                        ControlNode controlNode = new ControlNode();
                        for (int i = 0; i < reader.AttributeCount; i++)
                        {
                            reader.MoveToAttribute(i);
                            if (reader.Name == "Name")
                            {
                                controlNode.Name = reader.Value;
                            }
                        }
                        // Read the Image elements of this Control
                        while (reader.NodeType != XmlNodeType.EndElement)
                        {
                            reader.Read();
                            if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Image"))
                            {
                                ImageNode imageNode = new ImageNode();
                                for (int i = 0; i < reader.AttributeCount; i++)
                                {
                                    reader.MoveToAttribute(i);
                                    if (reader.Name == "Name")
                                    {
                                        imageNode.Name = reader.Value;
                                    }
                                    else if (reader.Name == "X")
                                    {
                                        imageNode.Rectangle.X = reader.ReadContentAsFloat();
                                    }
                                    else if (reader.Name == "Y")
                                    {
                                        imageNode.Rectangle.Y = reader.ReadContentAsFloat();
                                    }
                                    else if (reader.Name == "Width")
                                    {
                                        imageNode.Rectangle.Width = reader.ReadContentAsFloat();
                                    }
                                    else if (reader.Name == "Height")
                                    {
                                        imageNode.Rectangle.Height = reader.ReadContentAsFloat();
                                    }
                                    else if (reader.Name == "Color")
                                    {
                                        imageNode.Color = StringToColor(reader.Value);
                                    }
                                }
                                controlNode.Images.Add(imageNode);
                            }
                            else if (reader.Name == "DefaultValues")
                            {
                                controlNode.Defaults= new ControlDefaults();
                                controlNode.Defaults.TextSize = float.Parse(reader.GetAttribute("TextSize"));
                                controlNode.Defaults.Color = this.StringToColor(reader.GetAttribute("Color"));
                            }
                        }
                        m_controlNodes.Add(controlNode);
                    }
                    else if (reader.Name == "DefaultValues")
                    {
                        this.defaultValues = new ControlDefaults();
                        defaultValues.TextSize = float.Parse(reader.GetAttribute("TextSize"));
                        defaultValues.Color = this.StringToColor(reader.GetAttribute("Color"));
                    }
                }
            }
            if (this.Defaults == null)
            {
                this.defaultValues = new ControlDefaults();
                this.defaultValues.TextSize = DefaultValues.TextSize;
                this.defaultValues.Color = Color.Black;
            }
            foreach (ControlNode node in this.m_controlNodes)
            {
                if (node.Defaults == null)
                    node.Defaults = this.defaultValues;
            }
            reader.Close();
        }