From 6b958527ce457168a6d1bb55c13bd88759891bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Mon, 25 Aug 2014 17:22:13 +0200 Subject: [PATCH] First try to implement serialisation (for statics). --- VocaluxeLib/Menu/CMenu.cs | 12 ++++++++++++ VocaluxeLib/Menu/CStatic.cs | 29 +++++++++++++++++++++++++-- VocaluxeLib/Structs.cs | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/VocaluxeLib/Menu/CMenu.cs b/VocaluxeLib/Menu/CMenu.cs index 01fcb9ab..f754f487 100644 --- a/VocaluxeLib/Menu/CMenu.cs +++ b/VocaluxeLib/Menu/CMenu.cs @@ -21,6 +21,7 @@ using System.Drawing; using System.IO; using System.Windows.Forms; using System.Xml; +using System.Xml.Serialization; using VocaluxeLib.Draw; using VocaluxeLib.Menu.SingNotes; using VocaluxeLib.Menu.SongMenu; @@ -267,6 +268,17 @@ namespace VocaluxeLib.Menu writer.Flush(); } + + //This is only test-stuff and will be removed later + XmlSerializer serializer = new XmlSerializer(typeof(List)); + TextWriter textWriter = new StreamWriter(@Path.Combine(_ThemePath, ThemeName + "_test.xml")); + + List staticsThemes = new List(); + foreach (CStatic st in _Statics) + staticsThemes.Add(st.GetTheme()); + + serializer.Serialize(textWriter, staticsThemes); + textWriter.Close(); } public virtual void ReloadTextures() diff --git a/VocaluxeLib/Menu/CStatic.cs b/VocaluxeLib/Menu/CStatic.cs index 327dfc14..124c57f7 100644 --- a/VocaluxeLib/Menu/CStatic.cs +++ b/VocaluxeLib/Menu/CStatic.cs @@ -16,17 +16,24 @@ #endregion using System; -using System.Drawing; using System.Xml; +using System.Xml.Serialization; using VocaluxeLib.Draw; namespace VocaluxeLib.Menu { - struct SThemeStatic + [XmlType("Static")] + public struct SThemeStatic { + [XmlAttributeAttribute(AttributeName = "Name")] public string Name; + [XmlElement("Skin")] public string TextureName; + [XmlElement("ColorName")] public string ColorName; + public SColorF Color; + public SRectF Rect; + public SReflection Reflection; } public class CStatic : IMenuElement @@ -63,6 +70,11 @@ namespace VocaluxeLib.Menu public EAspect Aspect = EAspect.Stretch; + public CStatic() + { + + } + public CStatic(int partyModeID) { _PartyModeID = partyModeID; @@ -114,6 +126,8 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/W", ref Rect.W); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref Rect.H); + _Theme.Rect = new SRectF(Rect); + if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out Color); else @@ -124,14 +138,20 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/A", ref Color.A); } + _Theme.Color = new SColorF(Color); + if (xmlReader.ItemExists(item + "/Reflection")) { Reflection = true; _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Reflection/Space", ref ReflectionSpace); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Reflection/Height", ref ReflectionHeight); + _Theme.Reflection = new SReflection(true, ReflectionHeight, ReflectionSpace); } else + { Reflection = false; + _Theme.Reflection = new SReflection(false, 0f, 0f); + } if (_ThemeLoaded) { @@ -229,6 +249,11 @@ namespace VocaluxeLib.Menu LoadTextures(); } + public SThemeStatic GetTheme() + { + return _Theme; + } + #region ThemeEdit public void MoveElement(int stepX, int stepY) { diff --git a/VocaluxeLib/Structs.cs b/VocaluxeLib/Structs.cs index d0c73628..a0a29803 100644 --- a/VocaluxeLib/Structs.cs +++ b/VocaluxeLib/Structs.cs @@ -17,8 +17,10 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.Drawing; using System.Windows.Forms; +using System.Xml.Serialization; using VocaluxeLib.Songs; namespace VocaluxeLib @@ -27,9 +29,13 @@ namespace VocaluxeLib #region Drawing public struct SColorF { + [XmlElement("R")] public float R; + [XmlElement("G")] public float G; + [XmlElement("B")] public float B; + [XmlElement("A")] public float A; public SColorF(float r, float g, float b, float a) @@ -48,19 +54,27 @@ namespace VocaluxeLib A = color.A; } + [Pure] public Color AsColor() { return Color.FromArgb((int)(A * 255), (int)(R * 255), (int)(G * 255), (int)(B * 255)); } } + [XmlRoot()] public struct SRectF { + [XmlElement("X")] public float X; + [XmlElement("Y")] public float Y; + [XmlElement("W")] public float W; + [XmlElement("H")] public float H; + [XmlElement("Z")] public float Z; + [XmlIgnore] public float Rotation; //0..360° public SRectF(float x, float y, float w, float h, float z) @@ -84,6 +98,31 @@ namespace VocaluxeLib } } + [XmlRoot("Reflection")] + public struct SReflection + { + [XmlAttributeAttribute(AttributeName = "Enabled")] + public bool Enabled; + [XmlElement("Height")] + public float Height; + [XmlElement("Space")] + public float Space; + + public SReflection(bool enabled, float height, float space) + { + Enabled = enabled; + Height = height; + Space = space; + } + + public SReflection(SReflection refl) + { + Enabled = refl.Enabled; + Height = refl.Height; + Space = refl.Space; + } + } + public struct SPoint3F { public float X;