Serialize Themes
This commit is contained in:
1 parent
092f8df8f5
commit
acaf4eadb2
13 files changed
+207
-263
No files matched your search
@@ -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<SThemeCover>(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<STheme>(Path.Combine(CBase.Themes.GetThemeScreensPath(-1), "ScreenMain.xml"));
|
||||
theme = xml.Deserialize<SThemeScreen>(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();
|
||||
|
||||
+36
-133
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Struct used for describing a font family (a type of text with 4 different styles)
|
||||
/// </summary>
|
||||
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
|
||||
/// <returns></returns>
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads theme fonts from skin file
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads party mode fonts from skin file
|
||||
/// </summary>
|
||||
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<SDefaultFonts>(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)
|
||||
/// <summary>
|
||||
/// Loads theme fonts
|
||||
/// </summary>
|
||||
public static bool LoadThemeFonts(IEnumerable<SFontFamily> 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)
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Vocaluxe.Base.ThemeSystem
|
||||
{
|
||||
List<string> missingTextures = _RequiredTextures.FindAll(name => !_Textures.ContainsKey(name));
|
||||
List<string> missingVideos = _RequiredVideos.FindAll(name => !_Videos.ContainsKey(name));
|
||||
List<string> missingColors = _RequiredColors.FindAll(name => !_Colors.ContainsKey(name));
|
||||
List<string> 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: ";
|
||||
|
||||
@@ -15,16 +15,23 @@
|
||||
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
||||
#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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<string, CTextureRef> _Textures = new Dictionary<string, CTextureRef>();
|
||||
protected readonly Dictionary<string, CVideoSkinElement> _Videos = new Dictionary<string, CVideoSkinElement>();
|
||||
protected readonly Dictionary<string, SColorF> _Colors = new Dictionary<string, SColorF>();
|
||||
|
||||
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<SSkin>(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<string> names = xmlReader.GetNames("//root/Skins/*");
|
||||
foreach (string name in names)
|
||||
foreach (KeyValuePair<string, string> 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<string, string> 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<string> 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)
|
||||
|
||||
@@ -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<STheme>(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<string> 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;
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
#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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Struct used for describing a font family (a type of text with 4 different styles)
|
||||
/// </summary>
|
||||
[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<string, SColorF> Colors;
|
||||
public Dictionary<string, string> Skins;
|
||||
public Dictionary<string, string> Videos;
|
||||
}
|
||||
}
|
||||
@@ -226,6 +226,7 @@
|
||||
<Compile Include="Base\ThemeSystem\CTheme.cs" />
|
||||
<Compile Include="Base\CVideoPlayer.cs" />
|
||||
<Compile Include="Base\ThemeSystem\CSkin.cs" />
|
||||
<Compile Include="Base\XmlStructs.cs" />
|
||||
<Compile Include="COSFunctions.cs" />
|
||||
<Compile Include="Lib\Database\CCoverDB.cs" />
|
||||
<Compile Include="Lib\Database\CDatabaseBase.cs" />
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace VocaluxeLib.Menu
|
||||
}
|
||||
|
||||
[XmlType("Screen")]
|
||||
public struct STheme
|
||||
public struct SThemeScreen
|
||||
{
|
||||
public SScreenInformation Informations;
|
||||
[XmlArray("Backgrounds")] public List<SThemeBackground> 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();
|
||||
|
||||
+1
-12
@@ -72,21 +72,10 @@ namespace VocaluxeLib
|
||||
[XmlElement("CoverGenerator", IsNullable = false)] public List<SThemeCoverGenerator> 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)
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user