From acaf4eadb26a7a33c48d417d6341910c7bb00b2d Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 27 Oct 2014 11:10:29 +0100 Subject: [PATCH] Serialize Themes --- Vocaluxe/Base/CCover.cs | 11 +- Vocaluxe/Base/Fonts/CFonts.cs | 169 +++++------------------ Vocaluxe/Base/ThemeSystem/CBaseSkin.cs | 2 +- Vocaluxe/Base/ThemeSystem/CBaseTheme.cs | 28 ++-- Vocaluxe/Base/ThemeSystem/CPartySkin.cs | 2 +- Vocaluxe/Base/ThemeSystem/CPartyTheme.cs | 5 +- Vocaluxe/Base/ThemeSystem/CSkin.cs | 72 ++++------ Vocaluxe/Base/ThemeSystem/CTheme.cs | 47 +++---- Vocaluxe/Base/XmlStructs.cs | 100 ++++++++++++++ Vocaluxe/Vocaluxe.csproj | 1 + VocaluxeLib/Menu/CMenu.cs | 10 +- VocaluxeLib/Structs.cs | 13 +- VocaluxeLib/Xml/CXmlDeserializer.cs | 10 -- 13 files changed, 207 insertions(+), 263 deletions(-) create mode 100644 Vocaluxe/Base/XmlStructs.cs diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index 835c0bee..2ebc6963 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -170,7 +170,7 @@ namespace Vocaluxe.Base return new SThemeCover(); } - private static void Foo(STheme a, STheme b) + private static void Foo(SThemeScreen a, SThemeScreen b) { a = b; } @@ -180,14 +180,13 @@ namespace Vocaluxe.Base SThemeCover themeCover; var xml = new CXmlSerializer(); themeCover = xml.Deserialize(path); - xml.Serialize(path + "2", themeCover); string cover = themeCover.Info.Author; - STheme theme = new STheme(); - STheme theme2 = new STheme(); + SThemeScreen theme = new SThemeScreen(); + SThemeScreen theme2 = new SThemeScreen(); Stopwatch watch = new Stopwatch(); watch.Start(); for (int i = 0; i < 1; i++) - theme = xml.Deserialize(Path.Combine(CBase.Themes.GetThemeScreensPath(-1), "ScreenMain.xml")); + theme = xml.Deserialize(Path.Combine(CBase.Themes.GetThemeScreensPath(-1), "ScreenMain.xml")); watch.Stop(); xml.Serialize(Path.Combine(CBase.Themes.GetThemeScreensPath(-1), "ScreenMain2.xml"), theme); return; @@ -199,7 +198,7 @@ namespace Vocaluxe.Base { XmlSerializer deserializer = new XmlSerializer(typeof(STheme)); - theme2 = (STheme)deserializer.Deserialize(textReader); + theme2 = (SThemeScreen)deserializer.Deserialize(textReader); } } watch2.Stop(); diff --git a/Vocaluxe/Base/Fonts/CFonts.cs b/Vocaluxe/Base/Fonts/CFonts.cs index 446e12a8..31f3e1f8 100644 --- a/Vocaluxe/Base/Fonts/CFonts.cs +++ b/Vocaluxe/Base/Fonts/CFonts.cs @@ -21,46 +21,12 @@ using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; -using System.Xml; using VocaluxeLib; using VocaluxeLib.Menu; using VocaluxeLib.Xml; namespace Vocaluxe.Base.Fonts { - /// - /// Struct used for describing a font family (a type of text with 4 different styles) - /// - struct SFontFamily - { - public string Name; - - public int PartyModeID; - public string ThemeName; - public string Folder; - - public string FileNormal; - public string FileItalic; - public string FileBold; - public string FileBoldItalic; - - public float Outline; //0..1, 0=not outline 1=100% outline - public SColorF OutlineColor; - - public CFontStyle Normal; - public CFontStyle Italic; - public CFontStyle Bold; - public CFontStyle BoldItalic; - - public void Dispose() - { - Normal.Dispose(); - Italic.Dispose(); - Bold.Dispose(); - BoldItalic.Dispose(); - } - } - static class CFonts { private static bool _IsInitialized; @@ -291,116 +257,53 @@ namespace Vocaluxe.Base.Fonts /// private static bool _LoadDefaultFonts() { - CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts, CSettings.FileNameFonts)); - if (xmlReader == null) - return false; - - return _LoadFontFile(xmlReader, Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts)); - } - - /// - /// Loads theme fonts from skin file - /// - public static bool LoadThemeFonts(string themeName, string fontFolder, CXMLReader xmlReader) - { - bool ok = _LoadFontFile(xmlReader, fontFolder, themeName); - CLog.StartBenchmark("BuildGlyphs"); - _BuildGlyphs(); - CLog.StopBenchmark("BuildGlyphs"); - return ok; - } - - /// - /// Loads party mode fonts from skin file - /// - public static bool LoadPartyModeFonts(int partyModeID, string fontFolder, CXMLReader xmlReader) - { - bool ok = _LoadFontFile(xmlReader, fontFolder, "", partyModeID); - CLog.StartBenchmark("BuildGlyphs"); - _BuildGlyphs(); - CLog.StopBenchmark("BuildGlyphs"); - return ok; - } - - private static bool _LoadFontFile(CXMLReader xmlReader, string fontFolder, string themeName = "", int partyModeId = -1) - { - string value; - int i = 1; - while (xmlReader.GetValue("//root/Fonts/Font" + i + "/Folder", out value)) + SDefaultFonts defaultFonts; + try { - var sf = new SFontFamily {Folder = value, ThemeName = themeName, PartyModeID = partyModeId}; + var xml = new CXmlSerializer(); + defaultFonts = xml.Deserialize(Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts, CSettings.FileNameFonts)); + } + catch (Exception e) + { + CLog.LogError("Error loading default Fonts", false, false, e); + return false; + } - bool ok = true; + return LoadThemeFonts(defaultFonts.Fonts, Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts), "", -1); + } - ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/Name", out sf.Name); - ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileNormal", out sf.FileNormal); - ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileItalic", out sf.FileItalic); - ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileBold", out sf.FileBold); - ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileBoldItalic", out sf.FileBoldItalic); - ok &= xmlReader.TryGetNormalizedFloatValue("//root/Fonts/Font" + i + "/Outline", ref sf.Outline); - ok &= xmlReader.Read("//root/Fonts/Font" + i + "/OutlineColor", out sf.OutlineColor); - - if (ok) + /// + /// Loads theme fonts + /// + public static bool LoadThemeFonts(IEnumerable fontFamilies, string fontFolder, string themeName, int partyModeId) + { + if (fontFamilies == null) + return true; + foreach (SFontFamily fontFamily in fontFamilies) + { + if (!_LoadFont(fontFamily, fontFolder, themeName, partyModeId)) { - sf.Normal = new CFontStyle(Path.Combine(fontFolder, sf.Folder, sf.FileNormal), EStyle.Normal, sf.Outline, sf.OutlineColor); - sf.Italic = new CFontStyle(Path.Combine(fontFolder, sf.Folder, sf.FileItalic), EStyle.Italic, sf.Outline, sf.OutlineColor); - sf.Bold = new CFontStyle(Path.Combine(fontFolder, sf.Folder, sf.FileBold), EStyle.Bold, sf.Outline, sf.OutlineColor); - sf.BoldItalic = new CFontStyle(Path.Combine(fontFolder, sf.Folder, sf.FileBoldItalic), EStyle.BoldItalic, sf.Outline, sf.OutlineColor); - _FontFamilies.Add(sf); - } - else - { - string fontTypes; - if (partyModeId >= 0) - fontTypes = "theme fonts for party mode"; - else if (themeName != "") - fontTypes = "theme fonts for theme \"" + themeName + "\""; - else - fontTypes = "basic fonts"; - CLog.LogError("Error loading " + fontTypes + ": Error in Font" + i); + CLog.LogError("Error loading fonts for Theme " + themeName + "(" + partyModeId + ")"); return false; } - i++; } + CLog.StartBenchmark("BuildGlyphs"); + _BuildGlyphs(); + CLog.StopBenchmark("BuildGlyphs"); return true; } - public static void SaveThemeFonts(string themeName, XmlWriter writer) + private static bool _LoadFont(SFontFamily fontFamily, string fontFolder, string themeName, int partyModeId) { - if (_FontFamilies.Count == 0) - return; - - writer.WriteStartElement("Fonts"); - int fontNr = 1; - foreach (SFontFamily font in _FontFamilies) - { - if (font.ThemeName == themeName) - { - writer.WriteStartElement("Font" + fontNr); - - writer.WriteElementString("Name", font.Name); - writer.WriteElementString("Folder", font.Folder); - - writer.WriteElementString("Outline", font.Outline.ToString("#0.00")); - writer.WriteStartElement("OutlineColor"); - writer.WriteElementString("R", font.OutlineColor.R.ToString("#0.00")); - writer.WriteElementString("G", font.OutlineColor.G.ToString("#0.00")); - writer.WriteElementString("B", font.OutlineColor.B.ToString("#0.00")); - writer.WriteElementString("A", font.OutlineColor.A.ToString("#0.00")); - writer.WriteEndElement(); - - writer.WriteElementString("FileNormal", font.FileNormal); - writer.WriteElementString("FileBold", font.FileBold); - writer.WriteElementString("FileItalic", font.FileItalic); - writer.WriteElementString("FileBoldItalic", font.FileBoldItalic); - - writer.WriteEndElement(); - - fontNr++; - } - } - - writer.WriteEndElement(); + fontFamily.ThemeName = themeName; + fontFamily.PartyModeID = partyModeId; + fontFamily.Normal = new CFontStyle(Path.Combine(fontFolder, fontFamily.Folder, fontFamily.FileNormal), EStyle.Normal, fontFamily.Outline, fontFamily.OutlineColor); + fontFamily.Italic = new CFontStyle(Path.Combine(fontFolder, fontFamily.Folder, fontFamily.FileItalic), EStyle.Italic, fontFamily.Outline, fontFamily.OutlineColor); + fontFamily.Bold = new CFontStyle(Path.Combine(fontFolder, fontFamily.Folder, fontFamily.FileBold), EStyle.Bold, fontFamily.Outline, fontFamily.OutlineColor); + fontFamily.BoldItalic = new CFontStyle(Path.Combine(fontFolder, fontFamily.Folder, fontFamily.FileBoldItalic), EStyle.BoldItalic, fontFamily.Outline, + fontFamily.OutlineColor); + _FontFamilies.Add(fontFamily); + return true; } public static void UnloadThemeFonts(string themeName) diff --git a/Vocaluxe/Base/ThemeSystem/CBaseSkin.cs b/Vocaluxe/Base/ThemeSystem/CBaseSkin.cs index 11aa0a10..563b4744 100644 --- a/Vocaluxe/Base/ThemeSystem/CBaseSkin.cs +++ b/Vocaluxe/Base/ThemeSystem/CBaseSkin.cs @@ -42,7 +42,7 @@ namespace Vocaluxe.Base.ThemeSystem { List missingTextures = _RequiredTextures.FindAll(name => !_Textures.ContainsKey(name)); List missingVideos = _RequiredVideos.FindAll(name => !_Videos.ContainsKey(name)); - List missingColors = _RequiredColors.FindAll(name => !_Colors.ContainsKey(name)); + List missingColors = _RequiredColors.FindAll(name => !_Data.Colors.ContainsKey(name)); if (missingTextures.Count + missingVideos.Count + missingColors.Count == 0) return true; string msg = "The skin \"" + this + "\" is missing the following elements: "; diff --git a/Vocaluxe/Base/ThemeSystem/CBaseTheme.cs b/Vocaluxe/Base/ThemeSystem/CBaseTheme.cs index c9f37cec..cc4c5f3c 100644 --- a/Vocaluxe/Base/ThemeSystem/CBaseTheme.cs +++ b/Vocaluxe/Base/ThemeSystem/CBaseTheme.cs @@ -15,16 +15,23 @@ // along with Vocaluxe. If not, see . #endregion +using System.Diagnostics; using System.IO; using System.Linq; using Vocaluxe.Base.Fonts; -using VocaluxeLib.Xml; namespace Vocaluxe.Base.ThemeSystem { class CBaseTheme : CTheme { - public SThemeCursor CursorTheme; + public SThemeCursor CursorTheme + { + get + { + Debug.Assert(_Data.Cursor != null, "Check in _Load!"); + return _Data.Cursor.Value; + } + } public CBaseTheme(string filePath) : base(filePath, -1) {} @@ -39,21 +46,12 @@ namespace Vocaluxe.Base.ThemeSystem CFonts.UnloadThemeFonts(Name); } - protected override bool _Load(CXMLReader xmlReader) + protected override bool _Load() { - return _LoadCursor(xmlReader) && - CFonts.LoadThemeFonts(Name, Path.Combine(_Folder, Name, CSettings.FolderNameThemeFonts), xmlReader); - } + if (!_Data.Cursor.HasValue) + return false; - private bool _LoadCursor(CXMLReader xmlReader) - { - bool ok = xmlReader.GetValue("//root/Cursor/Skin", out CursorTheme.SkinName); - - ok &= xmlReader.TryGetFloatValue("//root/Cursor/W", ref CursorTheme.W); - ok &= xmlReader.TryGetFloatValue("//root/Cursor/H", ref CursorTheme.H); - ok &= xmlReader.Read("//root/Cursor/Color", out CursorTheme.Color); - - return ok; + return CFonts.LoadThemeFonts(_Data.Fonts, Path.Combine(_Folder, Name, CSettings.FolderNameThemeFonts), Name, -1); } protected override bool _LoadSkin() diff --git a/Vocaluxe/Base/ThemeSystem/CPartySkin.cs b/Vocaluxe/Base/ThemeSystem/CPartySkin.cs index f76bb6b7..95090087 100644 --- a/Vocaluxe/Base/ThemeSystem/CPartySkin.cs +++ b/Vocaluxe/Base/ThemeSystem/CPartySkin.cs @@ -33,7 +33,7 @@ namespace Vocaluxe.Base.ThemeSystem return false; for (int i = 1; i <= CSettings.MaxNumPlayer; i++) { - if (!_Colors.ContainsKey("Player" + i)) + if (!_Data.Colors.ContainsKey("Player" + i)) continue; CLog.LogDebug("Party themes cannot contain player colors. They will be ignored!"); break; diff --git a/Vocaluxe/Base/ThemeSystem/CPartyTheme.cs b/Vocaluxe/Base/ThemeSystem/CPartyTheme.cs index 9bc50d9c..f91a09d0 100644 --- a/Vocaluxe/Base/ThemeSystem/CPartyTheme.cs +++ b/Vocaluxe/Base/ThemeSystem/CPartyTheme.cs @@ -19,7 +19,6 @@ using System; using System.IO; using System.Linq; using Vocaluxe.Base.Fonts; -using VocaluxeLib.Xml; namespace Vocaluxe.Base.ThemeSystem { @@ -38,9 +37,9 @@ namespace Vocaluxe.Base.ThemeSystem return new CPartySkin(path, file, this); } - protected override bool _Load(CXMLReader xmlReader) + protected override bool _Load() { - return CFonts.LoadPartyModeFonts(PartyModeID, Path.Combine(_Folder, "..", CSettings.FolderNamePartyModeFonts), xmlReader); + return CFonts.LoadThemeFonts(_Data.Fonts, Path.Combine(_Folder, "..", CSettings.FolderNamePartyModeFonts), Name, PartyModeID); } private CSkin _GetSkinToLoad(int fallbackNum) diff --git a/Vocaluxe/Base/ThemeSystem/CSkin.cs b/Vocaluxe/Base/ThemeSystem/CSkin.cs index 7e161f4f..af21ec0c 100644 --- a/Vocaluxe/Base/ThemeSystem/CSkin.cs +++ b/Vocaluxe/Base/ThemeSystem/CSkin.cs @@ -42,15 +42,14 @@ namespace Vocaluxe.Base.ThemeSystem private readonly string _FileName; protected readonly CTheme _Parent; - private SInfo _Info; + protected SSkin _Data; public String Name { - get { return _Info.Name; } + get { return _Data.Info.Name; } } protected readonly Dictionary _Textures = new Dictionary(); protected readonly Dictionary _Videos = new Dictionary(); - protected readonly Dictionary _Colors = new Dictionary(); protected bool _IsLoaded; @@ -93,18 +92,20 @@ namespace Vocaluxe.Base.ThemeSystem public bool Init() { - CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(_Folder, _FileName)); - if (xmlReader == null) - return false; - - if (!xmlReader.CheckVersion("//root/SkinSystemVersion", _SkinSystemVersion)) - return false; - - bool ok = xmlReader.Read("//root/Info", out _Info); - - if (!ok) + try { - CLog.LogError("Can't load skin file \"" + _FileName + "\". Invalid file!"); + var xml = new CXmlSerializer(); + _Data = xml.Deserialize(Path.Combine(_Folder, _FileName)); + if (_Data.SkinSystemVersion != _SkinSystemVersion) + { + string errorMsg = _Data.SkinSystemVersion < _SkinSystemVersion ? "the file ist outdated!" : "the file is for newer program versions!"; + errorMsg += " Current Version is " + _SkinSystemVersion; + throw new Exception(errorMsg); + } + } + catch (Exception e) + { + CLog.LogError("Can't load skin file \"" + _FileName + "\". Invalid file!", false, false, e); return false; } @@ -116,42 +117,31 @@ namespace Vocaluxe.Base.ThemeSystem if (_IsLoaded) return true; Debug.Assert(_Textures.Count == 0 && _Videos.Count == 0); - CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(_Folder, _FileName)); - if (xmlReader == null) - return false; // load skins/textures - List names = xmlReader.GetNames("//root/Skins/*"); - foreach (string name in names) + foreach (KeyValuePair kvp in _Data.Skins) { - string fileName; - xmlReader.GetValue("//root/Skins/" + name, out fileName); - CTextureRef texture = CDraw.AddTexture(Path.Combine(_Folder, fileName)); + CTextureRef texture = CDraw.AddTexture(Path.Combine(_Folder, kvp.Value)); if (texture == null) { - CLog.LogError("Error on loading texture \"" + name + "\": " + fileName, true); + CLog.LogError("Error on loading texture \"" + kvp.Key + "\": " + kvp.Value, true); return false; } - _Textures.Add(name, texture); + _Textures.Add(kvp.Key, texture); } // load videos - names = xmlReader.GetNames("//root/Videos/*"); - foreach (string name in names) + foreach (KeyValuePair kvp in _Data.Videos) { - CVideoSkinElement sk = new CVideoSkinElement(); - xmlReader.GetValue("//root/Videos/" + name, out sk.FileName); + CVideoSkinElement sk = new CVideoSkinElement {FileName = kvp.Value}; if (!File.Exists(Path.Combine(_Folder, sk.FileName))) { - CLog.LogError("Video \"" + name + "\": (" + sk.FileName + ") not found!", true); + CLog.LogError("Video \"" + kvp.Key + "\": (" + sk.FileName + ") not found!", true); return false; } - _Videos.Add(name, sk); + _Videos.Add(kvp.Key, sk); } - if (!_LoadColors(xmlReader)) - return false; - _IsLoaded = true; return true; } @@ -166,27 +156,13 @@ namespace Vocaluxe.Base.ThemeSystem _Textures.Clear(); _Videos.Clear(); - _Colors.Clear(); _IsLoaded = false; } - private bool _LoadColors(CXMLReader xmlReader) - { - List names = xmlReader.GetNames("//root/Colors/*"); - foreach (string str in names) - { - SColorF color; - if (!xmlReader.Read("//root/Colors/" + str, out color)) - return false; - _Colors.Add(str, color); - } - return true; - } - public virtual bool GetColor(string colorName, out SColorF color) { - return _Colors.TryGetValue(colorName, out color); + return _Data.Colors.TryGetValue(colorName, out color); } public virtual CVideoStream GetVideo(string videoName, bool loop) diff --git a/Vocaluxe/Base/ThemeSystem/CTheme.cs b/Vocaluxe/Base/ThemeSystem/CTheme.cs index be6e6156..631e234b 100644 --- a/Vocaluxe/Base/ThemeSystem/CTheme.cs +++ b/Vocaluxe/Base/ThemeSystem/CTheme.cs @@ -25,25 +25,15 @@ using VocaluxeLib.Xml; namespace Vocaluxe.Base.ThemeSystem { - struct SThemeCursor - { - public string SkinName; - - public float W; - public float H; - - public SThemeColor Color; - } - abstract class CTheme { // Version number for theme files. Increment it, if you've changed something on the theme files! private const int _ThemeSystemVersion = 5; - private SInfo _Info; + protected STheme _Data; public String Name { - get { return _Info.Name; } + get { return _Data.Info.Name; } } public string[] SkinNames @@ -77,18 +67,20 @@ namespace Vocaluxe.Base.ThemeSystem public bool Init() { - CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(_Folder, _FileName)); - if (xmlReader == null) - return false; - - if (!xmlReader.CheckVersion("//root/ThemeSystemVersion", _ThemeSystemVersion)) - return false; - - bool ok = xmlReader.Read("//root/Info", out _Info); - - if (!ok) + try { - CLog.LogError("Can't load theme \"" + _FileName + "\". Invalid file!"); + var xml = new CXmlSerializer(); + _Data = xml.Deserialize(Path.Combine(_Folder, _FileName)); + if (_Data.ThemeSystemVersion != _ThemeSystemVersion) + { + string errorMsg = _Data.ThemeSystemVersion < _ThemeSystemVersion ? "the file ist outdated!" : "the file is for newer program versions!"; + errorMsg += " Current Version is " + _ThemeSystemVersion; + throw new Exception(errorMsg); + } + } + catch (Exception e) + { + CLog.LogError("Can't load theme \"" + _FileName + "\". Invalid file!", false, false, e); return false; } @@ -96,7 +88,7 @@ namespace Vocaluxe.Base.ThemeSystem List files = CHelper.ListFiles(path, "*.xml"); // Load skins, succeed if at least 1 skin was loaded - ok = false; + bool ok = false; foreach (string file in files) { CSkin skin = _GetNewSkin(path, file); @@ -110,20 +102,17 @@ namespace Vocaluxe.Base.ThemeSystem } protected abstract CSkin _GetNewSkin(string path, string file); - protected abstract bool _Load(CXMLReader xmlReader); + protected abstract bool _Load(); protected abstract bool _LoadSkin(); public bool Load() { if (_IsLoaded) return true; - CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(_Folder, _FileName)); - if (xmlReader == null) - return false; if (!_LoadSkin()) return false; - bool ok = _Load(xmlReader); + bool ok = _Load(); _IsLoaded = ok; return ok; diff --git a/Vocaluxe/Base/XmlStructs.cs b/Vocaluxe/Base/XmlStructs.cs new file mode 100644 index 00000000..366aa695 --- /dev/null +++ b/Vocaluxe/Base/XmlStructs.cs @@ -0,0 +1,100 @@ +#region license +// This file is part of Vocaluxe. +// +// Vocaluxe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Vocaluxe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Vocaluxe. If not, see . +#endregion + +using System.Collections.Generic; +using System.ComponentModel; +using System.Xml.Serialization; +using Vocaluxe.Base.Fonts; +using VocaluxeLib; +using VocaluxeLib.Xml; + +namespace Vocaluxe.Base +{ + public struct SInfo + { + public string Name; + public string Author; + public int VersionMajor; + public int VersionMinor; + } + + struct SThemeCursor + { + [XmlElement("Skin")] public string SkinName; + + public float W; + public float H; + + public SThemeColor Color; + } + + struct STheme + { + public int ThemeSystemVersion; + public SInfo Info; + [XmlArray, DefaultValue(null)] public SFontFamily[] Fonts; + public SThemeCursor? Cursor; + } + + struct SDefaultFonts + { + [XmlArray] public SFontFamily[] Fonts; + } + + /// + /// Struct used for describing a font family (a type of text with 4 different styles) + /// + [XmlType("Font")] + struct SFontFamily + { + public string Name; + [XmlIgnore] public int PartyModeID; + [XmlIgnore] public string ThemeName; + + [XmlNormalized] public float Outline; //0..1, 0=not outline 1=100% outline + public SColorF OutlineColor; + + public string Folder; + + public string FileNormal; + public string FileBold; + public string FileItalic; + public string FileBoldItalic; + + [XmlIgnore] public CFontStyle Normal; + [XmlIgnore] public CFontStyle Italic; + [XmlIgnore] public CFontStyle Bold; + [XmlIgnore] public CFontStyle BoldItalic; + + public void Dispose() + { + Normal.Dispose(); + Italic.Dispose(); + Bold.Dispose(); + BoldItalic.Dispose(); + } + } + + struct SSkin + { + public int SkinSystemVersion; + public SInfo Info; + public Dictionary Colors; + public Dictionary Skins; + public Dictionary Videos; + } +} \ No newline at end of file diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index c746bcc1..d38b6d10 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -226,6 +226,7 @@ + diff --git a/VocaluxeLib/Menu/CMenu.cs b/VocaluxeLib/Menu/CMenu.cs index bfe343e0..d84d7c97 100644 --- a/VocaluxeLib/Menu/CMenu.cs +++ b/VocaluxeLib/Menu/CMenu.cs @@ -34,7 +34,7 @@ namespace VocaluxeLib.Menu } [XmlType("Screen")] - public struct STheme + public struct SThemeScreen { public SScreenInformation Informations; [XmlArray("Backgrounds")] public List Backgrounds; @@ -65,7 +65,7 @@ namespace VocaluxeLib.Menu protected abstract int _ScreenVersion { get; } public int PartyModeID { get; protected set; } public string ThemeName { get; set; } - public STheme Theme; + public SThemeScreen Theme; // ReSharper disable MemberCanBePrivate.Global protected string[] _ThemeBackgrounds; @@ -171,8 +171,8 @@ namespace VocaluxeLib.Menu try { TextReader textReader = new StreamReader(file); - XmlSerializer deserializer = new XmlSerializer(typeof(STheme)); - Theme = (STheme)deserializer.Deserialize(textReader); + XmlSerializer deserializer = new XmlSerializer(typeof(SThemeScreen)); + Theme = (SThemeScreen)deserializer.Deserialize(textReader); foreach (SThemeBackground bg in Theme.Backgrounds) _AddBackground(new CBackground(bg, PartyModeID), bg.Name); @@ -334,7 +334,7 @@ namespace VocaluxeLib.Menu { TextWriter textWriter = new StreamWriter(Path.Combine(ThemePath, ThemeName + ".xml")); - XmlSerializer serializer = new XmlSerializer(typeof(STheme)); + XmlSerializer serializer = new XmlSerializer(typeof(SThemeScreen)); serializer.Serialize(textWriter, Theme); textWriter.Close(); diff --git a/VocaluxeLib/Structs.cs b/VocaluxeLib/Structs.cs index 364669f5..b5b046b7 100644 --- a/VocaluxeLib/Structs.cs +++ b/VocaluxeLib/Structs.cs @@ -72,21 +72,10 @@ namespace VocaluxeLib [XmlElement("CoverGenerator", IsNullable = false)] public List CoverGenerators; } - public struct SInfo - { - public string Name; - public string Author; - public int VersionMajor; - public int VersionMinor; - } - #region Drawing public struct SColorF { - public float R; - public float G; - public float B; - public float A; + [XmlNormalized] public float R, G, B, A; public SColorF(float r, float g, float b, float a) { diff --git a/VocaluxeLib/Xml/CXmlDeserializer.cs b/VocaluxeLib/Xml/CXmlDeserializer.cs index 42853ba4..0da230be 100644 --- a/VocaluxeLib/Xml/CXmlDeserializer.cs +++ b/VocaluxeLib/Xml/CXmlDeserializer.cs @@ -100,16 +100,6 @@ namespace VocaluxeLib.Xml return ok; } - public bool Read(string xPath, out SInfo el) - { - el = new SInfo(); - bool ok = GetValue(xPath + "/Name", out el.Name); - ok &= GetValue(xPath + "/Author", out el.Author); - ok &= TryGetIntValue(xPath + "/VersionMajor", ref el.VersionMajor); - ok &= TryGetIntValue(xPath + "/VersionMinor", ref el.VersionMinor); - return ok; - } - public bool Read(string xPath, out SColorF value) { value = new SColorF();