better Screens/CScreenProfiles.cs behavior
This commit is contained in:
1 parent
19339c6888
commit
2037e3edb4
2 files changed
+53
-7
No files matched your search
@@ -28,6 +28,8 @@ using VocaluxeLib.Profile;
|
||||
|
||||
namespace Vocaluxe.Base
|
||||
{
|
||||
|
||||
|
||||
static class CProfiles
|
||||
{
|
||||
private static Dictionary<int, CProfile> _Profiles;
|
||||
@@ -38,7 +40,8 @@ namespace Vocaluxe.Base
|
||||
private static Queue<int> _AvatarIDs;
|
||||
private static Object _AvatarMutex = new Object();
|
||||
|
||||
private static List<Delegate> _Callbacks;
|
||||
public delegate void ProfilesChangedNotification();
|
||||
private static List<ProfilesChangedNotification> _Callbacks;
|
||||
|
||||
public static int NumProfiles
|
||||
{
|
||||
@@ -66,11 +69,22 @@ namespace Vocaluxe.Base
|
||||
_ProfileIDs.Enqueue(i);
|
||||
}
|
||||
|
||||
_Callbacks = new List<Delegate>();
|
||||
_Callbacks = new List<ProfilesChangedNotification>();
|
||||
|
||||
LoadProfiles();
|
||||
}
|
||||
|
||||
public static void AddNotificationCallback(ProfilesChangedNotification Callback)
|
||||
{
|
||||
if (Callback == null)
|
||||
return;
|
||||
|
||||
lock (_Callbacks)
|
||||
{
|
||||
_Callbacks.Add(Callback);
|
||||
}
|
||||
}
|
||||
|
||||
public static CProfile[] GetProfiles()
|
||||
{
|
||||
List<CProfile> list = new List<CProfile>();
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user