diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index 2368532b..1965fc95 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -28,6 +28,8 @@ using VocaluxeLib.Profile; namespace Vocaluxe.Base { + + static class CProfiles { private static Dictionary _Profiles; @@ -38,7 +40,8 @@ namespace Vocaluxe.Base private static Queue _AvatarIDs; private static Object _AvatarMutex = new Object(); - private static List _Callbacks; + public delegate void ProfilesChangedNotification(); + private static List _Callbacks; public static int NumProfiles { @@ -66,11 +69,22 @@ namespace Vocaluxe.Base _ProfileIDs.Enqueue(i); } - _Callbacks = new List(); + _Callbacks = new List(); LoadProfiles(); } + public static void AddNotificationCallback(ProfilesChangedNotification Callback) + { + if (Callback == null) + return; + + lock (_Callbacks) + { + _Callbacks.Add(Callback); + } + } + public static CProfile[] GetProfiles() { List list = new List(); @@ -139,7 +153,7 @@ namespace Vocaluxe.Base profile.ID = _ProfileIDs.Dequeue(); _Profiles.Add(profile.ID, profile); } - + _Notification(); return profile.ID; } @@ -189,6 +203,7 @@ namespace Vocaluxe.Base } } } + _Notification(); } public static void LoadAvatars() @@ -223,6 +238,7 @@ namespace Vocaluxe.Base } } } + _Notification(); } public static string AddGetPlayerName(int profileID, char chr) @@ -385,6 +401,25 @@ namespace Vocaluxe.Base } #region private methods + private static void _Notification() + { + lock (_Callbacks) + { + for (int i = 0; i < _Callbacks.Count; i++) + { + try + { + _Callbacks[i](); + } + catch (Exception) + { + _Callbacks.RemoveAt(i); + } + } + + } + } + private static int _CompareByPlayerName(CProfile a, CProfile b) { return String.CompareOrdinal(a.PlayerName, b.PlayerName); @@ -409,6 +444,7 @@ namespace Vocaluxe.Base return; _Profiles.Remove(profileID); + _Notification(); } #endregion private methods } diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index 7a5ff289..27ce1d2b 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -356,14 +356,21 @@ namespace Vocaluxe.Screens private void _DeleteProfile() { + int selection = _SelectSlides[_SelectSlideProfiles].Selection; CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex); _LoadProfiles(); + + if (_SelectSlides[_SelectSlideProfiles].NumValues > selection) + _SelectSlides[_SelectSlideProfiles].Selection = selection; + else + _SelectSlides[_SelectSlideProfiles].Selection = selection - 1; UpdateGame(); } private void _LoadProfiles() { _EditMode = EEditMode.None; + int selectedProfileID = _SelectSlides[_SelectSlideProfiles].ValueIndex; _SelectSlides[_SelectSlideProfiles].Clear(); CProfile[] profiles = CProfiles.GetProfiles(); @@ -376,15 +383,17 @@ namespace Vocaluxe.Screens if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0) { - _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex); - _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex); - _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex); - _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex)); + _SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(selectedProfileID); + _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(selectedProfileID); + _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(selectedProfileID); + _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(selectedProfileID); + _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(selectedProfileID)); } } private void _LoadAvatars() { + int selectedAvatarID = _SelectSlides[_SelectSlideAvatars].ValueIndex; _SelectSlides[_SelectSlideAvatars].Clear(); CAvatar[] avatars = CProfiles.GetAvatars(); for (int i = 0; i < avatars.Length; i++) @@ -393,6 +402,7 @@ namespace Vocaluxe.Screens new STexture(-1), avatars[i].ID, -1); + _SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(selectedAvatarID); } private void _NewProfile()