void LoadStyleFile(Stream ContentStream, string XmlPath, string ComponentNodeNameInXml, bool LoadFromArchive) { XmlDocument xmlDoc = new XmlDocument(); if (LoadFromArchive) { xmlDoc.Load(ContentStream); ContentStream.Dispose(); FileManager.Dispose(); } else { xmlDoc.Load(FileManager.ContentFolder + XmlPath); } if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures") != null) { if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTexture") != null) { NormalComponentTexture = new ComponentTexture(); if (LoadFromArchive) { MemoryStream TextureStream; try { string TexturePath = xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTexture").Attributes.GetNamedItem("Path").Value; TextureStream = FileManager.GetFileMemoryStreamFromArchive(TexturePath); NormalComponentTexture.OriginalTexture = Texture2D.FromStream(Graphics.GraphicsDevice, TextureStream); if (ContentStream == null) { throw new Exception("Could not find file \"" + FileManager.ContentFolder + FileManager.SourceArchiveFileName + "/" + XmlPath + "\""); } else if (TextureStream == null) { throw new Exception("Could not find file \"" + FileManager.ContentFolder + FileManager.SourceArchiveFileName + "/" + TexturePath + "\""); } } catch (Exception ex) { throw ex; } TextureStream.Dispose(); FileManager.Dispose(); } else { NormalComponentTexture.OriginalTexture = StreamTexture.LoadTextureFromStream(Graphics, xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTexture").Attributes.GetNamedItem("Path").Value); } NormalComponentTexture.Color = new Color(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTextureColor").Attributes.GetNamedItem("Red").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTextureColor").Attributes.GetNamedItem("Green").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTextureColor").Attributes.GetNamedItem("Blue").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTextureColor").Attributes.GetNamedItem("Alpha").Value)); NormalComponentTexture.Initialize(Graphics); } if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTexture") != null) { HoveredComponentTexture = new ComponentTexture(); if (LoadFromArchive) { MemoryStream TextureStream; try { string TexturePath = xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTexture").Attributes.GetNamedItem("Path").Value; TextureStream = FileManager.GetFileMemoryStreamFromArchive(TexturePath); HoveredComponentTexture.OriginalTexture = Texture2D.FromStream(Graphics.GraphicsDevice, TextureStream); if (TextureStream == null) { throw new Exception("Could not find file \"" + FileManager.ContentFolder + FileManager.SourceArchiveFileName + "/" + TexturePath + "\""); } } catch (Exception ex) { throw ex; } TextureStream.Dispose(); FileManager.Dispose(); } else { HoveredComponentTexture.OriginalTexture = StreamTexture.LoadTextureFromStream(Graphics, xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTexture").Attributes.GetNamedItem("Path").Value); } HoveredComponentTexture.Color = new Color(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTextureColor").Attributes.GetNamedItem("Red").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTextureColor").Attributes.GetNamedItem("Green").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTextureColor").Attributes.GetNamedItem("Blue").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTextureColor").Attributes.GetNamedItem("Alpha").Value)); HoveredComponentTexture.Initialize(Graphics); } if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTexture") != null) { PressedComponentTexture = new ComponentTexture(); if (LoadFromArchive) { MemoryStream TextureStream; try { string TexturePath = xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTexture").Attributes.GetNamedItem("Path").Value; TextureStream = FileManager.GetFileMemoryStreamFromArchive(TexturePath); PressedComponentTexture.OriginalTexture = Texture2D.FromStream(Graphics.GraphicsDevice, TextureStream); if (TextureStream == null) { throw new Exception("Could not find file \"" + FileManager.ContentFolder + FileManager.SourceArchiveFileName + "/" + TexturePath + "\""); } } catch (Exception ex) { throw ex; } TextureStream.Dispose(); FileManager.Dispose(); } else { PressedComponentTexture.OriginalTexture = StreamTexture.LoadTextureFromStream(Graphics, xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTexture").Attributes.GetNamedItem("Path").Value); } PressedComponentTexture.Color = new Color(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTextureColor").Attributes.GetNamedItem("Red").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTextureColor").Attributes.GetNamedItem("Green").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTextureColor").Attributes.GetNamedItem("Blue").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTextureColor").Attributes.GetNamedItem("Alpha").Value)); PressedComponentTexture.Initialize(Graphics); } } if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Rendering") != null) { if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Rendering").Attributes.GetNamedItem("Mode").Value == "None Scalable") { if (NormalComponentTexture != null) { NormalComponentTexture.RendererMode = ComponentTexture.RenderMode.NoneScalable; } if (HoveredComponentTexture != null) { HoveredComponentTexture.RendererMode = ComponentTexture.RenderMode.NoneScalable; } if (PressedComponentTexture != null) { PressedComponentTexture.RendererMode = ComponentTexture.RenderMode.NoneScalable; } } else if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Rendering").Attributes.GetNamedItem("Mode").Value == "Scalable") { if (NormalComponentTexture != null) { NormalComponentTexture.RendererMode = ComponentTexture.RenderMode.Scalable; } if (HoveredComponentTexture != null) { HoveredComponentTexture.RendererMode = ComponentTexture.RenderMode.Scalable; } if (PressedComponentTexture != null) { PressedComponentTexture.RendererMode = ComponentTexture.RenderMode.Scalable; } } else if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Rendering").Attributes.GetNamedItem("Mode").Value == "Scalable RealTime") { if (NormalComponentTexture != null) { NormalComponentTexture.RendererMode = ComponentTexture.RenderMode.ScalableRealTime; } if (HoveredComponentTexture != null) { HoveredComponentTexture.RendererMode = ComponentTexture.RenderMode.ScalableRealTime; } if (PressedComponentTexture != null) { PressedComponentTexture.RendererMode = ComponentTexture.RenderMode.ScalableRealTime; } } } if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions") != null) { borderThickness = new BorderThickness(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/BorderThickness").Attributes.GetNamedItem("Top").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/BorderThickness").Attributes.GetNamedItem("Right").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/BorderThickness").Attributes.GetNamedItem("Bottom").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/BorderThickness").Attributes.GetNamedItem("Left").Value)); CornerSize = new Vector2(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/CornerSize").Attributes.GetNamedItem("X").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/CornerSize").Attributes.GetNamedItem("Y").Value)); if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/DefaultSize") != null) { if (Size.X <= 0 || Size.Y <= 0) { DefaultSize = new Vector2(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/DefaultSize").Attributes.GetNamedItem("X").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/DefaultSize").Attributes.GetNamedItem("Y").Value)); } } } if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text") != null) { string alignment = ""; // if (LoadFromArchive) //fontRenderer.LoadContentFromArchive(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/Font").Attributes.GetNamedItem("Path").Value); //else fontRenderer.LoadContent(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/Font").Attributes.GetNamedItem("Path").Value); if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultText") != null) { if (String.IsNullOrEmpty(Text)) { Text = xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultText").Attributes.GetNamedItem("Value").Value; } } if (TextAlignment == Alignment.Default) { alignment = xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultAlignment").Attributes.GetNamedItem("Value").Value; if (alignment.ToLowerInvariant() == "left") { TextAlignment = Alignment.Left; } if (alignment.ToLowerInvariant() == "center") { TextAlignment = Alignment.Center; } if (alignment.ToLowerInvariant() == "right") { TextAlignment = Alignment.Right; } } TextOffsetPosition = new Vector2(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/OffsetPosition").Attributes.GetNamedItem("X").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/OffsetPosition").Attributes.GetNamedItem("Y").Value)); if (TextColor == null) { TextColor = new Color(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultTextColor").Attributes.GetNamedItem("Red").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultTextColor").Attributes.GetNamedItem("Green").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultTextColor").Attributes.GetNamedItem("Blue").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultTextColor").Attributes.GetNamedItem("Alpha").Value)); } } }