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