From e3497641dd449dd0b5b11122849efb1811ed0eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Wed, 23 Dec 2015 14:23:55 +0100 Subject: [PATCH 01/21] Use GUID instead of int for player-ids; ID is now unique and saved to player.xml-file --- Output/Profiles/guest1.xml | 1 + Output/Profiles/guest2.xml | 1 + Output/Profiles/guest3.xml | 1 + .../PartyModeChallenge/CPartyModeChallenge.cs | 10 +-- .../CPartyScreenChallengeMain.cs | 2 +- .../CPartyScreenChallengeNames.cs | 3 +- .../CPartyModeChallengeMedley.cs | 23 ++---- .../CPartyScreenChallengeMedleyMain.cs | 2 +- .../CPartyScreenChallengeMedleyNames.cs | 3 +- .../PartyModeTicTacToe/CPartyModeTicTacToe.cs | 10 +-- .../CPartyScreenTicTacToeNames.cs | 3 +- Vocaluxe/Base/CConfig.cs | 2 +- Vocaluxe/Base/CMain.cs | 15 ++-- Vocaluxe/Base/CProfiles.cs | 80 +++++++++---------- Vocaluxe/Base/Server/CVocaluxeServer.cs | 16 ++-- Vocaluxe/Base/Server/CWebservice.cs | 20 ++--- Vocaluxe/Base/Server/ICWebservice.cs | 8 +- Vocaluxe/Base/Server/Session.cs | 6 +- Vocaluxe/Base/Server/SessionControl.cs | 16 ++-- Vocaluxe/Base/Server/VocaluxeStructs.cs | 2 +- Vocaluxe/Screens/CScreenNames.cs | 44 +++++----- Vocaluxe/Screens/CScreenProfiles.cs | 77 +++++++++++------- VocaluxeLib/IBasic.cs | 11 +-- VocaluxeLib/Menu/CMenuPartyNameSelection.cs | 67 +++++++++------- VocaluxeLib/Menu/CNameSelection.cs | 67 ++++++++-------- VocaluxeLib/Profile/CProfile.cs | 12 ++- VocaluxeLib/Structs.cs | 2 +- VocaluxeLib/Xml/CXmlDeserializer.cs | 2 + VocaluxeLib/Xml/CXmlSerializer.cs | 4 + 29 files changed, 275 insertions(+), 235 deletions(-) diff --git a/Output/Profiles/guest1.xml b/Output/Profiles/guest1.xml index 92f0b29d..a3c68568 100644 --- a/Output/Profiles/guest1.xml +++ b/Output/Profiles/guest1.xml @@ -1,5 +1,6 @@  + 600352d6-d975-4945-9758-e6b379972a12 Guest 1 TR_CONFIG_EASY TR_USERROLE_GUEST diff --git a/Output/Profiles/guest2.xml b/Output/Profiles/guest2.xml index 55c2c971..c4e6e421 100644 --- a/Output/Profiles/guest2.xml +++ b/Output/Profiles/guest2.xml @@ -1,5 +1,6 @@  + abeb987f-bf44-4d6d-b922-e5deb608a1ab Guest 2 TR_CONFIG_EASY TR_USERROLE_GUEST diff --git a/Output/Profiles/guest3.xml b/Output/Profiles/guest3.xml index ad3c3eb5..acaa3bb6 100644 --- a/Output/Profiles/guest3.xml +++ b/Output/Profiles/guest3.xml @@ -1,5 +1,6 @@  + fd433fc4-60c0-4521-87ef-53aa7d252337 Guest 3 TR_CONFIG_EASY TR_USERROLE_NORMAL diff --git a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs index f92f2dea..63b57d3a 100644 --- a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs +++ b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs @@ -27,7 +27,7 @@ namespace VocaluxeLib.PartyModes.Challenge public class CResultTableRow : IComparable { public int Position; - public int PlayerID; + public Guid PlayerID; public int NumPlayed; public int NumWon; public int NumSingPoints; @@ -116,7 +116,7 @@ namespace VocaluxeLib.PartyModes.Challenge public int NumJokers; public bool RefillJokers; public int[] Jokers; - public List ProfileIDs; + public List ProfileIDs; public CChallengeRounds Rounds; public List ResultTable; @@ -129,7 +129,7 @@ namespace VocaluxeLib.PartyModes.Challenge private struct SStats { - public int ProfileID; + public Guid ProfileID; public int SingPoints; public int GamePoints; public int Won; @@ -150,7 +150,7 @@ namespace VocaluxeLib.PartyModes.Challenge _ScreenSongOptions.Sorting.SearchActive = false; _ScreenSongOptions.Sorting.DuetOptions = EDuetOptions.NoDuets; - GameData = new SData {NumPlayer = 4, NumPlayerAtOnce = 2, NumRounds = 12, NumJokers = 5, RefillJokers = true, CurrentRoundNr = 1, ProfileIDs = new List(), CatSongIndices = null, Results = null}; + GameData = new SData {NumPlayer = 4, NumPlayerAtOnce = 2, NumRounds = 12, NumJokers = 5, RefillJokers = true, CurrentRoundNr = 1, ProfileIDs = new List(), CatSongIndices = null, Results = null}; } public override bool Init() @@ -358,7 +358,7 @@ namespace VocaluxeLib.PartyModes.Challenge if (c != null) players[i].ProfileID = GameData.ProfileIDs[c.Players[i]]; else - players[i].ProfileID = -1; + players[i].ProfileID = Guid.Empty; } CBase.Graphics.FadeTo(EScreen.Sing); diff --git a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs index 5e10bcff..e4c898e4 100644 --- a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs +++ b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs @@ -340,7 +340,7 @@ namespace VocaluxeLib.PartyModes.Challenge _Texts[_TextNextPlayerMessage].Visible = true; for (int i = 0; i < _PartyMode.GameData.NumPlayerAtOnce; i++) { - int id = _PartyMode.GameData.ProfileIDs[_PartyMode.GameData.Rounds[_PartyMode.GameData.CurrentRoundNr - 1].Players[i]]; + Guid id = _PartyMode.GameData.ProfileIDs[_PartyMode.GameData.Rounds[_PartyMode.GameData.CurrentRoundNr - 1].Players[i]]; _NextPlayerStatics[i].Texture = CBase.Profiles.GetAvatar(id); _NextPlayerTexts[i].Text = CBase.Profiles.GetPlayerName(id); _NextPlayerTexts[i].Color = CBase.Themes.GetPlayerColor(i + 1); diff --git a/PartyModes/PartyModeChallenge/CPartyScreenChallengeNames.cs b/PartyModes/PartyModeChallenge/CPartyScreenChallengeNames.cs index 9b79c0d2..bc015e37 100644 --- a/PartyModes/PartyModeChallenge/CPartyScreenChallengeNames.cs +++ b/PartyModes/PartyModeChallenge/CPartyScreenChallengeNames.cs @@ -15,6 +15,7 @@ // along with Vocaluxe. If not, see . #endregion +using System; using System.Collections.Generic; using VocaluxeLib.Menu; @@ -46,7 +47,7 @@ namespace VocaluxeLib.PartyModes.Challenge while (_PartyMode.GameData.ProfileIDs.Count > _NumPlayer) _PartyMode.GameData.ProfileIDs.RemoveAt(_PartyMode.GameData.ProfileIDs.Count - 1); - List[] ids = new List[] {_PartyMode.GameData.ProfileIDs}; + List[] ids = new List[] {_PartyMode.GameData.ProfileIDs}; SetPartyModeProfiles(ids); } diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index 38c49aa8..94f1aefc 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -39,7 +39,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public class CResultTableRow : IComparable { public int Position; - public int PlayerID; + public Guid PlayerID; public int NumPlayed; public int NumWon; public int NumSingPoints; @@ -135,7 +135,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public int NumPlayer; public int NumPlayerAtOnce; public int NumRounds; - public List ProfileIDs; + public List ProfileIDs; public int NumSongs; public List Songs; @@ -154,7 +154,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley private struct SStats { - public int ProfileID; + public Guid ProfileID; public int SingPoints; public int GamePoints; public int Won; @@ -165,7 +165,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public CPartyModeChallengeMedley(int id) : base(id) { - GameData = new SData {NumPlayer = 4, NumPlayerAtOnce = 2, NumRounds = 12, CurrentRoundNr = 1, ProfileIDs = new List(), NumSongs = 5, Songs = new List(), SongSource = ESongSource.TR_ALLSONGS, CatSongIndices = null, Results = null}; + GameData = new SData {NumPlayer = 4, NumPlayerAtOnce = 2, NumRounds = 12, CurrentRoundNr = 1, ProfileIDs = new List(), NumSongs = 5, Songs = new List(), SongSource = ESongSource.TR_ALLSONGS, CatSongIndices = null, Results = null}; } public override bool Init() @@ -322,7 +322,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley if (c != null) players[i].ProfileID = GameData.ProfileIDs[c.Players[i]]; else - players[i].ProfileID = -1; + players[i].ProfileID = Guid.Empty; } #endregion PlayerNames @@ -373,15 +373,8 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley private void _SetTeamNames() { - CProfile[] profiles = CBase.Profiles.GetProfiles(); - if (profiles == null) - { - _ScreenSongOptions.Selection.TeamNames = new string[] {"foo", "bar"}; - return; - } - - if (GameData.NumPlayerAtOnce < 1 || GameData.ProfileIDs.Count < GameData.NumPlayerAtOnce || profiles.Length < GameData.NumPlayerAtOnce) + if (CBase.Profiles.GetNum() == 0 || GameData.NumPlayerAtOnce < 1 || GameData.ProfileIDs.Count < GameData.NumPlayerAtOnce || CBase.Profiles.GetNum() < GameData.NumPlayerAtOnce) { _ScreenSongOptions.Selection.TeamNames = new string[] {"foo", "bar"}; return; @@ -394,8 +387,8 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { if (c != null) { - if (GameData.ProfileIDs[c.Players[i]] < profiles.Length) - _ScreenSongOptions.Selection.TeamNames[i] = profiles[GameData.ProfileIDs[c.Players[i]]].PlayerName; + if (CBase.Profiles.IsProfileIDValid(GameData.ProfileIDs[c.Players[i]])) + _ScreenSongOptions.Selection.TeamNames[i] = CBase.Profiles.GetPlayerName(GameData.ProfileIDs[c.Players[i]]); else _ScreenSongOptions.Selection.TeamNames[i] = "foobar"; } diff --git a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs index 8e2841b1..bc4c72a3 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs @@ -340,7 +340,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _Texts[_TextNextPlayerMessage].Visible = true; for (int i = 0; i < _PartyMode.GameData.NumPlayerAtOnce; i++) { - int id = _PartyMode.GameData.ProfileIDs[_PartyMode.GameData.Rounds[_PartyMode.GameData.CurrentRoundNr - 1].Players[i]]; + Guid id = _PartyMode.GameData.ProfileIDs[_PartyMode.GameData.Rounds[_PartyMode.GameData.CurrentRoundNr - 1].Players[i]]; _NextPlayerStatics[i].Texture = CBase.Profiles.GetAvatar(id); _NextPlayerTexts[i].Text = CBase.Profiles.GetPlayerName(id); _NextPlayerTexts[i].Color = CBase.Themes.GetPlayerColor(i + 1); diff --git a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyNames.cs b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyNames.cs index 4d92fc7d..68dc74b7 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyNames.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyNames.cs @@ -15,6 +15,7 @@ // along with Vocaluxe. If not, see . #endregion +using System; using System.Collections.Generic; using VocaluxeLib.Menu; @@ -46,7 +47,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley while (_PartyMode.GameData.ProfileIDs.Count > _NumPlayer) _PartyMode.GameData.ProfileIDs.RemoveAt(_PartyMode.GameData.ProfileIDs.Count - 1); - List[] ids = new List[] {_PartyMode.GameData.ProfileIDs}; + List[] ids = new List[] {_PartyMode.GameData.ProfileIDs}; SetPartyModeProfiles(ids); } diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index 81d3c308..8bc047b4 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -110,8 +110,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe public int NumPlayerTeam2; public int NumFields; public int Team; - public List ProfileIDsTeam1; - public List ProfileIDsTeam2; + public List ProfileIDsTeam1; + public List ProfileIDsTeam2; public List PlayerTeam1; public List PlayerTeam2; @@ -151,8 +151,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe NumPlayerTeam1 = 2, NumPlayerTeam2 = 2, NumFields = 9, - ProfileIDsTeam1 = new List(), - ProfileIDsTeam2 = new List(), + ProfileIDsTeam1 = new List(), + ProfileIDsTeam2 = new List(), PlayerTeam1 = new List(), PlayerTeam2 = new List(), CurrentRoundNr = 0, @@ -475,7 +475,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe for (int i = 0; i < 2; i++) { //default values - players[i].ProfileID = -1; + players[i].ProfileID = Guid.Empty; } //try to fill with the right data diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs index 8d0e6cae..c0e7cc1c 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs @@ -15,6 +15,7 @@ // along with Vocaluxe. If not, see . #endregion +using System; using System.Collections.Generic; using VocaluxeLib.Menu; @@ -49,7 +50,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe SetPartyModeData(2, _PartyMode.GameData.NumPlayerTeam1 + _PartyMode.GameData.NumPlayerTeam2, new int[] {_PartyMode.GameData.NumPlayerTeam1, _PartyMode.GameData.NumPlayerTeam2}); - List[] ids = new List[] {_PartyMode.GameData.ProfileIDsTeam1, _PartyMode.GameData.ProfileIDsTeam2}; + List[] ids = new List[] {_PartyMode.GameData.ProfileIDsTeam1, _PartyMode.GameData.ProfileIDsTeam2}; SetPartyModeProfiles(ids); } diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 6409815a..dede39bb 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -765,7 +765,7 @@ namespace Vocaluxe.Base for (int j = 0; j < CSettings.MaxNumPlayer; j++) { - CGame.Players[j].ProfileID = -1; + CGame.Players[j].ProfileID = Guid.Empty; if (string.IsNullOrEmpty(Config.Game.Players[j])) continue; diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index b5d2e0c7..89035210 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -636,17 +636,22 @@ namespace Vocaluxe.Base return CProfiles.GetProfiles(); } - public EGameDifficulty GetDifficulty(int profileID) + public int GetNum() + { + return CProfiles.NumProfiles; + } + + public EGameDifficulty GetDifficulty(Guid profileID) { return CProfiles.GetDifficulty(profileID); } - public string GetPlayerName(int profileID, int playerNum = 0) + public string GetPlayerName(Guid profileID, int playerNum = 0) { return CProfiles.GetPlayerName(profileID, playerNum); } - public CTextureRef GetAvatar(int profileID) + public CTextureRef GetAvatar(Guid profileID) { return CProfiles.GetAvatarTextureFromProfile(profileID); } @@ -656,12 +661,12 @@ namespace Vocaluxe.Base return CProfiles.GetAvatarByFilename(fileName); } - public bool IsProfileIDValid(int profileID) + public bool IsProfileIDValid(Guid profileID) { return CProfiles.IsProfileIDValid(profileID); } - public bool IsGuest(int profileID) + public bool IsGuest(Guid profileID) { return CProfiles.IsGuestProfile(profileID); } diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index 1cf1d983..65c22539 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -44,13 +44,12 @@ namespace Vocaluxe.Base public CProfile Profile; public CAvatar Avatar; public EAction Action; - public int ProfileID; + public Guid ProfileID; } #endregion enums and structs #region private vars - private static Dictionary _Profiles; - private static Queue _ProfileIDs; + private static Dictionary _Profiles; private static Dictionary _Avatars; private static Queue _AvatarIDs; @@ -83,10 +82,7 @@ namespace Vocaluxe.Base 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); + _Profiles = new Dictionary(); LoadProfiles(); } @@ -116,7 +112,7 @@ namespace Vocaluxe.Base if (newProf == null) break; - newProf.ID = _ProfileIDs.Dequeue(); + newProf.ID = Guid.NewGuid(); if (newProf.Avatar == null) newProf.Avatar = _Avatars.Values.First(); else if (newProf.Avatar.ID < 0) @@ -255,7 +251,7 @@ namespace Vocaluxe.Base } } - public static void DeleteProfile(int profileID) + public static void DeleteProfile(Guid profileID) { if (!IsProfileIDValid(profileID)) return; @@ -304,7 +300,7 @@ namespace Vocaluxe.Base return list.ToArray(); } - public static CProfile GetProfile(int profileID) + public static CProfile GetProfile(Guid profileID) { if (!IsProfileIDValid(profileID)) return null; @@ -323,7 +319,7 @@ namespace Vocaluxe.Base return result; } - public static int NewProfile(string fileName = "") + public static Guid NewProfile(string fileName = "") { var profile = new CProfile { @@ -331,9 +327,9 @@ namespace Vocaluxe.Base }; if (File.Exists(profile.FilePath)) - return -1; + return Guid.Empty; - profile.ID = _ProfileIDs.Dequeue(); + profile.ID = Guid.NewGuid(); _Profiles.Add(profile.ID, profile); _ProfilesChanged = true; return profile.ID; @@ -353,11 +349,11 @@ namespace Vocaluxe.Base public static void SaveProfiles() { - foreach (int id in _Profiles.Keys) + foreach (Guid id in _Profiles.Keys) _Profiles[id].SaveProfile(); } - public static bool IsProfileIDValid(int profileID) + public static bool IsProfileIDValid(Guid profileID) { return _Profiles.ContainsKey(profileID); } @@ -369,7 +365,7 @@ namespace Vocaluxe.Base #endregion public methods #region profile properties - public static string GetPlayerName(int profileID, int playerNum = 0) + public static string GetPlayerName(Guid profileID, int playerNum = 0) { if (IsProfileIDValid(profileID)) return _Profiles[profileID].PlayerName; @@ -380,7 +376,7 @@ namespace Vocaluxe.Base return playerName; } - public static void SetPlayerName(int profileID, string playerName) + public static void SetPlayerName(Guid profileID, string playerName) { if (!IsProfileIDValid(profileID)) return; @@ -388,7 +384,7 @@ namespace Vocaluxe.Base _Profiles[profileID].PlayerName = playerName; } - public static string GetProfileFileName(int profileID) + public static string GetProfileFileName(Guid profileID) { if (!IsProfileIDValid(profileID)) return String.Empty; @@ -396,7 +392,7 @@ namespace Vocaluxe.Base return Path.GetFileName(_Profiles[profileID].FilePath); } - public static string AddGetPlayerName(int profileID, char chr) + public static string AddGetPlayerName(Guid profileID, char chr) { if (!IsProfileIDValid(profileID)) return String.Empty; @@ -405,7 +401,7 @@ namespace Vocaluxe.Base return _Profiles[profileID].PlayerName; } - public static string GetDeleteCharInPlayerName(int profileID) + public static string GetDeleteCharInPlayerName(Guid profileID) { if (!IsProfileIDValid(profileID)) return String.Empty; @@ -417,12 +413,12 @@ namespace Vocaluxe.Base return profile.PlayerName; } - public static EGameDifficulty GetDifficulty(int profileID) + public static EGameDifficulty GetDifficulty(Guid profileID) { return IsProfileIDValid(profileID) ? _Profiles[profileID].Difficulty : EGameDifficulty.TR_CONFIG_NORMAL; } - public static void SetDifficulty(int profileID, EGameDifficulty difficulty) + public static void SetDifficulty(Guid profileID, EGameDifficulty difficulty) { if (!IsProfileIDValid(profileID)) return; @@ -430,12 +426,12 @@ namespace Vocaluxe.Base _Profiles[profileID].Difficulty = difficulty; } - public static EUserRole GetUserRoleProfile(int profileID) + public static EUserRole GetUserRoleProfile(Guid profileID) { return IsProfileIDValid(profileID) ? _Profiles[profileID].UserRole : EUserRole.TR_USERROLE_GUEST; } - public static void SetUserRoleProfile(int profileID, EUserRole option) + public static void SetUserRoleProfile(Guid profileID, EUserRole option) { if (!IsProfileIDValid(profileID)) return; @@ -445,12 +441,12 @@ namespace Vocaluxe.Base _Profiles[profileID].UserRole = (_Profiles[profileID].UserRole & ~mask) | option; } - public static EOffOn GetActive(int profileID) + public static EOffOn GetActive(Guid profileID) { return IsProfileIDValid(profileID) ? _Profiles[profileID].Active : EOffOn.TR_CONFIG_OFF; } - public static void SetActive(int profileID, EOffOn option) + public static void SetActive(Guid profileID, EOffOn option) { if (!IsProfileIDValid(profileID)) return; @@ -458,7 +454,7 @@ namespace Vocaluxe.Base _Profiles[profileID].Active = option; } - public static bool IsGuestProfile(int profileID) + public static bool IsGuestProfile(Guid profileID) { if (!IsProfileIDValid(profileID)) return true; // this will prevent from saving dummy profiles to highscore db @@ -466,14 +462,14 @@ namespace Vocaluxe.Base return _Profiles[profileID].UserRole <= EUserRole.TR_USERROLE_GUEST; } - public static bool IsActive(int profileID) + public static bool IsActive(Guid profileID) { if (!IsProfileIDValid(profileID)) return false; return _Profiles[profileID].Active == EOffOn.TR_CONFIG_ON; } - public static void SetAvatar(int profileID, int avatarID) + public static void SetAvatar(Guid profileID, int avatarID) { if (!IsProfileIDValid(profileID) || !IsAvatarIDValid(avatarID)) return; @@ -481,7 +477,7 @@ namespace Vocaluxe.Base _Profiles[profileID].Avatar = _Avatars[avatarID]; } - public static int GetAvatarID(int profileID) + public static int GetAvatarID(Guid profileID) { if (!IsProfileIDValid(profileID) || _Profiles[profileID].Avatar == null) return -1; @@ -489,7 +485,7 @@ namespace Vocaluxe.Base return _Profiles[profileID].Avatar.ID; } - public static CAvatar GetAvatar(int profileID) + public static CAvatar GetAvatar(Guid profileID) { if (!IsProfileIDValid(profileID)) return null; @@ -497,7 +493,8 @@ namespace Vocaluxe.Base return _Profiles[profileID].Avatar; } - public static int GetProfileID(int num) + //TODO: Remove this? + public static Guid GetProfileID(Guid num) { return _Profiles[num].ID; } @@ -512,7 +509,7 @@ namespace Vocaluxe.Base return _Avatars[avatarID].Texture; } - public static CTextureRef GetAvatarTextureFromProfile(int profileID) + public static CTextureRef GetAvatarTextureFromProfile(Guid profileID) { if (!IsProfileIDValid(profileID) || _Profiles[profileID].Avatar == null) return null; @@ -529,9 +526,9 @@ namespace Vocaluxe.Base var knownFiles = new List(); if (_Profiles.Count > 0) { - var ids = new int[_Profiles.Keys.Count]; + var ids = new Guid[_Profiles.Keys.Count]; _Profiles.Keys.CopyTo(ids, 0); - foreach (int id in ids) + foreach (Guid id in ids) { if (_Profiles[id].LoadProfile()) knownFiles.Add(Path.GetFileName(_Profiles[id].FilePath)); @@ -553,10 +550,7 @@ namespace Vocaluxe.Base var profile = new CProfile(); if (profile.LoadProfile(file)) - { - profile.ID = _ProfileIDs.Dequeue(); _Profiles.Add(profile.ID, profile); - } } _ProfilesChanged = true; } @@ -596,7 +590,7 @@ namespace Vocaluxe.Base _ProfilesChanged = true; } - private static void _DeleteProfile(int profileID) + private static void _DeleteProfile(Guid profileID) { if (!IsProfileIDValid(profileID)) return; @@ -624,10 +618,8 @@ namespace Vocaluxe.Base //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; + if (CGame.Players[i].ProfileID == profileID) + CGame.Players[i].ProfileID = Guid.Empty; } } catch (Exception) @@ -637,7 +629,7 @@ namespace Vocaluxe.Base _ProfilesChanged = true; } - private static void _RemoveProfile(int profileID) + private static void _RemoveProfile(Guid profileID) { if (!IsProfileIDValid(profileID)) return; diff --git a/Vocaluxe/Base/Server/CVocaluxeServer.cs b/Vocaluxe/Base/Server/CVocaluxeServer.cs index 138df11f..bb532725 100644 --- a/Vocaluxe/Base/Server/CVocaluxeServer.cs +++ b/Vocaluxe/Base/Server/CVocaluxeServer.cs @@ -388,7 +388,7 @@ namespace Vocaluxe.Base.Server } #region profile - public static SProfileData GetProfileData(int profileId, bool isReadonly) + public static SProfileData GetProfileData(Guid profileId, bool isReadonly) { CProfile profile = CProfiles.GetProfile(profileId); if (profile == null) @@ -788,7 +788,7 @@ namespace Vocaluxe.Base.Server #endregion #region user management - public static bool ValidatePassword(int profileId, string password) + public static bool ValidatePassword(Guid profileId, string password) { CProfile profile = CProfiles.GetProfile(profileId); if (profile == null) @@ -805,7 +805,7 @@ namespace Vocaluxe.Base.Server return _Hash((new UTF8Encoding()).GetBytes(password), salt).SequenceEqual(profile.PasswordHash); } - public static bool ValidatePassword(int profileId, byte[] hashedPassword) + public static bool ValidatePassword(Guid profileId, byte[] hashedPassword) { CProfile profile = CProfiles.GetProfile(profileId); if (profile == null) @@ -822,7 +822,7 @@ namespace Vocaluxe.Base.Server return hashedPassword.SequenceEqual(profile.PasswordHash); } - private static byte[] _GetPasswordSalt(int profileId) + private static byte[] _GetPasswordSalt(Guid profileId) { CProfile profile = CProfiles.GetProfile(profileId); if (profile == null) @@ -834,7 +834,7 @@ namespace Vocaluxe.Base.Server return profile.PasswordSalt; } - public static int GetUserRole(int profileId) + public static int GetUserRole(Guid profileId) { CProfile profile = CProfiles.GetProfile(profileId); if (profile == null) @@ -846,7 +846,7 @@ namespace Vocaluxe.Base.Server return (int)(profile.UserRole); } - public static void SetUserRole(int profileId, int userRole) + public static void SetUserRole(Guid profileId, int userRole) { CProfile profile = CProfiles.GetProfile(profileId); if (profile == null) @@ -865,9 +865,9 @@ namespace Vocaluxe.Base.Server CProfiles.SaveProfiles(); } - public static int GetUserIdFromUsername(string username) + public static Guid GetUserIdFromUsername(string username) { - IEnumerable playerIds = (from p in CProfiles.GetProfiles() + IEnumerable playerIds = (from p in CProfiles.GetProfiles() where String.Equals(p.PlayerName, username, StringComparison.OrdinalIgnoreCase) select p.ID); try diff --git a/Vocaluxe/Base/Server/CWebservice.cs b/Vocaluxe/Base/Server/CWebservice.cs index 471caf34..e44606a1 100644 --- a/Vocaluxe/Base/Server/CWebservice.cs +++ b/Vocaluxe/Base/Server/CWebservice.cs @@ -61,7 +61,7 @@ namespace Vocaluxe.Base.Server } #region profile - public int GetOwnProfileId() + public Guid GetOwnProfileId() { Guid sessionKey = _GetSession(); if (sessionKey == Guid.Empty) @@ -71,17 +71,17 @@ namespace Vocaluxe.Base.Server WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden; WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session"; } - return -1; + return Guid.Empty; } - int profileId = CSessionControl.GetUserIdFromSession(sessionKey); - if (profileId < 0) + Guid profileId = CSessionControl.GetUserIdFromSession(sessionKey); + if (profileId == Guid.Empty) { if (WebOperationContext.Current != null) { WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden; WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session"; } - return -1; + return Guid.Empty; } return profileId; } @@ -90,7 +90,7 @@ namespace Vocaluxe.Base.Server { Guid sessionKey = _GetSession(); - if (profile.ProfileId != -1) //-1 is the id for a new profile + if (profile.ProfileId != Guid.Empty) //-1 is the id for a new profile { if (CSessionControl.GetUserIdFromSession(sessionKey) != profile.ProfileId && !(_CheckRight(EUserRights.EditAllProfiles))) @@ -100,7 +100,7 @@ namespace Vocaluxe.Base.Server CVocaluxeServer.DoTask(CVocaluxeServer.SendProfileData, profile); } - public SProfileData GetProfile(int profileId) + public SProfileData GetProfile(Guid profileId) { Guid sessionKey = _GetSession(); if (CSessionControl.GetUserIdFromSession(sessionKey) == profileId || _CheckRight(EUserRights.ViewOtherProfiles)) @@ -146,7 +146,7 @@ namespace Vocaluxe.Base.Server public void Logout() { Guid sessionKey = _GetSession(); - CSessionControl.InvalidateSessions(sessionKey); + CSessionControl.InvalidateSessionByID(sessionKey); } public Stream Index() @@ -501,12 +501,12 @@ namespace Vocaluxe.Base.Server #endregion #region user management - public int GetUserRole(int profileId) + public int GetUserRole(Guid profileId) { return CVocaluxeServer.DoTask(CVocaluxeServer.GetUserRole, profileId); } - public void SetUserRole(int profileId, int userRole) + public void SetUserRole(Guid profileId, int userRole) { if (_CheckRight(EUserRights.EditAllProfiles)) CVocaluxeServer.DoTaskWithoutReturn(CVocaluxeServer.SetUserRole, profileId, userRole); diff --git a/Vocaluxe/Base/Server/ICWebservice.cs b/Vocaluxe/Base/Server/ICWebservice.cs index c34c12de..62fdb3d5 100644 --- a/Vocaluxe/Base/Server/ICWebservice.cs +++ b/Vocaluxe/Base/Server/ICWebservice.cs @@ -39,7 +39,7 @@ namespace Vocaluxe.Base.Server [OperationContract, WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "/getOwnProfileId")] - int GetOwnProfileId(); + Guid GetOwnProfileId(); [OperationContract, WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, @@ -49,7 +49,7 @@ namespace Vocaluxe.Base.Server [OperationContract, WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "/getProfile?profileId={profileId}")] - SProfileData GetProfile(int profileId); + SProfileData GetProfile(Guid profileId); [OperationContract, WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, @@ -195,12 +195,12 @@ namespace Vocaluxe.Base.Server [OperationContract, WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "/getUserRole?profileId={profileId}")] - int GetUserRole(int profileId); + int GetUserRole(Guid profileId); [OperationContract, WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "/setUserRole?profileId={profileId}&userRole={userRole}")] - void SetUserRole(int profileId, int userRole); + void SetUserRole(Guid profileId, int userRole); [OperationContract, WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, diff --git a/Vocaluxe/Base/Server/Session.cs b/Vocaluxe/Base/Server/Session.cs index b2493d4c..43ff2ae8 100644 --- a/Vocaluxe/Base/Server/Session.cs +++ b/Vocaluxe/Base/Server/Session.cs @@ -27,8 +27,8 @@ namespace Vocaluxe.Base.Server get { return _ID; } } - private readonly int _ProfileId; - public int ProfileId + private readonly Guid _ProfileId; + public Guid ProfileId { get { return _ProfileId; } } @@ -46,7 +46,7 @@ namespace Vocaluxe.Base.Server internal set { _LastSeen = value; } } - public CSession(Guid id, int profileId, EUserRoles roles) + public CSession(Guid id, Guid profileId, EUserRoles roles) { _ID = id; _ProfileId = profileId; diff --git a/Vocaluxe/Base/Server/SessionControl.cs b/Vocaluxe/Base/Server/SessionControl.cs index 13d674b2..e0ee47db 100644 --- a/Vocaluxe/Base/Server/SessionControl.cs +++ b/Vocaluxe/Base/Server/SessionControl.cs @@ -44,7 +44,7 @@ namespace Vocaluxe.Base.Server foreach (var sessionToRemove in sessionIdsToRemove) { - InvalidateSessions(sessionToRemove); + InvalidateSessionByID(sessionToRemove); } } @@ -54,7 +54,7 @@ namespace Vocaluxe.Base.Server return Guid.Empty; Guid newId = Guid.NewGuid(); - int id = _GetProfileIdFormUsername(userName); + Guid id = _GetProfileIdFormUsername(userName); EUserRoles roles = _GetUserRoles(id); CSession session = new CSession(newId, id, roles); //InvalidateSessions(id); @@ -68,17 +68,17 @@ namespace Vocaluxe.Base.Server return CVocaluxeServer.ValidatePassword(_GetProfileIdFormUsername(userName), password); } - private static int _GetProfileIdFormUsername(string username) + private static Guid _GetProfileIdFormUsername(string username) { return CVocaluxeServer.GetUserIdFromUsername(username); } - private static EUserRoles _GetUserRoles(int profileId) + private static EUserRoles _GetUserRoles(Guid profileId) { return (EUserRoles)CVocaluxeServer.GetUserRole(profileId); } - internal static void InvalidateSessions(int profileId) + internal static void InvalidateSessionByProfile(Guid profileId) { foreach (KeyValuePair s in (from kv in _ActiveSessions where kv.Value.ProfileId == profileId @@ -86,7 +86,7 @@ namespace Vocaluxe.Base.Server _ActiveSessions.Remove(s.Key); } - internal static void InvalidateSessions(Guid sessionId) + internal static void InvalidateSessionByID(Guid sessionId) { if (_ActiveSessions.ContainsKey(sessionId)) { @@ -100,10 +100,10 @@ namespace Vocaluxe.Base.Server .HasFlag(requestedRight))); } - internal static int GetUserIdFromSession(Guid sessionId) + internal static Guid GetUserIdFromSession(Guid sessionId) { if (!_ActiveSessions.ContainsKey(sessionId)) - return -1; + return Guid.Empty; return _ActiveSessions[sessionId].ProfileId; } diff --git a/Vocaluxe/Base/Server/VocaluxeStructs.cs b/Vocaluxe/Base/Server/VocaluxeStructs.cs index 9cc5b327..3467f81d 100644 --- a/Vocaluxe/Base/Server/VocaluxeStructs.cs +++ b/Vocaluxe/Base/Server/VocaluxeStructs.cs @@ -56,7 +56,7 @@ namespace Vocaluxe.Base.Server [DataMember] public int Difficulty; [DataMember] - public int ProfileId; + public Guid ProfileId; [DataMember] public bool IsEditable; [DataMember] diff --git a/Vocaluxe/Screens/CScreenNames.cs b/Vocaluxe/Screens/CScreenNames.cs index 873d4ad7..c1af06b2 100644 --- a/Vocaluxe/Screens/CScreenNames.cs +++ b/Vocaluxe/Screens/CScreenNames.cs @@ -61,7 +61,7 @@ namespace Vocaluxe.Screens private bool _SelectingFast; private int _SelectingSwitchNr = -1; private int _SelectingFastPlayerNr; - private int _SelectedProfileID = -1; + private Guid _SelectedProfileID = Guid.Empty; private bool _AvatarsChanged; private bool _ProfilesChanged; @@ -177,9 +177,9 @@ namespace Vocaluxe.Screens { case Keys.Enter: //Check, if a player is selected - if (_NameSelections[_NameSelection].Selection > -1) + if (_NameSelections[_NameSelection].SelectedID != Guid.Empty) { - _SelectedProfileID = _NameSelections[_NameSelection].Selection; + _SelectedProfileID = _NameSelections[_NameSelection].SelectedID; if (!CProfiles.IsProfileIDValid(_SelectedProfileID)) return true; @@ -359,7 +359,7 @@ namespace Vocaluxe.Screens base.HandleMouse(mouseEvent); //Check if LeftButton is hold and Select-Mode inactive - if (mouseEvent.LBH && _SelectedProfileID < 0 && !_SelectingFast) + if (mouseEvent.LBH && _SelectedProfileID == Guid.Empty && !_SelectingFast) { //Save mouse-coords _OldMouseX = mouseEvent.X; @@ -368,8 +368,8 @@ namespace Vocaluxe.Screens if (_NameSelections[_NameSelection].IsOverTile(mouseEvent)) { //Get player-number of tile - _SelectedProfileID = _NameSelections[_NameSelection].TilePlayerNr(mouseEvent); - if (_SelectedProfileID != -1) + _SelectedProfileID = _NameSelections[_NameSelection].TilePlayerID(mouseEvent); + if (_SelectedProfileID != Guid.Empty) { //Update of Drag/Drop-Texture CStatic selectedPlayer = _NameSelections[_NameSelection].TilePlayerAvatar(mouseEvent); @@ -402,7 +402,7 @@ namespace Vocaluxe.Screens } //Check if LeftButton is hold and Select-Mode active - if (mouseEvent.LBH && _SelectedProfileID >= 0 && !_SelectingFast) + if (mouseEvent.LBH && _SelectedProfileID != Guid.Empty && !_SelectingFast) { //Update coords for Drag/Drop-Texture _ChooseAvatarStatic.X += mouseEvent.X - _OldMouseX; @@ -411,7 +411,7 @@ namespace Vocaluxe.Screens _OldMouseY = mouseEvent.Y; } // LeftButton isn't hold anymore, but Select-Mode is still active -> "Drop" of Avatar - else if (_SelectedProfileID >= 0 && !_SelectingFast) + else if (_SelectedProfileID != Guid.Empty && !_SelectingFast) { //Foreach Drop-Area for (int i = 0; i < _StaticPlayer.Length; i++) @@ -422,7 +422,7 @@ namespace Vocaluxe.Screens //Check if Mouse is in area if (CHelper.IsInBounds(_Statics[_StaticPlayer[i]].Rect, mouseEvent)) { - if (_SelectingSwitchNr > -1 && CGame.Players[i].ProfileID > -1) + if (_SelectingSwitchNr > -1 && CGame.Players[i].ProfileID != Guid.Empty) _UpdateSelectedProfile(_SelectingSwitchNr, CGame.Players[i].ProfileID); else if (_SelectingSwitchNr > -1) _ResetPlayerSelection(_SelectingSwitchNr); @@ -438,7 +438,7 @@ namespace Vocaluxe.Screens _ResetPlayerSelection(_SelectingSwitchNr); } _SelectingSwitchNr = -1; - _SelectedProfileID = -1; + _SelectedProfileID = Guid.Empty; //Reset variables _ChooseAvatarStatic.Visible = false; } @@ -448,8 +448,8 @@ namespace Vocaluxe.Screens if (_NameSelections[_NameSelection].IsOverTile(mouseEvent)) { //Get player-number of tile - _SelectedProfileID = _NameSelections[_NameSelection].TilePlayerNr(mouseEvent); - if (_SelectedProfileID != -1) + _SelectedProfileID = _NameSelections[_NameSelection].TilePlayerID(mouseEvent); + if (_SelectedProfileID != Guid.Empty) { if (!CProfiles.IsProfileIDValid(_SelectedProfileID)) return true; @@ -480,12 +480,12 @@ namespace Vocaluxe.Screens if (mouseEvent.LD && _NameSelections[_NameSelection].IsOverTile(mouseEvent) && !_SelectingFast) { - _SelectedProfileID = _NameSelections[_NameSelection].TilePlayerNr(mouseEvent); - if (_SelectedProfileID > -1) + _SelectedProfileID = _NameSelections[_NameSelection].TilePlayerID(mouseEvent); + if (_SelectedProfileID != Guid.Empty) { for (int i = 0; i < CGame.NumPlayers; i++) { - if (CGame.Players[i].ProfileID == -1) + if (CGame.Players[i].ProfileID == Guid.Empty) { if (!CProfiles.IsProfileIDValid(_SelectedProfileID)) return true; @@ -657,7 +657,7 @@ namespace Vocaluxe.Screens _Statics["StaticPlayerAvatar" + i].Visible = true; _Texts["TextPlayer" + i].Visible = true; if (_Texts["TextPlayer" + i].Text == "") - _Texts["TextPlayer" + i].Text = CProfiles.GetPlayerName(-1, i); + _Texts["TextPlayer" + i].Text = CProfiles.GetPlayerName(Guid.Empty, i); _Equalizers["EqualizerPlayer" + i].Visible = true; if (CGame.GetNumSongs() == 1 && CGame.GetSong(0).IsDuet) _SelectSlides["SelectSlideDuetPlayer" + i].Visible = true; @@ -676,7 +676,7 @@ namespace Vocaluxe.Screens _CheckPlayers(); } - private void _UpdateSelectedProfile(int playerNum, int profileId) + private void _UpdateSelectedProfile(int playerNum, Guid profileId) { _NameSelections[_NameSelection].RemoveUsedProfile(CGame.Players[playerNum].ProfileID); _NameSelections[_NameSelection].UseProfile(profileId); @@ -699,12 +699,12 @@ namespace Vocaluxe.Screens for (int i = 0; i < CGame.NumPlayers; i++) { _NameSelections[_NameSelection].RemoveUsedProfile(CGame.Players[i].ProfileID); - CGame.Players[i].ProfileID = -1; + CGame.Players[i].ProfileID = Guid.Empty; //Update config for default players. CConfig.Config.Game.Players[i] = String.Empty; //Update texture and name _Statics[_StaticPlayerAvatar[i]].Texture = _OriginalPlayerAvatarTextures[i]; - _Texts[_TextPlayer[i]].Text = CProfiles.GetPlayerName(-1, i + 1); + _Texts[_TextPlayer[i]].Text = CProfiles.GetPlayerName(Guid.Empty, i + 1); } _NameSelections[_NameSelection].UpdateList(); CConfig.SaveConfig(); @@ -713,13 +713,13 @@ namespace Vocaluxe.Screens private void _ResetPlayerSelection(int playerNum) { _NameSelections[_NameSelection].RemoveUsedProfile(CGame.Players[playerNum].ProfileID); - CGame.Players[playerNum].ProfileID = -1; + CGame.Players[playerNum].ProfileID = Guid.Empty; //Update config for default players. CConfig.Config.Game.Players[playerNum] = String.Empty; CConfig.SaveConfig(); //Update texture and name _Statics[_StaticPlayerAvatar[playerNum]].Texture = _OriginalPlayerAvatarTextures[playerNum]; - _Texts[_TextPlayer[playerNum]].Text = CProfiles.GetPlayerName(-1, playerNum + 1); + _Texts[_TextPlayer[playerNum]].Text = CProfiles.GetPlayerName(Guid.Empty, playerNum + 1); //Update profile-warning _CheckPlayers(); //Update Tiles-List @@ -769,7 +769,7 @@ namespace Vocaluxe.Screens var playerWithoutProfile = new List(); for (int player = 0; player < CConfig.Config.Game.NumPlayers; player++) { - if (CGame.Players[player].ProfileID < 0) + if (CGame.Players[player].ProfileID == Guid.Empty) playerWithoutProfile.Add(player + 1); } diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index 44196e34..7aca2b7b 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -62,6 +62,8 @@ namespace Vocaluxe.Screens private bool _ProfilesChanged; private bool _AvatarsChanged; + private Dictionary _SelectSlideGuids = new Dictionary(); + private EEditMode _EditMode; private CTextureRef _WebcamTexture; @@ -109,7 +111,7 @@ namespace Vocaluxe.Screens break; case EEditMode.PlayerName: _SelectSlides[_SelectSlideProfiles].RenameValue( - CProfiles.AddGetPlayerName(_SelectSlides[_SelectSlideProfiles].SelectedTag, keyEvent.Unicode)); + CProfiles.AddGetPlayerName(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag), keyEvent.Unicode)); _ProfilesChanged = true; break; } @@ -155,7 +157,7 @@ namespace Vocaluxe.Screens if (_EditMode == EEditMode.PlayerName) { _SelectSlides[_SelectSlideProfiles].RenameValue( - CProfiles.GetDeleteCharInPlayerName(_SelectSlides[_SelectSlideProfiles].SelectedTag)); + CProfiles.GetDeleteCharInPlayerName(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag))); _ProfilesChanged = true; } else @@ -168,22 +170,22 @@ namespace Vocaluxe.Screens } if (_SelectSlides[_SelectSlideDifficulty].Selected) { - CProfiles.SetDifficulty(_SelectSlides[_SelectSlideProfiles].SelectedTag, + CProfiles.SetDifficulty(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag), (EGameDifficulty)_SelectSlides[_SelectSlideDifficulty].Selection); } else if (_SelectSlides[_SelectSlideAvatars].Selected) { - CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].SelectedTag, + CProfiles.SetAvatar(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag), _SelectSlides[_SelectSlideAvatars].SelectedTag); } else if (_SelectSlides[_SelectSlideUserRole].Selected) { - CProfiles.SetUserRoleProfile(_SelectSlides[_SelectSlideProfiles].SelectedTag, + CProfiles.SetUserRoleProfile(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag), (EUserRole)_SelectSlides[_SelectSlideUserRole].Selection); } else if (_SelectSlides[_SelectSlideActive].Selected) { - CProfiles.SetActive(_SelectSlides[_SelectSlideProfiles].SelectedTag, + CProfiles.SetActive(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag), (EOffOn)_SelectSlides[_SelectSlideActive].Selection); } } @@ -215,24 +217,24 @@ namespace Vocaluxe.Screens } else if (_SelectSlides[_SelectSlideDifficulty].Selected) { - CProfiles.SetDifficulty(_SelectSlides[_SelectSlideProfiles].SelectedTag, + CProfiles.SetDifficulty(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag), (EGameDifficulty)_SelectSlides[_SelectSlideDifficulty].Selection); } else if (_SelectSlides[_SelectSlideAvatars].Selected) { - CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].SelectedTag, + CProfiles.SetAvatar(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag), _SelectSlides[_SelectSlideAvatars].SelectedTag); if (CWebcam.IsDeviceAvailable() && _WebcamTexture != null) _OnDiscardSnapshot(); } else if (_SelectSlides[_SelectSlideUserRole].Selected) { - CProfiles.SetUserRoleProfile(_SelectSlides[_SelectSlideProfiles].SelectedTag, + CProfiles.SetUserRoleProfile(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag), (EUserRole)_SelectSlides[_SelectSlideUserRole].Selection); } else if (_SelectSlides[_SelectSlideActive].Selected) { - CProfiles.SetActive(_SelectSlides[_SelectSlideProfiles].SelectedTag, + CProfiles.SetActive(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag), (EOffOn)_SelectSlides[_SelectSlideActive].Selection); } else if (_Buttons[_ButtonWebcam].Selected) @@ -260,15 +262,15 @@ namespace Vocaluxe.Screens if (_SelectSlides[_SelectSlideProfiles].Selection > -1) { - _Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].SelectedTag); + _Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag)); if (_EditMode == EEditMode.PlayerName) _Buttons[_ButtonPlayerName].Text.Text += "|"; - _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].SelectedTag); - _SelectSlides[_SelectSlideUserRole].Selection = (int)CProfiles.GetUserRoleProfile(_SelectSlides[_SelectSlideProfiles].SelectedTag); - _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].SelectedTag); + _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag)); + _SelectSlides[_SelectSlideUserRole].Selection = (int)CProfiles.GetUserRoleProfile(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag)); + _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag)); - int avatarID = CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].SelectedTag); + int avatarID = CProfiles.GetAvatarID(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag)); _SelectSlides[_SelectSlideAvatars].SelectedTag = avatarID; if (_Snapshot == null) { @@ -357,7 +359,7 @@ namespace Vocaluxe.Screens _Buttons[_ButtonWebcam].Visible = CWebcam.IsDeviceAvailable(); int id = CProfiles.NewAvatar(file); - CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].SelectedTag, id); + CProfiles.SetAvatar(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag), id); _LoadAvatars(false); } @@ -379,11 +381,13 @@ namespace Vocaluxe.Screens private void _NewProfile() { _EditMode = EEditMode.None; - int id = CProfiles.NewProfile(); + Guid id = CProfiles.NewProfile(); _LoadProfiles(false); - _SelectSlides[_SelectSlideProfiles].SelectedTag = id; + int num = CProfiles.NumProfiles; + _SelectSlides[_SelectSlideProfiles].SelectedTag = num; + _SelectSlideGuids.Add(num, id); - CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].SelectedTag, _SelectSlides[_SelectSlideAvatars].SelectedTag); + CProfiles.SetAvatar(id, _SelectSlides[_SelectSlideAvatars].SelectedTag); _SelectElement(_Buttons[_ButtonPlayerName]); _EditMode = EEditMode.PlayerName; @@ -399,7 +403,8 @@ namespace Vocaluxe.Screens { _EditMode = EEditMode.None; - CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].SelectedTag); + CProfiles.DeleteProfile(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag)); + _SelectSlideGuids.Remove(_SelectSlides[_SelectSlideProfiles].SelectedTag); int selection = _SelectSlides[_SelectSlideProfiles].Selection; if (_SelectSlides[_SelectSlideProfiles].NumValues - 1 > selection) @@ -412,14 +417,20 @@ namespace Vocaluxe.Screens { string name = String.Empty; if (_EditMode == EEditMode.PlayerName) - name = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].SelectedTag); + name = CProfiles.GetPlayerName(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag)); int selectedProfileID = _SelectSlides[_SelectSlideProfiles].SelectedTag; _SelectSlides[_SelectSlideProfiles].Clear(); + _SelectSlideGuids.Clear(); CProfile[] profiles = CProfiles.GetProfiles(); + int i = 0; foreach (CProfile profile in profiles) - _SelectSlides[_SelectSlideProfiles].AddValue(profile.PlayerName, null, profile.ID); + { + _SelectSlides[_SelectSlideProfiles].AddValue(profile.PlayerName, null, i); + _SelectSlideGuids.Add(i, profile.ID); + i++; + } if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0) { @@ -433,14 +444,14 @@ namespace Vocaluxe.Screens if (!keep) { - _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(selectedProfileID); - _SelectSlides[_SelectSlideUserRole].Selection = (int)CProfiles.GetUserRoleProfile(selectedProfileID); - _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(selectedProfileID); - _SelectSlides[_SelectSlideAvatars].SelectedTag = CProfiles.GetAvatarID(selectedProfileID); + _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_GetIdFromTag(selectedProfileID)); + _SelectSlides[_SelectSlideUserRole].Selection = (int)CProfiles.GetUserRoleProfile(_GetIdFromTag(selectedProfileID)); + _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_GetIdFromTag(selectedProfileID)); + _SelectSlides[_SelectSlideAvatars].SelectedTag = CProfiles.GetAvatarID(_GetIdFromTag(selectedProfileID)); } if (_EditMode == EEditMode.PlayerName) - CProfiles.SetPlayerName(_SelectSlides[_SelectSlideProfiles].SelectedTag, name); + CProfiles.SetPlayerName(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag), name); } _ProfilesChanged = false; } @@ -459,12 +470,20 @@ namespace Vocaluxe.Screens if (keep) { _SelectSlides[_SelectSlideAvatars].SelectedTag = selectedAvatarID; - CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].SelectedTag, selectedAvatarID); + CProfiles.SetAvatar(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag), selectedAvatarID); } else - _SelectSlides[_SelectSlideAvatars].SelectedTag = CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].SelectedTag); + _SelectSlides[_SelectSlideAvatars].SelectedTag = CProfiles.GetAvatarID(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag)); _AvatarsChanged = false; } + + private Guid _GetIdFromTag(int tag) + { + if (tag == -1 || !_SelectSlideGuids.ContainsKey(tag)) + return Guid.Empty; + else + return _SelectSlideGuids[tag]; + } } } \ No newline at end of file diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index 1374ae86..50ff879b 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -215,12 +215,13 @@ namespace VocaluxeLib public interface IProfiles { CProfile[] GetProfiles(); - EGameDifficulty GetDifficulty(int profileID); - string GetPlayerName(int profileID, int playerNum = 0); - CTextureRef GetAvatar(int profileID); + int GetNum(); + EGameDifficulty GetDifficulty(Guid profileID); + string GetPlayerName(Guid profileID, int playerNum = 0); + CTextureRef GetAvatar(Guid profileID); CAvatar GetAvatarByFilename(string fileName); - bool IsProfileIDValid(int profileID); - bool IsGuest(int profileID); + bool IsProfileIDValid(Guid profileID); + bool IsGuest(Guid profileID); void AddProfileChangedCallback(ProfileChangedCallback notification); } diff --git a/VocaluxeLib/Menu/CMenuPartyNameSelection.cs b/VocaluxeLib/Menu/CMenuPartyNameSelection.cs index 423d89e8..b1baa36e 100644 --- a/VocaluxeLib/Menu/CMenuPartyNameSelection.cs +++ b/VocaluxeLib/Menu/CMenuPartyNameSelection.cs @@ -15,6 +15,7 @@ // along with Vocaluxe. If not, see . #endregion +using System; using System.Collections.Generic; using System.Windows.Forms; using VocaluxeLib.Draw; @@ -53,7 +54,7 @@ namespace VocaluxeLib.Menu private bool _SelectingKeyboardActive; private bool _SelectingFast; private int _SelectingFastPlayerNr; - private int _SelectedProfileID = -1; + private Guid _SelectedProfileID = Guid.Empty; private CStatic _ChooseAvatarStatic; private int _OldMouseX; @@ -70,7 +71,7 @@ namespace VocaluxeLib.Menu private const string _SelectSlidePlayer = "SelectSlidePlayer"; private const string _NameSelection = "NameSelection"; - protected List[] _TeamList; + protected List[] _TeamList; public override void Init() { @@ -98,13 +99,13 @@ namespace VocaluxeLib.Menu _NumPlayer = numPlayer; _NumPlayerTeams = numPlayerTeams; - _TeamList = new List[_NumTeams > 0 ? _NumTeams : 1]; + _TeamList = new List[_NumTeams > 0 ? _NumTeams : 1]; if (_NumTeams != _NumPlayerTeams.Length) _NumPlayerTeams = new int[_NumTeams]; for (int i = 0; i < _TeamList.Length; i++) - _TeamList[i] = new List(); + _TeamList[i] = new List(); _Teams = _NumTeams > 0; @@ -115,7 +116,7 @@ namespace VocaluxeLib.Menu _UpdateNextButtonVisibility(); } - public void SetPartyModeProfiles(List[] teamProfiles) + public void SetPartyModeProfiles(List[] teamProfiles) { _TeamList = teamProfiles; _UpdateSlides(); @@ -135,9 +136,9 @@ namespace VocaluxeLib.Menu { case Keys.Enter: //Check, if a player is selected - if (_NameSelections[_NameSelection].Selection > -1) + if (_NameSelections[_NameSelection].SelectedID != Guid.Empty) { - _SelectedProfileID = _NameSelections[_NameSelection].Selection; + _SelectedProfileID = _NameSelections[_NameSelection].SelectedID; if (!CBase.Profiles.IsProfileIDValid(_SelectedProfileID)) return true; @@ -373,7 +374,7 @@ namespace VocaluxeLib.Menu base.HandleMouse(mouseEvent); //Check if LeftButton is hold and Select-Mode inactive - if (mouseEvent.LBH && _SelectedProfileID < 0 && !_SelectingFast) + if (mouseEvent.LBH && _SelectedProfileID == Guid.Empty && !_SelectingFast) { //Save mouse-coords _OldMouseX = mouseEvent.X; @@ -382,8 +383,8 @@ namespace VocaluxeLib.Menu if (_NameSelections[_NameSelection].IsOverTile(mouseEvent)) { //Get player-number of tile - _SelectedProfileID = _NameSelections[_NameSelection].TilePlayerNr(mouseEvent); - if (_SelectedProfileID != -1) + _SelectedProfileID = _NameSelections[_NameSelection].TilePlayerID(mouseEvent); + if (_SelectedProfileID != Guid.Empty) { //Update of Drag/Drop-Texture CStatic selectedPlayer = _NameSelections[_NameSelection].TilePlayerAvatar(mouseEvent); @@ -396,7 +397,7 @@ namespace VocaluxeLib.Menu } } //Check if LeftButton is hold and Select-Mode active - if (mouseEvent.LBH && _SelectedProfileID >= 0 && !_SelectingFast) + if (mouseEvent.LBH && _SelectedProfileID != Guid.Empty && !_SelectingFast) { //Update coords for Drag/Drop-Texture _ChooseAvatarStatic.X += mouseEvent.X - _OldMouseX; @@ -405,7 +406,7 @@ namespace VocaluxeLib.Menu _OldMouseY = mouseEvent.Y; } // LeftButton isn't hold anymore, but Select-Mode is still active -> "Drop" of Avatar - else if (_SelectedProfileID >= 0 && !_SelectingFast) + else if (_SelectedProfileID != Guid.Empty && !_SelectingFast) { //Check if mouse is in drop-area if (CHelper.IsInBounds(_SelectSlides[_SelectSlidePlayer].Rect, mouseEvent)) @@ -417,7 +418,7 @@ namespace VocaluxeLib.Menu } //Reset variables - _SelectedProfileID = -1; + _SelectedProfileID = Guid.Empty; _ChooseAvatarStatic.Visible = false; } if (mouseEvent.LB && _SelectingFast) @@ -425,8 +426,8 @@ namespace VocaluxeLib.Menu if (_NameSelections[_NameSelection].IsOverTile(mouseEvent)) { //Get player-number of tile - _SelectedProfileID = _NameSelections[_NameSelection].TilePlayerNr(mouseEvent); - if (_SelectedProfileID != -1) + _SelectedProfileID = _NameSelections[_NameSelection].TilePlayerID(mouseEvent); + if (_SelectedProfileID != Guid.Empty) { if (!CBase.Profiles.IsProfileIDValid(_SelectedProfileID)) return true; @@ -475,8 +476,8 @@ namespace VocaluxeLib.Menu if (mouseEvent.LD && _NameSelections[_NameSelection].IsOverTile(mouseEvent) && !_SelectingFast) { - _SelectedProfileID = _NameSelections[_NameSelection].TilePlayerNr(mouseEvent); - if (_SelectedProfileID > -1) + _SelectedProfileID = _NameSelections[_NameSelection].TilePlayerID(mouseEvent); + if (_SelectedProfileID != Guid.Empty) { if (!CBase.Profiles.IsProfileIDValid(_SelectedProfileID)) return true; @@ -493,7 +494,7 @@ namespace VocaluxeLib.Menu if (_SelectSlides[_SelectSlidePlayer].Selected && _TeamList[_CurrentTeam].Count > _SelectSlides[_SelectSlidePlayer].Selection) { int currentSelection = _SelectSlides[_SelectSlidePlayer].Selection; - int id = _TeamList[_CurrentTeam][currentSelection]; + Guid id = _TeamList[_CurrentTeam][currentSelection]; _RemovePlayer(_CurrentTeam, id); _UpdatePlayerSlide(); exit = false; @@ -577,9 +578,9 @@ namespace VocaluxeLib.Menu { _NumTeams++; int[] numPlayerTeams = _NumPlayerTeams; - List[] teamList = _TeamList; + List[] teamList = _TeamList; _NumPlayerTeams = new int[_NumTeams]; - _TeamList = new List[_NumTeams]; + _TeamList = new List[_NumTeams]; for (int i = 0; i < _NumPlayerTeams.Length; i++) { if (i < numPlayerTeams.Length) @@ -590,7 +591,7 @@ namespace VocaluxeLib.Menu else { _NumPlayerTeams[i] = _NumPlayer; - _TeamList[i] = new List(); + _TeamList[i] = new List(); } } } @@ -721,7 +722,7 @@ namespace VocaluxeLib.Menu } } - private void _AddPlayer(int team, int profileID) + private void _AddPlayer(int team, Guid profileID, bool updateElements=true) { if (_NumPlayerTeams[team] == _TeamList[team].Count && !_ChangePlayerNumDynamic) return; @@ -731,17 +732,20 @@ namespace VocaluxeLib.Menu _NameSelections[_NameSelection].UseProfile(profileID); _TeamList[team].Add(profileID); - _UpdatePlayerSlide(); - _UpdateNextButtonVisibility(); + if (updateElements) + { + _UpdatePlayerSlide(); + _UpdateNextButtonVisibility(); + } } private void _RemoveAllPlayer() { for (int t = 0; t < _TeamList.Length; t++) { - List ids = new List(); + List ids = new List(); ids.AddRange(_TeamList[t]); - foreach (int id in ids) + foreach (Guid id in ids) _RemovePlayer(t, id); } } @@ -750,7 +754,7 @@ namespace VocaluxeLib.Menu { if (_TeamList[team].Count > index) { - int id = _TeamList[team][index]; + Guid id = _TeamList[team][index]; _TeamList[team].RemoveAt(index); _NameSelections[_NameSelection].RemoveUsedProfile(id); } @@ -758,7 +762,7 @@ namespace VocaluxeLib.Menu _UpdateNextButtonVisibility(); } - private void _RemovePlayer(int team, int profileID) + private void _RemovePlayer(int team, Guid profileID) { _TeamList[team].Remove(profileID); _NameSelections[_NameSelection].RemoveUsedProfile(profileID); @@ -773,10 +777,13 @@ namespace VocaluxeLib.Menu { for (int p = 0; p < _NumPlayerTeams[t]; p++) { - int profileID = _NameSelections[_NameSelection].GetRandomUnusedProfile(); - _AddPlayer(t, profileID); + Guid profileID = _NameSelections[_NameSelection].GetRandomUnusedProfile(); + _AddPlayer(t, profileID, false); } } + + _UpdatePlayerSlide(); + _UpdateButtonVisibility(); } private void _UpdateNextButtonVisibility() diff --git a/VocaluxeLib/Menu/CNameSelection.cs b/VocaluxeLib/Menu/CNameSelection.cs index 37806b5f..c1ee50b0 100644 --- a/VocaluxeLib/Menu/CNameSelection.cs +++ b/VocaluxeLib/Menu/CNameSelection.cs @@ -16,6 +16,7 @@ #endregion using System; +using System.Linq; using System.Collections.Generic; using System.Windows.Forms; using System.Xml.Serialization; @@ -60,11 +61,11 @@ namespace VocaluxeLib.Menu { private class CTile { - public int ProfileID; + public Guid ProfileID; public readonly CStatic Avatar; public readonly CText Name; - public CTile(CStatic av, CText tex, int pID) + public CTile(CStatic av, CText tex, Guid pID) { Avatar = av; Name = tex; @@ -96,12 +97,12 @@ namespace VocaluxeLib.Menu public int Offset; private int _ActualSelection = -1; - public int Selection = -1; + public Guid SelectedID = Guid.Empty; private int _Player = -1; - private readonly List _VisibleProfiles; - private readonly List _UsedProfiles; + private readonly List _VisibleProfiles; + private readonly List _UsedProfiles; private CStatic _PlayerSelector; @@ -122,8 +123,8 @@ namespace VocaluxeLib.Menu _Theme = new SThemeNameSelection {Tiles = new SThemeNameSelectionTiles {Name = new SThemeNameSelectionName()}}; _Tiles = new List(); - _VisibleProfiles = new List(); - _UsedProfiles = new List(); + _VisibleProfiles = new List(); + _UsedProfiles = new List(); } public CNameSelection(SThemeNameSelection theme, int partyModeID) @@ -132,8 +133,8 @@ namespace VocaluxeLib.Menu _Theme = theme; _Tiles = new List(); - _VisibleProfiles = new List(); - _UsedProfiles = new List(); + _VisibleProfiles = new List(); + _UsedProfiles = new List(); ThemeLoaded = true; } @@ -244,7 +245,7 @@ namespace VocaluxeLib.Menu case Keys.Right: if (_ActualSelection + 1 < _Tiles.Count) { - if (_Tiles[_ActualSelection + 1].ProfileID != -1) + if (_Tiles[_ActualSelection + 1].ProfileID != Guid.Empty) _ActualSelection++; } else @@ -279,7 +280,7 @@ namespace VocaluxeLib.Menu case Keys.Down: if (_ActualSelection + _Theme.Tiles.NumW < _Tiles.Count) { - if (_Tiles[_ActualSelection + _Theme.Tiles.NumW].ProfileID != -1) + if (_Tiles[_ActualSelection + _Theme.Tiles.NumW].ProfileID != Guid.Empty) _ActualSelection += _Theme.Tiles.NumW; } else @@ -289,11 +290,11 @@ namespace VocaluxeLib.Menu if (offset != Offset) { _ActualSelection = _ActualSelection - _Tiles.Count + _Theme.Tiles.NumW; - if (_Tiles[_ActualSelection].ProfileID == -1) + if (_Tiles[_ActualSelection].ProfileID == Guid.Empty) { for (int i = _Tiles.Count - 1; i >= 0; i--) { - if (_Tiles[i].ProfileID != -1) + if (_Tiles[i].ProfileID != Guid.Empty) { _ActualSelection = i; break; @@ -306,9 +307,9 @@ namespace VocaluxeLib.Menu } if (Offset * _Tiles.Count + _ActualSelection < _VisibleProfiles.Count) - Selection = _VisibleProfiles[Offset * _Tiles.Count + _ActualSelection]; + SelectedID = _VisibleProfiles.ElementAt(Offset * _Tiles.Count + _ActualSelection); else - Selection = -1; + SelectedID = Guid.Empty; } public void HandleMouse(SMouseEvent mevent) @@ -320,9 +321,9 @@ namespace VocaluxeLib.Menu _ActualSelection = i; if (Offset * _Tiles.Count + _ActualSelection < _VisibleProfiles.Count) - Selection = _VisibleProfiles[Offset * _Tiles.Count + _ActualSelection]; + SelectedID = _VisibleProfiles.ElementAt(Offset * _Tiles.Count + _ActualSelection); else - Selection = -1; + SelectedID = Guid.Empty; } } } @@ -330,7 +331,7 @@ namespace VocaluxeLib.Menu public void FastSelection(bool active, int player) { //Overwrite player-selection; Same profile, but other player - if (active && Selection != -1) + if (active && SelectedID != Guid.Empty) { _Player = player; _PlayerSelector.Color = CBase.Themes.GetPlayerColor(player); @@ -338,7 +339,7 @@ namespace VocaluxeLib.Menu //Normal activation else if (active) { - Selection = 0; + SelectedID = _VisibleProfiles.ElementAt(0); _ActualSelection = 0; _Player = player; _PlayerSelector.Color = CBase.Themes.GetPlayerColor(player); @@ -347,7 +348,7 @@ namespace VocaluxeLib.Menu //Deactivate else { - Selection = -1; + SelectedID = Guid.Empty; _ActualSelection = -1; _Player = -1; _PlayerSelector.Visible = false; @@ -375,14 +376,14 @@ namespace VocaluxeLib.Menu _Tiles[i].Avatar.Texture = CBase.Profiles.GetAvatar(_VisibleProfiles[i + offset * _Tiles.Count]); _Tiles[i].Avatar.Color = new SColorF(1, 1, 1, 1); _Tiles[i].Name.Text = CBase.Profiles.GetPlayerName(_VisibleProfiles[i + offset * _Tiles.Count]); - _Tiles[i].ProfileID = _VisibleProfiles[i + offset * _Tiles.Count]; + _Tiles[i].ProfileID = _VisibleProfiles.ElementAt(i + offset * _Tiles.Count); } else { _Tiles[i].Avatar.Texture = _TextureEmptyTile; _Tiles[i].Avatar.Color = _ColorEmptyTile; _Tiles[i].Name.Text = ""; - _Tiles[i].ProfileID = -1; + _Tiles[i].ProfileID = Guid.Empty; } } Offset = offset; @@ -399,7 +400,7 @@ namespace VocaluxeLib.Menu return isOver; } - public int TilePlayerNr(SMouseEvent mevent) + public Guid TilePlayerID(SMouseEvent mevent) { foreach (CTile tile in _Tiles) { @@ -407,7 +408,7 @@ namespace VocaluxeLib.Menu return tile.ProfileID; } - return -1; + return Guid.Empty; } public CStatic TilePlayerAvatar(SMouseEvent mevent) @@ -442,9 +443,9 @@ namespace VocaluxeLib.Menu _PrepareTiles(); } - public void UseProfile(int id) + public void UseProfile(Guid id) { - if (id > -1) + if (id != Guid.Empty) { if (!_UsedProfiles.Contains(id) && CBase.Profiles.IsProfileIDValid(id) && !CBase.Profiles.IsGuest(id)) { @@ -454,18 +455,18 @@ namespace VocaluxeLib.Menu } } - public void RemoveUsedProfile(int id) + public void RemoveUsedProfile(Guid id) { - if (id > -1) + if (id != Guid.Empty) { _UsedProfiles.Remove(id); UpdateList(); } } - public int GetRandomUnusedProfile() + public Guid GetRandomUnusedProfile() { - int id = -1; + Guid id = Guid.Empty; if (_VisibleProfiles.Count == 0) return id; @@ -473,12 +474,12 @@ namespace VocaluxeLib.Menu if (_VisibleProfiles.Count == _UsedProfiles.Count) return id; - while (id == -1) + while (id == Guid.Empty) { int rand = CBase.Game.GetRandom(_VisibleProfiles.Count); if (_UsedProfiles.Contains(_VisibleProfiles[rand])) continue; - id = _VisibleProfiles[rand]; + id = _VisibleProfiles.ElementAt(rand); } return id; @@ -496,7 +497,7 @@ namespace VocaluxeLib.Menu var tileStatic = new CStatic(_PartyModeID, _TextureEmptyTile, _ColorEmptyTile, rect) {Aspect = EAspect.Crop}; var tileText = new CText(rect.X + rect.W / 2, rect.Y + rect.H + _Theme.Tiles.Name.Space, rect.Z, _Theme.Tiles.Name.Height, rect.W, EAlignment.Center, _Theme.Tiles.Name.Style, _Theme.Tiles.Name.Font, _ColorNameTile, ""); - _Tiles.Add(new CTile(tileStatic, tileText, -1)); + _Tiles.Add(new CTile(tileStatic, tileText, Guid.Empty)); } } _Rect.X = MaxRect.X; diff --git a/VocaluxeLib/Profile/CProfile.cs b/VocaluxeLib/Profile/CProfile.cs index 2e168b97..48dd60fc 100644 --- a/VocaluxeLib/Profile/CProfile.cs +++ b/VocaluxeLib/Profile/CProfile.cs @@ -42,7 +42,7 @@ namespace VocaluxeLib.Profile #pragma warning restore 649 } - [XmlIgnore] public int ID; + [DefaultValue(null)] public Guid ID; public string PlayerName; [XmlIgnore] public string FilePath; @@ -73,6 +73,7 @@ namespace VocaluxeLib.Profile public CProfile() { + ID = Guid.NewGuid(); PlayerName = String.Empty; Difficulty = EGameDifficulty.TR_CONFIG_EASY; UserRole = EUserRole.TR_USERROLE_NORMAL; @@ -92,6 +93,12 @@ namespace VocaluxeLib.Profile try { xml.Deserialize(FilePath, this); + //If ID couldn't be loaded, generate a new one and save it + if (ID == Guid.Empty) + { + ID = Guid.NewGuid(); + SaveProfile(); + } } catch (Exception e) { @@ -112,7 +119,10 @@ namespace VocaluxeLib.Profile var old = xml.Deserialize(FilePath); string newXml = ser.Serialize(old.Info); xml.DeserializeString(newXml, this); + if (ID == null) + ID = Guid.NewGuid(); ser.Serialize(FilePath, this); + } catch (Exception e2) { diff --git a/VocaluxeLib/Structs.cs b/VocaluxeLib/Structs.cs index 09a1b960..eef91b2a 100644 --- a/VocaluxeLib/Structs.cs +++ b/VocaluxeLib/Structs.cs @@ -358,7 +358,7 @@ namespace VocaluxeLib #region Game public struct SPlayer { - public int ProfileID; + public Guid ProfileID; public double Points; public double PointsLineBonus; public double PointsGoldenNotes; diff --git a/VocaluxeLib/Xml/CXmlDeserializer.cs b/VocaluxeLib/Xml/CXmlDeserializer.cs index df8c7879..0a3b6e70 100644 --- a/VocaluxeLib/Xml/CXmlDeserializer.cs +++ b/VocaluxeLib/Xml/CXmlDeserializer.cs @@ -213,6 +213,8 @@ namespace VocaluxeLib.Xml return value; } } + if (type == typeof(Guid)) + return Guid.Parse(node.InnerText); if (type == typeof(string)) return node == null ? null : node.InnerText; if (type.IsPrimitive) diff --git a/VocaluxeLib/Xml/CXmlSerializer.cs b/VocaluxeLib/Xml/CXmlSerializer.cs index 46b44539..05188013 100644 --- a/VocaluxeLib/Xml/CXmlSerializer.cs +++ b/VocaluxeLib/Xml/CXmlSerializer.cs @@ -96,6 +96,10 @@ namespace VocaluxeLib.Xml writer.WriteEndElement(); } } + else if (type == typeof(Guid)) + { + writer.WriteElementString(name, value.ToString()); + } else if (type.IsNullable()) _WriteValue(writer, name, type.GetGenericArguments()[0], value, isAttribute, arrayItemName, nameAttribute); else if (type.IsList() || type.IsArray) From 06aee7f54782c9d62b92cac7d45f5a76dd710b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Mon, 28 Dec 2015 11:24:47 +0100 Subject: [PATCH 02/21] [player-guid] Guest3 is a guest again... --- Output/Profiles/guest3.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Output/Profiles/guest3.xml b/Output/Profiles/guest3.xml index acaa3bb6..9cb86c18 100644 --- a/Output/Profiles/guest3.xml +++ b/Output/Profiles/guest3.xml @@ -3,7 +3,7 @@ fd433fc4-60c0-4521-87ef-53aa7d252337 Guest 3 TR_CONFIG_EASY - TR_USERROLE_NORMAL + TR_USERROLE_GUEST TR_CONFIG_ON Avatar_m.png \ No newline at end of file From 416db5b518bfb8da7a9266fc4ea7616643fae97f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Mon, 28 Dec 2015 12:12:38 +0100 Subject: [PATCH 03/21] [player-guid] Fixed profiles-handling in CScreenProfiles #183 --- Vocaluxe/Screens/CScreenProfiles.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index 7aca2b7b..9575be1b 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -16,6 +16,7 @@ #endregion using System; +using System.Linq; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; @@ -419,7 +420,7 @@ namespace Vocaluxe.Screens if (_EditMode == EEditMode.PlayerName) name = CProfiles.GetPlayerName(_GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag)); - int selectedProfileID = _SelectSlides[_SelectSlideProfiles].SelectedTag; + Guid selectedProfileID = _GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag); _SelectSlides[_SelectSlideProfiles].Clear(); _SelectSlideGuids.Clear(); @@ -434,20 +435,20 @@ namespace Vocaluxe.Screens if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0) { - if (selectedProfileID != -1) - _SelectSlides[_SelectSlideProfiles].SelectedTag = selectedProfileID; + if (selectedProfileID != Guid.Empty) + _SelectSlides[_SelectSlideProfiles].SelectedTag = _SelectSlideGuids.FirstOrDefault(x => x.Value.Equals(selectedProfileID)).Key; else { _SelectSlides[_SelectSlideProfiles].Selection = 0; - selectedProfileID = _SelectSlides[_SelectSlideProfiles].SelectedTag; + selectedProfileID = _GetIdFromTag(_SelectSlides[_SelectSlideProfiles].SelectedTag); } if (!keep) { - _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_GetIdFromTag(selectedProfileID)); - _SelectSlides[_SelectSlideUserRole].Selection = (int)CProfiles.GetUserRoleProfile(_GetIdFromTag(selectedProfileID)); - _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_GetIdFromTag(selectedProfileID)); - _SelectSlides[_SelectSlideAvatars].SelectedTag = CProfiles.GetAvatarID(_GetIdFromTag(selectedProfileID)); + _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(selectedProfileID); + _SelectSlides[_SelectSlideUserRole].Selection = (int)CProfiles.GetUserRoleProfile(selectedProfileID); + _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(selectedProfileID); + _SelectSlides[_SelectSlideAvatars].SelectedTag = CProfiles.GetAvatarID(selectedProfileID); } if (_EditMode == EEditMode.PlayerName) From d94868f4660c092bc24ee4e1ceeccc1e7aa48dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Thu, 7 Sep 2017 16:56:31 +0200 Subject: [PATCH 04/21] Fixed drawing non-latin character not correctly, closes #310 --- Vocaluxe/Base/CCoverGenerator.cs | 4 ++-- Vocaluxe/Base/Fonts/CGlyph.cs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Vocaluxe/Base/CCoverGenerator.cs b/Vocaluxe/Base/CCoverGenerator.cs index 1ff20fa9..39034d1b 100644 --- a/Vocaluxe/Base/CCoverGenerator.cs +++ b/Vocaluxe/Base/CCoverGenerator.cs @@ -84,7 +84,7 @@ namespace Vocaluxe.Base if (_WidthTrimmed < 0f) { string text = Text.TrimEnd(null); - _WidthTrimmed = text.Length == Text.Length ? Width : _Graphics.MeasureString(text, _Font, -1, StringFormat.GenericTypographic).Width; + _WidthTrimmed = text.Length == Text.Length ? Width : _Graphics.MeasureString(text, _Font).Width; } return _WidthTrimmed; } @@ -94,7 +94,7 @@ namespace Vocaluxe.Base public CTextElement(string text, Graphics g, Font font) { Text = text; - SizeF dimensions = g.MeasureString(text, font, -1, StringFormat.GenericTypographic); + SizeF dimensions = g.MeasureString(text, font); Width = dimensions.Width; Height = (dimensions.Height + font.Height) / 2; _Graphics = g; diff --git a/Vocaluxe/Base/Fonts/CGlyph.cs b/Vocaluxe/Base/Fonts/CGlyph.cs index 6b949903..f9bc02ed 100644 --- a/Vocaluxe/Base/Fonts/CGlyph.cs +++ b/Vocaluxe/Base/Fonts/CGlyph.cs @@ -51,7 +51,13 @@ namespace Vocaluxe.Base.Fonts if (chr != ' ') { //Gets exact height and width for drawing more than 1 char. But width is to small to draw char on bitmap as e.g. italic chars will get cropped - _BoundingBox = g.MeasureString(chrString, fo, -1, StringFormat.GenericTypographic); + //See https://stackoverflow.com/questions/11708621/how-to-measure-width-of-a-string-precisely + StringFormat format = StringFormat.GenericTypographic; + RectangleF rect = new RectangleF(0, 0, 1000, 1000); + CharacterRange[] ranges = { new CharacterRange(0, chrString.Length) }; + format.SetMeasurableCharacterRanges(ranges); + _BoundingBox = g.MeasureCharacterRanges(chrString, fo, rect, format)[0].GetBounds(g).Size; + // ReSharper disable CompareOfFloatsByEqualityOperator if (_BoundingBox.Height == 0) // ReSharper restore CompareOfFloatsByEqualityOperator From 41cf7a5ac2572f3198c6886ef2871fbd35f65375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Thu, 28 Sep 2017 17:31:16 +0200 Subject: [PATCH 05/21] push to trigger appveyor From 4784e57370ae272a445666d89b5915644cd8de7a Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Wed, 4 Oct 2017 13:12:14 +0200 Subject: [PATCH 06/21] Refactored mutex use while closing streams in CPortAudioHandle (should fix #320) --- Vocaluxe/Lib/Sound/CPortAudioHandle.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Vocaluxe/Lib/Sound/CPortAudioHandle.cs b/Vocaluxe/Lib/Sound/CPortAudioHandle.cs index 217afafa..6443a8cb 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioHandle.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioHandle.cs @@ -74,12 +74,14 @@ namespace Vocaluxe.Lib.Sound } lock (_Mutex) { + if (_Disposed) + return; Debug.Assert(_RefCount > 0); _RefCount--; if (_RefCount == 0) PortAudio.Pa_Terminate(); + _Disposed = true; } - _Disposed = true; } public void Dispose() @@ -100,11 +102,11 @@ namespace Vocaluxe.Lib.Sound double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags, PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData) { - if (_Disposed) - throw new ObjectDisposedException("PortAudioHandle already disposed"); - lock (_Mutex) { + if (_Disposed) + throw new ObjectDisposedException("PortAudioHandle already disposed"); + PortAudio.PaError res = PortAudio.Pa_OpenStream(out stream, ref inputParameters, ref outputParameters, sampleRate, framesPerBuffer, streamFlags, streamCallback, userData); if (res == PortAudio.PaError.paNoError) @@ -157,11 +159,11 @@ namespace Vocaluxe.Lib.Sound public void CloseStream(IntPtr stream) { - if (_Disposed) - throw new ObjectDisposedException("PortAudioHandle already disposed"); - lock (_Mutex) { + if (_Disposed) + throw new ObjectDisposedException("PortAudioHandle already disposed"); + PortAudio.Pa_CloseStream(stream); _Streams.Remove(stream); } From ad5ffd7578736cfe45b0a9dc5bfa94ecc44dc46f Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Wed, 4 Oct 2017 14:20:31 +0200 Subject: [PATCH 07/21] Catch potential errors from PortAudio Close() and Dispose() --- Vocaluxe/Lib/Sound/CPortAudioHandle.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Vocaluxe/Lib/Sound/CPortAudioHandle.cs b/Vocaluxe/Lib/Sound/CPortAudioHandle.cs index 6443a8cb..81c4d9b0 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioHandle.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioHandle.cs @@ -79,7 +79,16 @@ namespace Vocaluxe.Lib.Sound Debug.Assert(_RefCount > 0); _RefCount--; if (_RefCount == 0) - PortAudio.Pa_Terminate(); + { + try + { + PortAudio.Pa_Terminate(); + } + catch (Exception ex) + { + CLog.LogError(errorText: $"Error disposing PortAudio: {ex.Message}", e: ex); + } + } _Disposed = true; } } @@ -164,7 +173,14 @@ namespace Vocaluxe.Lib.Sound if (_Disposed) throw new ObjectDisposedException("PortAudioHandle already disposed"); - PortAudio.Pa_CloseStream(stream); + try + { + PortAudio.Pa_CloseStream(stream); + } + catch (Exception ex) + { + CLog.LogError(errorText:$"Error closing stream: {ex.Message}", e:ex); + } _Streams.Remove(stream); } } From df34766f353cef0ece17bedf5677cb81dd5d967f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 8 Oct 2017 12:40:59 +0200 Subject: [PATCH 08/21] Fixed aspect of avatars --- PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs | 1 + PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs | 3 +++ Vocaluxe/Screens/CScreenScore.cs | 3 +++ VocaluxeLib/Menu/CSelectSlide.cs | 1 + 4 files changed, 8 insertions(+) diff --git a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs index 5e10bcff..77a5eb88 100644 --- a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs +++ b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs @@ -125,6 +125,7 @@ namespace VocaluxeLib.PartyModes.Challenge _AddText(_NextPlayerTexts[_NextPlayerTexts.Count - 1]); _NextPlayerStatics.Add(GetNewStatic(_Statics[_StaticNextPlayer])); _AddStatic(_NextPlayerStatics[_NextPlayerStatics.Count - 1]); + _NextPlayerStatics[_NextPlayerStatics.Count - 1].Aspect = EAspect.Crop; } _Statics[_StaticNextPlayer].Visible = false; } diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs index 35f45351..0588abeb 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs @@ -98,6 +98,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe _CreateFields(); _Buttons[_ButtonField].Visible = false; + + _Statics[_StaticAvatarT1].Aspect = EAspect.Crop; + _Statics[_StaticAvatarT2].Aspect = EAspect.Crop; } public override bool HandleInput(SKeyEvent keyEvent) diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index 2f4f564a..249198ef 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -139,6 +139,9 @@ namespace Vocaluxe.Screens _SetVisibility(); _UpdateRatings(); _SlideShowBG.Visible = _UpdateBackground(); + + for (int p = 0; p < CGame.NumPlayers; p++) + _Statics[_StaticAvatar[p, CGame.NumPlayers - 1]].Aspect = EAspect.Crop; } public override bool UpdateGame() diff --git a/VocaluxeLib/Menu/CSelectSlide.cs b/VocaluxeLib/Menu/CSelectSlide.cs index fa6310b2..f9fef6a2 100644 --- a/VocaluxeLib/Menu/CSelectSlide.cs +++ b/VocaluxeLib/Menu/CSelectSlide.cs @@ -586,6 +586,7 @@ namespace VocaluxeLib.Menu Text = new CText(0, 0, 0, _TextH, _MaxW, EAlignment.Center, _Theme.TextStyle, _Theme.TextFont, _TextColor, "T", _PartyModeID), Img = new CStatic(_PartyModeID) }; + el.Img.Aspect = EAspect.Crop; _VisibleElements.Add(el); } } From 85ad6050f80f9c125d08ebdef1dc0f0c3ef16dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 8 Oct 2017 12:56:16 +0200 Subject: [PATCH 09/21] Fixed lyrics visibility (closes #322) --- Vocaluxe/Screens/CScreenSing.cs | 49 +++++++++++++++++---------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 7bf7e042..c082e1bd 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -611,35 +611,38 @@ namespace Vocaluxe.Screens private void _SetDuetLyricsVisibility(bool isDuet) { - _Statics[_StaticLyricsDuet].Visible = isDuet; - _Lyrics[_LyricMainDuet].Visible = isDuet; - _Lyrics[_LyricSubDuet].Visible = isDuet; - - if (isDuet) - { - _Lyrics[_LyricMainTop].Visible = false; - _Lyrics[_LyricSubTop].Visible = false; - _Statics[_StaticLyricsTop].Visible = false; - } - else - { - bool lyricsOnTop = CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_TOP - || CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTH - || (CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_DYNAMIC && _DynamicLyricsTop); - _Lyrics[_LyricMainTop].Visible = lyricsOnTop; - _Lyrics[_LyricSubTop].Visible = lyricsOnTop; - _Statics[_StaticLyricsTop].Visible = lyricsOnTop; - } } private void _SetNormalLyricsVisibility() { - bool visible = CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTTOM + bool bottomLyricsVisible = CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTTOM || CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTH || (CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_DYNAMIC && _DynamicLyricsBottom); - _Lyrics[_LyricMain].Visible = visible; - _Lyrics[_LyricSub].Visible = visible; - _Statics[_StaticLyrics].Visible = visible; + + bool topLyricsVisible = CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_TOP + || CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTH + || (CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_DYNAMIC && _DynamicLyricsTop); + + bool duetLyricsVisible = false; + + if (CGame.GetSong() != null && CGame.GetSong().IsDuet) + { + bottomLyricsVisible = true; + topLyricsVisible = false; + duetLyricsVisible = true; + } + + _Lyrics[_LyricMain].Visible = bottomLyricsVisible; + _Lyrics[_LyricSub].Visible = bottomLyricsVisible; + _Statics[_StaticLyrics].Visible = bottomLyricsVisible; + + _Lyrics[_LyricMainTop].Visible = topLyricsVisible; + _Lyrics[_LyricSubTop].Visible = topLyricsVisible; + _Statics[_StaticLyricsTop].Visible = topLyricsVisible; + + _Lyrics[_LyricMainDuet].Visible = duetLyricsVisible; + _Lyrics[_LyricSubDuet].Visible = duetLyricsVisible; + _Statics[_StaticLyricsDuet].Visible = duetLyricsVisible; } private void _StartSong() From 8244fd638b2b049a04729e0f3b44bddc33a6eebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 8 Oct 2017 12:56:37 +0200 Subject: [PATCH 10/21] Log missing avatar as error instead of throwing exceptions --- VocaluxeLib/Profile/CProfile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VocaluxeLib/Profile/CProfile.cs b/VocaluxeLib/Profile/CProfile.cs index 2e168b97..828c2f1c 100644 --- a/VocaluxeLib/Profile/CProfile.cs +++ b/VocaluxeLib/Profile/CProfile.cs @@ -67,7 +67,7 @@ namespace VocaluxeLib.Profile { Avatar = CBase.Profiles.GetAvatarByFilename(value); if (Avatar == null) - throw new Exception("Avatar '" + value + "' not found"); + CBase.Log.LogError("Avatar '" + value + "' not found"); } } From 4d754c0876ef354b8516e77ccd3776206d2e6bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 8 Oct 2017 12:59:46 +0200 Subject: [PATCH 11/21] Forget to remove a function... --- Vocaluxe/Screens/CScreenSing.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index c082e1bd..2a0fa1b9 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -201,8 +201,6 @@ namespace Vocaluxe.Screens CConfig.Config.Theme.PlayerInfo = (EPlayerInfo)mode; CConfig.SaveConfig(); _SetVisibility(); - if (CGame.GetSong() != null) - _SetDuetLyricsVisibility(CGame.GetSong().IsDuet); //make sure duet lyrics remain visible break; case Keys.S: @@ -596,7 +594,6 @@ namespace Vocaluxe.Screens _DynamicLyricsTop = true; } - _SetDuetLyricsVisibility(song.IsDuet); _SetNormalLyricsVisibility(); _TimerSongText.Reset(); @@ -609,10 +606,6 @@ namespace Vocaluxe.Screens _StartSong(); } - private void _SetDuetLyricsVisibility(bool isDuet) - { - } - private void _SetNormalLyricsVisibility() { bool bottomLyricsVisible = CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTTOM From 3e0eec829422c0f7ff747b00530438e77febc98a Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sat, 4 Nov 2017 14:58:48 +0100 Subject: [PATCH 12/21] Synchronize access to _PreviewStartHelperTask object (may fixes #330) --- Vocaluxe/Base/CBackgroundMusic.cs | 64 ++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 65165cf4..f9146f12 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -51,6 +51,7 @@ namespace Vocaluxe.Base private static Task _PreviewStartHelperTask; private static int _PreviewStartWaitCounter; private const int _PreviewStartWaitMaxTries = 10; + private static readonly object _PreviewStartHelperTaskLock = new Object(); public static bool VideoEnabled { @@ -256,10 +257,17 @@ namespace Vocaluxe.Base { if (_PreviewStartHelperTask != null && ( _PreviewPlayer.Length > 0 || _PreviewStartWaitCounter++ >= _PreviewStartWaitMaxTries)) { - _PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext()); - _PreviewStartHelperTask.Dispose(); - _PreviewStartHelperTask = null; - _PreviewStartWaitCounter = 0; + lock (_PreviewStartHelperTaskLock) + { + // Recheck the condition as it cloud have change before we got the lock + if (_PreviewStartHelperTask != null && (_PreviewPlayer.Length > 0 || _PreviewStartWaitCounter++ >= _PreviewStartWaitMaxTries)) + { + _PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext()); + _PreviewStartHelperTask.Dispose(); + _PreviewStartHelperTask = null; + _PreviewStartWaitCounter = 0; + } + } } if (!IsPlaying) @@ -317,28 +325,46 @@ namespace Vocaluxe.Base //Change song position only if song is changed or near to end if (songChanged || _CurPlayer.Position + 30 < _CurPlayer.Length) { - _PreviewStartHelperTask = new Task(() => + lock (_PreviewStartHelperTaskLock) { - float length = _PreviewPlayer.Length; - if (length < 1) - length = 30; // If length is unknow or invalid assume a length of 30s + // Check if the old _PreviewStartHelperTask needs to disposed + if (_PreviewStartHelperTask != null) + { + _PreviewStartHelperTask.Dispose(); + } + _PreviewStartHelperTask = new Task(() => + { + float length = _PreviewPlayer.Length; + if (length < 1) + length = 30; // If length is unknow or invalid assume a length of 30s - if (start < 0) - start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime; - if (start > length - 5f) - start = Math.Max(0f, Math.Min(length / 4f, length - 5f)); - if (start >= 0.5f) - start -= 0.5f; + if (start < 0) + start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime; + if (start > length - 5f) + start = Math.Max(0f, Math.Min(length / 4f, length - 5f)); + if (start >= 0.5f) + start -= 0.5f; - _PreviewPlayer.Position = start; - Play(); - }); + _PreviewPlayer.Position = start; + Play(); + }); + } _CurPlayer = _PreviewPlayer; } else { - _PreviewStartHelperTask.Dispose(); - _PreviewStartHelperTask = null; + if (_PreviewStartHelperTask != null) + { + lock (_PreviewStartHelperTaskLock) + { + // Recheck the condition as it cloud have change before we got the lock + if (_PreviewStartHelperTask != null) + { + _PreviewStartHelperTask.Dispose(); + _PreviewStartHelperTask = null; + } + } + } _PreviewPlayer.Position = _CurPlayer.Position; _CurPlayer = _PreviewPlayer; Play(); From a92353c9a2dab0cce7d97cb62be6dc05d937905f Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sat, 4 Nov 2017 19:34:55 +0100 Subject: [PATCH 13/21] Try to fix exceptions while closing Vocaluxe (during closing bg video) (may fixes #320) --- Vocaluxe/Base/CMain.cs | 27 ++++++- Vocaluxe/Base/CVideo.cs | 73 +++++++++++++++++++ .../Record/PortAudio/CPortAudioRecord.cs | 16 +++- 3 files changed, 110 insertions(+), 6 deletions(-) diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 3a131649..b8ec6bfe 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -822,7 +822,14 @@ namespace Vocaluxe.Base public void Close(ref CVideoStream stream) { - CVideo.Close(ref stream); + try + { + CVideo.Close(ref stream); + } + catch (NotSupportedException e) + { + CLog.LogError($"Clould not close the background video: {e.Message}"); + } } public void SetLoop(CVideoStream stream, bool loop = true) @@ -832,12 +839,26 @@ namespace Vocaluxe.Base public void Pause(CVideoStream stream) { - CVideo.Pause(stream); + try + { + CVideo.Pause(stream); + } + catch (NotSupportedException e) + { + CLog.LogError($"Clould not pause the background video: {e.Message}"); + } } public void Resume(CVideoStream stream) { - CVideo.Resume(stream); + try + { + CVideo.Resume(stream); + } + catch (NotSupportedException e) + { + CLog.LogError($"Clould not resume the background video: {e.Message}"); + } } } diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index d9400cc8..d9af124b 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -15,6 +15,7 @@ // along with Vocaluxe. If not, see . #endregion +using System; using Vocaluxe.Lib.Video; using VocaluxeLib; @@ -61,6 +62,10 @@ namespace Vocaluxe.Base public static CVideoStream Load(string videoFileName) { + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } return _VideoDecoder.Load(videoFileName); } @@ -73,41 +78,109 @@ namespace Vocaluxe.Base public static float GetLength(CVideoStream stream) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + return _VideoDecoder.GetLength(stream); } public static bool GetFrame(CVideoStream stream, float time) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + return _VideoDecoder.GetFrame(stream, time); } public static bool Skip(CVideoStream stream, float start, float gap) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + return _VideoDecoder.Skip(stream, start, gap); } public static void SetLoop(CVideoStream stream, bool loop) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + _VideoDecoder.SetLoop(stream, loop); } public static void Pause(CVideoStream stream) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + _VideoDecoder.Pause(stream); } public static void Resume(CVideoStream stream) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + _VideoDecoder.Resume(stream); } public static bool Finished(CVideoStream stream) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + return _VideoDecoder.Finished(stream); } public static void Update() { + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + _VideoDecoder.Update(); } #endregion Interface diff --git a/Vocaluxe/Lib/Sound/Record/PortAudio/CPortAudioRecord.cs b/Vocaluxe/Lib/Sound/Record/PortAudio/CPortAudioRecord.cs index 4702e400..cfc8818c 100644 --- a/Vocaluxe/Lib/Sound/Record/PortAudio/CPortAudioRecord.cs +++ b/Vocaluxe/Lib/Sound/Record/PortAudio/CPortAudioRecord.cs @@ -16,6 +16,8 @@ #endregion using System; +using System.Collections.Generic; +using System.Linq; using System.Runtime.InteropServices; using System.Threading; using Vocaluxe.Base; @@ -142,9 +144,13 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio foreach (IntPtr handle in _RecHandle) { - PortAudioSharp.PortAudio.Pa_StopStream(handle); - PortAudioSharp.PortAudio.Pa_CloseStream(handle); + if (handle != IntPtr.Zero) + { + PortAudioSharp.PortAudio.Pa_StopStream(handle); + PortAudioSharp.PortAudio.Pa_CloseStream(handle); + } } + _RecHandle = new IntPtr[_Devices.Count]; return true; } @@ -153,13 +159,17 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio /// public override void Close() { - if (_RecHandle != null) + if (_RecHandle != null && _RecHandle.Length > 0) { foreach (IntPtr handle in _RecHandle) { if (handle != IntPtr.Zero) + { _PaHandle.CloseStream(handle); + } } + + _RecHandle = new IntPtr[_Devices.Count]; } if (_PaHandle != null) { From 79bbcbdccb0eb54f2b8e1e6f0090ffd6a404c48d Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sat, 4 Nov 2017 19:47:47 +0100 Subject: [PATCH 14/21] Try to close the other modules correctly if a single one fails to close ( on program shutdown) --- Vocaluxe/Program.cs | 99 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index d18660db..136508fd 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -285,23 +285,120 @@ namespace Vocaluxe try { CController.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CController)", false, false, e); + } + + try + { CVocaluxeServer.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CVocaluxeServer)", false, false, e); + } + + try + { CGraphics.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CGraphics)", false, false, e); + } + + try + { CThemes.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CThemes)", false, false, e); + } + + try + { CCover.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CCover)", false, false, e); + } + + try + { CFonts.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CFonts)", false, false, e); + } + + try + { CBackgroundMusic.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CBackgroundMusic)", false, false, e); + } + + try + { CWebcam.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CWebcam)", false, false, e); + } + + try + { CDataBase.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CDataBase)", false, false, e); + } + + try + { CVideo.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CVideo)", false, false, e); + } + + try + { CRecord.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CRecord)", false, false, e); + } + + try + { CSound.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CSound)", false, false, e); + } + + try + { CDraw.Close(); } catch (Exception e) { - CLog.LogError("Error during shutdown!", false, false, e); + CLog.LogError("Error during shutdown! (CDraw)", false, false, e); } + GC.Collect(); // Do a GC run here before we close logs to have finalizers run try { From 52f1b8f5463fb45bceb70b31e76a5f047288d362 Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sat, 4 Nov 2017 20:13:19 +0100 Subject: [PATCH 15/21] Fix: Vocaluxe crashes when _CopyDecodedFrameToBuffer() fails --- Vocaluxe/Lib/Video/Acinerella/CDecoderThread.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Vocaluxe/Lib/Video/Acinerella/CDecoderThread.cs b/Vocaluxe/Lib/Video/Acinerella/CDecoderThread.cs index 38275210..3d7229d0 100644 --- a/Vocaluxe/Lib/Video/Acinerella/CDecoderThread.cs +++ b/Vocaluxe/Lib/Video/Acinerella/CDecoderThread.cs @@ -429,7 +429,18 @@ namespace Vocaluxe.Lib.Video.Acinerella private bool _CopyDecodedFrameToBuffer() { bool result; - var decoder = (SACDecoder)Marshal.PtrToStructure(_Videodecoder, typeof(SACDecoder)); + SACDecoder decoder; + + try + { + decoder = (SACDecoder)Marshal.PtrToStructure(_Videodecoder, typeof(SACDecoder)); + } + catch (Exception e) + { + CLog.LogError("Couldn't copy the frame to the managed environment.", false, false, e); + return false; + } + if (decoder.Buffer != IntPtr.Zero) { _LastDecodedTime = (float)decoder.Timecode; From ce4529325bc1e8eec642a2c0ebbf1f40770c105e Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Mon, 6 Nov 2017 10:08:06 +0100 Subject: [PATCH 16/21] Fix: exception when intro video is missing --- Vocaluxe/Base/CVideoPlayer.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Vocaluxe/Base/CVideoPlayer.cs b/Vocaluxe/Base/CVideoPlayer.cs index 3e0762f6..1f451396 100644 --- a/Vocaluxe/Base/CVideoPlayer.cs +++ b/Vocaluxe/Base/CVideoPlayer.cs @@ -53,6 +53,10 @@ namespace Vocaluxe.Base { _VideoTimer.Reset(); _Finished = false; + if (_VideoStream == null) + { + return; + } //CVideo.VdSkip(_VideoStream, 0f, 0f); _VideoTimer.Start(); CVideo.Resume(_VideoStream); @@ -60,12 +64,19 @@ namespace Vocaluxe.Base public void Pause() { - CVideo.Pause(_VideoStream); + if (_VideoStream != null) + { + CVideo.Pause(_VideoStream); + } _VideoTimer.Stop(); } public void Resume() { + if (_VideoStream == null) + { + return; + } CVideo.Resume(_VideoStream); _VideoTimer.Start(); } @@ -92,7 +103,7 @@ namespace Vocaluxe.Base public void PreLoad() { - if (!_Loaded) + if (!_Loaded || _VideoStream == null) { return; } @@ -111,7 +122,10 @@ namespace Vocaluxe.Base public void Close() { - CVideo.Close(ref _VideoStream); + if (_VideoStream != null) + { + CVideo.Close(ref _VideoStream); + } _Loaded = false; _Finished = false; _VideoTimer.Reset(); From 06d6be528a0c35181edf41b130000bcd0b7e4519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Thu, 16 Nov 2017 12:26:38 +0100 Subject: [PATCH 17/21] Fixed wrong song folder path that leads to not working folder-sorting --- Vocaluxe/Base/CConfig.cs | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 7db2f250..1b7fde8e 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -191,13 +191,14 @@ namespace Vocaluxe.Base public static event OnSongMenuChanged SongMenuChanged; //Folders + //We need full path for folders for matching folder path with textfile path when loading public static readonly List SongFolders = new List { #if INSTALLER Path.Combine(CSettings.DataFolder, CSettings.FolderNameSongs), - CSettings.FolderNameSongs + Path.Combine(CSettings.ProgramFolder, FolderNameSongs) #elif WIN - CSettings.FolderNameSongs + Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameSongs) #elif LINUX Path.Combine(CSettings.DataFolder, CSettings.FolderNameSongs) #endif @@ -335,15 +336,8 @@ namespace Vocaluxe.Base else Config = xml.DeserializeString(""); - if (Config.Game.SongFolder.Length > 0 && Config.Game.SongFolder[0] != "") - { - SongFolders.Clear(); - SongFolders.AddRange(Config.Game.SongFolder); - } - else - { - Config.Game.SongFolder = SongFolders.ToArray(); - } + NormalizeSongPaths(); + if ((Config.Game.ScoreAnimationTime > 0 && Config.Game.ScoreAnimationTime < 1) || Config.Game.ScoreAnimationTime < 0) Config.Game.ScoreAnimationTime = 1; @@ -625,6 +619,29 @@ namespace Vocaluxe.Base return false; } + /// + /// Set song path if none is find in config and check if every path exists + /// + public static void NormalizeSongPaths() + { + //Check if there are configured songfolders + if (Config.Game.SongFolder.Length > 0 && Config.Game.SongFolder[0] != "") + { + SongFolders.Clear(); + + foreach (string folder in Config.Game.SongFolder) + { + //Check if folder exists + if (Directory.Exists(folder)) + SongFolders.Add(folder); + } + } + + //Test if songfolders are still empty or now empty + if(Config.Game.SongFolder.Length == 0) + Config.Game.SongFolder = SongFolders.ToArray(); + } + /// /// Load command-line-parameters and their values to lists. /// From b71437ee83ac3c4babe285cd0ed8bc3f158e8083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 19 Nov 2017 13:39:42 +0100 Subject: [PATCH 18/21] More dynamically statics and texts loading for pause screen --- Vocaluxe/Screens/CScreenSing.cs | 36 +++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index a7508f67..07c8ceb6 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -50,12 +50,12 @@ namespace Vocaluxe.Screens private const string _TextSongName = "TextSongName"; private const string _TextTime = "TextTime"; - private const string _TextPause = "TextPause"; private const string _TextDuetName1 = "TextDuetName1"; private const string _TextDuetName2 = "TextDuetName2"; private const string _TextMedleyCountdown = "TextMedleyCountdown"; private string[,,] _TextScores; private string[,,] _TextNames; + private List _TextsPause; private const string _StaticSongText = "StaticSongText"; private const string _StaticLyrics = "StaticLyrics"; @@ -69,7 +69,7 @@ namespace Vocaluxe.Screens private const string _StaticLyricHelper = "StaticLyricHelper"; private const string _StaticLyricHelperDuet = "StaticLyricHelperDuet"; private const string _StaticLyricHelperTop = "StaticLyricHelperTop"; - private const string _StaticPauseBG = "StaticPauseBG"; + private List _StaticsPause; private string[,,] _StaticScores; private string[,,] _StaticAvatars; @@ -139,7 +139,7 @@ namespace Vocaluxe.Screens { base.Init(); - var texts = new List { _TextSongName, _TextTime, _TextPause, _TextDuetName1, _TextDuetName2, _TextMedleyCountdown }; + var texts = new List { _TextSongName, _TextTime, _TextDuetName1, _TextDuetName2, _TextMedleyCountdown }; _BuildTextStrings(texts); _ThemeTexts = texts.ToArray(); @@ -156,9 +156,8 @@ namespace Vocaluxe.Screens _StaticTimePointer, _StaticLyricHelper, _StaticLyricHelperDuet, - _StaticLyricHelperTop, - _StaticPauseBG - }; + _StaticLyricHelperTop + }; _BuildStaticStrings(ref statics); _ThemeStatics = statics.ToArray(); @@ -181,6 +180,21 @@ namespace Vocaluxe.Screens _TimerDuetText2 = new Stopwatch(); } + public override void LoadTheme(string xmlPath) + { + base.LoadTheme(xmlPath); + + _StaticsPause = new List(); + _TextsPause = new List(); + + //Automatically find statics and texts with pause prefix + foreach (CStatic s in _Statics.Where(s => s.ThemeLoaded && s.GetThemeName().StartsWith("StaticPause"))) + _StaticsPause.Add(s.GetThemeName()); + + foreach (CText t in _Texts.Where(s => s.ThemeLoaded && s.GetThemeName().StartsWith("TextPause"))) + _TextsPause.Add(t.GetThemeName()); + } + public override bool HandleInput(SKeyEvent keyEvent) { base.HandleInput(keyEvent); @@ -826,11 +840,17 @@ namespace Vocaluxe.Screens private void _SetPause(bool paused) { _Pause = paused; - _Statics[_StaticPauseBG].Visible = _Pause; - _Texts[_TextPause].Visible = _Pause; + + foreach(String s in _StaticsPause) + _Statics[s].Visible = _Pause; + + foreach(String s in _TextsPause) + _Texts[s].Visible = _Pause; + _Buttons[_ButtonCancel].Visible = _Pause; _Buttons[_ButtonContinue].Visible = _Pause; _Buttons[_ButtonSkip].Visible = _Pause && CGame.NumRounds > CGame.RoundNr && CGame.NumRounds > 1; + if (_Pause) CSound.Pause(_CurrentStream); else From fd1eff08676d54501f91194f16308f9558a250b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Tue, 21 Nov 2017 09:37:00 +0100 Subject: [PATCH 19/21] Added methods for restarting song/game, for #282 --- Vocaluxe/Screens/CScreenSing.cs | 42 ++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 07c8ceb6..24eb6692 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -240,7 +240,7 @@ namespace Vocaluxe.Screens if (CGame.NumRounds > CGame.RoundNr) { if (keyEvent.ModCtrl) - _LoadNextSong(); + _NextSong(); } break; case Keys.W: @@ -262,7 +262,7 @@ namespace Vocaluxe.Screens _Stop(); if (_Buttons[_ButtonSkip].Selected) { - _LoadNextSong(); + _NextSong(); _SetPause(false); } } @@ -307,7 +307,7 @@ namespace Vocaluxe.Screens if (_Buttons[_ButtonSkip].Selected) { - _LoadNextSong(); + _NextSong(); _SetPause(false); } } @@ -330,7 +330,7 @@ namespace Vocaluxe.Screens finish = true; if (finish && !_FadeOut) - _LoadNextSong(); + _NextSong(); _UpdateSongText(); _UpdateDuetNames(); @@ -463,7 +463,7 @@ namespace Vocaluxe.Screens base.OnShowFinish(); CGame.Start(); - _LoadNextSong(); + _NextSong(); } public override void Draw() @@ -547,12 +547,40 @@ namespace Vocaluxe.Screens _Texts[_TextMedleyCountdown].Text = String.Empty; } - private void _LoadNextSong() + private void _RestartRound() + { + _CloseSong(); + + CGame.ResetPlayer(); + _LoadCurrentSong(); + + _StartSong(); + } + + private void _RestartGame() + { + _CloseSong(); + + CGame.Reset(); + CGame.ResetPlayer(); + CGame.NextRound(); + _LoadCurrentSong(); + + _StartSong(); + } + + private void _NextSong() { _CloseSong(); CGame.NextRound(); + _LoadCurrentSong(); + _StartSong(); + } + + private void _LoadCurrentSong() + { if (CGame.IsFinished()) { _FinishedSinging(); @@ -654,8 +682,6 @@ namespace Vocaluxe.Screens if (!song.IsDuet) _TimerSongText.Start(); - - _StartSong(); } private void _SetNormalLyricsVisibility() From 7dbd2363dbf59d81f2cb5d675d86f1b03961d5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Tue, 21 Nov 2017 09:49:45 +0100 Subject: [PATCH 20/21] Fix: Points were assigned to not sung songs --- Vocaluxe/Screens/CScreenSing.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 2a0fa1b9..4fdc3e76 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -651,7 +651,10 @@ namespace Vocaluxe.Screens { //Need this to set other songs to points-var while (!CGame.IsFinished()) + { CGame.NextRound(); + CGame.ResetPlayer(); + } _FinishedSinging(); } From 2318b518fc1c0051cde06ad55dce574b419631d0 Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sat, 25 Nov 2017 21:04:24 +0100 Subject: [PATCH 21/21] Upgraded all projects to dotNET 4.7.1 (closes #315) (VS2015 needs a developer pack see the issue for detail) --- .../PartyModeChallenge/PartyModeChallenge.csproj | 12 +++++++++--- .../PartyModeTicTacToe/PartyModeTicTacToe.csproj | 12 +++++++++--- Vocaluxe/Vocaluxe.csproj | 14 ++++++++++++-- Vocaluxe/app.config | 4 ++-- VocaluxeLib/VocaluxeLib.csproj | 12 +++++++++--- VocaluxeTests/VocaluxeTests.csproj | 5 +++-- WebserverInitalConfig/App.config | 2 +- WebserverInitalConfig/WebserverInitalConfig.csproj | 8 +++++--- 8 files changed, 50 insertions(+), 19 deletions(-) diff --git a/PartyModes/PartyModeChallenge/PartyModeChallenge.csproj b/PartyModes/PartyModeChallenge/PartyModeChallenge.csproj index c2ecf5b3..0d1764d8 100644 --- a/PartyModes/PartyModeChallenge/PartyModeChallenge.csproj +++ b/PartyModes/PartyModeChallenge/PartyModeChallenge.csproj @@ -1,5 +1,5 @@  - + DebugWin AnyCPU @@ -10,8 +10,9 @@ Properties VocaluxeLib.PartyModes.Challenge Challenge - v4.0 - Client + v4.7.1 + + 512 @@ -25,6 +26,7 @@ 4 Off ..\..\CheckingRules.ruleset + false AnyCPU @@ -36,6 +38,7 @@ false WIN Off + false AnyCPU @@ -47,6 +50,7 @@ prompt 4 Off + false AnyCPU @@ -58,6 +62,7 @@ false LINUX Off + false bin @@ -68,6 +73,7 @@ Off prompt ManagedMinimumRules.ruleset + false diff --git a/PartyModes/PartyModeTicTacToe/PartyModeTicTacToe.csproj b/PartyModes/PartyModeTicTacToe/PartyModeTicTacToe.csproj index 2c6f46d4..6e812ce8 100644 --- a/PartyModes/PartyModeTicTacToe/PartyModeTicTacToe.csproj +++ b/PartyModes/PartyModeTicTacToe/PartyModeTicTacToe.csproj @@ -1,5 +1,5 @@  - + DebugWin AnyCPU @@ -10,8 +10,9 @@ Properties VocaluxeLib.PartyModes.TicTacToe TicTacToe - v4.0 - Client + v4.7.1 + + 512 @@ -25,6 +26,7 @@ 4 Off ..\..\CheckingRules.ruleset + false AnyCPU @@ -36,6 +38,7 @@ false WIN Off + false AnyCPU @@ -47,6 +50,7 @@ prompt 4 Off + false AnyCPU @@ -58,6 +62,7 @@ false LINUX Off + false bin @@ -68,6 +73,7 @@ Off prompt ManagedMinimumRules.ruleset + false diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 248e7a46..e98af8cd 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -1,5 +1,5 @@  - + DebugWin x86 @@ -10,7 +10,7 @@ Properties Vocaluxe Vocaluxe - v4.0 + v4.7.1 512 false Vocaluxe.CMainProgram @@ -43,6 +43,7 @@ prompt 4 Off + false x86 @@ -54,6 +55,7 @@ false WIN;ARCH_X86 Off + false x64 @@ -66,6 +68,7 @@ 4 Off ..\CheckingRules.ruleset + false x64 @@ -77,6 +80,7 @@ false WIN;ARCH_X64 Off + false x86 @@ -88,6 +92,7 @@ prompt 4 Off + false x86 @@ -99,6 +104,7 @@ false LINUX;ARCH_X86 Off + false x64 @@ -110,6 +116,7 @@ prompt 4 Off + false x64 @@ -121,6 +128,7 @@ false LINUX;ARCH_X64 Off + false x86 @@ -132,6 +140,7 @@ false WIN;ARCH_X86;INSTALLER Off + false x64 @@ -143,6 +152,7 @@ false WIN;ARCH_X64;INSTALLER Off + false diff --git a/Vocaluxe/app.config b/Vocaluxe/app.config index d1480e79..bdab2be4 100644 --- a/Vocaluxe/app.config +++ b/Vocaluxe/app.config @@ -1,11 +1,11 @@ - + - +