From bc7aa797fae7343dc77012baf0f8ef11ea8733ac Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Tue, 11 Dec 2012 22:15:58 +0100 Subject: [PATCH] some preparations for party mode screens --- Vocaluxe/Base/CFont.cs | 105 ++++++++++++++++++++- Vocaluxe/Base/CLanguage.cs | 149 +++++++++++++++++++++++++++--- Vocaluxe/Base/CParty.cs | 113 ++++++++++++++++++++-- Vocaluxe/Base/CSettings.cs | 1 + Vocaluxe/Base/CTheme.cs | 2 - Vocaluxe/Menu/CGraphics.cs | 52 ++++++++++- Vocaluxe/PartyModes/CPartyMode.cs | 7 +- Vocaluxe/PartyModes/IPartyMode.cs | 2 +- 8 files changed, 399 insertions(+), 32 deletions(-) diff --git a/Vocaluxe/Base/CFont.cs b/Vocaluxe/Base/CFont.cs index 0c3fa048..4e558b9e 100644 --- a/Vocaluxe/Base/CFont.cs +++ b/Vocaluxe/Base/CFont.cs @@ -298,6 +298,7 @@ namespace Vocaluxe.Base public string Name; public bool IsThemeFont; + public int PartyModeID; public string ThemeName; public string Folder; @@ -323,6 +324,9 @@ namespace Vocaluxe.Base private static int _CurrentFont; private static float _Height = 1f; + public static int PartyModeID + { get; set; } + public static EStyle Style = EStyle.Normal; public static int CurrentFont @@ -377,6 +381,7 @@ namespace Vocaluxe.Base _settings.ConformanceLevel = ConformanceLevel.Document; _CurrentFont = 0; + PartyModeID = -1; BuildFonts(); } @@ -586,7 +591,20 @@ namespace Vocaluxe.Base public static void SetFont(string FontName) { - int Index = GetFontIndex(CConfig.Theme, FontName); + int Index = -1; + + if (PartyModeID != -1) + { + Index = GetFontIndexParty(PartyModeID, FontName); + + if (Index >= 0 && Index < _Fonts.Count) + { + _CurrentFont = Index; + return; + } + } + + Index = GetFontIndex(CConfig.Theme, FontName); if (Index >= 0 && Index < _Fonts.Count) { @@ -720,6 +738,7 @@ namespace Vocaluxe.Base sf.Name = name; sf.IsThemeFont = false; sf.ThemeName = String.Empty; + sf.PartyModeID = -1; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileItalic", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), @@ -769,6 +788,7 @@ namespace Vocaluxe.Base sf.IsThemeFont = true; sf.ThemeName = ThemeName; + sf.PartyModeID = -1; bool ok = true; @@ -889,6 +909,75 @@ namespace Vocaluxe.Base } } + /// + /// Loads party mode fonts from skin file + /// + public static void LoadPartyModeFonts(int PartyModeID, string FontFolder, XPathNavigator navigator) + { + string value = string.Empty; + int i = 1; + while (CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/Folder", navigator, ref value, value)) + { + SFont sf = new SFont(); + sf.Folder = value; + + sf.IsThemeFont = false; + sf.ThemeName = String.Empty; + sf.PartyModeID = PartyModeID; + + bool ok = true; + + ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileNormal", navigator, ref value, value); + sf.FileNormal = value; + value = Path.Combine(FontFolder, Path.Combine(sf.Folder, value)); + CFont f = new CFont(value); + sf.Normal = f; + + string name = String.Empty; + ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/Name", navigator, ref name, value); + sf.Name = name; + + ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileItalic", navigator, ref value, value); + sf.FileItalic = value; + value = Path.Combine(FontFolder, Path.Combine(sf.Folder, value)); + f = new CFont(value); + sf.Italic = f; + + ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileBold", navigator, ref value, value); + sf.FileBold = value; + value = Path.Combine(FontFolder, Path.Combine(sf.Folder, value)); + f = new CFont(value); + sf.Bold = f; + + ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileBoldItalic", navigator, ref value, value); + sf.FileBoldItalic = value; + value = Path.Combine(FontFolder, Path.Combine(sf.Folder, value)); + f = new CFont(value); + sf.BoldItalic = f; + + sf.Outline = 0f; + ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/Outline", navigator, ref sf.Outline); + + sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f); + ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorR", navigator, ref sf.OutlineColor.R); + ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorG", navigator, ref sf.OutlineColor.G); + ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorB", navigator, ref sf.OutlineColor.B); + ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorA", navigator, ref sf.OutlineColor.A); + + if (ok) + _Fonts.Add(sf); + else + { + CLog.LogError("Error loading theme fonts for party mode from Folder \"" + FontFolder + "\": Error in Font" + i.ToString()); + } + i++; + } + + CLog.StartBenchmark(1, "BuildGlyphs"); + BuildGlyphs(); + CLog.StopBenchmark(1, "BuildGlyphs"); + } + private static int GetFontIndex(string ThemeName, string FontName) { if (ThemeName == String.Empty || FontName == String.Empty) @@ -903,6 +992,20 @@ namespace Vocaluxe.Base return -1; } + private static int GetFontIndexParty(int PartyModeID, string FontName) + { + if (PartyModeID == -1 || FontName == String.Empty) + return -1; + + for (int i = 0; i < _Fonts.Count; i++) + { + if (!_Fonts[i].IsThemeFont && _Fonts[i].Name == FontName && _Fonts[i].PartyModeID == PartyModeID) + return i; + } + + return -1; + } + private static void BuildGlyphs() { string Text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPGRSTUVWGXZ1234567890"; diff --git a/Vocaluxe/Base/CLanguage.cs b/Vocaluxe/Base/CLanguage.cs index 6b209bba..9e8474ed 100644 --- a/Vocaluxe/Base/CLanguage.cs +++ b/Vocaluxe/Base/CLanguage.cs @@ -14,6 +14,13 @@ namespace Vocaluxe.Base public string LanguageFilePath; public Hashtable Texts; + public List PartyModeTexts; + } + + struct SPartyLanguage + { + public int PartyModeID; + public Hashtable Texts; } static class CLanguage @@ -63,16 +70,24 @@ namespace Vocaluxe.Base } public static bool SetLanguage(string Language) + { + int nr = GetLanguageNr(Language); + if (nr != -1) + { + _CurrentLanguage = nr; + return true; + } + return false; + } + + public static int GetLanguageNr(string Language) { for (int i = 0; i < _Languages.Count; i++) { if (_Languages[i].Name == Language) - { - _CurrentLanguage = i; - return true; - } + return i; } - return false; + return -1; } public static string Translate(string KeyWord) @@ -126,13 +141,37 @@ namespace Vocaluxe.Base return false; string result = String.Empty; - try + + int PartyModeNr = GetPartyModeNr(CFonts.PartyModeID, _CurrentLanguage); + if (CFonts.PartyModeID != -1) { - result = (string)_Languages[_CurrentLanguage].Texts[KeyWord]; + if (PartyModeNr != -1) + { + try + { + result = (string)_Languages[_CurrentLanguage].PartyModeTexts[CFonts.PartyModeID].Texts[KeyWord]; + } + catch { } + } + + if (result == null && (PartyModeNr = GetPartyModeNr(CFonts.PartyModeID, _FallbackLanguage)) != -1) + { + try + { + result = (string)_Languages[_FallbackLanguage].PartyModeTexts[CFonts.PartyModeID].Texts[KeyWord]; + } + catch { } + } } - catch (Exception) + + + if (result == null) { - ; + try + { + result = (string)_Languages[_CurrentLanguage].Texts[KeyWord]; + } + catch { } } if (result == null) @@ -142,10 +181,7 @@ namespace Vocaluxe.Base { result = (string)_Languages[_FallbackLanguage].Texts[KeyWord]; } - catch (Exception) - { - ; - } + catch { } if (result == null) return false; @@ -154,6 +190,82 @@ namespace Vocaluxe.Base return true; } + public static bool LoadPartyLanguageFiles(int PartyModeID, string Path) + { + List files = new List(); + files.AddRange(Helper.ListFiles(CSettings.sFolderLanguages, "*.xml", true, true)); + + foreach (string file in files) + { + if (!LoadPartyLanguageFile(PartyModeID, file)) + return false; + } + return true; + } + + private static bool LoadPartyLanguageFile(int PartyModeID, string file) + { + bool loaded = false; + XPathDocument xPathDoc = null; + XPathNavigator navigator = null; + + try + { + xPathDoc = new XPathDocument(file); + navigator = xPathDoc.CreateNavigator(); + loaded = true; + } + catch (Exception e) + { + loaded = false; + if (navigator != null) + navigator = null; + + if (xPathDoc != null) + xPathDoc = null; + + CLog.LogError("Error opening Party Language File " + file + ": " + e.Message); + } + + if (loaded) + { + string value = string.Empty; + if (loaded == CHelper.GetValueFromXML("//root/Info/Name", navigator, ref value, value)) + { + int nr = GetLanguageNr(value); + + if (nr == -1) + return true; + + SPartyLanguage lang = new SPartyLanguage(); + lang.PartyModeID = PartyModeID; + lang.Texts = new Hashtable(); + + List texts = CHelper.GetValuesFromXML("Texts", navigator); + for (int i = 0; i < texts.Count; i++) + { + if (CHelper.GetValueFromXML("//root/Texts/" + texts[i], navigator, ref value, value)) + { + try + { + lang.Texts.Add(texts[i], value); + } + catch (Exception e) + { + CLog.LogError("Error reading Party Language File " + file + ": " + e.Message); + return false; + } + } + + } + _Languages[nr].PartyModeTexts.Add(lang); + return true; + } + } + CLog.LogError("Error reading Party Language File " + file); + return false; + } + private static void LoadLanguageFile(string FileName) { bool loaded = false; @@ -191,6 +303,7 @@ namespace Vocaluxe.Base _FallbackLanguage = _Languages.Count; lang.Texts = new Hashtable(); + lang.PartyModeTexts = new List(); List texts = CHelper.GetValuesFromXML("Texts", navigator); for (int i = 0; i < texts.Count; i++) @@ -213,5 +326,15 @@ namespace Vocaluxe.Base } } } + + private static int GetPartyModeNr(int PartyModeID, int Language) + { + for (int i = 0; i < _Languages[Language].PartyModeTexts.Count; i++) + { + if (_Languages[Language].PartyModeTexts[i].PartyModeID == PartyModeID) + return i; + } + return -1; + } } } diff --git a/Vocaluxe/Base/CParty.cs b/Vocaluxe/Base/CParty.cs index 65d13dc7..2751b8a6 100644 --- a/Vocaluxe/Base/CParty.cs +++ b/Vocaluxe/Base/CParty.cs @@ -1,16 +1,47 @@ using System; using System.Collections.Generic; using System.Text; +using System.Xml; +using System.Xml.XPath; using Vocaluxe.Menu; using Vocaluxe.PartyModes; namespace Vocaluxe.Base { + #region Structs + struct SPartyMode + { + public int PartyModeSystemVersion; + public string Name; + public string Author; + public string Folder; + public int PartyModeVersionMajor; + public int PartyModeVersionMinor; + public bool NoErrors; + public IPartyMode PartyMode; + } + #endregion Structs + + static class CParty { - private static List _PartyModes; + const int PartyModeSystemVersion = 1; + + private static CHelper Helper; + private static List _PartyModes; + private static int _CurrentModeNr; + public static int CurrentPartyModeID + { + get + { + if (_CurrentModeNr == 0) + return -1; + + return _CurrentModeNr - 1; + } + } #region public stuff public static int NumModes @@ -20,10 +51,13 @@ namespace Vocaluxe.Base public static void Init() { - _PartyModes = new List(); + Helper = new CHelper(); + _PartyModes = new List(); //add dummy normal game mode and set it as default - _PartyModes.Add(new CPartyModeNone()); + SPartyMode pm = new SPartyMode(); + pm.PartyMode = new CPartyModeNone(); + _PartyModes.Add(pm); _CurrentModeNr = 0; //load other party modes @@ -37,40 +71,101 @@ namespace Vocaluxe.Base public static CMenu GetNextPartyScreen() { - return _PartyModes[_CurrentModeNr].GetNextPartyScreen(); + return _PartyModes[_CurrentModeNr].PartyMode.GetNextPartyScreen(); } #endregion public stuff #region Interface public static EScreens GetStartScreen() { - return _PartyModes[_CurrentModeNr].GetStartScreen(); + return _PartyModes[_CurrentModeNr].PartyMode.GetStartScreen(); } public static EScreens GetMainScreen() { - return _PartyModes[_CurrentModeNr].GetMainScreen(); + return _PartyModes[_CurrentModeNr].PartyMode.GetMainScreen(); } public static ScreenSongOptions GetSongSelectionOptions() { - return _PartyModes[_CurrentModeNr].GetScreenSongOptions(); + return _PartyModes[_CurrentModeNr].PartyMode.GetScreenSongOptions(); } public static void SetSearchString(string SearchString, bool Visible) { - _PartyModes[_CurrentModeNr].SetSearchString(SearchString, Visible); + _PartyModes[_CurrentModeNr].PartyMode.SetSearchString(SearchString, Visible); } public static void JokerUsed(int TeamNr) { - _PartyModes[_CurrentModeNr].JokerUsed(TeamNr); + _PartyModes[_CurrentModeNr].PartyMode.JokerUsed(TeamNr); } #endregion Interface #region private stuff private static void LoadPartyModes() { + List files = new List(); + files.AddRange(Helper.ListFiles(CSettings.sFolderPartyModes, "*.xml", false, true)); + + foreach (string file in files) + { + _PartyModes.Add(LoadPartyMode(file)); + } + } + + private static SPartyMode LoadPartyMode(string file) + { + SPartyMode pm = new SPartyMode(); + pm.NoErrors = false; + + bool loaded = false; + XPathDocument xPathDoc = null; + XPathNavigator navigator = null; + + try + { + xPathDoc = new XPathDocument(file); + navigator = xPathDoc.CreateNavigator(); + loaded = true; + } + catch (Exception e) + { + loaded = false; + if (navigator != null) + navigator = null; + + if (xPathDoc != null) + xPathDoc = null; + + CLog.LogError("Error opening party mode file " + file + ": " + e.Message); + } + + if (loaded) + { + loaded &= CHelper.TryGetIntValueFromXML("//root/Info/PartyModeSystemVersion", navigator, ref pm.PartyModeSystemVersion); + loaded &= CHelper.GetValueFromXML("//root/Info/Name", navigator, ref pm.Name, "ERROR Name"); + loaded &= CHelper.GetValueFromXML("//root/Info/Author", navigator, ref pm.Author, "ERROR Author"); + loaded &= CHelper.GetValueFromXML("//root/Info/Folder", navigator, ref pm.Folder, "ERROR Folder"); + loaded &= CHelper.TryGetIntValueFromXML("//root/Info/PartyModeSystemVersion", navigator, ref pm.PartyModeVersionMajor); + loaded &= CHelper.TryGetIntValueFromXML("//root/Info/PartyModeSystemVersion", navigator, ref pm.PartyModeVersionMinor); + + if (pm.PartyModeSystemVersion != PartyModeSystemVersion) + { + CLog.LogError("Error loading PartyMode file (wrong PartyModeSystemVersion): " + file); + return pm; + } + } + + if (!loaded) + { + CLog.LogError("Error loading PartyMode file: " + file); + return pm; + } + + + + return pm; } #endregion private stuff } diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index da827ca0..16fb0475 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -95,6 +95,7 @@ namespace Vocaluxe.Base public const string sFolderScreenshots = "Screenshots"; public const string sFolderBackgroundMusic = "BackgroundMusic"; public static string sFolderPlaylists = "Playlists"; + public static string sFolderPartyModes = "PartyModes"; //public const String[] ToneStrings = new String[]{ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" }; public const int ToneMin = -36; diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index 66ee9023..da75d10e 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -126,8 +126,6 @@ namespace Vocaluxe.Base _settings.Encoding = Encoding.UTF8; _settings.ConformanceLevel = ConformanceLevel.Document; - //ThemeColors.Player = new SColorF[6]; - ListThemes(); ListSkins(); diff --git a/Vocaluxe/Menu/CGraphics.cs b/Vocaluxe/Menu/CGraphics.cs index 7c64de84..0e5ca85e 100644 --- a/Vocaluxe/Menu/CGraphics.cs +++ b/Vocaluxe/Menu/CGraphics.cs @@ -377,7 +377,16 @@ namespace Vocaluxe.Menu _Fading = true; _FadingTimer.Reset(); _FadingTimer.Start(); - _Screens[(int)_NextScreen].OnShow(); + + if (_NextScreen == EScreens.ScreenPartyDummy) + { + CFonts.PartyModeID = CParty.CurrentPartyModeID; + _Screens[(int)_NextScreen].OnShow(); + CFonts.PartyModeID = -1; + } + else + _Screens[(int)_NextScreen].OnShow(); + HidePopup(EPopupScreens.PopupPlayerControl); } @@ -395,11 +404,28 @@ namespace Vocaluxe.Menu _GlobalAlpha = 1f;// -factor / 100f; _ZOffset = CSettings.zFar/2; - _Screens[(int)_CurrentScreen].Draw(); + + if (_CurrentScreen == EScreens.ScreenPartyDummy) + { + CFonts.PartyModeID = CParty.CurrentPartyModeID; + _Screens[(int)_CurrentScreen].Draw(); + CFonts.PartyModeID = -1; + } + else + _Screens[(int)_CurrentScreen].Draw(); + _GlobalAlpha = factor; _ZOffset = 0f; - _Screens[(int)_NextScreen].Draw(); + + if (_NextScreen == EScreens.ScreenPartyDummy) + { + CFonts.PartyModeID = CParty.CurrentPartyModeID; + _Screens[(int)_NextScreen].Draw(); + CFonts.PartyModeID = -1; + } + else + _Screens[(int)_NextScreen].Draw(); _GlobalAlpha = 1f; } @@ -412,14 +438,30 @@ namespace Vocaluxe.Menu CBackgroundMusic.Play(); _Screens[(int)_CurrentScreen].OnShowFinish(); _Screens[(int)_CurrentScreen].ProcessMouseMove(_Cursor.X, _Cursor.Y); - _Screens[(int)_CurrentScreen].Draw(); + + if (_CurrentScreen == EScreens.ScreenPartyDummy) + { + CFonts.PartyModeID = CParty.CurrentPartyModeID; + _Screens[(int)_CurrentScreen].Draw(); + CFonts.PartyModeID = -1; + } + else + _Screens[(int)_CurrentScreen].Draw(); + _Fading = false; _FadingTimer.Stop(); } } else { - _Screens[(int)_CurrentScreen].Draw(); + if (_CurrentScreen == EScreens.ScreenPartyDummy) + { + CFonts.PartyModeID = CParty.CurrentPartyModeID; + _Screens[(int)_CurrentScreen].Draw(); + CFonts.PartyModeID = -1; + } + else + _Screens[(int)_CurrentScreen].Draw(); } for (int i = 0; i < _PopupScreens.Count; i++) diff --git a/Vocaluxe/PartyModes/CPartyMode.cs b/Vocaluxe/PartyModes/CPartyMode.cs index d7ade268..f8e47254 100644 --- a/Vocaluxe/PartyModes/CPartyMode.cs +++ b/Vocaluxe/PartyModes/CPartyMode.cs @@ -10,17 +10,22 @@ namespace Vocaluxe.PartyModes abstract class CPartyMode : IPartyMode { protected ScreenSongOptions _ScreenSongOptions; + protected List _Screens; + protected string _Folder; public CPartyMode() { + _Screens = new List(); + _Folder = String.Empty; _ScreenSongOptions = new ScreenSongOptions(); _ScreenSongOptions.Selection = new SelectionOptions(); _ScreenSongOptions.Sorting = new SortingOptions(); } #region Implementation - public virtual void Init() + public virtual bool Init(string Folder) { + return false; } public virtual CMenu GetNextPartyScreen() diff --git a/Vocaluxe/PartyModes/IPartyMode.cs b/Vocaluxe/PartyModes/IPartyMode.cs index ef959509..d3a1220e 100644 --- a/Vocaluxe/PartyModes/IPartyMode.cs +++ b/Vocaluxe/PartyModes/IPartyMode.cs @@ -52,7 +52,7 @@ namespace Vocaluxe.PartyModes interface IPartyMode { - void Init(); + bool Init(string Folder); CMenu GetNextPartyScreen(); EScreens GetStartScreen();