From 6ebbf7df6f5d5d06363ca4ad41afdcb6b8e3e906 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Wed, 1 Oct 2014 00:13:40 +0200 Subject: [PATCH] Introduce example for a more flexible deserialization Also make the CoverGenerator themes serializeable Rest is automatic reformatting. --- Output/Cover/Blue.xml | 58 ++++++------ Vocaluxe/Base/CConfig.cs | 3 +- Vocaluxe/Base/CCover.cs | 82 ++++++++-------- Vocaluxe/Base/CLanguage.cs | 1 + Vocaluxe/Base/CNoCoverGenerator.cs | 93 +++++-------------- Vocaluxe/Base/CParty.cs | 2 +- Vocaluxe/Base/CTheme.cs | 1 + Vocaluxe/Base/Fonts/CFonts.cs | 1 + Vocaluxe/Lib/Playlist/CPlaylistFile.cs | 1 + VocaluxeLib/CFont.cs | 12 ++- VocaluxeLib/Menu/CBackground.cs | 16 ++-- VocaluxeLib/Menu/CButton.cs | 29 ++---- VocaluxeLib/Menu/CEqualizer.cs | 33 +++---- VocaluxeLib/Menu/CLyric.cs | 17 ++-- VocaluxeLib/Menu/CMenu.cs | 1 + VocaluxeLib/Menu/CNameSelection.cs | 62 +++++-------- VocaluxeLib/Menu/CParticle.cs | 24 ++--- VocaluxeLib/Menu/CPlaylist.cs | 66 +++++-------- VocaluxeLib/Menu/CScreenSetting.cs | 10 +- VocaluxeLib/Menu/CSelectSlide.cs | 1 + VocaluxeLib/Menu/CStatic.cs | 12 +-- VocaluxeLib/Menu/CText.cs | 1 + VocaluxeLib/Menu/IMenuElement.cs | 1 + VocaluxeLib/Menu/SingNotes/CSingNotes.cs | 1 + VocaluxeLib/Menu/SongMenu/CSongMenu.cs | 1 + .../Menu/SongMenu/CSongMenuFramework.cs | 51 +++------- .../Menu/SongMenu/CSongMenuTileBoard.cs | 1 + VocaluxeLib/Profile/CProfile.cs | 1 + VocaluxeLib/Structs.cs | 48 ++++++++++ VocaluxeLib/VocaluxeLib.csproj | 4 +- VocaluxeLib/{ => Xml}/CXMLReader.cs | 62 ++++--------- VocaluxeLib/Xml/CXmlDeserializer.cs | 68 ++++++++++++++ VocaluxeLib/Xml/CXmlReaderBase.cs | 61 ++++++++++++ 33 files changed, 428 insertions(+), 397 deletions(-) rename VocaluxeLib/{ => Xml}/CXMLReader.cs (70%) create mode 100644 VocaluxeLib/Xml/CXmlDeserializer.cs create mode 100644 VocaluxeLib/Xml/CXmlReaderBase.cs diff --git a/Output/Cover/Blue.xml b/Output/Cover/Blue.xml index 4448fe2b..8afbbb3b 100644 --- a/Output/Cover/Blue.xml +++ b/Output/Cover/Blue.xml @@ -5,37 +5,41 @@ Blue flokuep - - + + - - - - %TEXT% - - Outline + Default + + + %TEXT% + + Normal 500 - - + + + + 1110.8 - - 24 - 24 - - 100 - - - 1111 - - - EmptyCover.png - - true - - 0.75 - - + + + + 24 + 24 + + + 100 + + + 1111 + + + EmptyCover.png + + true + + 0.75 + diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 12d913a0..3e201c06 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -28,6 +28,7 @@ using Vocaluxe.Lib.Sound.Record; using Vocaluxe.Lib.Webcam; using VocaluxeLib; using VocaluxeLib.Profile; +using VocaluxeLib.Xml; namespace Vocaluxe.Base { @@ -840,7 +841,7 @@ namespace Vocaluxe.Base break; case "oldtheme": - if(value == "yes") + if (value == "yes") LoadOldThemeFiles = true; break; } diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index 0297ab7c..096e988f 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -23,24 +23,23 @@ using System.Threading.Tasks; using VocaluxeLib; using VocaluxeLib.Draw; using VocaluxeLib.Songs; +using VocaluxeLib.Xml; namespace Vocaluxe.Base { - struct SCoverTheme + struct SThemeCover { - public string Name; - public string Folder; - public string File; + public string Name, Folder; + public string FilePath; } static class CCover { private const string _NoCoverName = "No Cover"; private const string _NoCoverNameAlt = "NoCover"; - private const string _DefaultTypeName = "Default"; private static readonly Dictionary _Covers = new Dictionary(); - private static readonly Dictionary _NoCoverThemes = new Dictionary(); - private static readonly List _CoverThemes = new List(); + private static readonly Dictionary _NoCoverGenerators = new Dictionary(); + private static readonly List _CoverThemes = new List(); public static CTextureRef NoCover { get; private set; } @@ -105,9 +104,10 @@ namespace Vocaluxe.Base CTextureRef texture = CDraw.CopyTexture(NoCover); Task.Factory.StartNew(() => { - Bitmap coverBmp = _NoCoverThemes[_SongSortingToType(sorting)].GetCover(text, firstSong != null ? Path.Combine(firstSong.Folder, firstSong.CoverFileName) : null); - if (coverBmp == null) - coverBmp = _NoCoverThemes[_DefaultTypeName].GetCover(text, firstSong != null ? Path.Combine(firstSong.Folder, firstSong.CoverFileName) : null); + ECoverGeneratorType type = _SongSortingToType(sorting); + Bitmap coverBmp = !_NoCoverGenerators.ContainsKey(type)?null:_NoCoverGenerators[type].GetCover(text, firstSong != null ? Path.Combine(firstSong.Folder, firstSong.CoverFileName) : null); + if (coverBmp == null && _NoCoverGenerators.ContainsKey(ECoverGeneratorType.Default)) + coverBmp = _NoCoverGenerators[ECoverGeneratorType.Default].GetCover(text, firstSong != null ? Path.Combine(firstSong.Folder, firstSong.CoverFileName) : null); if (coverBmp != null) CDraw.EnqueueTextureUpdate(texture, coverBmp); }); @@ -147,23 +147,23 @@ namespace Vocaluxe.Base } _Covers.Clear(); } - lock (_NoCoverThemes) + lock (_NoCoverGenerators) { - _NoCoverThemes.Clear(); + _NoCoverGenerators.Clear(); } } /// /// Returns a SCoverTheme by cover-theme-name /// - private static SCoverTheme _CoverTheme(string coverThemeName) + private static SThemeCover _CoverTheme(string coverThemeName) { for (int i = 0; i < _CoverThemes.Count; i++) { if (_CoverThemes[i].Name == coverThemeName) return _CoverThemes[i]; } - return new SCoverTheme(); + return new SThemeCover(); } /// @@ -182,14 +182,14 @@ namespace Vocaluxe.Base if (xmlReader != null) { - var coverTheme = new SCoverTheme(); + var coverTheme = new SThemeCover(); xmlReader.GetValue("//root/Info/Name", out coverTheme.Name, String.Empty); xmlReader.GetValue("//root/Info/Folder", out coverTheme.Folder, String.Empty); if (coverTheme.Folder != "" && coverTheme.Name != "") { - coverTheme.File = file; + coverTheme.FilePath = xmlReader.FilePath; _CoverThemes.Add(coverTheme); } @@ -202,7 +202,7 @@ namespace Vocaluxe.Base /// private static void _LoadCovers(string coverThemeName) { - SCoverTheme coverTheme = _CoverTheme(coverThemeName); + SThemeCover coverTheme = _CoverTheme(coverThemeName); if (String.IsNullOrEmpty(coverTheme.Name)) return; @@ -224,51 +224,53 @@ namespace Vocaluxe.Base _LoadNoCoverThemes(coverTheme); } - private static string _SongSortingToType(ESongSorting sorting) + private static ECoverGeneratorType _SongSortingToType(ESongSorting sorting) { switch (sorting) { case ESongSorting.TR_CONFIG_NONE: - return _DefaultTypeName; + return ECoverGeneratorType.Default; case ESongSorting.TR_CONFIG_FOLDER: - return "Folder"; + return ECoverGeneratorType.Folder; case ESongSorting.TR_CONFIG_ARTIST: - return "Artist"; + return ECoverGeneratorType.Artist; case ESongSorting.TR_CONFIG_ARTIST_LETTER: case ESongSorting.TR_CONFIG_TITLE_LETTER: - return "Letter"; + return ECoverGeneratorType.Letter; case ESongSorting.TR_CONFIG_EDITION: - return "Edition"; + return ECoverGeneratorType.Edition; case ESongSorting.TR_CONFIG_GENRE: - return "Genre"; + return ECoverGeneratorType.Genre; case ESongSorting.TR_CONFIG_LANGUAGE: - return "Language"; + return ECoverGeneratorType.Language; case ESongSorting.TR_CONFIG_YEAR: - return "Year"; + return ECoverGeneratorType.Year; case ESongSorting.TR_CONFIG_DECADE: - return "Decade"; + return ECoverGeneratorType.Decade; case ESongSorting.TR_CONFIG_DATEADDED: - return "Date"; + return ECoverGeneratorType.Date; default: throw new ArgumentOutOfRangeException("sorting"); } } - private static void _LoadNoCoverThemes(SCoverTheme coverTheme) + private static void _LoadNoCoverThemes(SThemeCover coverTheme) { - CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover, coverTheme.File)); - List types = new List(); - foreach (ESongSorting sorting in Enum.GetValues(typeof(ESongSorting))) - types.Add(_SongSortingToType(sorting)); + CXMLReader xmlReader = CXMLReader.OpenFile(coverTheme.FilePath); string coverPath = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover, coverTheme.Folder); - lock (_NoCoverThemes) + lock (_NoCoverGenerators) { - foreach (string type in types) - { - if (_NoCoverThemes.ContainsKey(type)) - continue; - CNoCoverGenerator el = new CNoCoverGenerator(xmlReader, "//root/MissingCover/" + type, coverPath); - _NoCoverThemes.Add(type, el); + int i = 1; + while(xmlReader.ItemExists("//root/CoverGenerator"+i)){ + SThemeCoverGenerator theme; + if (xmlReader.Read("//root/CoverGenerator" + i, out theme)) + { + if (_NoCoverGenerators.ContainsKey(theme.Type)) + continue; + CNoCoverGenerator el = new CNoCoverGenerator(theme, coverPath); + _NoCoverGenerators.Add(theme.Type, el); + } + i++; } } } diff --git a/Vocaluxe/Base/CLanguage.cs b/Vocaluxe/Base/CLanguage.cs index fb452747..9f529b4f 100644 --- a/Vocaluxe/Base/CLanguage.cs +++ b/Vocaluxe/Base/CLanguage.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using VocaluxeLib; +using VocaluxeLib.Xml; namespace Vocaluxe.Base { diff --git a/Vocaluxe/Base/CNoCoverGenerator.cs b/Vocaluxe/Base/CNoCoverGenerator.cs index 6c7803ef..d92177e0 100644 --- a/Vocaluxe/Base/CNoCoverGenerator.cs +++ b/Vocaluxe/Base/CNoCoverGenerator.cs @@ -36,20 +36,10 @@ namespace Vocaluxe.Base class CNoCoverGenerator { private readonly bool _Valid; - private readonly string _Text; - private readonly SColorF _BGColor; - private readonly SColorF _TextColor; - private readonly int _TextMarginLeft; - private readonly int _TextMarginRight; - private readonly int _TextMarginTop; - private readonly int _TextMarginBottom; - private readonly int _TextIndent; - private readonly int _TextSize; - private readonly string _Font; - private readonly EStyle _Style; + private readonly SThemeCoverGenerator _Theme; private readonly string _Image; - private readonly bool _ShowFirstCover; - private readonly float _ImageAlpha; + private readonly SColorF _TextColor; + private readonly SColorF _BGColor; private const int _LineSpace = 5; /// @@ -59,52 +49,15 @@ namespace Vocaluxe.Base private static readonly char[] _SplitCharAfter = {':', '/', '-', ' ', ')', '.', '*', ','}; private static readonly char[] _SplitCharBefore = {'('}; - public CNoCoverGenerator(CXMLReader xmlReader, string xPath, string basePath) + public CNoCoverGenerator(SThemeCoverGenerator theme, string basePath) { - _Valid = xmlReader.ItemExists(xPath); - if (!_Valid) - return; - _Valid &= xmlReader.GetValue(xPath + "/Text/Text", out _Text); - _Valid &= xmlReader.GetValue(xPath + "/Text/Font", out _Font); - _Valid &= xmlReader.TryGetEnumValue(xPath + "/Text/Style", ref _Style); - _Valid &= xmlReader.TryGetIntValue(xPath + "/Text/Size", ref _TextSize); - string colorName; - if (xmlReader.GetValue(xPath + "/Text/Color", out colorName)) - _Valid &= CBase.Theme.GetColor(colorName, CBase.Theme.GetSkinIndex(-1), out _TextColor); - else - _Valid &= xmlReader.TryGetColorFromRGBA(xPath + "/Text", ref _TextColor); - int tmpMargin = 0; - bool marginSet = xmlReader.TryGetIntValue(xPath + "/Text/Margin", ref tmpMargin); - if (marginSet) - { - _TextMarginLeft = tmpMargin; - _TextMarginRight = tmpMargin; - _TextMarginTop = tmpMargin; - _TextMarginBottom = tmpMargin; - } - _Valid &= xmlReader.TryGetIntValue(xPath + "/Text/MarginLeft", ref _TextMarginLeft) || marginSet; - _Valid &= xmlReader.TryGetIntValue(xPath + "/Text/MarginRight", ref _TextMarginRight) || marginSet; - _Valid &= xmlReader.TryGetIntValue(xPath + "/Text/MarginTop", ref _TextMarginTop) || marginSet; - _Valid &= xmlReader.TryGetIntValue(xPath + "/Text/MarginBottom", ref _TextMarginBottom) || marginSet; - if (!xmlReader.TryGetIntValue(xPath + "/Text/Indent", ref _TextIndent)) - _TextIndent = 6 * (_TextMarginLeft + _TextMarginRight) / 2; - - if (xmlReader.GetValue(xPath + "/Background/Color", out colorName)) - _Valid &= CBase.Theme.GetColor(colorName, CBase.Theme.GetSkinIndex(-1), out _BGColor); - else - _Valid &= xmlReader.TryGetColorFromRGBA(xPath + "/Background", ref _BGColor); - _Valid &= xmlReader.GetValue(xPath + "/Image", out _Image); - string tmp; - if (xmlReader.GetValue(xPath + "/ShowFirstCover", out tmp)) - Boolean.TryParse(tmp, out _ShowFirstCover); - else - _ShowFirstCover = false; - _ImageAlpha = !xmlReader.TryGetFloatValue(xPath + "/ImageAlpha", ref _ImageAlpha) ? 0.5f : _ImageAlpha.Clamp(0f, 1f); + _Theme = theme; + _Valid = true; + _Valid &= _Theme.Text.Color.Get(-1, out _TextColor); + _Valid &= _Theme.BackgroundColor.Get(-1, out _BGColor); if (_Valid) { - // ReSharper disable AssignNullToNotNullAttribute - _Image = Path.Combine(basePath, _Image); - // ReSharper restore AssignNullToNotNullAttribute + _Image = Path.Combine(basePath, _Theme.Image); _Valid = File.Exists(_Image); } } @@ -153,11 +106,11 @@ namespace Vocaluxe.Base g.Clear(_BGColor.AsColor()); ImageAttributes ia = null; - if (_ShowFirstCover && !String.IsNullOrEmpty(firstCoverPath) && File.Exists(firstCoverPath)) + if (_Theme.ShowFirstCover && !String.IsNullOrEmpty(firstCoverPath) && File.Exists(firstCoverPath)) { using (Bitmap bmp2 = new Bitmap(firstCoverPath)) g.DrawImage(bmp2, bmpBackground.GetRect(), 0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel); - ColorMatrix cm = new ColorMatrix {Matrix33 = _ImageAlpha}; + ColorMatrix cm = new ColorMatrix {Matrix33 = _Theme.ImageAlpha}; ia = new ImageAttributes(); ia.SetColorMatrix(cm); } @@ -182,7 +135,7 @@ namespace Vocaluxe.Base { pen.LineJoin = LineJoin.Round; pen.Alignment = PenAlignment.Outset; - float top = (bmpSize.Height - _TextMarginBottom - _TextMarginTop - maxHeight * lineCount) / 2 + _TextMarginTop; + float top = (bmpSize.Height - _Theme.Text.Margin.Bottom - _Theme.Text.Margin.Top - maxHeight * lineCount) / 2 + _Theme.Text.Margin.Top; int nextLineEl = 0; for (int i = 0; i < lineCount; i++) { @@ -199,16 +152,16 @@ namespace Vocaluxe.Base { //Center Text if this is the only line or the middle line float width = _GetWidth(elements, firstEl, nextLineEl - 1); - left = (bmpSize.Width - _TextMarginLeft - _TextMarginRight - width) / 2 + _TextMarginLeft; + left = (bmpSize.Width - _Theme.Text.Margin.Left - _Theme.Text.Margin.Right - width) / 2 + _Theme.Text.Margin.Left; } else if (i == lineCount - 1) { //Place last line at right float width = _GetWidth(elements, firstEl, nextLineEl - 1); - left = bmpSize.Width - width - _TextMarginRight; + left = bmpSize.Width - width - _Theme.Text.Margin.Right; } else - left = _TextMarginLeft; + left = _Theme.Text.Margin.Left; //g.DrawString(line, fo, new SolidBrush(_TextColor.AsColor()), left, top, StringFormat.GenericTypographic); path.AddString(line, fo.FontFamily, (int)fo.Style, emSize, new PointF(left, top), StringFormat.GenericTypographic); top += maxHeight + _LineSpace; @@ -222,7 +175,7 @@ namespace Vocaluxe.Base { if (!_Valid) return null; - text = CLanguage.Translate(_Text.Replace("%TEXT%", text)); + text = CLanguage.Translate(_Theme.Text.Text.Replace("%TEXT%", text)); using (Bitmap bmpImage = new Bitmap(_Image)) { Bitmap bmp = new Bitmap(bmpImage.Width, bmpImage.Height, PixelFormat.Format32bppArgb); @@ -238,7 +191,7 @@ namespace Vocaluxe.Base if (text != "") { - CFont font = new CFont(_Font, _Style, bmp.Height - _TextMarginTop - _TextMarginBottom); + CFont font = new CFont(_Theme.Text.Font); Font fo = CFonts.GetSystemFont(font); IEnumerable textParts = _SplitText(text); List elements = textParts.Select(line => new CTextElement(line, g, fo)).ToList(); @@ -269,14 +222,14 @@ namespace Vocaluxe.Base /// Factor for resizing the text (Maximizing this factor means maximizing the height) private float _DistributeText(List elements, int width, int height) { - int availableWidth = width - _TextMarginLeft - _TextMarginRight; - int availableHeight = height - _TextMarginTop - _TextMarginBottom; + int availableWidth = width - _Theme.Text.Margin.Left - _Theme.Text.Margin.Right; + int availableHeight = height - _Theme.Text.Margin.Top - _Theme.Text.Margin.Bottom; float textHeight = elements.Select(el => el.Height).Max(); //Try 1 line: float textWidth = _GetWidth(elements, 0); - int maxHeight = Math.Min(availableHeight, _TextSize); + int maxHeight = Math.Min(availableHeight, (int)_Theme.Text.Font.Size); float factorH = maxHeight / textHeight; float factorW = availableWidth / textWidth; if (factorH <= factorW) @@ -289,8 +242,8 @@ namespace Vocaluxe.Base //Only 1 element -> 1 line return factor1; } - availableWidth -= _TextIndent; - maxHeight = Math.Min(availableHeight / 2 - _LineSpace, _TextSize); + availableWidth -= _Theme.Text.Indent; + maxHeight = Math.Min(availableHeight / 2 - _LineSpace, (int)_Theme.Text.Font.Size); factorH = maxHeight / textHeight; if (factorH <= factor1) return factor1; //Cannot get any bigger with more lines @@ -311,7 +264,7 @@ namespace Vocaluxe.Base float factor2 = factorW; //Try 3 lines - maxHeight = Math.Min(availableHeight / 3 - 2 * _LineSpace, _TextSize); + maxHeight = Math.Min(availableHeight / 3 - 2 * _LineSpace, (int)_Theme.Text.Font.Size); factorH = maxHeight / textHeight; if (elements.Count == 2 || factorH <= Math.Max(factor1, factor2)) { diff --git a/Vocaluxe/Base/CParty.cs b/Vocaluxe/Base/CParty.cs index 469e8af9..87607df9 100644 --- a/Vocaluxe/Base/CParty.cs +++ b/Vocaluxe/Base/CParty.cs @@ -23,6 +23,7 @@ using System.Reflection; using VocaluxeLib; using VocaluxeLib.Menu; using VocaluxeLib.PartyModes; +using VocaluxeLib.Xml; namespace Vocaluxe.Base { @@ -99,7 +100,6 @@ namespace Vocaluxe.Base pair.Value.PartyMode.SaveScreens(); } - public static List GetPartyModeInfos() { var infos = new List(); diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index 8c8e9068..b66796f1 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -23,6 +23,7 @@ using System.Xml; using Vocaluxe.Base.Fonts; using VocaluxeLib; using VocaluxeLib.Draw; +using VocaluxeLib.Xml; namespace Vocaluxe.Base { diff --git a/Vocaluxe/Base/Fonts/CFonts.cs b/Vocaluxe/Base/Fonts/CFonts.cs index a617dfd5..bdcdefbe 100644 --- a/Vocaluxe/Base/Fonts/CFonts.cs +++ b/Vocaluxe/Base/Fonts/CFonts.cs @@ -24,6 +24,7 @@ using System.Linq; using System.Xml; using VocaluxeLib; using VocaluxeLib.Menu; +using VocaluxeLib.Xml; namespace Vocaluxe.Base.Fonts { diff --git a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs index ff86215f..d09c9b95 100644 --- a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs +++ b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs @@ -24,6 +24,7 @@ using Vocaluxe.Base; using VocaluxeLib; using VocaluxeLib.Menu; using VocaluxeLib.Songs; +using VocaluxeLib.Xml; namespace Vocaluxe.Lib.Playlist { diff --git a/VocaluxeLib/CFont.cs b/VocaluxeLib/CFont.cs index 00524ec5..bb8fed4e 100644 --- a/VocaluxeLib/CFont.cs +++ b/VocaluxeLib/CFont.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Xml.Serialization; namespace VocaluxeLib { @@ -8,6 +9,13 @@ namespace VocaluxeLib void FontChanged(); } + public struct SThemeFont + { + public string Name; + public EStyle Style; + public float Size; + } + public class CFont { private string _Name; @@ -59,11 +67,11 @@ namespace VocaluxeLib _Height = 25f; } - public CFont(CFont font) + public CFont(SThemeFont font) { _Name = font.Name; _Style = font.Style; - _Height = font.Height; + _Height = font.Size; } public CFont(string fontFamily, EStyle style, float h) diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index 9faeb4c9..46a64c3d 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -21,6 +21,7 @@ using System.Xml.Serialization; using System.Diagnostics; using System.Collections.Generic; using VocaluxeLib.Draw; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { @@ -36,16 +37,11 @@ namespace VocaluxeLib.Menu [XmlType("Background")] public struct SThemeBackground { - [XmlAttributeAttribute(AttributeName = "Name")] - public string Name; - [XmlElement("Type")] - public EBackgroundTypes Type; - [XmlArray] - public List SlideShowTextures; - [XmlElement("Video")] - public string VideoName; - [XmlElement("Skin")] - public string TextureName; + [XmlAttribute(AttributeName = "Name")] public string Name; + [XmlElement("Type")] public EBackgroundTypes Type; + [XmlArray] public List SlideShowTextures; + [XmlElement("Video")] public string VideoName; + [XmlElement("Skin")] public string TextureName; public SThemeColor Color; } diff --git a/VocaluxeLib/Menu/CButton.cs b/VocaluxeLib/Menu/CButton.cs index d842a04a..d2652ba4 100644 --- a/VocaluxeLib/Menu/CButton.cs +++ b/VocaluxeLib/Menu/CButton.cs @@ -19,33 +19,25 @@ using System; using System.Xml; using System.Xml.Serialization; using VocaluxeLib.Draw; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { [XmlType("Button")] public struct SThemeButton { - [XmlAttributeAttribute(AttributeName = "Name")] - public string Name; + [XmlAttribute(AttributeName = "Name")] public string Name; - [XmlElement("Skin")] - public string TextureName; - [XmlElement("SkinSelected")] - public string SelTextureName; + [XmlElement("Skin")] public string TextureName; + [XmlElement("SkinSelected")] public string SelTextureName; public SRectF Rect; - [XmlElement("Color")] - public SThemeColor Color; - [XmlElement("SelColor")] - public SThemeColor SelColor; - [XmlElement("Text")] - public SThemeText Text; - [XmlElement("SText")] - public SThemeText SText; + [XmlElement("Color")] public SThemeColor Color; + [XmlElement("SelColor")] public SThemeColor SelColor; + [XmlElement("Text")] public SThemeText Text; + [XmlElement("SText")] public SThemeText SText; public bool STextSpecified; - [XmlElement("Reflection")] - public SReflection Reflection; - [XmlElement("SelReflection")] - public SReflection SelReflection; + [XmlElement("Reflection")] public SReflection Reflection; + [XmlElement("SelReflection")] public SReflection SelReflection; } public class CButton : IMenuElement @@ -257,7 +249,6 @@ namespace VocaluxeLib.Menu return _ThemeLoaded; } - public void Draw(bool forceDraw = false) { if (!Visible && CBase.Settings.GetProgramState() != EProgramState.EditTheme && !forceDraw) diff --git a/VocaluxeLib/Menu/CEqualizer.cs b/VocaluxeLib/Menu/CEqualizer.cs index 732d3105..3faf40a1 100644 --- a/VocaluxeLib/Menu/CEqualizer.cs +++ b/VocaluxeLib/Menu/CEqualizer.cs @@ -18,6 +18,7 @@ using System; using System.Xml; using System.Xml.Serialization; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { @@ -29,30 +30,20 @@ namespace VocaluxeLib.Menu [XmlType("Equalizer")] public struct SThemeEqualizer { - [XmlAttributeAttribute(AttributeName = "Name")] - public string Name; + [XmlAttribute(AttributeName = "Name")] public string Name; - [XmlElement("Skin")] - public string TextureName; + [XmlElement("Skin")] public string TextureName; - [XmlElement("Rect")] - public SRectF Rect; + [XmlElement("Rect")] public SRectF Rect; - [XmlElement("NumBars")] - public int NumBars; - [XmlElement("Space")] - public float Space; - [XmlElement("Style")] - public EEqualizerStyle Style; - [XmlElement("DrawNegative")] - public EOffOn DrawNegative; + [XmlElement("NumBars")] public int NumBars; + [XmlElement("Space")] public float Space; + [XmlElement("Style")] public EEqualizerStyle Style; + [XmlElement("DrawNegative")] public EOffOn DrawNegative; - [XmlElement("Color")] - public SThemeColor Color; - [XmlElement("MaxColor")] - public SThemeColor MaxColor; - [XmlElement("Reflection")] - public SReflection Reflection; + [XmlElement("Color")] public SThemeColor Color; + [XmlElement("MaxColor")] public SThemeColor MaxColor; + [XmlElement("Reflection")] public SReflection Reflection; } public class CEqualizer : IMenuElement @@ -273,7 +264,7 @@ namespace VocaluxeLib.Menu Rect = _Theme.Rect; Space = _Theme.Space; Reflection = _Theme.Reflection.Enabled; - if(Reflection) + if (Reflection) { ReflectionHeight = _Theme.Reflection.Height; ReflectionSpace = _Theme.Reflection.Space; diff --git a/VocaluxeLib/Menu/CLyric.cs b/VocaluxeLib/Menu/CLyric.cs index 7a15a8a3..eb057bbd 100644 --- a/VocaluxeLib/Menu/CLyric.cs +++ b/VocaluxeLib/Menu/CLyric.cs @@ -19,22 +19,19 @@ using System; using System.Xml; using System.Xml.Serialization; using VocaluxeLib.Songs; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { [XmlType("Lyric")] public struct SThemeLyrics { - [XmlAttributeAttribute(AttributeName = "Name")] - public string Name; + [XmlAttribute(AttributeName = "Name")] public string Name; - [XmlElement("Rect")] - public SRectF Rect; + [XmlElement("Rect")] public SRectF Rect; - [XmlElement("Color")] - public SThemeColor Color; - [XmlElement("SColor")] - public SThemeColor SColor; + [XmlElement("Color")] public SThemeColor Color; + [XmlElement("SColor")] public SThemeColor SColor; } public class CLyric : IMenuElement @@ -192,7 +189,7 @@ namespace VocaluxeLib.Menu private void _SetText(CSongNote note) { _Text.Text = note.Text; - _Text.Font.Style = (note.Type == ENoteType.Freestyle)? EStyle.BoldItalic:EStyle.Bold; + _Text.Font.Style = (note.Type == ENoteType.Freestyle) ? EStyle.BoldItalic : EStyle.Bold; } public void Clear() @@ -338,7 +335,7 @@ namespace VocaluxeLib.Menu float tz = _Text.Z; SRectF normalRect = _Text.Rect; - _Text.Font.Height *= 1f+ p * 0.4f; + _Text.Font.Height *= 1f + p * 0.4f; _Text.X -= (_Text.Rect.W - normalRect.W) / 2f; _Text.Y -= (_Text.Rect.H - normalRect.H) / 2f; _Text.Z -= 0.1f; diff --git a/VocaluxeLib/Menu/CMenu.cs b/VocaluxeLib/Menu/CMenu.cs index 2a69aed7..500c1d82 100644 --- a/VocaluxeLib/Menu/CMenu.cs +++ b/VocaluxeLib/Menu/CMenu.cs @@ -25,6 +25,7 @@ using System.Xml.Serialization; using VocaluxeLib.Draw; using VocaluxeLib.Menu.SingNotes; using VocaluxeLib.Menu.SongMenu; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { diff --git a/VocaluxeLib/Menu/CNameSelection.cs b/VocaluxeLib/Menu/CNameSelection.cs index f02fa261..99a39a5d 100644 --- a/VocaluxeLib/Menu/CNameSelection.cs +++ b/VocaluxeLib/Menu/CNameSelection.cs @@ -22,56 +22,39 @@ using System.Xml; using System.Xml.Serialization; using VocaluxeLib.Draw; using VocaluxeLib.Profile; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { [XmlType("NameSelection")] public struct SThemeNameSelection { - [XmlAttributeAttribute(AttributeName = "Name")] - public string Name; - [XmlElement("Rect")] - public SRectF Rect; - [XmlElement("SkinEmptyTile")] - public string TextureEmptyTileName; - [XmlElement("ColorEmptyTile")] - public SThemeColor ColorEmptyTile; - [XmlElement("SkinTileSelected")] - public string TextureTileSelectedName; - [XmlElement("Tiles")] - public SThemeNameSelectionTiles Tiles; + [XmlAttribute(AttributeName = "Name")] public string Name; + [XmlElement("Rect")] public SRectF Rect; + [XmlElement("SkinEmptyTile")] public string TextureEmptyTileName; + [XmlElement("ColorEmptyTile")] public SThemeColor ColorEmptyTile; + [XmlElement("SkinTileSelected")] public string TextureTileSelectedName; + [XmlElement("Tiles")] public SThemeNameSelectionTiles Tiles; } public struct SThemeNameSelectionTiles { - [XmlElement("W")] - public int W; - [XmlElement("H")] - public int H; - [XmlElement("NumW")] - public int NumW; - [XmlElement("NumH")] - public int NumH; - [XmlElement("SpaceW")] - public float SpaceW; - [XmlElement("SpaceH")] - public float SpaceH; - [XmlElement("Name")] - public SThemeNameSelectionName Name; + [XmlElement("W")] public int W; + [XmlElement("H")] public int H; + [XmlElement("NumW")] public int NumW; + [XmlElement("NumH")] public int NumH; + [XmlElement("SpaceW")] public float SpaceW; + [XmlElement("SpaceH")] public float SpaceH; + [XmlElement("Name")] public SThemeNameSelectionName Name; } public struct SThemeNameSelectionName { - [XmlElement("Space")] - public float Space; - [XmlElement("H")] - public float Height; - [XmlElement("Font")] - public string Font; - [XmlElement("Style")] - public EStyle Style; - [XmlElement("Color")] - public SThemeColor Color; + [XmlElement("Space")] public float Space; + [XmlElement("H")] public float Height; + [XmlElement("Font")] public string Font; + [XmlElement("Style")] public EStyle Style; + [XmlElement("Color")] public SThemeColor Color; } public class CNameSelection : IMenuElement @@ -119,7 +102,6 @@ namespace VocaluxeLib.Menu public SColorF ColorEmptyTile; - public int Offset; private int _ActualSelection = -1; public int Selection = -1; @@ -517,9 +499,11 @@ namespace VocaluxeLib.Menu { for (int j = 0; j < _Theme.Tiles.NumW; j++) { - var rect = new SRectF(Rect.X + j * (_Theme.Tiles.W + _Theme.Tiles.SpaceW), Rect.Y + i * (_Theme.Tiles.H + _Theme.Tiles.SpaceH), _Theme.Tiles.W, _Theme.Tiles.H, Rect.Z); + var rect = new SRectF(Rect.X + j * (_Theme.Tiles.W + _Theme.Tiles.SpaceW), Rect.Y + i * (_Theme.Tiles.H + _Theme.Tiles.SpaceH), _Theme.Tiles.W, _Theme.Tiles.H, + Rect.Z); var tileStatic = new CStatic(_PartyModeID, _TextureEmptyTile, ColorEmptyTile, rect) {Aspect = EAspect.Crop}; - var tileText = new CText(rect.X + rect.W / 2, rect.Y + rect.H + _Theme.Tiles.Name.Space, rect.Z, _Theme.Tiles.Name.Height, rect.W, EAlignment.Center, _Theme.Tiles.Name.Style, + var tileText = new CText(rect.X + rect.W / 2, rect.Y + rect.H + _Theme.Tiles.Name.Space, rect.Z, _Theme.Tiles.Name.Height, rect.W, EAlignment.Center, + _Theme.Tiles.Name.Style, _Theme.Tiles.Name.Font, _Theme.Tiles.Name.Color.Color, ""); _Tiles.Add(new CTile(tileStatic, tileText, -1)); } diff --git a/VocaluxeLib/Menu/CParticle.cs b/VocaluxeLib/Menu/CParticle.cs index 25c72041..b21d52f6 100644 --- a/VocaluxeLib/Menu/CParticle.cs +++ b/VocaluxeLib/Menu/CParticle.cs @@ -21,27 +21,21 @@ using System.Diagnostics; using System.Xml; using System.Xml.Serialization; using VocaluxeLib.Draw; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { [XmlType("ParticleEffect")] public struct SThemeParticleEffect { - [XmlAttributeAttribute(AttributeName = "Name")] - public string Name; + [XmlAttribute(AttributeName = "Name")] public string Name; - [XmlElement("Skin")] - public string TextureName; - [XmlElement("Rect")] - public SRectF Rect; - [XmlElement("Color")] - public SThemeColor Color; - [XmlElement("Type")] - public EParticleType Type; - [XmlElement("Size")] - public float Size; - [XmlElement("MaxNumber")] - public int MaxNumber; + [XmlElement("Skin")] public string TextureName; + [XmlElement("Rect")] public SRectF Rect; + [XmlElement("Color")] public SThemeColor Color; + [XmlElement("Type")] public EParticleType Type; + [XmlElement("Size")] public float Size; + [XmlElement("MaxNumber")] public int MaxNumber; } public enum EParticleType @@ -159,8 +153,6 @@ namespace VocaluxeLib.Menu _MaxAge = maxage; _Rotation = (float)(CBase.Game.GetRandomDouble() * 360.0); } - - #endregion Constructors public void Update() diff --git a/VocaluxeLib/Menu/CPlaylist.cs b/VocaluxeLib/Menu/CPlaylist.cs index 6d3ec87f..57381f9a 100644 --- a/VocaluxeLib/Menu/CPlaylist.cs +++ b/VocaluxeLib/Menu/CPlaylist.cs @@ -21,6 +21,7 @@ using System.Windows.Forms; using System.Xml; using System.Xml.Serialization; using VocaluxeLib.Songs; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { @@ -57,48 +58,31 @@ namespace VocaluxeLib.Menu [XmlType("Playlist")] public struct SThemePlaylist { - [XmlAttributeAttribute(AttributeName = "Name")] - public string Name; + [XmlAttribute(AttributeName = "Name")] public string Name; - [XmlElement("Rect")] - public SRectF Rect; + [XmlElement("Rect")] public SRectF Rect; - [XmlElement("EntryHeight")] - public float EntryHeight; + [XmlElement("EntryHeight")] public float EntryHeight; - [XmlElement("SkinBackground")] - public string TextureBackgroundName; - [XmlElement("SkinBackgroundSelected")] - public string SelTextureBackgroundName; + [XmlElement("SkinBackground")] public string TextureBackgroundName; + [XmlElement("SkinBackgroundSelected")] public string SelTextureBackgroundName; - [XmlElement("ColorBackground")] - public SThemeColor ColorBackground; - [XmlElement("SColorBackground")] - public SThemeColor SelColorBackground; + [XmlElement("ColorBackground")] public SThemeColor ColorBackground; + [XmlElement("SColorBackground")] public SThemeColor SelColorBackground; - [XmlElement("Text1")] - public SThemeText SText1; + [XmlElement("Text1")] public SThemeText SText1; - [XmlElement("StaticCover")] - public SThemeStatic SStaticCover; - [XmlElement("StaticPlaylistHeader")] - public SThemeStatic SStaticPlaylistHeader; - [XmlElement("StaticPlaylistFooter")] - public SThemeStatic SStaticPlaylistFooter; + [XmlElement("StaticCover")] public SThemeStatic SStaticCover; + [XmlElement("StaticPlaylistHeader")] public SThemeStatic SStaticPlaylistHeader; + [XmlElement("StaticPlaylistFooter")] public SThemeStatic SStaticPlaylistFooter; - [XmlElement("ButtonPlaylistName")] - public SThemeButton SButtonPlaylistName; - [XmlElement("ButtonPlaylistClose")] - public SThemeButton SButtonPlaylistClose; - [XmlElement("ButtonPlaylistSave")] - public SThemeButton SButtonPlaylistSave; - [XmlElement("ButtonPlaylistDelete")] - public SThemeButton SButtonPlaylistDelete; - [XmlElement("ButtonPlaylistSing")] - public SThemeButton SButtonPlaylistSing; + [XmlElement("ButtonPlaylistName")] public SThemeButton SButtonPlaylistName; + [XmlElement("ButtonPlaylistClose")] public SThemeButton SButtonPlaylistClose; + [XmlElement("ButtonPlaylistSave")] public SThemeButton SButtonPlaylistSave; + [XmlElement("ButtonPlaylistDelete")] public SThemeButton SButtonPlaylistDelete; + [XmlElement("ButtonPlaylistSing")] public SThemeButton SButtonPlaylistSing; - [XmlElement("SelectSlideGameMode")] - public SThemeSelectSlide SSelectSlideGameMode; + [XmlElement("SelectSlideGameMode")] public SThemeSelectSlide SSelectSlideGameMode; } public class CPlaylist : IMenuElement @@ -187,7 +171,7 @@ namespace VocaluxeLib.Menu public SColorF BackgroundSelColor; public CButton ButtonPlaylistName; - public CButton ButtonPlaylistClose; + public CButton ButtonPlaylistClose; public CButton ButtonPlaylistSave; public CButton ButtonPlaylistDelete; public CButton ButtonPlaylistSing; @@ -353,7 +337,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= ButtonPlaylistSave.LoadTheme(item, "ButtonPlaylistSave", xmlReader, skinIndex); _ThemeLoaded &= ButtonPlaylistDelete.LoadTheme(item, "ButtonPlaylistDelete", xmlReader, skinIndex); - _ThemeLoaded &=SelectSlideGameMode.LoadTheme(item, "SelectSlideGameMode", xmlReader, skinIndex); + _ThemeLoaded &= SelectSlideGameMode.LoadTheme(item, "SelectSlideGameMode", xmlReader, skinIndex); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/EntryHeight", ref _Theme.EntryHeight); if (_ThemeLoaded) @@ -366,11 +350,11 @@ namespace VocaluxeLib.Menu _Theme.SStaticCover = StaticCover.GetTheme(); _Theme.SStaticPlaylistFooter = StaticPlaylistFooter.GetTheme(); _Theme.SStaticPlaylistHeader = StaticPlaylistHeader.GetTheme(); - _Theme.SButtonPlaylistName =ButtonPlaylistName.GetTheme(); - _Theme.SButtonPlaylistSing =ButtonPlaylistSing.GetTheme(); - _Theme.SButtonPlaylistClose =ButtonPlaylistClose.GetTheme(); - _Theme.SButtonPlaylistSave =ButtonPlaylistSave.GetTheme(); - _Theme.SButtonPlaylistDelete =ButtonPlaylistDelete.GetTheme(); + _Theme.SButtonPlaylistName = ButtonPlaylistName.GetTheme(); + _Theme.SButtonPlaylistSing = ButtonPlaylistSing.GetTheme(); + _Theme.SButtonPlaylistClose = ButtonPlaylistClose.GetTheme(); + _Theme.SButtonPlaylistSave = ButtonPlaylistSave.GetTheme(); + _Theme.SButtonPlaylistDelete = ButtonPlaylistDelete.GetTheme(); LoadTextures(); } diff --git a/VocaluxeLib/Menu/CScreenSetting.cs b/VocaluxeLib/Menu/CScreenSetting.cs index c46667c1..2bbc887c 100644 --- a/VocaluxeLib/Menu/CScreenSetting.cs +++ b/VocaluxeLib/Menu/CScreenSetting.cs @@ -19,6 +19,7 @@ using System; using System.Xml; using System.Xml.Serialization; using VocaluxeLib.Draw; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { @@ -33,12 +34,9 @@ namespace VocaluxeLib.Menu [XmlType("ScreenSetting")] public struct SScreenSetting { - [XmlAttributeAttribute(AttributeName = "Name")] - public string Name; - [XmlElement("Value")] - public string Value; - [XmlElement("Type")] - public ESettingType Type; + [XmlAttribute(AttributeName = "Name")] public string Name; + [XmlElement("Value")] public string Value; + [XmlElement("Type")] public ESettingType Type; } // ReSharper disable ClassNeverInstantiated.Global diff --git a/VocaluxeLib/Menu/CSelectSlide.cs b/VocaluxeLib/Menu/CSelectSlide.cs index 639e1c9e..05289057 100644 --- a/VocaluxeLib/Menu/CSelectSlide.cs +++ b/VocaluxeLib/Menu/CSelectSlide.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.Drawing; using System.Xml.Serialization; using VocaluxeLib.Draw; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { diff --git a/VocaluxeLib/Menu/CStatic.cs b/VocaluxeLib/Menu/CStatic.cs index 7d1dde1e..a223dc05 100644 --- a/VocaluxeLib/Menu/CStatic.cs +++ b/VocaluxeLib/Menu/CStatic.cs @@ -19,16 +19,15 @@ using System; using System.Xml; using System.Xml.Serialization; using VocaluxeLib.Draw; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { [XmlType("Static")] public struct SThemeStatic { - [XmlAttributeAttribute(AttributeName = "Name")] - public string Name; - [XmlElement("Skin")] - public string TextureName; + [XmlAttribute(AttributeName = "Name")] public string Name; + [XmlElement("Skin")] public string TextureName; public SThemeColor Color; public SRectF Rect; public SReflection Reflection; @@ -73,10 +72,7 @@ namespace VocaluxeLib.Menu public EAspect Aspect = EAspect.Stretch; - public CStatic() - { - - } + public CStatic() {} public CStatic(int partyModeID) { diff --git a/VocaluxeLib/Menu/CText.cs b/VocaluxeLib/Menu/CText.cs index d03de785..9f8c164f 100644 --- a/VocaluxeLib/Menu/CText.cs +++ b/VocaluxeLib/Menu/CText.cs @@ -18,6 +18,7 @@ using System; using System.Drawing; using System.Xml.Serialization; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { diff --git a/VocaluxeLib/Menu/IMenuElement.cs b/VocaluxeLib/Menu/IMenuElement.cs index dc805d70..391dd1ad 100644 --- a/VocaluxeLib/Menu/IMenuElement.cs +++ b/VocaluxeLib/Menu/IMenuElement.cs @@ -16,6 +16,7 @@ #endregion using System.Xml; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { diff --git a/VocaluxeLib/Menu/SingNotes/CSingNotes.cs b/VocaluxeLib/Menu/SingNotes/CSingNotes.cs index bda44a04..276f586b 100644 --- a/VocaluxeLib/Menu/SingNotes/CSingNotes.cs +++ b/VocaluxeLib/Menu/SingNotes/CSingNotes.cs @@ -21,6 +21,7 @@ using System.Diagnostics; using System.Xml.Serialization; using VocaluxeLib.Draw; using VocaluxeLib.Songs; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu.SingNotes { diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenu.cs b/VocaluxeLib/Menu/SongMenu/CSongMenu.cs index 529ec03b..1fcb9619 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenu.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenu.cs @@ -17,6 +17,7 @@ using System.Xml; using VocaluxeLib.PartyModes; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu.SongMenu { diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 8e7a224d..7906499d 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -23,34 +23,26 @@ using System.Xml.Serialization; using VocaluxeLib.Draw; using VocaluxeLib.PartyModes; using VocaluxeLib.Songs; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu.SongMenu { [XmlType("SongMenu")] public struct SThemeSongMenu { - [XmlAttributeAttribute(AttributeName = "Name")] - public string Name; + [XmlAttribute(AttributeName = "Name")] public string Name; - [XmlElement("CoverBackground")] - public string CoverBackgroundName; - [XmlElement("CoverBigBackground")] - public string CoverBigBackgroundName; - [XmlElement("DuetIcon")] - public string DuetIconName; - [XmlElement("VideoIcon")] - public string VideoIconName; - [XmlElement("MedleyCalcIcon")] - public string MedleyCalcIcon; - [XmlElement("MedleyTagIcon")] - public string MedleyTagIcon; - [XmlElement("Color")] - public SThemeColor Color; + [XmlElement("CoverBackground")] public string CoverBackgroundName; + [XmlElement("CoverBigBackground")] public string CoverBigBackgroundName; + [XmlElement("DuetIcon")] public string DuetIconName; + [XmlElement("VideoIcon")] public string VideoIconName; + [XmlElement("MedleyCalcIcon")] public string MedleyCalcIcon; + [XmlElement("MedleyTagIcon")] public string MedleyTagIcon; + [XmlElement("Color")] public SThemeColor Color; //public SThemeSongMenuBook songMenuBook; //public SThemeSongMenuDreidel songMenuDreidel; //public SThemeSongMenuList songMenuList; - [XmlElement("SongMenuTileBoard")] public SThemeSongMenuTileBoard SongMenuTileBoard; public SThemeSongMenu(SThemeSongMenu theme) @@ -69,65 +61,48 @@ namespace VocaluxeLib.Menu.SongMenu public struct SThemeSongMenuTileBoard { - [XmlElement("NumW")] /// /// Number of tiles horizontal /// public int NumW; - [XmlElement("NumH")] /// /// Number of tiles vertical /// public int NumH; - [XmlElement("NumWsmall")] /// /// Number of tiles horizontal in small-modus /// public int NumWsmall; - - [XmlElement("NumHsmall")] + /// /// Number of tiles vertical in small-modus /// public int NumHsmall; - [XmlElement("SpaceW")] /// /// Space between tiles horizontal /// public float SpaceW; - [XmlElement("SpaceH")] /// /// Space between tiles vertical /// public float SpaceH; - [XmlElement("TileRect")] public SRectF TileRect; - [XmlElement("TileRectSmall")] public SRectF TileRectSmall; - [XmlElement("TextArtist")] public SThemeText TextArtist; - [XmlElement("TextTitle")] public SThemeText TextTitle; - [XmlElement("TextSongLength")] public SThemeText TextSongLength; - [XmlElement("StaticCoverBig")] public SThemeStatic StaticCoverBig; - [XmlElement("StaticTextBG")] public SThemeStatic StaticTextBG; - [XmlElement("StaticDuetIcon")] public SThemeStatic StaticDuetIcon; - [XmlElement("StaticVideoIcon")] public SThemeStatic StaticVideoIcon; - [XmlElement("StaticMedleyCalcIcon")] public SThemeStatic StaticMedleyCalcIcon; - [XmlElement("StaticMedleyTagIcon")] public SThemeStatic StaticMedleyTagIcon; } @@ -278,7 +253,6 @@ namespace VocaluxeLib.Menu.SongMenu return _ThemeLoaded; } - #endregion Theme public virtual void Init() @@ -294,10 +268,10 @@ namespace VocaluxeLib.Menu.SongMenu } public virtual void OnShow() {} - + public virtual void OnHide() { - if(CBase.Graphics.GetNextScreen() != EScreens.ScreenNames) + if (CBase.Graphics.GetNextScreen() != EScreens.ScreenNames) _ResetPreview(); } @@ -373,7 +347,6 @@ namespace VocaluxeLib.Menu.SongMenu _ColorInternal = CBase.Theme.GetColor(_Theme.Color.Name, _PartyModeID); else _ColorInternal = _Theme.Color.Color; - } public void ReloadTextures() diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 14504d80..8a3c8190 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -23,6 +23,7 @@ using System.Xml; using VocaluxeLib.Draw; using VocaluxeLib.PartyModes; using VocaluxeLib.Songs; +using VocaluxeLib.Xml; namespace VocaluxeLib.Menu.SongMenu { diff --git a/VocaluxeLib/Profile/CProfile.cs b/VocaluxeLib/Profile/CProfile.cs index cf03f5b0..95ad5d4f 100644 --- a/VocaluxeLib/Profile/CProfile.cs +++ b/VocaluxeLib/Profile/CProfile.cs @@ -18,6 +18,7 @@ using System; using System.IO; using System.Xml; +using VocaluxeLib.Xml; namespace VocaluxeLib.Profile { diff --git a/VocaluxeLib/Structs.cs b/VocaluxeLib/Structs.cs index 4d80e919..743585d5 100644 --- a/VocaluxeLib/Structs.cs +++ b/VocaluxeLib/Structs.cs @@ -26,6 +26,44 @@ using VocaluxeLib.Songs; namespace VocaluxeLib { + public enum ECoverGeneratorType + { + Default, + Folder, + Artist, + Letter, + Edition, + Genre, + Language, + Year, + Decade, + Date + } + + public struct SMargin + { + public int Default; + public int Left, Right, Top, Bottom; + } + + public struct SThemeCoverGeneratorText + { + public string Text; + public SThemeFont Font; + public SThemeColor Color; + public SMargin Margin; + public int Indent; + } + + public struct SThemeCoverGenerator + { + public ECoverGeneratorType Type; + public SThemeCoverGeneratorText Text; + public SThemeColor BackgroundColor; + public string Image; + public float ImageAlpha; + public bool ShowFirstCover; + } #region Drawing public struct SColorF @@ -82,6 +120,16 @@ namespace VocaluxeLib Color = new SColorF(theme.Color); Name = theme.Name; } + + public bool Get(int partyModeId, out SColorF color) + { + if (String.IsNullOrEmpty(Name)) + { + color = Color; + return true; + } + return CBase.Theme.GetColor(Name, CBase.Theme.GetSkinIndex(partyModeId), out color); + } } public struct SRectF diff --git a/VocaluxeLib/VocaluxeLib.csproj b/VocaluxeLib/VocaluxeLib.csproj index f270b839..fb1e0737 100644 --- a/VocaluxeLib/VocaluxeLib.csproj +++ b/VocaluxeLib/VocaluxeLib.csproj @@ -103,7 +103,8 @@ - + + @@ -139,6 +140,7 @@ + diff --git a/VocaluxeLib/CXMLReader.cs b/VocaluxeLib/Xml/CXMLReader.cs similarity index 70% rename from VocaluxeLib/CXMLReader.cs rename to VocaluxeLib/Xml/CXMLReader.cs index 3f06c661..2f266ba6 100644 --- a/VocaluxeLib/CXMLReader.cs +++ b/VocaluxeLib/Xml/CXMLReader.cs @@ -19,9 +19,9 @@ using System; using System.Collections.Generic; using System.Xml.XPath; -namespace VocaluxeLib +namespace VocaluxeLib.Xml { - public class CXMLReader + public class CXMLReader : CXmlDeserializer { private readonly XPathNavigator _Navigator; private readonly String _FilePath; @@ -57,49 +57,6 @@ namespace VocaluxeLib } } - public bool TryGetEnumValue(string xPath, ref T value) - where T : struct - { - string val; - if (GetValue(xPath, out val, Enum.GetName(typeof(T), value))) - return CHelper.TryParse(val, out value, true); - return false; - } - - public bool TryGetIntValue(string xPath, ref int value) - { - string val; - if (GetValue(xPath, out val, value.ToString())) - return int.TryParse(val, out value); - return false; - } - - public bool TryGetIntValueRange(string xPath, ref int value, int min = 0, int max = 100) - { - bool result = TryGetIntValue(xPath, ref value); - if (result) - value = value.Clamp(min, max); - return result; - } - - public bool TryGetFloatValue(string xPath, ref float value) - { - string val; - return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value); - } - - /// - /// Gets a normalized (0<=x<=1) float value - /// - /// - /// - /// True if exists and is normalized - public bool TryGetNormalizedFloatValue(string xPath, ref float value) - { - string val; - return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value) && value.IsInRange(0f, 1f); - } - public bool TryGetColorFromRGBA(string xPath, ref SColorF value) { bool result = true; @@ -110,7 +67,7 @@ namespace VocaluxeLib return result; } - public bool GetValue(string xPath, out string value, string defaultValue = "") + public override bool GetValue(string xPath, out string value, string defaultValue = "") { int resultCt = 0; string val = string.Empty; @@ -133,6 +90,19 @@ namespace VocaluxeLib return true; } + public override bool GetAttribute(string xPath, string attribute, out string value) + { + _Navigator.MoveToRoot(); + XPathNodeIterator iterator = _Navigator.Select(xPath); + if (iterator.MoveNext()) + { + value = iterator.Current.GetAttribute(attribute, ""); + return true; + } + value = ""; + return false; + } + public List GetNames(string xPath) { var values = new List(); diff --git a/VocaluxeLib/Xml/CXmlDeserializer.cs b/VocaluxeLib/Xml/CXmlDeserializer.cs new file mode 100644 index 00000000..0b202c6b --- /dev/null +++ b/VocaluxeLib/Xml/CXmlDeserializer.cs @@ -0,0 +1,68 @@ +using System.Linq; + +namespace VocaluxeLib.Xml +{ + public abstract class CXmlDeserializer : CXmlReaderBase + { + public bool Read(string xPath, out SThemeFont el) + { + el = new SThemeFont(); + bool ok = true; + ok &= GetValue(xPath + "/Name", out el.Name); + ok &= TryGetFloatValue(xPath + "/Size", ref el.Size); + ok &= TryGetEnumValue(xPath + "/Style", ref el.Style); + return ok; + } + + public bool Read(string xPath, out SMargin el) + { + el = new SMargin(); + bool ok = true; + bool defOk = TryGetIntValue(xPath + "/Default", ref el.Default); + ok &= TryGetIntValue(xPath + "/Left", ref el.Left, el.Default); + ok &= TryGetIntValue(xPath + "/Right", ref el.Right, el.Default); + ok &= TryGetIntValue(xPath + "/Top", ref el.Top, el.Default); + ok &= TryGetIntValue(xPath + "/Bottom", ref el.Bottom, el.Default); + return ok || defOk; + } + + public bool Read(string xPath, out SThemeCoverGeneratorText el) + { + el = new SThemeCoverGeneratorText(); + bool ok = true; + ok &= GetValue(xPath + "/Text", out el.Text); + ok &= Read(xPath + "/Font", out el.Font); + ok &= Read(xPath + "/Color", out el.Color); + ok &= Read(xPath + "/Margin", out el.Margin); + if (ok) + TryGetIntValue(xPath + "/Indent", ref el.Indent, 6 * (el.Margin.Left + el.Margin.Right) / 2); + return ok; + } + + public bool Read(string xPath, out SThemeColor el) + { + el = new SThemeColor(); + bool ok = true; + ok &= TryGetNormalizedFloatValue(xPath + "/R", ref el.Color.R); + ok &= TryGetNormalizedFloatValue(xPath + "/G", ref el.Color.G); + ok &= TryGetNormalizedFloatValue(xPath + "/B", ref el.Color.B); + ok &= TryGetNormalizedFloatValue(xPath + "/A", ref el.Color.A); + if (!ok) + ok = GetValue(xPath, out el.Name) && !el.Name.Contains('<'); + return ok; + } + + public bool Read(string xPath, out SThemeCoverGenerator el) + { + el = new SThemeCoverGenerator(); + bool ok = true; + ok &= TryGetEnumValue(xPath + "/Type", ref el.Type); + ok &= Read(xPath + "/Text", out el.Text); + ok &= Read(xPath + "/BackgroundColor", out el.BackgroundColor); + ok &= GetValue(xPath + "/Image", out el.Image); + TryGetNormalizedFloatValue(xPath + "/ImageAlpha", ref el.ImageAlpha, 0.5f); + TryGetBoolValue(xPath + "/ShowFirstCover", out el.ShowFirstCover); + return ok; + } + } +} \ No newline at end of file diff --git a/VocaluxeLib/Xml/CXmlReaderBase.cs b/VocaluxeLib/Xml/CXmlReaderBase.cs new file mode 100644 index 00000000..152ecfad --- /dev/null +++ b/VocaluxeLib/Xml/CXmlReaderBase.cs @@ -0,0 +1,61 @@ +using System; + +namespace VocaluxeLib.Xml +{ + /// + /// Base class that provides basic methods for reading xml, while the actual XML implementation is still abstract to allow different implementations + /// + public abstract class CXmlReaderBase + { + public abstract bool GetValue(string xPath, out string value, string defaultValue = ""); + public abstract bool GetAttribute(string xPath, string attribute, out string value); + + public bool TryGetBoolValue(string xPath, out bool value, bool defaultValue = false) + { + value = defaultValue; + string val; + return GetValue(xPath, out val) && bool.TryParse(val, out value); + } + + public bool TryGetIntValue(string xPath, ref int value, int? defaultValue = null) + { + string val; + bool ok = GetValue(xPath, out val) && int.TryParse(val, out value); + if (!ok && defaultValue.HasValue) + value = defaultValue.Value; + return ok; + } + + public bool TryGetFloatValue(string xPath, ref float value) + { + string val; + return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value); + } + + public bool TryGetEnumValue(string xPath, ref T value) where T : struct + { + string val; + return GetValue(xPath, out val, Enum.GetName(typeof(T), value)) && CHelper.TryParse(val, out value, true); + } + + public bool TryGetIntValueRange(string xPath, ref int value, int min = 0, int max = 100) + { + return TryGetIntValue(xPath, ref value) && value.IsInRange(min, max); + } + + /// + /// Gets a normalized (0<=x<=1) float value + /// + /// + /// + /// + /// True if exists and is normalized + public bool TryGetNormalizedFloatValue(string xPath, ref float value, float defaultValue = 0) + { + bool ok = TryGetFloatValue(xPath, ref value) && value.IsInRange(0f, 1f); + if (!ok) + value = defaultValue; + return ok; + } + } +} \ No newline at end of file