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();
|
return new SThemeCover();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Foo(STheme a, STheme b)
|
private static void Foo(SThemeScreen a, SThemeScreen b)
|
||||||
{
|
{
|
||||||
a = b;
|
a = b;
|
||||||
}
|
}
|
||||||
@@ -180,14 +180,13 @@ namespace Vocaluxe.Base
|
|||||||
SThemeCover themeCover;
|
SThemeCover themeCover;
|
||||||
var xml = new CXmlSerializer();
|
var xml = new CXmlSerializer();
|
||||||
themeCover = xml.Deserialize<SThemeCover>(path);
|
themeCover = xml.Deserialize<SThemeCover>(path);
|
||||||
xml.Serialize(path + "2", themeCover);
|
|
||||||
string cover = themeCover.Info.Author;
|
string cover = themeCover.Info.Author;
|
||||||
STheme theme = new STheme();
|
SThemeScreen theme = new SThemeScreen();
|
||||||
STheme theme2 = new STheme();
|
SThemeScreen theme2 = new SThemeScreen();
|
||||||
Stopwatch watch = new Stopwatch();
|
Stopwatch watch = new Stopwatch();
|
||||||
watch.Start();
|
watch.Start();
|
||||||
for (int i = 0; i < 1; i++)
|
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();
|
watch.Stop();
|
||||||
xml.Serialize(Path.Combine(CBase.Themes.GetThemeScreensPath(-1), "ScreenMain2.xml"), theme);
|
xml.Serialize(Path.Combine(CBase.Themes.GetThemeScreensPath(-1), "ScreenMain2.xml"), theme);
|
||||||
return;
|
return;
|
||||||
@@ -199,7 +198,7 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
XmlSerializer deserializer = new XmlSerializer(typeof(STheme));
|
XmlSerializer deserializer = new XmlSerializer(typeof(STheme));
|
||||||
|
|
||||||
theme2 = (STheme)deserializer.Deserialize(textReader);
|
theme2 = (SThemeScreen)deserializer.Deserialize(textReader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
watch2.Stop();
|
watch2.Stop();
|
||||||
|
|||||||
+36
-133
@@ -21,46 +21,12 @@ using System.Diagnostics;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml;
|
|
||||||
using VocaluxeLib;
|
using VocaluxeLib;
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
using VocaluxeLib.Xml;
|
using VocaluxeLib.Xml;
|
||||||
|
|
||||||
namespace Vocaluxe.Base.Fonts
|
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
|
static class CFonts
|
||||||
{
|
{
|
||||||
private static bool _IsInitialized;
|
private static bool _IsInitialized;
|
||||||
@@ -291,116 +257,53 @@ namespace Vocaluxe.Base.Fonts
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static bool _LoadDefaultFonts()
|
private static bool _LoadDefaultFonts()
|
||||||
{
|
{
|
||||||
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts, CSettings.FileNameFonts));
|
SDefaultFonts defaultFonts;
|
||||||
if (xmlReader == null)
|
try
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
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);
|
/// <summary>
|
||||||
ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileNormal", out sf.FileNormal);
|
/// Loads theme fonts
|
||||||
ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileItalic", out sf.FileItalic);
|
/// </summary>
|
||||||
ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileBold", out sf.FileBold);
|
public static bool LoadThemeFonts(IEnumerable<SFontFamily> fontFamilies, string fontFolder, string themeName, int partyModeId)
|
||||||
ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileBoldItalic", out sf.FileBoldItalic);
|
{
|
||||||
ok &= xmlReader.TryGetNormalizedFloatValue("//root/Fonts/Font" + i + "/Outline", ref sf.Outline);
|
if (fontFamilies == null)
|
||||||
ok &= xmlReader.Read("//root/Fonts/Font" + i + "/OutlineColor", out sf.OutlineColor);
|
return true;
|
||||||
|
foreach (SFontFamily fontFamily in fontFamilies)
|
||||||
if (ok)
|
{
|
||||||
|
if (!_LoadFont(fontFamily, fontFolder, themeName, partyModeId))
|
||||||
{
|
{
|
||||||
sf.Normal = new CFontStyle(Path.Combine(fontFolder, sf.Folder, sf.FileNormal), EStyle.Normal, sf.Outline, sf.OutlineColor);
|
CLog.LogError("Error loading fonts for Theme " + themeName + "(" + partyModeId + ")");
|
||||||
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);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
CLog.StartBenchmark("BuildGlyphs");
|
||||||
|
_BuildGlyphs();
|
||||||
|
CLog.StopBenchmark("BuildGlyphs");
|
||||||
return true;
|
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)
|
fontFamily.ThemeName = themeName;
|
||||||
return;
|
fontFamily.PartyModeID = partyModeId;
|
||||||
|
fontFamily.Normal = new CFontStyle(Path.Combine(fontFolder, fontFamily.Folder, fontFamily.FileNormal), EStyle.Normal, fontFamily.Outline, fontFamily.OutlineColor);
|
||||||
writer.WriteStartElement("Fonts");
|
fontFamily.Italic = new CFontStyle(Path.Combine(fontFolder, fontFamily.Folder, fontFamily.FileItalic), EStyle.Italic, fontFamily.Outline, fontFamily.OutlineColor);
|
||||||
int fontNr = 1;
|
fontFamily.Bold = new CFontStyle(Path.Combine(fontFolder, fontFamily.Folder, fontFamily.FileBold), EStyle.Bold, fontFamily.Outline, fontFamily.OutlineColor);
|
||||||
foreach (SFontFamily font in _FontFamilies)
|
fontFamily.BoldItalic = new CFontStyle(Path.Combine(fontFolder, fontFamily.Folder, fontFamily.FileBoldItalic), EStyle.BoldItalic, fontFamily.Outline,
|
||||||
{
|
fontFamily.OutlineColor);
|
||||||
if (font.ThemeName == themeName)
|
_FontFamilies.Add(fontFamily);
|
||||||
{
|
return true;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UnloadThemeFonts(string themeName)
|
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> missingTextures = _RequiredTextures.FindAll(name => !_Textures.ContainsKey(name));
|
||||||
List<string> missingVideos = _RequiredVideos.FindAll(name => !_Videos.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)
|
if (missingTextures.Count + missingVideos.Count + missingColors.Count == 0)
|
||||||
return true;
|
return true;
|
||||||
string msg = "The skin \"" + this + "\" is missing the following elements: ";
|
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/>.
|
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Vocaluxe.Base.Fonts;
|
using Vocaluxe.Base.Fonts;
|
||||||
using VocaluxeLib.Xml;
|
|
||||||
|
|
||||||
namespace Vocaluxe.Base.ThemeSystem
|
namespace Vocaluxe.Base.ThemeSystem
|
||||||
{
|
{
|
||||||
class CBaseTheme : CTheme
|
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) {}
|
public CBaseTheme(string filePath) : base(filePath, -1) {}
|
||||||
|
|
||||||
@@ -39,21 +46,12 @@ namespace Vocaluxe.Base.ThemeSystem
|
|||||||
CFonts.UnloadThemeFonts(Name);
|
CFonts.UnloadThemeFonts(Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool _Load(CXMLReader xmlReader)
|
protected override bool _Load()
|
||||||
{
|
{
|
||||||
return _LoadCursor(xmlReader) &&
|
if (!_Data.Cursor.HasValue)
|
||||||
CFonts.LoadThemeFonts(Name, Path.Combine(_Folder, Name, CSettings.FolderNameThemeFonts), xmlReader);
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
private bool _LoadCursor(CXMLReader xmlReader)
|
return CFonts.LoadThemeFonts(_Data.Fonts, Path.Combine(_Folder, Name, CSettings.FolderNameThemeFonts), Name, -1);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool _LoadSkin()
|
protected override bool _LoadSkin()
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace Vocaluxe.Base.ThemeSystem
|
|||||||
return false;
|
return false;
|
||||||
for (int i = 1; i <= CSettings.MaxNumPlayer; i++)
|
for (int i = 1; i <= CSettings.MaxNumPlayer; i++)
|
||||||
{
|
{
|
||||||
if (!_Colors.ContainsKey("Player" + i))
|
if (!_Data.Colors.ContainsKey("Player" + i))
|
||||||
continue;
|
continue;
|
||||||
CLog.LogDebug("Party themes cannot contain player colors. They will be ignored!");
|
CLog.LogDebug("Party themes cannot contain player colors. They will be ignored!");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Vocaluxe.Base.Fonts;
|
using Vocaluxe.Base.Fonts;
|
||||||
using VocaluxeLib.Xml;
|
|
||||||
|
|
||||||
namespace Vocaluxe.Base.ThemeSystem
|
namespace Vocaluxe.Base.ThemeSystem
|
||||||
{
|
{
|
||||||
@@ -38,9 +37,9 @@ namespace Vocaluxe.Base.ThemeSystem
|
|||||||
return new CPartySkin(path, file, this);
|
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)
|
private CSkin _GetSkinToLoad(int fallbackNum)
|
||||||
|
|||||||
@@ -42,15 +42,14 @@ namespace Vocaluxe.Base.ThemeSystem
|
|||||||
private readonly string _FileName;
|
private readonly string _FileName;
|
||||||
protected readonly CTheme _Parent;
|
protected readonly CTheme _Parent;
|
||||||
|
|
||||||
private SInfo _Info;
|
protected SSkin _Data;
|
||||||
public String Name
|
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, CTextureRef> _Textures = new Dictionary<string, CTextureRef>();
|
||||||
protected readonly Dictionary<string, CVideoSkinElement> _Videos = new Dictionary<string, CVideoSkinElement>();
|
protected readonly Dictionary<string, CVideoSkinElement> _Videos = new Dictionary<string, CVideoSkinElement>();
|
||||||
protected readonly Dictionary<string, SColorF> _Colors = new Dictionary<string, SColorF>();
|
|
||||||
|
|
||||||
protected bool _IsLoaded;
|
protected bool _IsLoaded;
|
||||||
|
|
||||||
@@ -93,18 +92,20 @@ namespace Vocaluxe.Base.ThemeSystem
|
|||||||
|
|
||||||
public bool Init()
|
public bool Init()
|
||||||
{
|
{
|
||||||
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(_Folder, _FileName));
|
try
|
||||||
if (xmlReader == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!xmlReader.CheckVersion("//root/SkinSystemVersion", _SkinSystemVersion))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
bool ok = xmlReader.Read("//root/Info", out _Info);
|
|
||||||
|
|
||||||
if (!ok)
|
|
||||||
{
|
{
|
||||||
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,42 +117,31 @@ namespace Vocaluxe.Base.ThemeSystem
|
|||||||
if (_IsLoaded)
|
if (_IsLoaded)
|
||||||
return true;
|
return true;
|
||||||
Debug.Assert(_Textures.Count == 0 && _Videos.Count == 0);
|
Debug.Assert(_Textures.Count == 0 && _Videos.Count == 0);
|
||||||
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(_Folder, _FileName));
|
|
||||||
if (xmlReader == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// load skins/textures
|
// load skins/textures
|
||||||
List<string> names = xmlReader.GetNames("//root/Skins/*");
|
foreach (KeyValuePair<string, string> kvp in _Data.Skins)
|
||||||
foreach (string name in names)
|
|
||||||
{
|
{
|
||||||
string fileName;
|
CTextureRef texture = CDraw.AddTexture(Path.Combine(_Folder, kvp.Value));
|
||||||
xmlReader.GetValue("//root/Skins/" + name, out fileName);
|
|
||||||
CTextureRef texture = CDraw.AddTexture(Path.Combine(_Folder, fileName));
|
|
||||||
if (texture == null)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
_Textures.Add(name, texture);
|
_Textures.Add(kvp.Key, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
// load videos
|
// load videos
|
||||||
names = xmlReader.GetNames("//root/Videos/*");
|
foreach (KeyValuePair<string, string> kvp in _Data.Videos)
|
||||||
foreach (string name in names)
|
|
||||||
{
|
{
|
||||||
CVideoSkinElement sk = new CVideoSkinElement();
|
CVideoSkinElement sk = new CVideoSkinElement {FileName = kvp.Value};
|
||||||
xmlReader.GetValue("//root/Videos/" + name, out sk.FileName);
|
|
||||||
if (!File.Exists(Path.Combine(_Folder, sk.FileName)))
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
_Videos.Add(name, sk);
|
_Videos.Add(kvp.Key, sk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_LoadColors(xmlReader))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_IsLoaded = true;
|
_IsLoaded = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -166,27 +156,13 @@ namespace Vocaluxe.Base.ThemeSystem
|
|||||||
|
|
||||||
_Textures.Clear();
|
_Textures.Clear();
|
||||||
_Videos.Clear();
|
_Videos.Clear();
|
||||||
_Colors.Clear();
|
|
||||||
|
|
||||||
_IsLoaded = false;
|
_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)
|
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)
|
public virtual CVideoStream GetVideo(string videoName, bool loop)
|
||||||
|
|||||||
@@ -25,25 +25,15 @@ using VocaluxeLib.Xml;
|
|||||||
|
|
||||||
namespace Vocaluxe.Base.ThemeSystem
|
namespace Vocaluxe.Base.ThemeSystem
|
||||||
{
|
{
|
||||||
struct SThemeCursor
|
|
||||||
{
|
|
||||||
public string SkinName;
|
|
||||||
|
|
||||||
public float W;
|
|
||||||
public float H;
|
|
||||||
|
|
||||||
public SThemeColor Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class CTheme
|
abstract class CTheme
|
||||||
{
|
{
|
||||||
// Version number for theme files. Increment it, if you've changed something on the theme files!
|
// Version number for theme files. Increment it, if you've changed something on the theme files!
|
||||||
private const int _ThemeSystemVersion = 5;
|
private const int _ThemeSystemVersion = 5;
|
||||||
|
|
||||||
private SInfo _Info;
|
protected STheme _Data;
|
||||||
public String Name
|
public String Name
|
||||||
{
|
{
|
||||||
get { return _Info.Name; }
|
get { return _Data.Info.Name; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string[] SkinNames
|
public string[] SkinNames
|
||||||
@@ -77,18 +67,20 @@ namespace Vocaluxe.Base.ThemeSystem
|
|||||||
|
|
||||||
public bool Init()
|
public bool Init()
|
||||||
{
|
{
|
||||||
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(_Folder, _FileName));
|
try
|
||||||
if (xmlReader == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!xmlReader.CheckVersion("//root/ThemeSystemVersion", _ThemeSystemVersion))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
bool ok = xmlReader.Read("//root/Info", out _Info);
|
|
||||||
|
|
||||||
if (!ok)
|
|
||||||
{
|
{
|
||||||
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +88,7 @@ namespace Vocaluxe.Base.ThemeSystem
|
|||||||
List<string> files = CHelper.ListFiles(path, "*.xml");
|
List<string> files = CHelper.ListFiles(path, "*.xml");
|
||||||
|
|
||||||
// Load skins, succeed if at least 1 skin was loaded
|
// Load skins, succeed if at least 1 skin was loaded
|
||||||
ok = false;
|
bool ok = false;
|
||||||
foreach (string file in files)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
CSkin skin = _GetNewSkin(path, file);
|
CSkin skin = _GetNewSkin(path, file);
|
||||||
@@ -110,20 +102,17 @@ namespace Vocaluxe.Base.ThemeSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract CSkin _GetNewSkin(string path, string file);
|
protected abstract CSkin _GetNewSkin(string path, string file);
|
||||||
protected abstract bool _Load(CXMLReader xmlReader);
|
protected abstract bool _Load();
|
||||||
protected abstract bool _LoadSkin();
|
protected abstract bool _LoadSkin();
|
||||||
|
|
||||||
public bool Load()
|
public bool Load()
|
||||||
{
|
{
|
||||||
if (_IsLoaded)
|
if (_IsLoaded)
|
||||||
return true;
|
return true;
|
||||||
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(_Folder, _FileName));
|
|
||||||
if (xmlReader == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!_LoadSkin())
|
if (!_LoadSkin())
|
||||||
return false;
|
return false;
|
||||||
bool ok = _Load(xmlReader);
|
bool ok = _Load();
|
||||||
|
|
||||||
_IsLoaded = ok;
|
_IsLoaded = ok;
|
||||||
return 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\ThemeSystem\CTheme.cs" />
|
||||||
<Compile Include="Base\CVideoPlayer.cs" />
|
<Compile Include="Base\CVideoPlayer.cs" />
|
||||||
<Compile Include="Base\ThemeSystem\CSkin.cs" />
|
<Compile Include="Base\ThemeSystem\CSkin.cs" />
|
||||||
|
<Compile Include="Base\XmlStructs.cs" />
|
||||||
<Compile Include="COSFunctions.cs" />
|
<Compile Include="COSFunctions.cs" />
|
||||||
<Compile Include="Lib\Database\CCoverDB.cs" />
|
<Compile Include="Lib\Database\CCoverDB.cs" />
|
||||||
<Compile Include="Lib\Database\CDatabaseBase.cs" />
|
<Compile Include="Lib\Database\CDatabaseBase.cs" />
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace VocaluxeLib.Menu
|
|||||||
}
|
}
|
||||||
|
|
||||||
[XmlType("Screen")]
|
[XmlType("Screen")]
|
||||||
public struct STheme
|
public struct SThemeScreen
|
||||||
{
|
{
|
||||||
public SScreenInformation Informations;
|
public SScreenInformation Informations;
|
||||||
[XmlArray("Backgrounds")] public List<SThemeBackground> Backgrounds;
|
[XmlArray("Backgrounds")] public List<SThemeBackground> Backgrounds;
|
||||||
@@ -65,7 +65,7 @@ namespace VocaluxeLib.Menu
|
|||||||
protected abstract int _ScreenVersion { get; }
|
protected abstract int _ScreenVersion { get; }
|
||||||
public int PartyModeID { get; protected set; }
|
public int PartyModeID { get; protected set; }
|
||||||
public string ThemeName { get; set; }
|
public string ThemeName { get; set; }
|
||||||
public STheme Theme;
|
public SThemeScreen Theme;
|
||||||
|
|
||||||
// ReSharper disable MemberCanBePrivate.Global
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
protected string[] _ThemeBackgrounds;
|
protected string[] _ThemeBackgrounds;
|
||||||
@@ -171,8 +171,8 @@ namespace VocaluxeLib.Menu
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
TextReader textReader = new StreamReader(file);
|
TextReader textReader = new StreamReader(file);
|
||||||
XmlSerializer deserializer = new XmlSerializer(typeof(STheme));
|
XmlSerializer deserializer = new XmlSerializer(typeof(SThemeScreen));
|
||||||
Theme = (STheme)deserializer.Deserialize(textReader);
|
Theme = (SThemeScreen)deserializer.Deserialize(textReader);
|
||||||
|
|
||||||
foreach (SThemeBackground bg in Theme.Backgrounds)
|
foreach (SThemeBackground bg in Theme.Backgrounds)
|
||||||
_AddBackground(new CBackground(bg, PartyModeID), bg.Name);
|
_AddBackground(new CBackground(bg, PartyModeID), bg.Name);
|
||||||
@@ -334,7 +334,7 @@ namespace VocaluxeLib.Menu
|
|||||||
{
|
{
|
||||||
TextWriter textWriter = new StreamWriter(Path.Combine(ThemePath, ThemeName + ".xml"));
|
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);
|
serializer.Serialize(textWriter, Theme);
|
||||||
|
|
||||||
textWriter.Close();
|
textWriter.Close();
|
||||||
|
|||||||
+1
-12
@@ -72,21 +72,10 @@ namespace VocaluxeLib
|
|||||||
[XmlElement("CoverGenerator", IsNullable = false)] public List<SThemeCoverGenerator> CoverGenerators;
|
[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
|
#region Drawing
|
||||||
public struct SColorF
|
public struct SColorF
|
||||||
{
|
{
|
||||||
public float R;
|
[XmlNormalized] public float R, G, B, A;
|
||||||
public float G;
|
|
||||||
public float B;
|
|
||||||
public float A;
|
|
||||||
|
|
||||||
public SColorF(float r, float g, float b, float a)
|
public SColorF(float r, float g, float b, float a)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -100,16 +100,6 @@ namespace VocaluxeLib.Xml
|
|||||||
return ok;
|
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)
|
public bool Read(string xPath, out SColorF value)
|
||||||
{
|
{
|
||||||
value = new SColorF();
|
value = new SColorF();
|
||||||
|
|||||||
Reference in new issue
Block a user