From 19339c6888822e383b045b747efde015bfb4ad5a Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Tue, 7 May 2013 16:56:23 +0200 Subject: [PATCH 1/9] reconstructed CProfiles (preparing for async profile adding) --- Vocaluxe/Base/CConfig.cs | 8 +- Vocaluxe/Base/CMain.cs | 7 +- Vocaluxe/Base/CProfiles.cs | 349 +++++++++++++++++----------- Vocaluxe/Screens/CScreenNames.cs | 56 +++-- Vocaluxe/Screens/CScreenProfiles.cs | 85 ++++--- Vocaluxe/Screens/CScreenScore.cs | 2 +- Vocaluxe/Screens/CScreenSing.cs | 4 +- VocaluxeLib/IBasic.cs | 2 + VocaluxeLib/Menu/CNameSelection.cs | 10 +- VocaluxeLib/Profile/CAvatar.cs | 18 +- VocaluxeLib/Profile/CProfile.cs | 37 ++- 11 files changed, 353 insertions(+), 225 deletions(-) diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 204c8f73..9bc011eb 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -30,6 +30,7 @@ using Vocaluxe.Lib.Sound; using Vocaluxe.Lib.Webcam; using VocaluxeLib; using VocaluxeLib.Menu; +using VocaluxeLib.Profile; namespace Vocaluxe.Base { @@ -810,12 +811,13 @@ namespace Vocaluxe.Base CGame.Players[j].ProfileID = -1; if (Players[j] == "") continue; - for (int i = 0; i < CProfiles.Profiles.Length; i++) + CProfile[] profiles = CProfiles.GetProfiles(); + for (int i = 0; i < profiles.Length; i++) { - if (Path.GetFileName(CProfiles.Profiles[i].FileName) == Players[j] && CProfiles.Profiles[i].Active == EOffOn.TR_CONFIG_ON) + if (Path.GetFileName(profiles[i].FileName) == Players[j] && profiles[i].Active == EOffOn.TR_CONFIG_ON) { //Update Game-infos with player - CGame.Players[j].ProfileID = i; + CGame.Players[j].ProfileID = profiles[i].ID; } } } diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 02bc2092..5a55a92e 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -214,6 +214,11 @@ namespace Vocaluxe.Base { return CSettings.MedleyMinDuration; } + + public string GetFolderProfiles() + { + return CSettings.FolderProfiles; + } } class CBtheme : ITheme @@ -549,7 +554,7 @@ namespace Vocaluxe.Base { public CProfile[] GetProfiles() { - return CProfiles.Profiles; + return CProfiles.GetProfiles(); } public EGameDifficulty GetDifficulty(int profileID) diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index 51607c5f..2368532b 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -30,24 +30,21 @@ namespace Vocaluxe.Base { static class CProfiles { - private static List _Profiles; - private static readonly List _Avatars = new List(); + private static Dictionary _Profiles; + private static Queue _ProfileIDs; + private static Object _ProfileMutex = new Object(); - public static CProfile[] Profiles - { - get { return _Profiles.ToArray(); } - } + private static Dictionary _Avatars; + private static Queue _AvatarIDs; + private static Object _AvatarMutex = new Object(); + + private static List _Callbacks; public static int NumProfiles { get { return _Profiles.Count; } } - public static CAvatar[] Avatars - { - get { return _Avatars.ToArray(); } - } - public static int NumAvatars { get { return _Avatars.Count; } @@ -55,80 +52,175 @@ namespace Vocaluxe.Base public static void Init() { + _Avatars = new Dictionary(); + _AvatarIDs = new Queue(1000); + for (int i = 0; i < 1000; i++) + { + _AvatarIDs.Enqueue(i); + } + + _Profiles = new Dictionary(); + _ProfileIDs = new Queue(100); + for (int i = 0; i < 100; i++) + { + _ProfileIDs.Enqueue(i); + } + + _Callbacks = new List(); + LoadProfiles(); } + public static CProfile[] GetProfiles() + { + List list = new List(); + + lock (_ProfileMutex) + { + if (_Profiles.Count == 0) + return null; + + CProfile[] result = new CProfile[_Profiles.Count]; + _Profiles.Values.CopyTo(result, 0); + for (int i = 0; i < result.Length; i++) + { + list.Add(result[i]); + } + list.Sort(_CompareByPlayerName); + } + return list.ToArray(); + } + + public static CAvatar[] GetAvatars() + { + CAvatar[] result = null; + lock (_AvatarMutex) + { + if (_Avatars.Count == 0) + return null; + + result = new CAvatar[_Avatars.Count]; + _Avatars.Values.CopyTo(result, 0); + } + return result; + } + public static string GetPlayerName(int profileID, int playerNum = 0) { if (ICProfileIDValid(profileID)) return _Profiles[profileID].PlayerName; + string playerName = CLanguage.Translate("TR_SCREENNAMES_PLAYER"); if (playerNum > 0) playerName += " " + playerNum; return playerName; } + public static string GetProfileFileName(int profileID) + { + if (!ICProfileIDValid(profileID)) + return String.Empty; + + return Path.GetFileName(_Profiles[profileID].FileName); + } + public static int NewProfile(string fileName = "") { CProfile profile = new CProfile { - PlayerName = String.Empty, - Difficulty = EGameDifficulty.TR_CONFIG_EASY, - Avatar = new CAvatar(-1), - GuestProfile = EOffOn.TR_CONFIG_OFF, - Active = EOffOn.TR_CONFIG_ON, FileName = fileName != "" ? Path.Combine(CSettings.FolderProfiles, fileName) : String.Empty }; if (File.Exists(profile.FileName)) return -1; - _Profiles.Add(profile); - return _Profiles.Count - 1; + lock (_ProfileMutex) + { + profile.ID = _ProfileIDs.Dequeue(); + _Profiles.Add(profile.ID, profile); + } + + return profile.ID; } public static void SaveProfiles() { - for (int i = 0; i < _Profiles.Count; i++) - _SaveProfile(i); + foreach (int id in _Profiles.Keys) + { + _Profiles[id].SaveProfile(); + } + LoadProfiles(); } public static void LoadProfiles() { LoadAvatars(); - _Profiles = new List(); - List files = new List(); - files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.xml", true, true)); - foreach (string file in files) - _LoadProfile(file); + lock (_ProfileMutex) + { + List knownFiles = new List(); + foreach (int id in _Profiles.Keys) + { + _Profiles[id].LoadProfile(); + knownFiles.Add(_Profiles[id].FileName); + } - _SortProfilesByName(); + List files = new List(); + files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.xml", true, true)); + + foreach (string file in knownFiles) + { + files.Remove(file); + } + + foreach (string file in files) + { + CProfile profile = new CProfile + { + FileName = Path.Combine(CSettings.FolderProfiles, file) + }; + + if (profile.LoadProfile()) + { + profile.Avatar = _GetAvatar(profile.AvatarFileName); + profile.ID = _ProfileIDs.Dequeue(); + _Profiles.Add(profile.ID, profile); + } + } + } } public static void LoadAvatars() { - for (int i = 0; i < _Avatars.Count; i++) + lock (_AvatarMutex) { - STexture texture = _Avatars[i].Texture; - CDraw.RemoveTexture(ref texture); - } - _Avatars.Clear(); - - List files = new List(); - files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.png", true, true)); - files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpg", true, true)); - files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpeg", true, true)); - files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.bmp", true, true)); - - foreach (string file in files) - { - STexture tex = CDraw.AddTexture(file); - if (tex.Index != -1) + List knownFiles = new List(); + foreach (int id in _Avatars.Keys) { - CAvatar avatar = new CAvatar(-1) {Texture = tex, FileName = Path.GetFileName(file)}; - _Avatars.Add(avatar); + _Avatars[id].Reload(); + knownFiles.Add(_Avatars[id].FileName); + } + + List files = new List(); + files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.png", true, true)); + files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpg", true, true)); + files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpeg", true, true)); + files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.bmp", true, true)); + + foreach (string file in knownFiles) + { + files.Remove(file); + } + + foreach (string file in files) + { + CAvatar avatar = new CAvatar(-1); + if (avatar.LoadFromFile(file)) + { + avatar.ID = _AvatarIDs.Dequeue(); + _Avatars.Add(avatar.ID, avatar); + } } } } @@ -138,11 +230,8 @@ namespace Vocaluxe.Base if (!ICProfileIDValid(profileID)) return String.Empty; - CProfile profile = _Profiles[profileID]; - profile.PlayerName += chr; - _Profiles[profileID] = profile; - - return profile.PlayerName; + _Profiles[profileID].PlayerName += chr; + return _Profiles[profileID].PlayerName; } public static string GetDeleteCharInPlayerName(int profileID) @@ -153,14 +242,18 @@ namespace Vocaluxe.Base CProfile profile = _Profiles[profileID]; if (profile.PlayerName != "") profile.PlayerName = profile.PlayerName.Remove(profile.PlayerName.Length - 1); - _Profiles[profileID] = profile; return profile.PlayerName; } public static bool ICProfileIDValid(int profileID) { - return profileID >= 0 && profileID < _Profiles.Count; + return _Profiles.ContainsKey(profileID); + } + + public static bool ICAvatarIDValid(int avatarID) + { + return _Avatars.ContainsKey(avatarID); } public static EGameDifficulty GetDifficulty(int profileID) @@ -173,9 +266,7 @@ namespace Vocaluxe.Base if (!ICProfileIDValid(profileID)) return; - CProfile profile = _Profiles[profileID]; - profile.Difficulty = difficulty; - _Profiles[profileID] = profile; + _Profiles[profileID].Difficulty = difficulty; } public static EOffOn GetGuestProfile(int profileID) @@ -193,18 +284,14 @@ namespace Vocaluxe.Base if (!ICProfileIDValid(profileID)) return; - CProfile profile = _Profiles[profileID]; - profile.GuestProfile = option; - _Profiles[profileID] = profile; + _Profiles[profileID].GuestProfile = option; } public static void SetActive(int profileID, EOffOn option) { if (!ICProfileIDValid(profileID)) return; - CProfile profile = _Profiles[profileID]; - profile.Active = option; - _Profiles[profileID] = profile; + _Profiles[profileID].Active = option; } public static bool IsGuestProfile(int profileID) @@ -222,126 +309,106 @@ namespace Vocaluxe.Base return _Profiles[profileID].Active == EOffOn.TR_CONFIG_ON; } - public static void SetAvatar(int profileID, int avatarNr) + public static void SetAvatar(int profileID, int avatarID) { - if (!ICProfileIDValid(profileID) || avatarNr < 0 || avatarNr >= _Avatars.Count) + if (!ICProfileIDValid(profileID) || !ICAvatarIDValid(avatarID)) return; - CProfile profile = _Profiles[profileID]; - profile.Avatar = _Avatars[avatarNr]; - _Profiles[profileID] = profile; + _Profiles[profileID].Avatar = _Avatars[avatarID]; } - public static int GetAvatarNr(int profileID) + public static int GetAvatarID(int profileID) { if (!ICProfileIDValid(profileID)) - return 0; + return -1; - for (int i = 0; i < _Avatars.Count; i++) - { - if (_Profiles[profileID].Avatar.FileName == _Avatars[i].FileName) - return i; - } + return _Profiles[profileID].Avatar.ID; + } - return 0; + public static STexture GetAvatarTexture(int avatarID) + { + if (!ICAvatarIDValid(avatarID)) + return new STexture(-1); + + return _Avatars[avatarID].Texture; + } + + public static STexture GetAvatarTextureFromProfile(int profileID) + { + if (!ICProfileIDValid(profileID)) + return new STexture(-1); + + return _Profiles[profileID].Avatar.Texture; } public static void DeleteProfile(int profileID) { - if (!ICProfileIDValid(profileID)) - return; - if (_Profiles[profileID].FileName == "") - return; - try + lock (_ProfileMutex) { - //Check if profile saved in config - for (int i = 0; i < CConfig.Players.Length; i++) + if (!ICProfileIDValid(profileID)) + return; + + if (_Profiles[profileID].FileName == "") { - if (CConfig.Players[i] == _Profiles[profileID].FileName) + _RemoveProfile(profileID); + return; + } + + try + { + //Check if profile saved in config + for (int i = 0; i < CConfig.Players.Length; i++) { - CConfig.Players[i] = string.Empty; - CConfig.SaveConfig(); + if (CConfig.Players[i] == _Profiles[profileID].FileName) + { + CConfig.Players[i] = string.Empty; + CConfig.SaveConfig(); + } + } + File.Delete(_Profiles[profileID].FileName); + _RemoveProfile(profileID); + + //Check if profile is selected in game + for (int i = 0; i < CGame.Players.Length; i++) + { + if (CGame.Players[i].ProfileID > profileID) + CGame.Players[i].ProfileID--; + else if (CGame.Players[i].ProfileID == profileID) + CGame.Players[i].ProfileID = -1; } } - File.Delete(_Profiles[profileID].FileName); - _Profiles.RemoveAt(profileID); - //Check if profile is selected in game - for (int i = 0; i < CGame.Players.Length; i++) + catch (Exception) { - if (CGame.Players[i].ProfileID > profileID) - CGame.Players[i].ProfileID--; - else if (CGame.Players[i].ProfileID == profileID) - CGame.Players[i].ProfileID = -1; + CLog.LogError("Can't delete Profile File " + _Profiles[profileID].FileName + ".xml"); } } - catch (Exception) - { - CLog.LogError("Can't delete Profile File " + _Profiles[profileID].FileName + ".xml"); - } - } - - private static void _SortProfilesByName() - { - _Profiles.Sort(_CompareByPlayerName); } + #region private methods private static int _CompareByPlayerName(CProfile a, CProfile b) { return String.CompareOrdinal(a.PlayerName, b.PlayerName); } - #region private methods private static CAvatar _GetAvatar(string fileName) { - foreach (CAvatar avatar in _Avatars) + lock (_AvatarMutex) { - if (fileName == avatar.FileName) - return avatar; + foreach (int id in _Avatars.Keys) + { + if (Path.GetFileName(_Avatars[id].FileName) == fileName) + return _Avatars[id]; + } } return new CAvatar(-1); } - private static void _SaveProfile(int profileID) + private static void _RemoveProfile(int profileID) { if (!ICProfileIDValid(profileID)) return; - if (_Profiles[profileID].FileName == "") - { - string filename = string.Empty; - foreach (char chr in _Profiles[profileID].PlayerName) - { - if (char.IsLetter(chr)) - filename += chr.ToString(); - } - - if (filename == "") - filename = "1"; - - int i = 0; - while (File.Exists(Path.Combine(CSettings.FolderProfiles, filename + ".xml"))) - { - i++; - if (!File.Exists(Path.Combine(CSettings.FolderProfiles, filename + i + ".xml"))) - filename += i; - } - - CProfile profile = _Profiles[profileID]; - profile.FileName = Path.Combine(CSettings.FolderProfiles, filename + ".xml"); - _Profiles[profileID] = profile; - } - - _Profiles[profileID].SaveProfile(); - } - - private static void _LoadProfile(string fileName) - { - CProfile profile = new CProfile {FileName = Path.Combine(CSettings.FolderProfiles, fileName)}; - if (profile.LoadProfile()) - { - profile.Avatar = _GetAvatar(profile.AvatarFileName); - _Profiles.Add(profile); - } + _Profiles.Remove(profileID); } #endregion private methods } diff --git a/Vocaluxe/Screens/CScreenNames.cs b/Vocaluxe/Screens/CScreenNames.cs index 28efb832..8db82dcf 100644 --- a/Vocaluxe/Screens/CScreenNames.cs +++ b/Vocaluxe/Screens/CScreenNames.cs @@ -23,6 +23,7 @@ using System.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib; using VocaluxeLib.Menu; +using VocaluxeLib.Profile; namespace Vocaluxe.Screens { @@ -166,15 +167,19 @@ namespace Vocaluxe.Screens //Check, if a player is selected if (_NameSelections[_NameSelection].Selection > -1) { + CProfile[] profiles = CProfiles.GetProfiles(); _SelectedPlayerNr = _NameSelections[_NameSelection].Selection; + if (profiles.Length <= _SelectedPlayerNr) + return true; + //Update Game-infos with new player - CGame.Players[_SelectingFastPlayerNr - 1].ProfileID = _SelectedPlayerNr; + CGame.Players[_SelectingFastPlayerNr - 1].ProfileID = profiles[_SelectedPlayerNr].ID; //Update config for default players. - CConfig.Players[_SelectingFastPlayerNr - 1] = CProfiles.Profiles[_SelectedPlayerNr].FileName; + CConfig.Players[_SelectingFastPlayerNr - 1] = profiles[_SelectedPlayerNr].FileName; CConfig.SaveConfig(); //Update texture and name - _Statics[_StaticPlayerAvatar[_SelectingFastPlayerNr - 1]].Texture = CProfiles.Profiles[_SelectedPlayerNr].Avatar.Texture; - _Texts[_TextPlayer[_SelectingFastPlayerNr - 1]].Text = CProfiles.Profiles[_SelectedPlayerNr].PlayerName; + _Statics[_StaticPlayerAvatar[_SelectingFastPlayerNr - 1]].Texture = profiles[_SelectedPlayerNr].Avatar.Texture; + _Texts[_TextPlayer[_SelectingFastPlayerNr - 1]].Text = profiles[_SelectedPlayerNr].PlayerName; //Update profile-warning _CheckPlayers(); //Update Tiles-List @@ -418,10 +423,10 @@ namespace Vocaluxe.Screens //Update Game-infos with new player CGame.Players[_SelectingSwitchNr].ProfileID = CGame.Players[i].ProfileID; //Update config for default players. - CConfig.Players[_SelectingSwitchNr] = CProfiles.Profiles[i].FileName; + CConfig.Players[_SelectingSwitchNr] = CProfiles.GetProfileFileName(CGame.Players[i].ProfileID); //Update texture and name - _Statics[_StaticPlayerAvatar[_SelectingSwitchNr]].Texture = CProfiles.Profiles[CGame.Players[i].ProfileID].Avatar.Texture; - _Texts[_TextPlayer[_SelectingSwitchNr]].Text = CProfiles.Profiles[CGame.Players[i].ProfileID].PlayerName; + _Statics[_StaticPlayerAvatar[_SelectingSwitchNr]].Texture = CProfiles.GetAvatarTextureFromProfile(CGame.Players[i].ProfileID); + _Texts[_TextPlayer[_SelectingSwitchNr]].Text = CProfiles.GetPlayerName(CGame.Players[i].ProfileID); } else if (_SelectingSwitchNr > -1) { @@ -433,14 +438,19 @@ namespace Vocaluxe.Screens _Statics[_StaticPlayerAvatar[_SelectingSwitchNr]].Texture = _OriginalPlayerAvatarTextures[_SelectingSwitchNr]; _Texts[_TextPlayer[_SelectingSwitchNr]].Text = CProfiles.GetPlayerName(-1, (_SelectingSwitchNr+1)); } + + CProfile[] profiles = CProfiles.GetProfiles(); + if (profiles.Length <= _SelectedPlayerNr) + return true; + //Update Game-infos with new player - CGame.Players[i].ProfileID = _SelectedPlayerNr; + CGame.Players[i].ProfileID = profiles[_SelectedPlayerNr].ID; //Update config for default players. - CConfig.Players[i] = CProfiles.Profiles[_SelectedPlayerNr].FileName; + CConfig.Players[i] = profiles[_SelectedPlayerNr].FileName; CConfig.SaveConfig(); //Update texture and name _Statics[_StaticPlayerAvatar[i]].Texture = _ChooseAvatarStatic.Texture; - _Texts[_TextPlayer[i]].Text = CProfiles.Profiles[_SelectedPlayerNr].PlayerName; + _Texts[_TextPlayer[i]].Text = profiles[_SelectedPlayerNr].PlayerName; //Update profile-warning _CheckPlayers(); //Update Tiles-List @@ -473,14 +483,18 @@ namespace Vocaluxe.Screens _SelectedPlayerNr = _NameSelections[_NameSelection].TilePlayerNr(mouseEvent); if (_SelectedPlayerNr != -1) { + CProfile[] profiles = CProfiles.GetProfiles(); + if (profiles.Length <= _SelectedPlayerNr) + return true; + //Update Game-infos with new player - CGame.Players[_SelectingFastPlayerNr - 1].ProfileID = _SelectedPlayerNr; + CGame.Players[_SelectingFastPlayerNr - 1].ProfileID = profiles[_SelectedPlayerNr].ID; //Update config for default players. - CConfig.Players[_SelectingFastPlayerNr - 1] = CProfiles.Profiles[_SelectedPlayerNr].FileName; + CConfig.Players[_SelectingFastPlayerNr - 1] = profiles[_SelectedPlayerNr].FileName; CConfig.SaveConfig(); //Update texture and name - _Statics[_StaticPlayerAvatar[_SelectingFastPlayerNr - 1]].Texture = CProfiles.Profiles[_SelectedPlayerNr].Avatar.Texture; - _Texts[_TextPlayer[_SelectingFastPlayerNr - 1]].Text = CProfiles.Profiles[_SelectedPlayerNr].PlayerName; + _Statics[_StaticPlayerAvatar[_SelectingFastPlayerNr - 1]].Texture = profiles[_SelectedPlayerNr].Avatar.Texture; + _Texts[_TextPlayer[_SelectingFastPlayerNr - 1]].Text = profiles[_SelectedPlayerNr].PlayerName; //Update profile-warning _CheckPlayers(); //Update Tiles-List @@ -516,14 +530,18 @@ namespace Vocaluxe.Screens { if (CGame.Players[i].ProfileID == -1) { + CProfile[] profiles = CProfiles.GetProfiles(); + if (profiles.Length <= _SelectedPlayerNr) + return true; + //Update Game-infos with new player - CGame.Players[i].ProfileID = _SelectedPlayerNr; + CGame.Players[i].ProfileID = profiles[_SelectedPlayerNr].ID; //Update config for default players. - CConfig.Players[i] = CProfiles.Profiles[_SelectedPlayerNr].FileName; + CConfig.Players[i] = profiles[_SelectedPlayerNr].FileName; CConfig.SaveConfig(); //Update texture and name - _Statics[_StaticPlayerAvatar[i]].Texture = CProfiles.Profiles[_SelectedPlayerNr].Avatar.Texture; - _Texts[_TextPlayer[i]].Text = CProfiles.Profiles[_SelectedPlayerNr].PlayerName; + _Statics[_StaticPlayerAvatar[i]].Texture = profiles[_SelectedPlayerNr].Avatar.Texture; + _Texts[_TextPlayer[i]].Text = profiles[_SelectedPlayerNr].PlayerName; //Update profile-warning _CheckPlayers(); //Update Tiles-List @@ -624,7 +642,7 @@ namespace Vocaluxe.Screens for (int i = 0; i < CSettings.MaxNumPlayer; i++) { _Statics[_StaticPlayerAvatar[i]].Texture = CProfiles.ICProfileIDValid(CGame.Players[i].ProfileID) ? - CProfiles.Profiles[CGame.Players[i].ProfileID].Avatar.Texture : + CProfiles.GetAvatarTextureFromProfile(CGame.Players[i].ProfileID) : _OriginalPlayerAvatarTextures[i]; _Texts[_TextPlayer[i]].Text = CProfiles.GetPlayerName(CGame.Players[i].ProfileID, i + 1); if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet) diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index bd637050..7a5ff289 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -18,6 +18,7 @@ #endregion using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; @@ -25,6 +26,7 @@ using System.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib; using VocaluxeLib.Menu; +using VocaluxeLib.Profile; namespace Vocaluxe.Screens { @@ -103,7 +105,7 @@ namespace Vocaluxe.Screens break; case EEditMode.PlayerName: _SelectSlides[_SelectSlideProfiles].RenameValue( - CProfiles.AddGetPlayerName(_SelectSlides[_SelectSlideProfiles].Selection, keyEvent.Unicode)); + CProfiles.AddGetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex, keyEvent.Unicode)); break; } } @@ -145,7 +147,7 @@ namespace Vocaluxe.Screens if (_EditMode == EEditMode.PlayerName) { _SelectSlides[_SelectSlideProfiles].RenameValue( - CProfiles.GetDeleteCharInPlayerName(_SelectSlides[_SelectSlideProfiles].Selection)); + CProfiles.GetDeleteCharInPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex)); } else CGraphics.FadeTo(EScreens.ScreenMain); @@ -157,22 +159,22 @@ namespace Vocaluxe.Screens } if (_SelectSlides[_SelectSlideDifficulty].Selected) { - CProfiles.SetDifficulty(_SelectSlides[_SelectSlideProfiles].Selection, + CProfiles.SetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex, (EGameDifficulty)_SelectSlides[_SelectSlideDifficulty].Selection); } else if (_SelectSlides[_SelectSlideAvatars].Selected) { - CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection, - _SelectSlides[_SelectSlideAvatars].Selection); + CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, + _SelectSlides[_SelectSlideAvatars].ValueIndex); } else if (_SelectSlides[_SelectSlideGuestProfile].Selected) { - CProfiles.SetGuestProfile(_SelectSlides[_SelectSlideProfiles].Selection, + CProfiles.SetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex, (EOffOn)_SelectSlides[_SelectSlideGuestProfile].Selection); } else if (_SelectSlides[_SelectSlideActive].Selected) { - CProfiles.SetActive(_SelectSlides[_SelectSlideProfiles].Selection, + CProfiles.SetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex, (EOffOn)_SelectSlides[_SelectSlideActive].Selection); } } @@ -204,24 +206,24 @@ namespace Vocaluxe.Screens } else if (_SelectSlides[_SelectSlideDifficulty].Selected) { - CProfiles.SetDifficulty(_SelectSlides[_SelectSlideProfiles].Selection, + CProfiles.SetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex, (EGameDifficulty)_SelectSlides[_SelectSlideDifficulty].Selection); } else if (_SelectSlides[_SelectSlideAvatars].Selected) { - CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection, - _SelectSlides[_SelectSlideAvatars].Selection); + CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, + _SelectSlides[_SelectSlideAvatars].ValueIndex); if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index > 0) _OnDiscardSnapshot(); } else if (_SelectSlides[_SelectSlideGuestProfile].Selected) { - CProfiles.SetGuestProfile(_SelectSlides[_SelectSlideProfiles].Selection, + CProfiles.SetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex, (EOffOn)_SelectSlides[_SelectSlideGuestProfile].Selection); } else if (_SelectSlides[_SelectSlideActive].Selected) { - CProfiles.SetActive(_SelectSlides[_SelectSlideProfiles].Selection, + CProfiles.SetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex, (EOffOn)_SelectSlides[_SelectSlideActive].Selection); } else if (_Buttons[_ButtonWebcam].Selected && CWebcam.IsDeviceAvailable()) @@ -272,11 +274,12 @@ namespace Vocaluxe.Screens CWebcam.Stop(); CDraw.RemoveTexture(ref _WebcamTexture); - for (int j = 0; j < CProfiles.Avatars.Length; j++) + CAvatar[] avatars = CProfiles.GetAvatars(); + for (int j = 0; j < avatars.Length; j++) { - if (CProfiles.Avatars[j].FileName == (filename + i + ".png")) + if (Path.GetFileName(avatars[j].FileName) == (filename + i + ".png")) { - CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection, j); + CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, avatars[j].ID); break; } } @@ -302,17 +305,17 @@ namespace Vocaluxe.Screens { if (_SelectSlides[_SelectSlideProfiles].Selection > -1) { - _Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].Selection); + _Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex); if (_EditMode == EEditMode.PlayerName) _Buttons[_ButtonPlayerName].Text.Text += "|"; - _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].Selection); - _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].Selection); - _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].Selection); + _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex); + _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex); + _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex); - int avatarNr = CProfiles.GetAvatarNr(_SelectSlides[_SelectSlideProfiles].Selection); - _SelectSlides[_SelectSlideAvatars].Selection = avatarNr; - if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index > 0) + int avatarID = CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex); + _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(avatarID); + if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index != -1) { if (_Snapshot == null) CWebcam.GetFrame(ref _WebcamTexture); @@ -320,7 +323,7 @@ namespace Vocaluxe.Screens _Statics[_StaticAvatar].Texture = _WebcamTexture; } else - _Statics[_StaticAvatar].Texture = CProfiles.Avatars[avatarNr].Texture; + _Statics[_StaticAvatar].Texture = CProfiles.GetAvatarTexture(avatarID); } return true; @@ -353,7 +356,7 @@ namespace Vocaluxe.Screens private void _DeleteProfile() { - CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].Selection); + CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex); _LoadProfiles(); UpdateGame(); } @@ -363,34 +366,44 @@ namespace Vocaluxe.Screens _EditMode = EEditMode.None; _SelectSlides[_SelectSlideProfiles].Clear(); - for (int i = 0; i < CProfiles.NumProfiles; i++) - _SelectSlides[_SelectSlideProfiles].AddValue(CProfiles.GetPlayerName(i)); + CProfile[] profiles = CProfiles.GetProfiles(); + for (int i = 0; i < profiles.Length; i++) + _SelectSlides[_SelectSlideProfiles].AddValue( + profiles[i].PlayerName, + new STexture(-1), + profiles[i].ID, + -1); if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0) { - _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].Selection); - _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].Selection); - _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].Selection); - _SelectSlides[_SelectSlideAvatars].Selection = CProfiles.GetAvatarNr(_SelectSlides[_SelectSlideProfiles].Selection); + _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex); + _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex); + _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex); + _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex)); } } private void _LoadAvatars() { _SelectSlides[_SelectSlideAvatars].Clear(); - for (int i = 0; i < CProfiles.NumAvatars; i++) - _SelectSlides[_SelectSlideAvatars].AddValue(CProfiles.Avatars[i].FileName); + CAvatar[] avatars = CProfiles.GetAvatars(); + for (int i = 0; i < avatars.Length; i++) + _SelectSlides[_SelectSlideAvatars].AddValue( + Path.GetFileName(avatars[i].FileName), + new STexture(-1), + avatars[i].ID, + -1); } private void _NewProfile() { _EditMode = EEditMode.None; - CProfiles.NewProfile(); + int id = CProfiles.NewProfile(); _LoadProfiles(); - _SelectSlides[_SelectSlideProfiles].LastValue(); + _SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(id); - CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection, - _SelectSlides[_SelectSlideAvatars].Selection); + CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, + _SelectSlides[_SelectSlideAvatars].ValueIndex); _SetInteractionToButton(_Buttons[_ButtonPlayerName]); _EditMode = EEditMode.PlayerName; diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index 192cac34..22756d7f 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -334,7 +334,7 @@ namespace Vocaluxe.Screens _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H; } if (CProfiles.ICProfileIDValid(players[p].ProfileID)) - _Statics[_StaticAvatar[p, CGame.NumPlayer - 1]].Texture = CProfiles.Profiles[players[p].ProfileID].Avatar.Texture; + _Statics[_StaticAvatar[p, CGame.NumPlayer - 1]].Texture = CProfiles.GetAvatarTextureFromProfile(players[p].ProfileID); } if (CConfig.ScoreAnimationTime < 1) diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index e34df75d..472037b2 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -1384,7 +1384,7 @@ namespace Vocaluxe.Screens for (int i = 0; i < CGame.NumPlayer; i++) { if (CProfiles.ICProfileIDValid(CGame.Players[i].ProfileID)) - _Statics[_StaticAvatars[i, CGame.NumPlayer - 1]].Texture = CProfiles.Profiles[CGame.Players[i].ProfileID].Avatar.Texture; + _Statics[_StaticAvatars[i, CGame.NumPlayer - 1]].Texture = CProfiles.GetAvatarTextureFromProfile(CGame.Players[i].ProfileID); else _Statics[_StaticAvatars[i, CGame.NumPlayer - 1]].Visible = false; } @@ -1395,7 +1395,7 @@ namespace Vocaluxe.Screens for (int i = 0; i < CGame.NumPlayer; i++) { if (CProfiles.ICProfileIDValid(CGame.Players[i].ProfileID)) - _Texts[_TextNames[i, CGame.NumPlayer - 1]].Text = CProfiles.Profiles[CGame.Players[i].ProfileID].PlayerName; + _Texts[_TextNames[i, CGame.NumPlayer - 1]].Text = CProfiles.GetPlayerName(CGame.Players[i].ProfileID); else _Texts[_TextNames[i, CGame.NumPlayer - 1]].Visible = false; } diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index 990dff45..fe92c5b8 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -70,6 +70,8 @@ namespace VocaluxeLib float GetDefaultMedleyFadeOutTime(); int GetMedleyMinSeriesLength(); float GetMedleyMinDuration(); + + string GetFolderProfiles(); } public interface ITheme diff --git a/VocaluxeLib/Menu/CNameSelection.cs b/VocaluxeLib/Menu/CNameSelection.cs index 2888d8ea..72fedb85 100644 --- a/VocaluxeLib/Menu/CNameSelection.cs +++ b/VocaluxeLib/Menu/CNameSelection.cs @@ -22,6 +22,8 @@ using System.Collections.Generic; using System.Windows.Forms; using System.Xml; +using VocaluxeLib.Profile; + namespace VocaluxeLib.Menu { struct SThemeNameSelection @@ -497,16 +499,18 @@ namespace VocaluxeLib.Menu private void _UpdateVisibleProfiles() { _VisibleProfiles.Clear(); - for (int i = 0; i < CBase.Profiles.GetProfiles().Length; i++) + CProfile[] profiles = CBase.Profiles.GetProfiles(); + + for (int i = 0; i < profiles.Length; i++) { - bool visible = CBase.Profiles.GetProfiles()[i].Active == EOffOn.TR_CONFIG_ON; + bool visible = profiles[i].Active == EOffOn.TR_CONFIG_ON; if (visible) { //Show profile only if active for (int p = 0; p < CBase.Game.GetNumPlayer(); p++) { //Don't show profile if is selected, but if selected and guest - if (CBase.Game.GetPlayers()[p].ProfileID == i && CBase.Profiles.GetProfiles()[i].GuestProfile == EOffOn.TR_CONFIG_OFF) + if (CBase.Game.GetPlayers()[p].ProfileID == profiles[i].ID && profiles[i].GuestProfile == EOffOn.TR_CONFIG_OFF) visible = false; } } diff --git a/VocaluxeLib/Profile/CAvatar.cs b/VocaluxeLib/Profile/CAvatar.cs index 466ceab8..3f7dd941 100644 --- a/VocaluxeLib/Profile/CAvatar.cs +++ b/VocaluxeLib/Profile/CAvatar.cs @@ -9,28 +9,23 @@ namespace VocaluxeLib.Profile { public class CAvatar { - private int _ID; - - public int ID - { - get { return _ID; } - } - + public int ID; public string FileName; public STexture Texture; public CAvatar(int ID) { - _ID = ID; + this.ID = ID; FileName = String.Empty; Texture = new STexture(-1); } - public void LoadFromFile(string NewFileName) + public bool LoadFromFile(string NewFileName) { FileName = NewFileName; CBase.Drawing.RemoveTexture(ref Texture); Texture = CBase.Drawing.AddTexture(FileName); + return (Texture.Index != -1); } public void Reload() @@ -38,5 +33,10 @@ namespace VocaluxeLib.Profile CBase.Drawing.RemoveTexture(ref Texture); Texture = CBase.Drawing.AddTexture(FileName); } + + public void Unload() + { + CBase.Drawing.RemoveTexture(ref Texture); + } } } diff --git a/VocaluxeLib/Profile/CProfile.cs b/VocaluxeLib/Profile/CProfile.cs index fc9f19b4..f4ed3efd 100644 --- a/VocaluxeLib/Profile/CProfile.cs +++ b/VocaluxeLib/Profile/CProfile.cs @@ -16,20 +16,14 @@ namespace VocaluxeLib.Profile ConformanceLevel = ConformanceLevel.Document }; - private int _ID; - private int _AvatarID; - - public int ID - { - get { return _ID; } - } - + public int ID; + public string PlayerName; public string FileName; public string AvatarFileName; public EGameDifficulty Difficulty; - public CAvatar Avatar; //should be removed! use avatar id + public CAvatar Avatar; public EOffOn GuestProfile; public EOffOn Active; @@ -78,6 +72,29 @@ namespace VocaluxeLib.Profile public void SaveProfile() { + if (FileName == String.Empty) + { + string filename = string.Empty; + foreach (char chr in PlayerName) + { + if (char.IsLetter(chr)) + filename += chr.ToString(); + } + + if (filename == "") + filename = "1"; + + int i = 0; + while (File.Exists(Path.Combine(CBase.Settings.GetFolderProfiles(), filename + ".xml"))) + { + i++; + if (!File.Exists(Path.Combine(CBase.Settings.GetFolderProfiles(), filename + i + ".xml"))) + filename += i; + } + + FileName = Path.Combine(Environment.CurrentDirectory, CBase.Settings.GetFolderProfiles(), filename + ".xml"); + } + if (FileName == String.Empty) return; @@ -99,7 +116,7 @@ namespace VocaluxeLib.Profile writer.WriteStartElement("Info"); writer.WriteElementString("PlayerName", PlayerName); writer.WriteElementString("Difficulty", Enum.GetName(typeof(EGameDifficulty), Difficulty)); - writer.WriteElementString("Avatar", Avatar.FileName); + writer.WriteElementString("Avatar", Path.GetFileName(Avatar.FileName)); writer.WriteElementString("GuestProfile", Enum.GetName(typeof(EOffOn), GuestProfile)); writer.WriteElementString("Active", Enum.GetName(typeof(EOffOn), Active)); writer.WriteEndElement(); From 2037e3edb4729eadada6e40c14a101fbe99efcf8 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Tue, 7 May 2013 18:18:43 +0200 Subject: [PATCH 2/9] better Screens/CScreenProfiles.cs behavior --- Vocaluxe/Base/CProfiles.cs | 42 ++++++++++++++++++++++++++--- Vocaluxe/Screens/CScreenProfiles.cs | 18 ++++++++++--- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index 2368532b..1965fc95 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -28,6 +28,8 @@ using VocaluxeLib.Profile; namespace Vocaluxe.Base { + + static class CProfiles { private static Dictionary _Profiles; @@ -38,7 +40,8 @@ namespace Vocaluxe.Base private static Queue _AvatarIDs; private static Object _AvatarMutex = new Object(); - private static List _Callbacks; + public delegate void ProfilesChangedNotification(); + private static List _Callbacks; public static int NumProfiles { @@ -66,11 +69,22 @@ namespace Vocaluxe.Base _ProfileIDs.Enqueue(i); } - _Callbacks = new List(); + _Callbacks = new List(); LoadProfiles(); } + public static void AddNotificationCallback(ProfilesChangedNotification Callback) + { + if (Callback == null) + return; + + lock (_Callbacks) + { + _Callbacks.Add(Callback); + } + } + public static CProfile[] GetProfiles() { List list = new List(); @@ -139,7 +153,7 @@ namespace Vocaluxe.Base profile.ID = _ProfileIDs.Dequeue(); _Profiles.Add(profile.ID, profile); } - + _Notification(); return profile.ID; } @@ -189,6 +203,7 @@ namespace Vocaluxe.Base } } } + _Notification(); } public static void LoadAvatars() @@ -223,6 +238,7 @@ namespace Vocaluxe.Base } } } + _Notification(); } public static string AddGetPlayerName(int profileID, char chr) @@ -385,6 +401,25 @@ namespace Vocaluxe.Base } #region private methods + private static void _Notification() + { + lock (_Callbacks) + { + for (int i = 0; i < _Callbacks.Count; i++) + { + try + { + _Callbacks[i](); + } + catch (Exception) + { + _Callbacks.RemoveAt(i); + } + } + + } + } + private static int _CompareByPlayerName(CProfile a, CProfile b) { return String.CompareOrdinal(a.PlayerName, b.PlayerName); @@ -409,6 +444,7 @@ namespace Vocaluxe.Base return; _Profiles.Remove(profileID); + _Notification(); } #endregion private methods } diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index 7a5ff289..27ce1d2b 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -356,14 +356,21 @@ namespace Vocaluxe.Screens private void _DeleteProfile() { + int selection = _SelectSlides[_SelectSlideProfiles].Selection; CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex); _LoadProfiles(); + + if (_SelectSlides[_SelectSlideProfiles].NumValues > selection) + _SelectSlides[_SelectSlideProfiles].Selection = selection; + else + _SelectSlides[_SelectSlideProfiles].Selection = selection - 1; UpdateGame(); } private void _LoadProfiles() { _EditMode = EEditMode.None; + int selectedProfileID = _SelectSlides[_SelectSlideProfiles].ValueIndex; _SelectSlides[_SelectSlideProfiles].Clear(); CProfile[] profiles = CProfiles.GetProfiles(); @@ -376,15 +383,17 @@ namespace Vocaluxe.Screens if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0) { - _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex); - _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex); - _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex); - _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex)); + _SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(selectedProfileID); + _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(selectedProfileID); + _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(selectedProfileID); + _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(selectedProfileID); + _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(selectedProfileID)); } } private void _LoadAvatars() { + int selectedAvatarID = _SelectSlides[_SelectSlideAvatars].ValueIndex; _SelectSlides[_SelectSlideAvatars].Clear(); CAvatar[] avatars = CProfiles.GetAvatars(); for (int i = 0; i < avatars.Length; i++) @@ -393,6 +402,7 @@ namespace Vocaluxe.Screens new STexture(-1), avatars[i].ID, -1); + _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(selectedAvatarID); } private void _NewProfile() From 8ab93db26f70ebc7a981709b282783f09ec97d7f Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Tue, 7 May 2013 19:18:46 +0200 Subject: [PATCH 3/9] functional async profile adding --- Vocaluxe/Base/CProfiles.cs | 37 ++++++++++++--- Vocaluxe/Base/Server/CVocaluxeServer.cs | 1 + Vocaluxe/Screens/CScreenProfiles.cs | 60 +++++++++++++++++++------ VocaluxeLib/Profile/CAvatar.cs | 7 ++- 4 files changed, 83 insertions(+), 22 deletions(-) diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index 1965fc95..aed33efc 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -174,10 +174,20 @@ namespace Vocaluxe.Base lock (_ProfileMutex) { List knownFiles = new List(); - foreach (int id in _Profiles.Keys) + if (_Profiles.Count > 0) { - _Profiles[id].LoadProfile(); - knownFiles.Add(_Profiles[id].FileName); + int[] ids = new int[_Profiles.Keys.Count]; + _Profiles.Keys.CopyTo(ids, 0); + for (int i = 0; i < ids.Length; i++) + { + if (_Profiles[ids[i]].LoadProfile()) + { + _Profiles[ids[i]].Avatar = _GetAvatar(_Profiles[ids[i]].AvatarFileName); + knownFiles.Add(_Profiles[ids[i]].FileName); + } + else + _Profiles.Remove(ids[i]); + } } List files = new List(); @@ -211,10 +221,17 @@ namespace Vocaluxe.Base lock (_AvatarMutex) { List knownFiles = new List(); - foreach (int id in _Avatars.Keys) + if (_Avatars.Count > 0) { - _Avatars[id].Reload(); - knownFiles.Add(_Avatars[id].FileName); + int[] ids = new int[_Avatars.Keys.Count]; + _Avatars.Keys.CopyTo(ids, 0); + for (int i = 0; i < ids.Length; i++) + { + if (_Avatars[ids[i]].Reload()) + knownFiles.Add(_Avatars[ids[i]].FileName); + else + _Avatars.Remove(ids[i]); + } } List files = new List(); @@ -241,6 +258,14 @@ namespace Vocaluxe.Base _Notification(); } + public static void SetPlayerName(int profileID, string PlayerName) + { + if (!ICProfileIDValid(profileID)) + return; + + _Profiles[profileID].PlayerName = PlayerName; + } + public static string AddGetPlayerName(int profileID, char chr) { if (!ICProfileIDValid(profileID)) diff --git a/Vocaluxe/Base/Server/CVocaluxeServer.cs b/Vocaluxe/Base/Server/CVocaluxeServer.cs index 479306a8..a20201cf 100644 --- a/Vocaluxe/Base/Server/CVocaluxeServer.cs +++ b/Vocaluxe/Base/Server/CVocaluxeServer.cs @@ -161,6 +161,7 @@ namespace Vocaluxe.Base.Server fs.Flush(); fs.Close(); success = true; + CProfiles.LoadProfiles(); } catch {} diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index 27ce1d2b..8eea3b29 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -62,6 +62,7 @@ namespace Vocaluxe.Screens private const string _StaticAvatar = "StaticAvatar"; private EEditMode _EditMode; + private bool _ProfilesChanged; private STexture _WebcamTexture = new STexture(-1); private Bitmap _Snapshot; @@ -76,6 +77,7 @@ namespace Vocaluxe.Screens _ThemeStatics = new string[] {_StaticAvatar}; _EditMode = EEditMode.None; + CProfiles.AddNotificationCallback(_OnProfilesChanged); } public override void LoadTheme(string xmlPath) @@ -269,7 +271,7 @@ namespace Vocaluxe.Screens i++; _Snapshot.Save(Path.Combine(CSettings.FolderProfiles, filename + i + ".png"), ImageFormat.Png); CProfiles.LoadAvatars(); - _LoadAvatars(); + _LoadAvatars(false); _Snapshot = null; CWebcam.Stop(); CDraw.RemoveTexture(ref _WebcamTexture); @@ -303,6 +305,13 @@ namespace Vocaluxe.Screens public override bool UpdateGame() { + if (_ProfilesChanged) + { + _LoadAvatars(true); + _LoadProfiles(true); + _ProfilesChanged = false; + } + if (_SelectSlides[_SelectSlideProfiles].Selection > -1) { _Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex); @@ -334,8 +343,8 @@ namespace Vocaluxe.Screens base.OnShow(); CProfiles.LoadProfiles(); - _LoadAvatars(); - _LoadProfiles(); + _LoadAvatars(false); + _LoadProfiles(false); UpdateGame(); } @@ -346,19 +355,25 @@ namespace Vocaluxe.Screens _OnDiscardSnapshot(); } + private void _OnProfilesChanged() + { + _ProfilesChanged = true; + } + private void _SaveProfiles() { _EditMode = EEditMode.None; CProfiles.SaveProfiles(); - _LoadProfiles(); + _LoadProfiles(true); UpdateGame(); } private void _DeleteProfile() { + _EditMode = EEditMode.None; int selection = _SelectSlides[_SelectSlideProfiles].Selection; CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex); - _LoadProfiles(); + _LoadProfiles(false); if (_SelectSlides[_SelectSlideProfiles].NumValues > selection) _SelectSlides[_SelectSlideProfiles].Selection = selection; @@ -367,9 +382,12 @@ namespace Vocaluxe.Screens UpdateGame(); } - private void _LoadProfiles() + private void _LoadProfiles(bool Keep) { - _EditMode = EEditMode.None; + string name = String.Empty; + if (_EditMode == EEditMode.PlayerName) + name = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex); + int selectedProfileID = _SelectSlides[_SelectSlideProfiles].ValueIndex; _SelectSlides[_SelectSlideProfiles].Clear(); @@ -384,14 +402,21 @@ namespace Vocaluxe.Screens if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0) { _SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(selectedProfileID); - _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(selectedProfileID); - _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(selectedProfileID); - _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(selectedProfileID); - _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(selectedProfileID)); + + if (!Keep) + { + _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(selectedProfileID); + _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(selectedProfileID); + _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(selectedProfileID); + _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(selectedProfileID)); + } + + if (_EditMode == EEditMode.PlayerName) + CProfiles.SetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex, name); } } - private void _LoadAvatars() + private void _LoadAvatars(bool Keep) { int selectedAvatarID = _SelectSlides[_SelectSlideAvatars].ValueIndex; _SelectSlides[_SelectSlideAvatars].Clear(); @@ -402,14 +427,21 @@ namespace Vocaluxe.Screens new STexture(-1), avatars[i].ID, -1); - _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(selectedAvatarID); + + if (Keep) + { + _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(selectedAvatarID); + CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, selectedAvatarID); + } + else + _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex)); } private void _NewProfile() { _EditMode = EEditMode.None; int id = CProfiles.NewProfile(); - _LoadProfiles(); + _LoadProfiles(false); _SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(id); CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, diff --git a/VocaluxeLib/Profile/CAvatar.cs b/VocaluxeLib/Profile/CAvatar.cs index 3f7dd941..36567868 100644 --- a/VocaluxeLib/Profile/CAvatar.cs +++ b/VocaluxeLib/Profile/CAvatar.cs @@ -28,10 +28,13 @@ namespace VocaluxeLib.Profile return (Texture.Index != -1); } - public void Reload() + public bool Reload() { - CBase.Drawing.RemoveTexture(ref Texture); + STexture oldTexture = Texture; Texture = CBase.Drawing.AddTexture(FileName); + CBase.Drawing.RemoveTexture(ref oldTexture); + + return Texture.Index != -1; } public void Unload() From e70ce5ad68de961e14486a19113164efe4b56ebd Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Thu, 9 May 2013 22:01:29 +0200 Subject: [PATCH 4/9] rewrite of CProfiles.cs, some optimizations in CScreenProfiles.cs, added IsCapturing() to Webcam/IWebcam.cs --- Vocaluxe/Base/CConfig.cs | 6 +- Vocaluxe/Base/CGame.cs | 2 - Vocaluxe/Base/CGraphics.cs | 1 + Vocaluxe/Base/CProfiles.cs | 680 +++++++++++++++--------- Vocaluxe/Base/CWebcam.cs | 5 + Vocaluxe/Base/Server/CVocaluxeServer.cs | 15 +- Vocaluxe/Lib/Webcam/CAForgeNet.cs | 5 + Vocaluxe/Lib/Webcam/IWebcam.cs | 1 + Vocaluxe/Program.cs | 8 + Vocaluxe/Screens/CScreenProfiles.cs | 192 +++---- VocaluxeLib/Profile/CProfile.cs | 12 +- 11 files changed, 590 insertions(+), 337 deletions(-) diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 9bc011eb..7b6e35e2 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -806,12 +806,14 @@ namespace Vocaluxe.Base /// public static void UsePlayers() { + CProfile[] profiles = CProfiles.GetProfiles(); + for (int j = 0; j < CSettings.MaxNumPlayer; j++) { CGame.Players[j].ProfileID = -1; - if (Players[j] == "") + if (Players[j] == "" || profiles == null) continue; - CProfile[] profiles = CProfiles.GetProfiles(); + for (int i = 0; i < profiles.Length; i++) { if (Path.GetFileName(profiles[i].FileName) == Players[j] && profiles[i].Active == EOffOn.TR_CONFIG_ON) diff --git a/Vocaluxe/Base/CGame.cs b/Vocaluxe/Base/CGame.cs index c6b58e0e..40942314 100644 --- a/Vocaluxe/Base/CGame.cs +++ b/Vocaluxe/Base/CGame.cs @@ -68,8 +68,6 @@ namespace Vocaluxe.Base _SongQueue.Init(); Players = new SPlayer[CSettings.MaxNumPlayer]; ResetPlayer(); - - CConfig.UsePlayers(); } public static EGameMode GameMode diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index b08f6373..5e7001fb 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -322,6 +322,7 @@ namespace Vocaluxe.Base CSound.Update(); CBackgroundMusic.Update(); CController.Update(); + CProfiles.Update(); if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && _CurrentScreen != EScreens.ScreenSing) CSongs.LoadCover(); diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index aed33efc..47efb51d 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -28,21 +28,55 @@ using VocaluxeLib.Profile; namespace Vocaluxe.Base { - + [Flags] + public enum EProfileChangedFlags + { + None = 1, + Avatar = 2, + Profile = 4 + } + + public delegate void ProfileChangedCallback(EProfileChangedFlags TypeChanged); static class CProfiles { + #region enums and structs + enum EAction + { + LoadProfiles, + LoadAvatars, + AddProfile, + EditProfile, + DeleteProfile, + AddAvatar, + EditAvatar + } + + struct SChange + { + public CProfile Profile; + public CAvatar Avatar; + public EAction Action; + public int ProfileID; + } + #endregion enums and structs + + #region private vars private static Dictionary _Profiles; private static Queue _ProfileIDs; - private static Object _ProfileMutex = new Object(); private static Dictionary _Avatars; private static Queue _AvatarIDs; - private static Object _AvatarMutex = new Object(); - public delegate void ProfilesChangedNotification(); - private static List _Callbacks; + private static Queue _Queue = new Queue(); + private static Object _QueueMutex = new Object(); + private static List _ProfileChangedCallbacks = new List(); + private static bool _ProfilesChanged = false; + private static bool _AvatarsChanged = false; + #endregion private vars + + #region properties public static int NumProfiles { get { return _Profiles.Count; } @@ -52,7 +86,9 @@ namespace Vocaluxe.Base { get { return _Avatars.Count; } } + #endregion properties + #region public methods public static void Init() { _Avatars = new Dictionary(); @@ -69,56 +105,293 @@ namespace Vocaluxe.Base _ProfileIDs.Enqueue(i); } - _Callbacks = new List(); - LoadProfiles(); } - public static void AddNotificationCallback(ProfilesChangedNotification Callback) + public static void Update() { - if (Callback == null) + lock (_QueueMutex) + { + while (_Queue.Count > 0) + { + SChange change = _Queue.Dequeue(); + switch (change.Action) + { + case EAction.LoadProfiles: + _LoadProfiles(); + _ProfilesChanged = true; + _AvatarsChanged = true; + break; + + case EAction.LoadAvatars: + _LoadAvatars(); + _AvatarsChanged = true; + break; + + case EAction.AddProfile: + if (change.Profile == null) + break; + + change.Profile.ID = _ProfileIDs.Dequeue(); + _Profiles.Add(change.Profile.ID, change.Profile); + _ProfilesChanged = true; + break; + + case EAction.EditProfile: + if (change.Profile == null) + break; + + if (!ICProfileIDValid(change.Profile.ID)) + return; + + _Profiles[change.Profile.ID] = change.Profile; + _ProfilesChanged = true; + break; + + case EAction.DeleteProfile: + if (!ICProfileIDValid(change.ProfileID)) + break; + + _DeleteProfile(change.ProfileID); + _ProfilesChanged = true; + break; + + case EAction.AddAvatar: + if (change.Avatar == null) + break; + + change.Avatar.ID = _AvatarIDs.Dequeue(); + _Avatars.Add(change.Avatar.ID, change.Avatar); + _AvatarsChanged = true; + break; + + case EAction.EditAvatar: + if (change.Avatar == null) + break; + + if (!ICAvatarIDValid(change.Avatar.ID)) + return; + + _Avatars[change.Avatar.ID] = change.Avatar; + _AvatarsChanged = true; + break; + + default: + break; + } + } + } + + if (_ProfileChangedCallbacks.Count == 0) return; - lock (_Callbacks) + EProfileChangedFlags flags = EProfileChangedFlags.None; + + if (_AvatarsChanged) + flags = EProfileChangedFlags.Avatar; + + if (_ProfilesChanged) + flags |= EProfileChangedFlags.Profile; + + if (flags != EProfileChangedFlags.None) { - _Callbacks.Add(Callback); + int index = 0; + while (index < _ProfileChangedCallbacks.Count) + { + try + { + _ProfileChangedCallbacks[index](flags); + } + catch (Exception) + { + _ProfileChangedCallbacks.RemoveAt(index); + } + index++; + } + } + _AvatarsChanged = false; + _ProfilesChanged = false; + } + + public static void AddProfileChangedCallback(ProfileChangedCallback Notification) + { + _ProfileChangedCallbacks.Add(Notification); + } + + public static void LoadProfiles() + { + SChange change = new SChange(); + change.Action = EAction.LoadProfiles; + + lock (_QueueMutex) + { + _Queue.Enqueue(change); } } + public static void LoadAvatars() + { + SChange change = new SChange(); + change.Action = EAction.LoadAvatars; + + lock (_QueueMutex) + { + _Queue.Enqueue(change); + } + } + + public static void AddProfile(CProfile NewProfile) + { + if (NewProfile == null) + return; + + SChange change = new SChange(); + change.Action = EAction.AddProfile; + change.Profile = NewProfile; + + lock (_QueueMutex) + { + _Queue.Enqueue(change); + } + } + + public static void EditProfile(CProfile EditProfile) + { + if (EditProfile == null) + return; + + SChange change = new SChange(); + change.Action = EAction.EditProfile; + change.Profile = EditProfile; + + lock (_QueueMutex) + { + _Queue.Enqueue(change); + } + } + + public static void DeleteProfile(int profileID) + { + if (!ICProfileIDValid(profileID)) + return; + + SChange change = new SChange(); + change.Action = EAction.DeleteProfile; + change.ProfileID = profileID; + + lock (_QueueMutex) + { + _Queue.Enqueue(change); + } + } + + public static void AddAvatar(CAvatar NewAvatar) + { + if (NewAvatar == null) + return; + + SChange change = new SChange(); + change.Action = EAction.AddAvatar; + change.Avatar = NewAvatar; + + lock (_QueueMutex) + { + _Queue.Enqueue(change); + } + } + + public static void EditAvatar(CAvatar EditAvatar) + { + if (EditAvatar == null) + return; + + SChange change = new SChange(); + change.Action = EAction.EditAvatar; + change.Avatar = EditAvatar; + + lock (_QueueMutex) + { + _Queue.Enqueue(change); + } + } + public static CProfile[] GetProfiles() { List list = new List(); - lock (_ProfileMutex) - { - if (_Profiles.Count == 0) - return null; + if (_Profiles.Count == 0) + return null; - CProfile[] result = new CProfile[_Profiles.Count]; - _Profiles.Values.CopyTo(result, 0); - for (int i = 0; i < result.Length; i++) - { - list.Add(result[i]); - } - list.Sort(_CompareByPlayerName); + CProfile[] result = new CProfile[_Profiles.Count]; + _Profiles.Values.CopyTo(result, 0); + for (int i = 0; i < result.Length; i++) + { + list.Add(result[i]); } + list.Sort(_CompareByPlayerName); return list.ToArray(); } public static CAvatar[] GetAvatars() { CAvatar[] result = null; - lock (_AvatarMutex) - { - if (_Avatars.Count == 0) - return null; + if (_Avatars.Count == 0) + return null; - result = new CAvatar[_Avatars.Count]; - _Avatars.Values.CopyTo(result, 0); - } + result = new CAvatar[_Avatars.Count]; + _Avatars.Values.CopyTo(result, 0); + return result; } + + public static int NewProfile(string fileName = "") + { + CProfile profile = new CProfile + { + FileName = fileName != "" ? Path.Combine(CSettings.FolderProfiles, fileName) : String.Empty + }; + if (File.Exists(profile.FileName)) + return -1; + + profile.ID = _ProfileIDs.Dequeue(); + _Profiles.Add(profile.ID, profile); + _ProfilesChanged = true; + return profile.ID; + } + + public static int NewAvatar(string fileName) + { + CAvatar avatar = new CAvatar(-1); + if (!avatar.LoadFromFile(fileName)) + return -1; + + avatar.ID = _AvatarIDs.Dequeue(); + _Avatars.Add(avatar.ID, avatar); + _AvatarsChanged = true; + return avatar.ID; + } + + public static void SaveProfiles() + { + foreach (int id in _Profiles.Keys) + { + _Profiles[id].SaveProfile(); + } + } + + public static bool ICProfileIDValid(int profileID) + { + return _Profiles.ContainsKey(profileID); + } + + public static bool ICAvatarIDValid(int avatarID) + { + return _Avatars.ContainsKey(avatarID); + } + #endregion public methods + + #region profile properties public static string GetPlayerName(int profileID, int playerNum = 0) { if (ICProfileIDValid(profileID)) @@ -130,134 +403,6 @@ namespace Vocaluxe.Base return playerName; } - public static string GetProfileFileName(int profileID) - { - if (!ICProfileIDValid(profileID)) - return String.Empty; - - return Path.GetFileName(_Profiles[profileID].FileName); - } - - public static int NewProfile(string fileName = "") - { - CProfile profile = new CProfile - { - FileName = fileName != "" ? Path.Combine(CSettings.FolderProfiles, fileName) : String.Empty - }; - - if (File.Exists(profile.FileName)) - return -1; - - lock (_ProfileMutex) - { - profile.ID = _ProfileIDs.Dequeue(); - _Profiles.Add(profile.ID, profile); - } - _Notification(); - return profile.ID; - } - - public static void SaveProfiles() - { - foreach (int id in _Profiles.Keys) - { - _Profiles[id].SaveProfile(); - } - - LoadProfiles(); - } - - public static void LoadProfiles() - { - LoadAvatars(); - - lock (_ProfileMutex) - { - List knownFiles = new List(); - if (_Profiles.Count > 0) - { - int[] ids = new int[_Profiles.Keys.Count]; - _Profiles.Keys.CopyTo(ids, 0); - for (int i = 0; i < ids.Length; i++) - { - if (_Profiles[ids[i]].LoadProfile()) - { - _Profiles[ids[i]].Avatar = _GetAvatar(_Profiles[ids[i]].AvatarFileName); - knownFiles.Add(_Profiles[ids[i]].FileName); - } - else - _Profiles.Remove(ids[i]); - } - } - - List files = new List(); - files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.xml", true, true)); - - foreach (string file in knownFiles) - { - files.Remove(file); - } - - foreach (string file in files) - { - CProfile profile = new CProfile - { - FileName = Path.Combine(CSettings.FolderProfiles, file) - }; - - if (profile.LoadProfile()) - { - profile.Avatar = _GetAvatar(profile.AvatarFileName); - profile.ID = _ProfileIDs.Dequeue(); - _Profiles.Add(profile.ID, profile); - } - } - } - _Notification(); - } - - public static void LoadAvatars() - { - lock (_AvatarMutex) - { - List knownFiles = new List(); - if (_Avatars.Count > 0) - { - int[] ids = new int[_Avatars.Keys.Count]; - _Avatars.Keys.CopyTo(ids, 0); - for (int i = 0; i < ids.Length; i++) - { - if (_Avatars[ids[i]].Reload()) - knownFiles.Add(_Avatars[ids[i]].FileName); - else - _Avatars.Remove(ids[i]); - } - } - - List files = new List(); - files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.png", true, true)); - files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpg", true, true)); - files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpeg", true, true)); - files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.bmp", true, true)); - - foreach (string file in knownFiles) - { - files.Remove(file); - } - - foreach (string file in files) - { - CAvatar avatar = new CAvatar(-1); - if (avatar.LoadFromFile(file)) - { - avatar.ID = _AvatarIDs.Dequeue(); - _Avatars.Add(avatar.ID, avatar); - } - } - } - _Notification(); - } - public static void SetPlayerName(int profileID, string PlayerName) { if (!ICProfileIDValid(profileID)) @@ -266,6 +411,14 @@ namespace Vocaluxe.Base _Profiles[profileID].PlayerName = PlayerName; } + public static string GetProfileFileName(int profileID) + { + if (!ICProfileIDValid(profileID)) + return String.Empty; + + return Path.GetFileName(_Profiles[profileID].FileName); + } + public static string AddGetPlayerName(int profileID, char chr) { if (!ICProfileIDValid(profileID)) @@ -287,16 +440,6 @@ namespace Vocaluxe.Base return profile.PlayerName; } - public static bool ICProfileIDValid(int profileID) - { - return _Profiles.ContainsKey(profileID); - } - - public static bool ICAvatarIDValid(int avatarID) - { - return _Avatars.ContainsKey(avatarID); - } - public static EGameDifficulty GetDifficulty(int profileID) { return ICProfileIDValid(profileID) ? _Profiles[profileID].Difficulty : EGameDifficulty.TR_CONFIG_NORMAL; @@ -315,11 +458,6 @@ namespace Vocaluxe.Base return ICProfileIDValid(profileID) ? _Profiles[profileID].GuestProfile : EOffOn.TR_CONFIG_OFF; } - public static EOffOn GetActive(int profileID) - { - return ICProfileIDValid(profileID) ? _Profiles[profileID].Active : EOffOn.TR_CONFIG_OFF; - } - public static void SetGuestProfile(int profileID, EOffOn option) { if (!ICProfileIDValid(profileID)) @@ -328,10 +466,16 @@ namespace Vocaluxe.Base _Profiles[profileID].GuestProfile = option; } + public static EOffOn GetActive(int profileID) + { + return ICProfileIDValid(profileID) ? _Profiles[profileID].Active : EOffOn.TR_CONFIG_OFF; + } + public static void SetActive(int profileID, EOffOn option) { if (!ICProfileIDValid(profileID)) return; + _Profiles[profileID].Active = option; } @@ -365,7 +509,9 @@ namespace Vocaluxe.Base return _Profiles[profileID].Avatar.ID; } + #endregion profile properties + #region avatar texture public static STexture GetAvatarTexture(int avatarID) { if (!ICAvatarIDValid(avatarID)) @@ -381,68 +527,138 @@ namespace Vocaluxe.Base return _Profiles[profileID].Avatar.Texture; } - - public static void DeleteProfile(int profileID) - { - lock (_ProfileMutex) - { - if (!ICProfileIDValid(profileID)) - return; - - if (_Profiles[profileID].FileName == "") - { - _RemoveProfile(profileID); - return; - } - - try - { - //Check if profile saved in config - for (int i = 0; i < CConfig.Players.Length; i++) - { - if (CConfig.Players[i] == _Profiles[profileID].FileName) - { - CConfig.Players[i] = string.Empty; - CConfig.SaveConfig(); - } - } - File.Delete(_Profiles[profileID].FileName); - _RemoveProfile(profileID); - - //Check if profile is selected in game - for (int i = 0; i < CGame.Players.Length; i++) - { - if (CGame.Players[i].ProfileID > profileID) - CGame.Players[i].ProfileID--; - else if (CGame.Players[i].ProfileID == profileID) - CGame.Players[i].ProfileID = -1; - } - } - catch (Exception) - { - CLog.LogError("Can't delete Profile File " + _Profiles[profileID].FileName + ".xml"); - } - } - } + #endregion avatar texture #region private methods - private static void _Notification() + private static void _LoadProfiles() { - lock (_Callbacks) + _LoadAvatars(); + + List knownFiles = new List(); + if (_Profiles.Count > 0) { - for (int i = 0; i < _Callbacks.Count; i++) + int[] ids = new int[_Profiles.Keys.Count]; + _Profiles.Keys.CopyTo(ids, 0); + for (int i = 0; i < ids.Length; i++) { - try + if (_Profiles[ids[i]].LoadProfile()) { - _Callbacks[i](); + _Profiles[ids[i]].Avatar = _GetAvatar(_Profiles[ids[i]].AvatarFileName); + knownFiles.Add(Path.GetFileName(_Profiles[ids[i]].FileName)); } - catch (Exception) + else + _Profiles.Remove(ids[i]); + } + } + + List files = new List(); + files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.xml", true, true)); + + foreach (string file in files) + { + if (knownFiles.Contains(Path.GetFileName(file))) + continue; + + CProfile profile = new CProfile + { + FileName = Path.Combine(CSettings.FolderProfiles, file) + }; + + if (profile.LoadProfile()) + { + profile.Avatar = _GetAvatar(profile.AvatarFileName); + profile.ID = _ProfileIDs.Dequeue(); + _Profiles.Add(profile.ID, profile); + } + } + _ProfilesChanged = true; + } + + private static void _LoadAvatars() + { + List knownFiles = new List(); + if (_Avatars.Count > 0) + { + int[] ids = new int[_Avatars.Keys.Count]; + _Avatars.Keys.CopyTo(ids, 0); + for (int i = 0; i < ids.Length; i++) + { + if (_Avatars[ids[i]].Reload()) + knownFiles.Add(Path.GetFileName(_Avatars[ids[i]].FileName)); + else + _Avatars.Remove(ids[i]); + } + } + + List files = new List(); + files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.png", true, true)); + files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpg", true, true)); + files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpeg", true, true)); + files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.bmp", true, true)); + + foreach (string file in files) + { + if (knownFiles.Contains(Path.GetFileName(file))) + continue; + + CAvatar avatar = new CAvatar(-1); + if (avatar.LoadFromFile(file)) + { + avatar.ID = _AvatarIDs.Dequeue(); + _Avatars.Add(avatar.ID, avatar); + } + } + _ProfilesChanged = true; + } + + private static void _DeleteProfile(int profileID) + { + if (!ICProfileIDValid(profileID)) + return; + + if (_Profiles[profileID].FileName == "") + { + _RemoveProfile(profileID); + return; + } + + try + { + //Check if profile saved in config + for (int i = 0; i < CConfig.Players.Length; i++) + { + if (CConfig.Players[i] == _Profiles[profileID].FileName) { - _Callbacks.RemoveAt(i); + CConfig.Players[i] = string.Empty; + CConfig.SaveConfig(); } } - + File.Delete(_Profiles[profileID].FileName); + _RemoveProfile(profileID); + + //Check if profile is selected in game + for (int i = 0; i < CGame.Players.Length; i++) + { + if (CGame.Players[i].ProfileID > profileID) + CGame.Players[i].ProfileID--; + else if (CGame.Players[i].ProfileID == profileID) + CGame.Players[i].ProfileID = -1; + } } + catch (Exception) + { + CLog.LogError("Can't delete Profile File " + _Profiles[profileID].FileName + ".xml"); + } + _ProfilesChanged = true; + } + + private static void _RemoveProfile(int profileID) + { + if (!ICProfileIDValid(profileID)) + return; + + _Profiles.Remove(profileID); + _ProfilesChanged = true; } private static int _CompareByPlayerName(CProfile a, CProfile b) @@ -452,25 +668,13 @@ namespace Vocaluxe.Base private static CAvatar _GetAvatar(string fileName) { - lock (_AvatarMutex) + foreach (int id in _Avatars.Keys) { - foreach (int id in _Avatars.Keys) - { - if (Path.GetFileName(_Avatars[id].FileName) == fileName) - return _Avatars[id]; - } + if (Path.GetFileName(_Avatars[id].FileName) == fileName) + return _Avatars[id]; } return new CAvatar(-1); } - - private static void _RemoveProfile(int profileID) - { - if (!ICProfileIDValid(profileID)) - return; - - _Profiles.Remove(profileID); - _Notification(); - } #endregion private methods } } \ No newline at end of file diff --git a/Vocaluxe/Base/CWebcam.cs b/Vocaluxe/Base/CWebcam.cs index bfe48e78..c30787f1 100644 --- a/Vocaluxe/Base/CWebcam.cs +++ b/Vocaluxe/Base/CWebcam.cs @@ -91,5 +91,10 @@ namespace Vocaluxe.Base { return _Webcam.IsDeviceAvailable(); } + + public static bool IsCapturing() + { + return _Webcam.IsCapturing(); + } } } \ No newline at end of file diff --git a/Vocaluxe/Base/Server/CVocaluxeServer.cs b/Vocaluxe/Base/Server/CVocaluxeServer.cs index a20201cf..b9bc7b99 100644 --- a/Vocaluxe/Base/Server/CVocaluxeServer.cs +++ b/Vocaluxe/Base/Server/CVocaluxeServer.cs @@ -12,6 +12,7 @@ using ClientServerLib; using Vocaluxe.Base; using Vocaluxe.Lib.Input; using VocaluxeLib; +using VocaluxeLib.Profile; namespace Vocaluxe.Base.Server { @@ -156,12 +157,20 @@ namespace Vocaluxe.Base.Server while (File.Exists(filename + i + ".jpg")) i++; - FileStream fs = File.Create(filename + i + ".jpg"); + filename = filename + i + ".jpg"; + FileStream fs = File.Create(filename); fs.Write(avatarPictureJpg.data, 0, avatarPictureJpg.data.Length); fs.Flush(); fs.Close(); - success = true; - CProfiles.LoadProfiles(); + + CAvatar avatar = new CAvatar(-1); + success = avatar.LoadFromFile(filename); + + if (success) + { + CProfiles.AddAvatar(avatar); + } + } catch {} diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index 614a90c7..78d54321 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -164,6 +164,11 @@ namespace Vocaluxe.Lib.Webcam return _Devices.Count > 0; } + public bool IsCapturing() + { + return _Webcam.IsRunning; + } + public bool Select(SWebcamConfig config) { //Close old camera connection diff --git a/Vocaluxe/Lib/Webcam/IWebcam.cs b/Vocaluxe/Lib/Webcam/IWebcam.cs index 75eb3fe4..75f33716 100644 --- a/Vocaluxe/Lib/Webcam/IWebcam.cs +++ b/Vocaluxe/Lib/Webcam/IWebcam.cs @@ -59,6 +59,7 @@ namespace Vocaluxe.Lib.Webcam SWebcamConfig GetConfig(); SWebcamDevice[] GetDevices(); bool IsDeviceAvailable(); + bool IsCapturing(); bool Select(SWebcamConfig webcamConfig); } diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index ea384764..d00b8d67 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -197,15 +197,23 @@ namespace Vocaluxe CController.Connect(); CLog.StopBenchmark(0, "Init Input"); + Application.DoEvents(); + // Init Game; CLog.StartBenchmark(0, "Init Game"); CGame.Init(); + CProfiles.Update(); + CConfig.UsePlayers(); CLog.StopBenchmark(0, "Init Game"); + Application.DoEvents(); + // Init Party Modes; CLog.StartBenchmark(0, "Init Party Modes"); CParty.Init(); CLog.StopBenchmark(0, "Init Party Modes"); + + Application.DoEvents(); } catch (Exception e) { diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index 8eea3b29..26b43d12 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -60,9 +60,10 @@ namespace Vocaluxe.Screens private const string _ButtonTakeSnapshot = "ButtonTakeSnapshot"; private const string _StaticAvatar = "StaticAvatar"; + private bool _ProfilesChanged; + private bool _AvatarsChanged; private EEditMode _EditMode; - private bool _ProfilesChanged; private STexture _WebcamTexture = new STexture(-1); private Bitmap _Snapshot; @@ -77,7 +78,9 @@ namespace Vocaluxe.Screens _ThemeStatics = new string[] {_StaticAvatar}; _EditMode = EEditMode.None; - CProfiles.AddNotificationCallback(_OnProfilesChanged); + _ProfilesChanged = false; + _AvatarsChanged = false; + CProfiles.AddProfileChangedCallback(new ProfileChangedCallback(_OnProfileChanged)); } public override void LoadTheme(string xmlPath) @@ -108,6 +111,7 @@ namespace Vocaluxe.Screens case EEditMode.PlayerName: _SelectSlides[_SelectSlideProfiles].RenameValue( CProfiles.AddGetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex, keyEvent.Unicode)); + _ProfilesChanged = true; break; } } @@ -116,7 +120,10 @@ namespace Vocaluxe.Screens switch (keyEvent.Key) { case Keys.Escape: - CGraphics.FadeTo(EScreens.ScreenMain); + if (_EditMode == EEditMode.PlayerName) + _EditMode = EEditMode.None; + else + CGraphics.FadeTo(EScreens.ScreenMain); break; case Keys.Enter: @@ -150,6 +157,7 @@ namespace Vocaluxe.Screens { _SelectSlides[_SelectSlideProfiles].RenameValue( CProfiles.GetDeleteCharInPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex)); + _ProfilesChanged = true; } else CGraphics.FadeTo(EScreens.ScreenMain); @@ -243,6 +251,64 @@ namespace Vocaluxe.Screens return true; } + public override bool UpdateGame() + { + if (_AvatarsChanged) + _LoadAvatars(true); + + if (_ProfilesChanged) + _LoadProfiles(true); + + if (_SelectSlides[_SelectSlideProfiles].Selection > -1) + { + _Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex); + if (_EditMode == EEditMode.PlayerName) + _Buttons[_ButtonPlayerName].Text.Text += "|"; + + _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex); + _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex); + _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex); + + int avatarID = CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex); + _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(avatarID); + if (CWebcam.IsDeviceAvailable() && CWebcam.IsCapturing()) + { + if (_Snapshot == null) + CWebcam.GetFrame(ref _WebcamTexture); + + _Statics[_StaticAvatar].Texture = _WebcamTexture; + } + else + _Statics[_StaticAvatar].Texture = CProfiles.GetAvatarTexture(avatarID); + } + + return true; + } + + public override void OnShow() + { + base.OnShow(); + _LoadAvatars(false); + _LoadProfiles(false); + UpdateGame(); + } + + public override void OnClose() + { + base.OnClose(); + _EditMode = EEditMode.None; + _OnDiscardSnapshot(); + } + + private void _OnProfileChanged(EProfileChangedFlags Flags) + { + if (EProfileChangedFlags.Avatar == (EProfileChangedFlags.Avatar & Flags)) + _AvatarsChanged = true; + + if (EProfileChangedFlags.Profile == (EProfileChangedFlags.Profile & Flags)) + _ProfilesChanged = true; + } + private void _OnTakeSnapshot() { _Buttons[_ButtonSaveSnapshot].Visible = true; @@ -265,31 +331,26 @@ namespace Vocaluxe.Screens private void _OnSaveSnapshot() { - const string filename = "snapshot"; + string filename = Path.Combine(CSettings.FolderProfiles, "snapshot"); int i = 0; - while (File.Exists(Path.Combine(CSettings.FolderProfiles, filename + i + ".png"))) + while (File.Exists(filename + i + ".png")) i++; - _Snapshot.Save(Path.Combine(CSettings.FolderProfiles, filename + i + ".png"), ImageFormat.Png); - CProfiles.LoadAvatars(); - _LoadAvatars(false); + + filename = filename + i + ".png"; + _Snapshot.Save(filename, ImageFormat.Png); + _Snapshot = null; CWebcam.Stop(); CDraw.RemoveTexture(ref _WebcamTexture); - CAvatar[] avatars = CProfiles.GetAvatars(); - for (int j = 0; j < avatars.Length; j++) - { - if (Path.GetFileName(avatars[j].FileName) == (filename + i + ".png")) - { - CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, avatars[j].ID); - break; - } - } - _Buttons[_ButtonSaveSnapshot].Visible = false; _Buttons[_ButtonDiscardSnapshot].Visible = false; _Buttons[_ButtonTakeSnapshot].Visible = false; _Buttons[_ButtonWebcam].Visible = true; + + int id = CProfiles.NewAvatar(filename); + CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, id); + _LoadAvatars(false); } private void _OnWebcam() @@ -303,83 +364,37 @@ namespace Vocaluxe.Screens _Buttons[_ButtonWebcam].Visible = false; } - public override bool UpdateGame() + private void _NewProfile() { - if (_ProfilesChanged) - { - _LoadAvatars(true); - _LoadProfiles(true); - _ProfilesChanged = false; - } - - if (_SelectSlides[_SelectSlideProfiles].Selection > -1) - { - _Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex); - if (_EditMode == EEditMode.PlayerName) - _Buttons[_ButtonPlayerName].Text.Text += "|"; - - _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex); - _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex); - _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex); - - int avatarID = CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex); - _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(avatarID); - if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index != -1) - { - if (_Snapshot == null) - CWebcam.GetFrame(ref _WebcamTexture); - - _Statics[_StaticAvatar].Texture = _WebcamTexture; - } - else - _Statics[_StaticAvatar].Texture = CProfiles.GetAvatarTexture(avatarID); - } - - return true; - } - - public override void OnShow() - { - base.OnShow(); - - CProfiles.LoadProfiles(); - _LoadAvatars(false); + _EditMode = EEditMode.None; + int id = CProfiles.NewProfile(); _LoadProfiles(false); - UpdateGame(); - } + _SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(id); - public override void OnClose() - { - base.OnClose(); + CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, + _SelectSlides[_SelectSlideAvatars].ValueIndex); - _OnDiscardSnapshot(); - } - - private void _OnProfilesChanged() - { - _ProfilesChanged = true; + _SetInteractionToButton(_Buttons[_ButtonPlayerName]); + _EditMode = EEditMode.PlayerName; } private void _SaveProfiles() { _EditMode = EEditMode.None; CProfiles.SaveProfiles(); - _LoadProfiles(true); - UpdateGame(); } private void _DeleteProfile() { _EditMode = EEditMode.None; - int selection = _SelectSlides[_SelectSlideProfiles].Selection; + CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex); - _LoadProfiles(false); - if (_SelectSlides[_SelectSlideProfiles].NumValues > selection) - _SelectSlides[_SelectSlideProfiles].Selection = selection; + int selection = _SelectSlides[_SelectSlideProfiles].Selection; + if (_SelectSlides[_SelectSlideProfiles].NumValues - 1 > selection) + _SelectSlides[_SelectSlideProfiles].Selection = selection + 1; else _SelectSlides[_SelectSlideProfiles].Selection = selection - 1; - UpdateGame(); } private void _LoadProfiles(bool Keep) @@ -401,7 +416,13 @@ namespace Vocaluxe.Screens if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0) { - _SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(selectedProfileID); + if (selectedProfileID != -1) + _SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(selectedProfileID); + else + { + _SelectSlides[_SelectSlideProfiles].Selection = 0; + selectedProfileID = _SelectSlides[_SelectSlideProfiles].ValueIndex; + } if (!Keep) { @@ -414,6 +435,7 @@ namespace Vocaluxe.Screens if (_EditMode == EEditMode.PlayerName) CProfiles.SetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex, name); } + _ProfilesChanged = false; } private void _LoadAvatars(bool Keep) @@ -435,20 +457,8 @@ namespace Vocaluxe.Screens } else _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex)); - } - private void _NewProfile() - { - _EditMode = EEditMode.None; - int id = CProfiles.NewProfile(); - _LoadProfiles(false); - _SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(id); - - CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, - _SelectSlides[_SelectSlideAvatars].ValueIndex); - - _SetInteractionToButton(_Buttons[_ButtonPlayerName]); - _EditMode = EEditMode.PlayerName; - } + _AvatarsChanged = false; + } } } \ No newline at end of file diff --git a/VocaluxeLib/Profile/CProfile.cs b/VocaluxeLib/Profile/CProfile.cs index f4ed3efd..c4b9b0ac 100644 --- a/VocaluxeLib/Profile/CProfile.cs +++ b/VocaluxeLib/Profile/CProfile.cs @@ -23,7 +23,17 @@ namespace VocaluxeLib.Profile public string AvatarFileName; public EGameDifficulty Difficulty; - public CAvatar Avatar; + + private CAvatar _Avatar; + public CAvatar Avatar + { + get { return _Avatar; } + set + { + _Avatar = value; + AvatarFileName = _Avatar.FileName; + } + } public EOffOn GuestProfile; public EOffOn Active; From 1a68c26e9fac5974f9a16019a94491d5f845edc8 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Thu, 9 May 2013 23:14:04 +0200 Subject: [PATCH 5/9] added SendProfile --- .../ClientServerLib/Vocaluxe/CCommands.cs | 35 ++++++-- .../Vocaluxe/VocaluxeStructs.cs | 7 ++ .../ClientTest/ClientTest.Designer.cs | 14 +++ ClientServerLib/ClientTest/ClientTest.cs | 40 ++++++++- Output/ClientServerLib.dll | Bin 40448 -> 40960 bytes Vocaluxe/Base/CProfiles.cs | 6 +- Vocaluxe/Base/Server/CVocaluxeServer.cs | 84 ++++++++++++------ Vocaluxe/Screens/CScreenNames.cs | 64 +++++++++---- 8 files changed, 199 insertions(+), 51 deletions(-) diff --git a/ClientServerLib/ClientServerLib/Vocaluxe/CCommands.cs b/ClientServerLib/ClientServerLib/Vocaluxe/CCommands.cs index 4da37608..ff9f518b 100644 --- a/ClientServerLib/ClientServerLib/Vocaluxe/CCommands.cs +++ b/ClientServerLib/ClientServerLib/Vocaluxe/CCommands.cs @@ -41,6 +41,9 @@ namespace Vocaluxe.Base.Server public const int CommandSendAvatarPicture = 500; public const int CommandSendAvatarPictureJpg = 501; + + public const int CommandSendProfile = 510; + #endregion Commands #region General @@ -69,7 +72,7 @@ namespace Vocaluxe.Base.Server #endregion Keyboard - #region Avatar + #region Profiles public static byte[] CreateCommandSendAvatarPicture(int Width, int Height, byte[] data) { SAvatarPicture ap = new SAvatarPicture(); @@ -86,17 +89,39 @@ namespace Vocaluxe.Base.Server return TryDeserialize(Message, out AvatarPicture); } - public static byte[] CreateCommandSendAvatarPictureJpg(byte[] data) + public static byte[] CreateCommandSendAvatarPictureJpg(byte[] AvatarJpgData) { SAvatarPicture ap = new SAvatarPicture(); ap.Height = 0; ap.Width = 0; - ap.data = new byte[data.Length]; - Array.Copy(data, ap.data, data.Length); + ap.data = new byte[AvatarJpgData.Length]; + Array.Copy(AvatarJpgData, ap.data, AvatarJpgData.Length); return Serialize(CommandSendAvatarPictureJpg, ap); } - #endregion Avatar + + public static byte[] CreateCommandSendProfile(byte[] AvatarJpgData, string PlayerName, int Difficulty) + { + SAvatarPicture ap = new SAvatarPicture(); + ap.Height = 0; + ap.Width = 0; + ap.data = new byte[AvatarJpgData.Length]; + Array.Copy(AvatarJpgData, ap.data, AvatarJpgData.Length); + + SProfile profile = new SProfile(); + profile.Avatar = ap; + profile.PlayerName = PlayerName; + profile.Difficulty = Difficulty; + + return Serialize(CommandSendProfile, profile); + } + + public static bool DecodeCommandSendProfile(byte[] Message, out SProfile Profile) + { + return TryDeserialize(Message, out Profile); + } + + #endregion Profiles #region Serializing private static byte[] Serialize(int Command, T obj) diff --git a/ClientServerLib/ClientServerLib/Vocaluxe/VocaluxeStructs.cs b/ClientServerLib/ClientServerLib/Vocaluxe/VocaluxeStructs.cs index 8242b9d2..99b917d2 100644 --- a/ClientServerLib/ClientServerLib/Vocaluxe/VocaluxeStructs.cs +++ b/ClientServerLib/ClientServerLib/Vocaluxe/VocaluxeStructs.cs @@ -13,4 +13,11 @@ namespace Vocaluxe.Base.Server public int Height; public byte[] data; } + + public struct SProfile + { + public SAvatarPicture Avatar; + public string PlayerName; + public int Difficulty; + } } \ No newline at end of file diff --git a/ClientServerLib/ClientTest/ClientTest.Designer.cs b/ClientServerLib/ClientTest/ClientTest.Designer.cs index 2d0584c9..65d2f867 100644 --- a/ClientServerLib/ClientTest/ClientTest.Designer.cs +++ b/ClientServerLib/ClientTest/ClientTest.Designer.cs @@ -48,6 +48,7 @@ this.btUp = new System.Windows.Forms.Button(); this.btDown = new System.Windows.Forms.Button(); this.btSendAvatar = new System.Windows.Forms.Button(); + this.btSendProfile = new System.Windows.Forms.Button(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -239,11 +240,23 @@ this.btSendAvatar.UseVisualStyleBackColor = true; this.btSendAvatar.Click += new System.EventHandler(this.btSendAvatar_Click); // + // btSendProfile + // + this.btSendProfile.Enabled = false; + this.btSendProfile.Location = new System.Drawing.Point(831, 339); + this.btSendProfile.Name = "btSendProfile"; + this.btSendProfile.Size = new System.Drawing.Size(165, 23); + this.btSendProfile.TabIndex = 15; + this.btSendProfile.Text = "Send Profile"; + this.btSendProfile.UseVisualStyleBackColor = true; + this.btSendProfile.Click += new System.EventHandler(this.btSendProfile_Click); + // // ClientTest // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1008, 550); + this.Controls.Add(this.btSendProfile); this.Controls.Add(this.btSendAvatar); this.Controls.Add(this.btDown); this.Controls.Add(this.btUp); @@ -293,6 +306,7 @@ private System.Windows.Forms.Button btUp; private System.Windows.Forms.Button btDown; private System.Windows.Forms.Button btSendAvatar; + private System.Windows.Forms.Button btSendProfile; } } diff --git a/ClientServerLib/ClientTest/ClientTest.cs b/ClientServerLib/ClientTest/ClientTest.cs index 2a33884c..f8c4a60d 100644 --- a/ClientServerLib/ClientTest/ClientTest.cs +++ b/ClientServerLib/ClientTest/ClientTest.cs @@ -3,8 +3,11 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.Drawing.Imaging; using System.Linq; using System.Net; +using System.IO; +using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; @@ -119,6 +122,7 @@ namespace ClientTest btLeft.Enabled = true; btRight.Enabled = true; btSendAvatar.Enabled = true; + btSendProfile.Enabled = true; }); } else @@ -136,6 +140,7 @@ namespace ClientTest btLeft.Enabled = false; btRight.Enabled = false; btSendAvatar.Enabled = false; + btSendProfile.Enabled = false; }); } } @@ -222,7 +227,40 @@ namespace ClientTest { data[i] = (byte) (i % 255); } - client.SendMessage(CCommands.CreateCommandSendAvatarPicture(512, 512, data), null); + client.SendMessage(CCommands.CreateCommandSendAvatarPicture(512, 512, data), OnResponse); + } + + private void btSendProfile_Click(object sender, EventArgs e) + { + if (!client.Connected || !loggedIn) + return; + + if (!File.Exists("test.jpg")) + { + byte[] data = new byte[512 * 512 * 4]; + for (int i = 0; i < data.Length; i++) + { + data[i] = (byte)(i % 255); + } + + Bitmap bmp = new Bitmap(512, 512); + BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); + Marshal.Copy(data, 0, bmpData.Scan0, data.Length); + bmp.UnlockBits(bmpData); + + bmp.Save("test.jpg", ImageFormat.Jpeg); + bmp.Dispose(); + } + + if (File.Exists("test.jpg")) + { + byte[] data = File.ReadAllBytes("test.jpg"); + + if (data == null) + return; + + client.SendMessage(CCommands.CreateCommandSendProfile(data, "TestUser", 0), OnResponse); + } } } } diff --git a/Output/ClientServerLib.dll b/Output/ClientServerLib.dll index a3caa6116c3a859b05b818b3e3ae0aaf2d0d726f..6931132f5b8400fa0372ce81c076a7c3da7e4ed8 100644 GIT binary patch delta 18529 zcmb_^37k~bv3K32@4dav^zEMMo?-SG1{#{#S%w{CM`RJu8AOLw9YjVLB*J89h!Hdj ziq}Cj%BRLGCgd3(#xLeGpO~0U6JrvSn7nA*l4ueQd0!UwCHVeT=XNs?Fy?#dpHuf# z)j4(Q)TvXa&bb$NJ*MwErr&aX?SF=ET0;KsCDLocTA1h%2$mu)eB{7qFDUry7l{@z z;TTc7aiAsydMdgBJ@*H|)63H1J=ZAFI=zub72td$9k~eH zFj;oh(4J0jr?GK*8xyS5omE47xfs#=bhNFi+^OM_W?@mXN^6$^ihovL}q`QHh zE4_?4u|NnG2$l%mYJRulGivtfCk7NbfUIp(tHS z6be}l(1P)vUa!V#(i*%a*2H8j>r(-~-ct$KQw7jJ$-B>*Q#}Q&IO+Y97NP|^uDQH&|cSN(iQ*Wy)2#k!tdeH*PnW0Je-572CtzDU4Z~z28FEIVzeKZ6QKCwA8kckKP7J+V=K3bB8mb7i~hj*jy;E;A*sm ztGP5p>=N2p=l$8KT#fz)kwj94)wh!A20X(VvPW|B5;QLmwbBr1ZMz}_*}E2nE&C!- zzp=NGJFMdlEA@07$jF0wQU5S+Rk)~X7|436A3B;O`k3?=2!vhTT%D<0#|Y_3sg+5? z8>CeqH!_MhbzOPbsH$EY)AV{Fr8<;2Be|gwo-*9~uVAe<%&QEw+kQLm;?VFkw@#kW z@L$+&uutlcfH^-26|6xj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UHgJ`3wu)C#`qT>4$(bU2g4g=K`(-eVfMHQlW^uSYS}+ z(@+ zxU1~N#H<(7cipx2Hth%Q1%S_iMIpW5ZU(zo@$cda>DTUT?E>u&?mpBFY~2xnwSa#S z)*rf$*_(y+X5uZ2C$7Sc5sxY(x8O;83=J#z8OBx>{KDRx5_vaMs^9~A1hp1?h=!Y8 z(`m}BDdO;&j(F!>vNLlXE)HVUum7j+&`$jgT(<7g-v+!|;PrqG-3NLDe(dOS8t7Ww zyERa$Jl6_>=LW5yFLY(kwGm=6JKsTx@olYt0Sj zHuFkzuesm6)x6vMp834_s`;k*u4x5I1J!|+z@os4z`DRifvW;{2fh)TRM` z!C8YGaldmeU{z?1&V3B@>BYqiwkw>Ib-vc2T}Gk(4g1^nkL(>N;Z7xU2WO4JAJoI% zg%_)(?@N0YXloDs&z{$`L(gB+X5|0Rvc;R`AMQVW z?~9v` zguelzGnTY3iC!_|{kO0F*{OFvki6^I*I#_!yX)o^1zQgD($r@!KUeOnO6WTd9~ybf XE!v^jtsfZrUE>eA2Y;{aYqb9tj@}w- diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index 47efb51d..e5e7d964 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -133,7 +133,9 @@ namespace Vocaluxe.Base break; change.Profile.ID = _ProfileIDs.Dequeue(); + change.Profile.Avatar = _GetAvatar(change.Profile.AvatarFileName); _Profiles.Add(change.Profile.ID, change.Profile); + _ProfilesChanged = true; break; @@ -668,9 +670,11 @@ namespace Vocaluxe.Base private static CAvatar _GetAvatar(string fileName) { + string Name = Path.GetFileName(fileName); + foreach (int id in _Avatars.Keys) { - if (Path.GetFileName(_Avatars[id].FileName) == fileName) + if (Path.GetFileName(_Avatars[id].FileName) == Name) return _Avatars[id]; } return new CAvatar(-1); diff --git a/Vocaluxe/Base/Server/CVocaluxeServer.cs b/Vocaluxe/Base/Server/CVocaluxeServer.cs index b9bc7b99..3268d72a 100644 --- a/Vocaluxe/Base/Server/CVocaluxeServer.cs +++ b/Vocaluxe/Base/Server/CVocaluxeServer.cs @@ -149,41 +149,73 @@ namespace Vocaluxe.Base.Server SAvatarPicture avatarPictureJpg; if (CCommands.DecodeCommandSendAvatarPicture(Message, out avatarPictureJpg)) { - bool success = false; - try - { - string filename = Path.Combine(CSettings.FolderProfiles, "snapshot"); - int i = 0; - while (File.Exists(filename + i + ".jpg")) - i++; - - filename = filename + i + ".jpg"; - FileStream fs = File.Create(filename); - fs.Write(avatarPictureJpg.data, 0, avatarPictureJpg.data.Length); - fs.Flush(); - fs.Close(); - - CAvatar avatar = new CAvatar(-1); - success = avatar.LoadFromFile(filename); - - if (success) - { - CProfiles.AddAvatar(avatar); - } - - } - catch {} - - if (success) + if (_AddAvatar(avatarPictureJpg.data) != String.Empty) answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK); } break; + case CCommands.CommandSendProfile: + SProfile profile; + if (CCommands.DecodeCommandSendProfile(Message, out profile)) + { + try + { + string AvatarFilename = _AddAvatar(profile.Avatar.data); + if (AvatarFilename != String.Empty) + { + CProfile p = new CProfile(); + p.Active = EOffOn.TR_CONFIG_ON; + p.AvatarFileName = AvatarFilename; + p.Difficulty = (EGameDifficulty)profile.Difficulty; + p.GuestProfile = EOffOn.TR_CONFIG_OFF; + p.PlayerName = profile.PlayerName; + p.SaveProfile(); + CProfiles.AddProfile(p); + answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK); + } + } + catch (Exception) + { + + } + } + + break; + default: break; } return answer; } + + private static string _AddAvatar(byte[] JpgData) + { + string result = String.Empty; + try + { + string filename = Path.Combine(CSettings.FolderProfiles, "snapshot"); + int i = 0; + while (File.Exists(filename + i + ".jpg")) + i++; + + filename = filename + i + ".jpg"; + FileStream fs = File.Create(filename); + fs.Write(JpgData, 0, JpgData.Length); + fs.Flush(); + fs.Close(); + + CAvatar avatar = new CAvatar(-1); + if (avatar.LoadFromFile(filename)) + { + CProfiles.AddAvatar(avatar); + result = filename; + } + + } + catch { } + + return result; + } } } diff --git a/Vocaluxe/Screens/CScreenNames.cs b/Vocaluxe/Screens/CScreenNames.cs index 8db82dcf..dba74e56 100644 --- a/Vocaluxe/Screens/CScreenNames.cs +++ b/Vocaluxe/Screens/CScreenNames.cs @@ -62,7 +62,10 @@ namespace Vocaluxe.Screens private int _SelectingSwitchNr = -1; private int _SelectingFastPlayerNr = 0; private int _SelectedPlayerNr = -1; + private bool _AvatarsChanged = false; + private bool _ProfilesChanged = false; + #region public methods public override void Init() { base.Init(); @@ -100,6 +103,8 @@ namespace Vocaluxe.Screens _ChooseAvatarStatic = GetNewStatic(); _ChooseAvatarStatic.Visible = false; + + CProfiles.AddProfileChangedCallback(new ProfileChangedCallback(_OnProfileChanged)); } public override void LoadTheme(string xmlPath) @@ -619,6 +624,9 @@ namespace Vocaluxe.Screens public override bool UpdateGame() { + if (_ProfilesChanged || _AvatarsChanged) + _LoadProfiles(); + for (int i = 1; i <= CGame.NumPlayer; i++) { CSound.AnalyzeBuffer(i - 1); @@ -633,6 +641,41 @@ namespace Vocaluxe.Screens CSound.RecordStart(); _NameSelections[_NameSelection].Init(); + _LoadProfiles(); + _SetInteractionToButton(_Buttons[_ButtonStart]); + } + + public override void OnClose() + { + base.OnClose(); + CSound.RecordStop(); + } + + public override bool Draw() + { + base.Draw(); + + if (_ChooseAvatarStatic.Visible) + _ChooseAvatarStatic.Draw(); + for (int i = 1; i <= CGame.NumPlayer; i++) + _Equalizers["EqualizerPlayer" + i].Draw(); + return true; + } + #endregion public methods + + #region private methods + private void _OnProfileChanged(EProfileChangedFlags Flags) + { + if (EProfileChangedFlags.Avatar == (EProfileChangedFlags.Avatar & Flags)) + _AvatarsChanged = true; + + if (EProfileChangedFlags.Profile == (EProfileChangedFlags.Profile & Flags)) + _ProfilesChanged = true; + } + + private void _LoadProfiles() + { + _NameSelections[_NameSelection].UpdateList(); _UpdateSlides(); _UpdatePlayerNumber(); @@ -657,24 +700,8 @@ namespace Vocaluxe.Screens _SelectSlides[_SelectSlideDuetPlayer[i]].Visible = false; } - _SetInteractionToButton(_Buttons[_ButtonStart]); - } - - public override void OnClose() - { - base.OnClose(); - CSound.RecordStop(); - } - - public override bool Draw() - { - base.Draw(); - - if (_ChooseAvatarStatic.Visible) - _ChooseAvatarStatic.Draw(); - for (int i = 1; i <= CGame.NumPlayer; i++) - _Equalizers["EqualizerPlayer" + i].Draw(); - return true; + _ProfilesChanged = false; + _AvatarsChanged = false; } private void _StartSong() @@ -818,5 +845,6 @@ namespace Vocaluxe.Screens _Texts[_TextWarningProfiles].Visible = false; } } + #endregion private methods } } \ No newline at end of file From 2f1795d9a300978072821c0ef2bda8ea3872ee71 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Thu, 9 May 2013 23:58:48 +0200 Subject: [PATCH 6/9] added SendProfile to the android test app, fixed some bugs --- ClientServerLib/AndroidRemote/MainActivity.cs | 68 +++++++++++++------ .../Resources/Resource.designer.cs | 66 ++++++++++-------- .../AndroidRemote/Resources/layout/Main.axml | 33 +++++---- .../Resources/values/Strings.xml | 8 ++- Vocaluxe/Base/CProfiles.cs | 1 + Vocaluxe/Base/Server/CVocaluxeServer.cs | 3 +- 6 files changed, 109 insertions(+), 70 deletions(-) diff --git a/ClientServerLib/AndroidRemote/MainActivity.cs b/ClientServerLib/AndroidRemote/MainActivity.cs index ff59e44b..73a17639 100644 --- a/ClientServerLib/AndroidRemote/MainActivity.cs +++ b/ClientServerLib/AndroidRemote/MainActivity.cs @@ -16,15 +16,14 @@ using Vocaluxe.Base.Server; namespace AndroidRemote { - [Activity (Label = "Vocaluxe Remote", MainLauncher = true)] + [Activity (Label = "Vocaluxe Remote", MainLauncher = true, ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation)] public class Activity1 : Activity { CClient client = new CClient(); Button bConnect; Button bLogin; - Button bUp; - Button bDown; Button bSendAvatar; + Button bSendProfile; bool loggedIn; byte[] fileBytes; @@ -32,6 +31,8 @@ namespace AndroidRemote Java.IO.File file; Java.IO.File dir; System.IO.FileStream fs; + + bool sendProfile; protected override void OnCreate (Bundle bundle) { @@ -47,21 +48,14 @@ namespace AndroidRemote bLogin = FindViewById