rewrite of CProfiles.cs, some optimizations in CScreenProfiles.cs, added IsCapturing() to Webcam/IWebcam.cs
This commit is contained in:
1 parent
8ab93db26f
commit
e70ce5ad68
11 files changed
+520
-267
No files matched your search
@@ -806,12 +806,14 @@ namespace Vocaluxe.Base
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void UsePlayers()
|
public static void UsePlayers()
|
||||||
{
|
{
|
||||||
|
CProfile[] profiles = CProfiles.GetProfiles();
|
||||||
|
|
||||||
for (int j = 0; j < CSettings.MaxNumPlayer; j++)
|
for (int j = 0; j < CSettings.MaxNumPlayer; j++)
|
||||||
{
|
{
|
||||||
CGame.Players[j].ProfileID = -1;
|
CGame.Players[j].ProfileID = -1;
|
||||||
if (Players[j] == "")
|
if (Players[j] == "" || profiles == null)
|
||||||
continue;
|
continue;
|
||||||
CProfile[] profiles = CProfiles.GetProfiles();
|
|
||||||
for (int i = 0; i < profiles.Length; i++)
|
for (int i = 0; i < profiles.Length; i++)
|
||||||
{
|
{
|
||||||
if (Path.GetFileName(profiles[i].FileName) == Players[j] && profiles[i].Active == EOffOn.TR_CONFIG_ON)
|
if (Path.GetFileName(profiles[i].FileName) == Players[j] && profiles[i].Active == EOffOn.TR_CONFIG_ON)
|
||||||
|
|||||||
@@ -68,8 +68,6 @@ namespace Vocaluxe.Base
|
|||||||
_SongQueue.Init();
|
_SongQueue.Init();
|
||||||
Players = new SPlayer[CSettings.MaxNumPlayer];
|
Players = new SPlayer[CSettings.MaxNumPlayer];
|
||||||
ResetPlayer();
|
ResetPlayer();
|
||||||
|
|
||||||
CConfig.UsePlayers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EGameMode GameMode
|
public static EGameMode GameMode
|
||||||
|
|||||||
@@ -322,6 +322,7 @@ namespace Vocaluxe.Base
|
|||||||
CSound.Update();
|
CSound.Update();
|
||||||
CBackgroundMusic.Update();
|
CBackgroundMusic.Update();
|
||||||
CController.Update();
|
CController.Update();
|
||||||
|
CProfiles.Update();
|
||||||
|
|
||||||
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && _CurrentScreen != EScreens.ScreenSing)
|
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && _CurrentScreen != EScreens.ScreenSing)
|
||||||
CSongs.LoadCover();
|
CSongs.LoadCover();
|
||||||
|
|||||||
+374
-170
@@ -28,21 +28,55 @@ using VocaluxeLib.Profile;
|
|||||||
|
|
||||||
namespace Vocaluxe.Base
|
namespace Vocaluxe.Base
|
||||||
{
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum EProfileChangedFlags
|
||||||
|
{
|
||||||
|
None = 1,
|
||||||
|
Avatar = 2,
|
||||||
|
Profile = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void ProfileChangedCallback(EProfileChangedFlags TypeChanged);
|
||||||
|
|
||||||
static class CProfiles
|
static class CProfiles
|
||||||
{
|
{
|
||||||
|
#region enums and structs
|
||||||
|
enum EAction
|
||||||
|
{
|
||||||
|
LoadProfiles,
|
||||||
|
LoadAvatars,
|
||||||
|
AddProfile,
|
||||||
|
EditProfile,
|
||||||
|
DeleteProfile,
|
||||||
|
AddAvatar,
|
||||||
|
EditAvatar
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SChange
|
||||||
|
{
|
||||||
|
public CProfile Profile;
|
||||||
|
public CAvatar Avatar;
|
||||||
|
public EAction Action;
|
||||||
|
public int ProfileID;
|
||||||
|
}
|
||||||
|
#endregion enums and structs
|
||||||
|
|
||||||
|
#region private vars
|
||||||
private static Dictionary<int, CProfile> _Profiles;
|
private static Dictionary<int, CProfile> _Profiles;
|
||||||
private static Queue<int> _ProfileIDs;
|
private static Queue<int> _ProfileIDs;
|
||||||
private static Object _ProfileMutex = new Object();
|
|
||||||
|
|
||||||
private static Dictionary<int, CAvatar> _Avatars;
|
private static Dictionary<int, CAvatar> _Avatars;
|
||||||
private static Queue<int> _AvatarIDs;
|
private static Queue<int> _AvatarIDs;
|
||||||
private static Object _AvatarMutex = new Object();
|
|
||||||
|
|
||||||
public delegate void ProfilesChangedNotification();
|
private static Queue<SChange> _Queue = new Queue<SChange>();
|
||||||
private static List<ProfilesChangedNotification> _Callbacks;
|
private static Object _QueueMutex = new Object();
|
||||||
|
|
||||||
|
private static List<ProfileChangedCallback> _ProfileChangedCallbacks = new List<ProfileChangedCallback>();
|
||||||
|
private static bool _ProfilesChanged = false;
|
||||||
|
private static bool _AvatarsChanged = false;
|
||||||
|
#endregion private vars
|
||||||
|
|
||||||
|
#region properties
|
||||||
public static int NumProfiles
|
public static int NumProfiles
|
||||||
{
|
{
|
||||||
get { return _Profiles.Count; }
|
get { return _Profiles.Count; }
|
||||||
@@ -52,7 +86,9 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
get { return _Avatars.Count; }
|
get { return _Avatars.Count; }
|
||||||
}
|
}
|
||||||
|
#endregion properties
|
||||||
|
|
||||||
|
#region public methods
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
_Avatars = new Dictionary<int, CAvatar>();
|
_Avatars = new Dictionary<int, CAvatar>();
|
||||||
@@ -69,19 +105,213 @@ namespace Vocaluxe.Base
|
|||||||
_ProfileIDs.Enqueue(i);
|
_ProfileIDs.Enqueue(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
_Callbacks = new List<ProfilesChangedNotification>();
|
|
||||||
|
|
||||||
LoadProfiles();
|
LoadProfiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddNotificationCallback(ProfilesChangedNotification Callback)
|
public static void Update()
|
||||||
{
|
{
|
||||||
if (Callback == null)
|
lock (_QueueMutex)
|
||||||
|
{
|
||||||
|
while (_Queue.Count > 0)
|
||||||
|
{
|
||||||
|
SChange change = _Queue.Dequeue();
|
||||||
|
switch (change.Action)
|
||||||
|
{
|
||||||
|
case EAction.LoadProfiles:
|
||||||
|
_LoadProfiles();
|
||||||
|
_ProfilesChanged = true;
|
||||||
|
_AvatarsChanged = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EAction.LoadAvatars:
|
||||||
|
_LoadAvatars();
|
||||||
|
_AvatarsChanged = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EAction.AddProfile:
|
||||||
|
if (change.Profile == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
change.Profile.ID = _ProfileIDs.Dequeue();
|
||||||
|
_Profiles.Add(change.Profile.ID, change.Profile);
|
||||||
|
_ProfilesChanged = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EAction.EditProfile:
|
||||||
|
if (change.Profile == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!ICProfileIDValid(change.Profile.ID))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock (_Callbacks)
|
_Profiles[change.Profile.ID] = change.Profile;
|
||||||
|
_ProfilesChanged = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EAction.DeleteProfile:
|
||||||
|
if (!ICProfileIDValid(change.ProfileID))
|
||||||
|
break;
|
||||||
|
|
||||||
|
_DeleteProfile(change.ProfileID);
|
||||||
|
_ProfilesChanged = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EAction.AddAvatar:
|
||||||
|
if (change.Avatar == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
change.Avatar.ID = _AvatarIDs.Dequeue();
|
||||||
|
_Avatars.Add(change.Avatar.ID, change.Avatar);
|
||||||
|
_AvatarsChanged = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EAction.EditAvatar:
|
||||||
|
if (change.Avatar == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!ICAvatarIDValid(change.Avatar.ID))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_Avatars[change.Avatar.ID] = change.Avatar;
|
||||||
|
_AvatarsChanged = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_ProfileChangedCallbacks.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EProfileChangedFlags flags = EProfileChangedFlags.None;
|
||||||
|
|
||||||
|
if (_AvatarsChanged)
|
||||||
|
flags = EProfileChangedFlags.Avatar;
|
||||||
|
|
||||||
|
if (_ProfilesChanged)
|
||||||
|
flags |= EProfileChangedFlags.Profile;
|
||||||
|
|
||||||
|
if (flags != EProfileChangedFlags.None)
|
||||||
{
|
{
|
||||||
_Callbacks.Add(Callback);
|
int index = 0;
|
||||||
|
while (index < _ProfileChangedCallbacks.Count)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ProfileChangedCallbacks[index](flags);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
_ProfileChangedCallbacks.RemoveAt(index);
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_AvatarsChanged = false;
|
||||||
|
_ProfilesChanged = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddProfileChangedCallback(ProfileChangedCallback Notification)
|
||||||
|
{
|
||||||
|
_ProfileChangedCallbacks.Add(Notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LoadProfiles()
|
||||||
|
{
|
||||||
|
SChange change = new SChange();
|
||||||
|
change.Action = EAction.LoadProfiles;
|
||||||
|
|
||||||
|
lock (_QueueMutex)
|
||||||
|
{
|
||||||
|
_Queue.Enqueue(change);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LoadAvatars()
|
||||||
|
{
|
||||||
|
SChange change = new SChange();
|
||||||
|
change.Action = EAction.LoadAvatars;
|
||||||
|
|
||||||
|
lock (_QueueMutex)
|
||||||
|
{
|
||||||
|
_Queue.Enqueue(change);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddProfile(CProfile NewProfile)
|
||||||
|
{
|
||||||
|
if (NewProfile == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SChange change = new SChange();
|
||||||
|
change.Action = EAction.AddProfile;
|
||||||
|
change.Profile = NewProfile;
|
||||||
|
|
||||||
|
lock (_QueueMutex)
|
||||||
|
{
|
||||||
|
_Queue.Enqueue(change);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void EditProfile(CProfile EditProfile)
|
||||||
|
{
|
||||||
|
if (EditProfile == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SChange change = new SChange();
|
||||||
|
change.Action = EAction.EditProfile;
|
||||||
|
change.Profile = EditProfile;
|
||||||
|
|
||||||
|
lock (_QueueMutex)
|
||||||
|
{
|
||||||
|
_Queue.Enqueue(change);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DeleteProfile(int profileID)
|
||||||
|
{
|
||||||
|
if (!ICProfileIDValid(profileID))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SChange change = new SChange();
|
||||||
|
change.Action = EAction.DeleteProfile;
|
||||||
|
change.ProfileID = profileID;
|
||||||
|
|
||||||
|
lock (_QueueMutex)
|
||||||
|
{
|
||||||
|
_Queue.Enqueue(change);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddAvatar(CAvatar NewAvatar)
|
||||||
|
{
|
||||||
|
if (NewAvatar == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SChange change = new SChange();
|
||||||
|
change.Action = EAction.AddAvatar;
|
||||||
|
change.Avatar = NewAvatar;
|
||||||
|
|
||||||
|
lock (_QueueMutex)
|
||||||
|
{
|
||||||
|
_Queue.Enqueue(change);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void EditAvatar(CAvatar EditAvatar)
|
||||||
|
{
|
||||||
|
if (EditAvatar == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SChange change = new SChange();
|
||||||
|
change.Action = EAction.EditAvatar;
|
||||||
|
change.Avatar = EditAvatar;
|
||||||
|
|
||||||
|
lock (_QueueMutex)
|
||||||
|
{
|
||||||
|
_Queue.Enqueue(change);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,8 +319,6 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
List<CProfile> list = new List<CProfile>();
|
List<CProfile> list = new List<CProfile>();
|
||||||
|
|
||||||
lock (_ProfileMutex)
|
|
||||||
{
|
|
||||||
if (_Profiles.Count == 0)
|
if (_Profiles.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -101,43 +329,21 @@ namespace Vocaluxe.Base
|
|||||||
list.Add(result[i]);
|
list.Add(result[i]);
|
||||||
}
|
}
|
||||||
list.Sort(_CompareByPlayerName);
|
list.Sort(_CompareByPlayerName);
|
||||||
}
|
|
||||||
return list.ToArray();
|
return list.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CAvatar[] GetAvatars()
|
public static CAvatar[] GetAvatars()
|
||||||
{
|
{
|
||||||
CAvatar[] result = null;
|
CAvatar[] result = null;
|
||||||
lock (_AvatarMutex)
|
|
||||||
{
|
|
||||||
if (_Avatars.Count == 0)
|
if (_Avatars.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
result = new CAvatar[_Avatars.Count];
|
result = new CAvatar[_Avatars.Count];
|
||||||
_Avatars.Values.CopyTo(result, 0);
|
_Avatars.Values.CopyTo(result, 0);
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetPlayerName(int profileID, int playerNum = 0)
|
|
||||||
{
|
|
||||||
if (ICProfileIDValid(profileID))
|
|
||||||
return _Profiles[profileID].PlayerName;
|
|
||||||
|
|
||||||
string playerName = CLanguage.Translate("TR_SCREENNAMES_PLAYER");
|
|
||||||
if (playerNum > 0)
|
|
||||||
playerName += " " + playerNum;
|
|
||||||
return playerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetProfileFileName(int profileID)
|
|
||||||
{
|
|
||||||
if (!ICProfileIDValid(profileID))
|
|
||||||
return String.Empty;
|
|
||||||
|
|
||||||
return Path.GetFileName(_Profiles[profileID].FileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int NewProfile(string fileName = "")
|
public static int NewProfile(string fileName = "")
|
||||||
{
|
{
|
||||||
CProfile profile = new CProfile
|
CProfile profile = new CProfile
|
||||||
@@ -148,114 +354,53 @@ namespace Vocaluxe.Base
|
|||||||
if (File.Exists(profile.FileName))
|
if (File.Exists(profile.FileName))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
lock (_ProfileMutex)
|
|
||||||
{
|
|
||||||
profile.ID = _ProfileIDs.Dequeue();
|
profile.ID = _ProfileIDs.Dequeue();
|
||||||
_Profiles.Add(profile.ID, profile);
|
_Profiles.Add(profile.ID, profile);
|
||||||
}
|
_ProfilesChanged = true;
|
||||||
_Notification();
|
|
||||||
return profile.ID;
|
return profile.ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int NewAvatar(string fileName)
|
||||||
|
{
|
||||||
|
CAvatar avatar = new CAvatar(-1);
|
||||||
|
if (!avatar.LoadFromFile(fileName))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
avatar.ID = _AvatarIDs.Dequeue();
|
||||||
|
_Avatars.Add(avatar.ID, avatar);
|
||||||
|
_AvatarsChanged = true;
|
||||||
|
return avatar.ID;
|
||||||
|
}
|
||||||
|
|
||||||
public static void SaveProfiles()
|
public static void SaveProfiles()
|
||||||
{
|
{
|
||||||
foreach (int id in _Profiles.Keys)
|
foreach (int id in _Profiles.Keys)
|
||||||
{
|
{
|
||||||
_Profiles[id].SaveProfile();
|
_Profiles[id].SaveProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadProfiles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadProfiles()
|
public static bool ICProfileIDValid(int profileID)
|
||||||
{
|
{
|
||||||
LoadAvatars();
|
return _Profiles.ContainsKey(profileID);
|
||||||
|
|
||||||
lock (_ProfileMutex)
|
|
||||||
{
|
|
||||||
List<string> knownFiles = new List<string>();
|
|
||||||
if (_Profiles.Count > 0)
|
|
||||||
{
|
|
||||||
int[] ids = new int[_Profiles.Keys.Count];
|
|
||||||
_Profiles.Keys.CopyTo(ids, 0);
|
|
||||||
for (int i = 0; i < ids.Length; i++)
|
|
||||||
{
|
|
||||||
if (_Profiles[ids[i]].LoadProfile())
|
|
||||||
{
|
|
||||||
_Profiles[ids[i]].Avatar = _GetAvatar(_Profiles[ids[i]].AvatarFileName);
|
|
||||||
knownFiles.Add(_Profiles[ids[i]].FileName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
_Profiles.Remove(ids[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> files = new List<string>();
|
public static bool ICAvatarIDValid(int avatarID)
|
||||||
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.xml", true, true));
|
{
|
||||||
|
return _Avatars.ContainsKey(avatarID);
|
||||||
|
}
|
||||||
|
#endregion public methods
|
||||||
|
|
||||||
foreach (string file in knownFiles)
|
#region profile properties
|
||||||
|
public static string GetPlayerName(int profileID, int playerNum = 0)
|
||||||
{
|
{
|
||||||
files.Remove(file);
|
if (ICProfileIDValid(profileID))
|
||||||
}
|
return _Profiles[profileID].PlayerName;
|
||||||
|
|
||||||
foreach (string file in files)
|
string playerName = CLanguage.Translate("TR_SCREENNAMES_PLAYER");
|
||||||
{
|
if (playerNum > 0)
|
||||||
CProfile profile = new CProfile
|
playerName += " " + playerNum;
|
||||||
{
|
return playerName;
|
||||||
FileName = Path.Combine(CSettings.FolderProfiles, file)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (profile.LoadProfile())
|
|
||||||
{
|
|
||||||
profile.Avatar = _GetAvatar(profile.AvatarFileName);
|
|
||||||
profile.ID = _ProfileIDs.Dequeue();
|
|
||||||
_Profiles.Add(profile.ID, profile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_Notification();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LoadAvatars()
|
|
||||||
{
|
|
||||||
lock (_AvatarMutex)
|
|
||||||
{
|
|
||||||
List<string> knownFiles = new List<string>();
|
|
||||||
if (_Avatars.Count > 0)
|
|
||||||
{
|
|
||||||
int[] ids = new int[_Avatars.Keys.Count];
|
|
||||||
_Avatars.Keys.CopyTo(ids, 0);
|
|
||||||
for (int i = 0; i < ids.Length; i++)
|
|
||||||
{
|
|
||||||
if (_Avatars[ids[i]].Reload())
|
|
||||||
knownFiles.Add(_Avatars[ids[i]].FileName);
|
|
||||||
else
|
|
||||||
_Avatars.Remove(ids[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<string> files = new List<string>();
|
|
||||||
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.png", true, true));
|
|
||||||
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpg", true, true));
|
|
||||||
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpeg", true, true));
|
|
||||||
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.bmp", true, true));
|
|
||||||
|
|
||||||
foreach (string file in knownFiles)
|
|
||||||
{
|
|
||||||
files.Remove(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string file in files)
|
|
||||||
{
|
|
||||||
CAvatar avatar = new CAvatar(-1);
|
|
||||||
if (avatar.LoadFromFile(file))
|
|
||||||
{
|
|
||||||
avatar.ID = _AvatarIDs.Dequeue();
|
|
||||||
_Avatars.Add(avatar.ID, avatar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_Notification();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetPlayerName(int profileID, string PlayerName)
|
public static void SetPlayerName(int profileID, string PlayerName)
|
||||||
@@ -266,6 +411,14 @@ namespace Vocaluxe.Base
|
|||||||
_Profiles[profileID].PlayerName = PlayerName;
|
_Profiles[profileID].PlayerName = PlayerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetProfileFileName(int profileID)
|
||||||
|
{
|
||||||
|
if (!ICProfileIDValid(profileID))
|
||||||
|
return String.Empty;
|
||||||
|
|
||||||
|
return Path.GetFileName(_Profiles[profileID].FileName);
|
||||||
|
}
|
||||||
|
|
||||||
public static string AddGetPlayerName(int profileID, char chr)
|
public static string AddGetPlayerName(int profileID, char chr)
|
||||||
{
|
{
|
||||||
if (!ICProfileIDValid(profileID))
|
if (!ICProfileIDValid(profileID))
|
||||||
@@ -287,16 +440,6 @@ namespace Vocaluxe.Base
|
|||||||
return profile.PlayerName;
|
return profile.PlayerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ICProfileIDValid(int profileID)
|
|
||||||
{
|
|
||||||
return _Profiles.ContainsKey(profileID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ICAvatarIDValid(int avatarID)
|
|
||||||
{
|
|
||||||
return _Avatars.ContainsKey(avatarID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EGameDifficulty GetDifficulty(int profileID)
|
public static EGameDifficulty GetDifficulty(int profileID)
|
||||||
{
|
{
|
||||||
return ICProfileIDValid(profileID) ? _Profiles[profileID].Difficulty : EGameDifficulty.TR_CONFIG_NORMAL;
|
return ICProfileIDValid(profileID) ? _Profiles[profileID].Difficulty : EGameDifficulty.TR_CONFIG_NORMAL;
|
||||||
@@ -315,11 +458,6 @@ namespace Vocaluxe.Base
|
|||||||
return ICProfileIDValid(profileID) ? _Profiles[profileID].GuestProfile : EOffOn.TR_CONFIG_OFF;
|
return ICProfileIDValid(profileID) ? _Profiles[profileID].GuestProfile : EOffOn.TR_CONFIG_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EOffOn GetActive(int profileID)
|
|
||||||
{
|
|
||||||
return ICProfileIDValid(profileID) ? _Profiles[profileID].Active : EOffOn.TR_CONFIG_OFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetGuestProfile(int profileID, EOffOn option)
|
public static void SetGuestProfile(int profileID, EOffOn option)
|
||||||
{
|
{
|
||||||
if (!ICProfileIDValid(profileID))
|
if (!ICProfileIDValid(profileID))
|
||||||
@@ -328,10 +466,16 @@ namespace Vocaluxe.Base
|
|||||||
_Profiles[profileID].GuestProfile = option;
|
_Profiles[profileID].GuestProfile = option;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static EOffOn GetActive(int profileID)
|
||||||
|
{
|
||||||
|
return ICProfileIDValid(profileID) ? _Profiles[profileID].Active : EOffOn.TR_CONFIG_OFF;
|
||||||
|
}
|
||||||
|
|
||||||
public static void SetActive(int profileID, EOffOn option)
|
public static void SetActive(int profileID, EOffOn option)
|
||||||
{
|
{
|
||||||
if (!ICProfileIDValid(profileID))
|
if (!ICProfileIDValid(profileID))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_Profiles[profileID].Active = option;
|
_Profiles[profileID].Active = option;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,7 +509,9 @@ namespace Vocaluxe.Base
|
|||||||
|
|
||||||
return _Profiles[profileID].Avatar.ID;
|
return _Profiles[profileID].Avatar.ID;
|
||||||
}
|
}
|
||||||
|
#endregion profile properties
|
||||||
|
|
||||||
|
#region avatar texture
|
||||||
public static STexture GetAvatarTexture(int avatarID)
|
public static STexture GetAvatarTexture(int avatarID)
|
||||||
{
|
{
|
||||||
if (!ICAvatarIDValid(avatarID))
|
if (!ICAvatarIDValid(avatarID))
|
||||||
@@ -381,10 +527,91 @@ namespace Vocaluxe.Base
|
|||||||
|
|
||||||
return _Profiles[profileID].Avatar.Texture;
|
return _Profiles[profileID].Avatar.Texture;
|
||||||
}
|
}
|
||||||
|
#endregion avatar texture
|
||||||
|
|
||||||
public static void DeleteProfile(int profileID)
|
#region private methods
|
||||||
|
private static void _LoadProfiles()
|
||||||
{
|
{
|
||||||
lock (_ProfileMutex)
|
_LoadAvatars();
|
||||||
|
|
||||||
|
List<string> knownFiles = new List<string>();
|
||||||
|
if (_Profiles.Count > 0)
|
||||||
|
{
|
||||||
|
int[] ids = new int[_Profiles.Keys.Count];
|
||||||
|
_Profiles.Keys.CopyTo(ids, 0);
|
||||||
|
for (int i = 0; i < ids.Length; i++)
|
||||||
|
{
|
||||||
|
if (_Profiles[ids[i]].LoadProfile())
|
||||||
|
{
|
||||||
|
_Profiles[ids[i]].Avatar = _GetAvatar(_Profiles[ids[i]].AvatarFileName);
|
||||||
|
knownFiles.Add(Path.GetFileName(_Profiles[ids[i]].FileName));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_Profiles.Remove(ids[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<string> files = new List<string>();
|
||||||
|
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.xml", true, true));
|
||||||
|
|
||||||
|
foreach (string file in files)
|
||||||
|
{
|
||||||
|
if (knownFiles.Contains(Path.GetFileName(file)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
CProfile profile = new CProfile
|
||||||
|
{
|
||||||
|
FileName = Path.Combine(CSettings.FolderProfiles, file)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (profile.LoadProfile())
|
||||||
|
{
|
||||||
|
profile.Avatar = _GetAvatar(profile.AvatarFileName);
|
||||||
|
profile.ID = _ProfileIDs.Dequeue();
|
||||||
|
_Profiles.Add(profile.ID, profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ProfilesChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void _LoadAvatars()
|
||||||
|
{
|
||||||
|
List<string> knownFiles = new List<string>();
|
||||||
|
if (_Avatars.Count > 0)
|
||||||
|
{
|
||||||
|
int[] ids = new int[_Avatars.Keys.Count];
|
||||||
|
_Avatars.Keys.CopyTo(ids, 0);
|
||||||
|
for (int i = 0; i < ids.Length; i++)
|
||||||
|
{
|
||||||
|
if (_Avatars[ids[i]].Reload())
|
||||||
|
knownFiles.Add(Path.GetFileName(_Avatars[ids[i]].FileName));
|
||||||
|
else
|
||||||
|
_Avatars.Remove(ids[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<string> files = new List<string>();
|
||||||
|
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.png", true, true));
|
||||||
|
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpg", true, true));
|
||||||
|
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpeg", true, true));
|
||||||
|
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.bmp", true, true));
|
||||||
|
|
||||||
|
foreach (string file in files)
|
||||||
|
{
|
||||||
|
if (knownFiles.Contains(Path.GetFileName(file)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
CAvatar avatar = new CAvatar(-1);
|
||||||
|
if (avatar.LoadFromFile(file))
|
||||||
|
{
|
||||||
|
avatar.ID = _AvatarIDs.Dequeue();
|
||||||
|
_Avatars.Add(avatar.ID, avatar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ProfilesChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void _DeleteProfile(int profileID)
|
||||||
{
|
{
|
||||||
if (!ICProfileIDValid(profileID))
|
if (!ICProfileIDValid(profileID))
|
||||||
return;
|
return;
|
||||||
@@ -422,27 +649,16 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
CLog.LogError("Can't delete Profile File " + _Profiles[profileID].FileName + ".xml");
|
CLog.LogError("Can't delete Profile File " + _Profiles[profileID].FileName + ".xml");
|
||||||
}
|
}
|
||||||
}
|
_ProfilesChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region private methods
|
private static void _RemoveProfile(int profileID)
|
||||||
private static void _Notification()
|
|
||||||
{
|
{
|
||||||
lock (_Callbacks)
|
if (!ICProfileIDValid(profileID))
|
||||||
{
|
return;
|
||||||
for (int i = 0; i < _Callbacks.Count; i++)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_Callbacks[i]();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
_Callbacks.RemoveAt(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
_Profiles.Remove(profileID);
|
||||||
|
_ProfilesChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int _CompareByPlayerName(CProfile a, CProfile b)
|
private static int _CompareByPlayerName(CProfile a, CProfile b)
|
||||||
@@ -451,26 +667,14 @@ namespace Vocaluxe.Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static CAvatar _GetAvatar(string fileName)
|
private static CAvatar _GetAvatar(string fileName)
|
||||||
{
|
|
||||||
lock (_AvatarMutex)
|
|
||||||
{
|
{
|
||||||
foreach (int id in _Avatars.Keys)
|
foreach (int id in _Avatars.Keys)
|
||||||
{
|
{
|
||||||
if (Path.GetFileName(_Avatars[id].FileName) == fileName)
|
if (Path.GetFileName(_Avatars[id].FileName) == fileName)
|
||||||
return _Avatars[id];
|
return _Avatars[id];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return new CAvatar(-1);
|
return new CAvatar(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void _RemoveProfile(int profileID)
|
|
||||||
{
|
|
||||||
if (!ICProfileIDValid(profileID))
|
|
||||||
return;
|
|
||||||
|
|
||||||
_Profiles.Remove(profileID);
|
|
||||||
_Notification();
|
|
||||||
}
|
|
||||||
#endregion private methods
|
#endregion private methods
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,5 +91,10 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
return _Webcam.IsDeviceAvailable();
|
return _Webcam.IsDeviceAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsCapturing()
|
||||||
|
{
|
||||||
|
return _Webcam.IsCapturing();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ using ClientServerLib;
|
|||||||
using Vocaluxe.Base;
|
using Vocaluxe.Base;
|
||||||
using Vocaluxe.Lib.Input;
|
using Vocaluxe.Lib.Input;
|
||||||
using VocaluxeLib;
|
using VocaluxeLib;
|
||||||
|
using VocaluxeLib.Profile;
|
||||||
|
|
||||||
namespace Vocaluxe.Base.Server
|
namespace Vocaluxe.Base.Server
|
||||||
{
|
{
|
||||||
@@ -156,12 +157,20 @@ namespace Vocaluxe.Base.Server
|
|||||||
while (File.Exists(filename + i + ".jpg"))
|
while (File.Exists(filename + i + ".jpg"))
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
FileStream fs = File.Create(filename + i + ".jpg");
|
filename = filename + i + ".jpg";
|
||||||
|
FileStream fs = File.Create(filename);
|
||||||
fs.Write(avatarPictureJpg.data, 0, avatarPictureJpg.data.Length);
|
fs.Write(avatarPictureJpg.data, 0, avatarPictureJpg.data.Length);
|
||||||
fs.Flush();
|
fs.Flush();
|
||||||
fs.Close();
|
fs.Close();
|
||||||
success = true;
|
|
||||||
CProfiles.LoadProfiles();
|
CAvatar avatar = new CAvatar(-1);
|
||||||
|
success = avatar.LoadFromFile(filename);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
CProfiles.AddAvatar(avatar);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
|
|
||||||
|
|||||||
@@ -164,6 +164,11 @@ namespace Vocaluxe.Lib.Webcam
|
|||||||
return _Devices.Count > 0;
|
return _Devices.Count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsCapturing()
|
||||||
|
{
|
||||||
|
return _Webcam.IsRunning;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Select(SWebcamConfig config)
|
public bool Select(SWebcamConfig config)
|
||||||
{
|
{
|
||||||
//Close old camera connection
|
//Close old camera connection
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ namespace Vocaluxe.Lib.Webcam
|
|||||||
SWebcamConfig GetConfig();
|
SWebcamConfig GetConfig();
|
||||||
SWebcamDevice[] GetDevices();
|
SWebcamDevice[] GetDevices();
|
||||||
bool IsDeviceAvailable();
|
bool IsDeviceAvailable();
|
||||||
|
bool IsCapturing();
|
||||||
|
|
||||||
bool Select(SWebcamConfig webcamConfig);
|
bool Select(SWebcamConfig webcamConfig);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,15 +197,23 @@ namespace Vocaluxe
|
|||||||
CController.Connect();
|
CController.Connect();
|
||||||
CLog.StopBenchmark(0, "Init Input");
|
CLog.StopBenchmark(0, "Init Input");
|
||||||
|
|
||||||
|
Application.DoEvents();
|
||||||
|
|
||||||
// Init Game;
|
// Init Game;
|
||||||
CLog.StartBenchmark(0, "Init Game");
|
CLog.StartBenchmark(0, "Init Game");
|
||||||
CGame.Init();
|
CGame.Init();
|
||||||
|
CProfiles.Update();
|
||||||
|
CConfig.UsePlayers();
|
||||||
CLog.StopBenchmark(0, "Init Game");
|
CLog.StopBenchmark(0, "Init Game");
|
||||||
|
|
||||||
|
Application.DoEvents();
|
||||||
|
|
||||||
// Init Party Modes;
|
// Init Party Modes;
|
||||||
CLog.StartBenchmark(0, "Init Party Modes");
|
CLog.StartBenchmark(0, "Init Party Modes");
|
||||||
CParty.Init();
|
CParty.Init();
|
||||||
CLog.StopBenchmark(0, "Init Party Modes");
|
CLog.StopBenchmark(0, "Init Party Modes");
|
||||||
|
|
||||||
|
Application.DoEvents();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -60,9 +60,10 @@ namespace Vocaluxe.Screens
|
|||||||
private const string _ButtonTakeSnapshot = "ButtonTakeSnapshot";
|
private const string _ButtonTakeSnapshot = "ButtonTakeSnapshot";
|
||||||
|
|
||||||
private const string _StaticAvatar = "StaticAvatar";
|
private const string _StaticAvatar = "StaticAvatar";
|
||||||
|
private bool _ProfilesChanged;
|
||||||
|
private bool _AvatarsChanged;
|
||||||
|
|
||||||
private EEditMode _EditMode;
|
private EEditMode _EditMode;
|
||||||
private bool _ProfilesChanged;
|
|
||||||
|
|
||||||
private STexture _WebcamTexture = new STexture(-1);
|
private STexture _WebcamTexture = new STexture(-1);
|
||||||
private Bitmap _Snapshot;
|
private Bitmap _Snapshot;
|
||||||
@@ -77,7 +78,9 @@ namespace Vocaluxe.Screens
|
|||||||
_ThemeStatics = new string[] {_StaticAvatar};
|
_ThemeStatics = new string[] {_StaticAvatar};
|
||||||
|
|
||||||
_EditMode = EEditMode.None;
|
_EditMode = EEditMode.None;
|
||||||
CProfiles.AddNotificationCallback(_OnProfilesChanged);
|
_ProfilesChanged = false;
|
||||||
|
_AvatarsChanged = false;
|
||||||
|
CProfiles.AddProfileChangedCallback(new ProfileChangedCallback(_OnProfileChanged));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void LoadTheme(string xmlPath)
|
public override void LoadTheme(string xmlPath)
|
||||||
@@ -108,6 +111,7 @@ namespace Vocaluxe.Screens
|
|||||||
case EEditMode.PlayerName:
|
case EEditMode.PlayerName:
|
||||||
_SelectSlides[_SelectSlideProfiles].RenameValue(
|
_SelectSlides[_SelectSlideProfiles].RenameValue(
|
||||||
CProfiles.AddGetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex, keyEvent.Unicode));
|
CProfiles.AddGetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex, keyEvent.Unicode));
|
||||||
|
_ProfilesChanged = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,6 +120,9 @@ namespace Vocaluxe.Screens
|
|||||||
switch (keyEvent.Key)
|
switch (keyEvent.Key)
|
||||||
{
|
{
|
||||||
case Keys.Escape:
|
case Keys.Escape:
|
||||||
|
if (_EditMode == EEditMode.PlayerName)
|
||||||
|
_EditMode = EEditMode.None;
|
||||||
|
else
|
||||||
CGraphics.FadeTo(EScreens.ScreenMain);
|
CGraphics.FadeTo(EScreens.ScreenMain);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -150,6 +157,7 @@ namespace Vocaluxe.Screens
|
|||||||
{
|
{
|
||||||
_SelectSlides[_SelectSlideProfiles].RenameValue(
|
_SelectSlides[_SelectSlideProfiles].RenameValue(
|
||||||
CProfiles.GetDeleteCharInPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex));
|
CProfiles.GetDeleteCharInPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex));
|
||||||
|
_ProfilesChanged = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CGraphics.FadeTo(EScreens.ScreenMain);
|
CGraphics.FadeTo(EScreens.ScreenMain);
|
||||||
@@ -243,6 +251,64 @@ namespace Vocaluxe.Screens
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool UpdateGame()
|
||||||
|
{
|
||||||
|
if (_AvatarsChanged)
|
||||||
|
_LoadAvatars(true);
|
||||||
|
|
||||||
|
if (_ProfilesChanged)
|
||||||
|
_LoadProfiles(true);
|
||||||
|
|
||||||
|
if (_SelectSlides[_SelectSlideProfiles].Selection > -1)
|
||||||
|
{
|
||||||
|
_Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex);
|
||||||
|
if (_EditMode == EEditMode.PlayerName)
|
||||||
|
_Buttons[_ButtonPlayerName].Text.Text += "|";
|
||||||
|
|
||||||
|
_SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex);
|
||||||
|
_SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex);
|
||||||
|
_SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex);
|
||||||
|
|
||||||
|
int avatarID = CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex);
|
||||||
|
_SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(avatarID);
|
||||||
|
if (CWebcam.IsDeviceAvailable() && CWebcam.IsCapturing())
|
||||||
|
{
|
||||||
|
if (_Snapshot == null)
|
||||||
|
CWebcam.GetFrame(ref _WebcamTexture);
|
||||||
|
|
||||||
|
_Statics[_StaticAvatar].Texture = _WebcamTexture;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_Statics[_StaticAvatar].Texture = CProfiles.GetAvatarTexture(avatarID);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnShow()
|
||||||
|
{
|
||||||
|
base.OnShow();
|
||||||
|
_LoadAvatars(false);
|
||||||
|
_LoadProfiles(false);
|
||||||
|
UpdateGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnClose()
|
||||||
|
{
|
||||||
|
base.OnClose();
|
||||||
|
_EditMode = EEditMode.None;
|
||||||
|
_OnDiscardSnapshot();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _OnProfileChanged(EProfileChangedFlags Flags)
|
||||||
|
{
|
||||||
|
if (EProfileChangedFlags.Avatar == (EProfileChangedFlags.Avatar & Flags))
|
||||||
|
_AvatarsChanged = true;
|
||||||
|
|
||||||
|
if (EProfileChangedFlags.Profile == (EProfileChangedFlags.Profile & Flags))
|
||||||
|
_ProfilesChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
private void _OnTakeSnapshot()
|
private void _OnTakeSnapshot()
|
||||||
{
|
{
|
||||||
_Buttons[_ButtonSaveSnapshot].Visible = true;
|
_Buttons[_ButtonSaveSnapshot].Visible = true;
|
||||||
@@ -265,31 +331,26 @@ namespace Vocaluxe.Screens
|
|||||||
|
|
||||||
private void _OnSaveSnapshot()
|
private void _OnSaveSnapshot()
|
||||||
{
|
{
|
||||||
const string filename = "snapshot";
|
string filename = Path.Combine(CSettings.FolderProfiles, "snapshot");
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (File.Exists(Path.Combine(CSettings.FolderProfiles, filename + i + ".png")))
|
while (File.Exists(filename + i + ".png"))
|
||||||
i++;
|
i++;
|
||||||
_Snapshot.Save(Path.Combine(CSettings.FolderProfiles, filename + i + ".png"), ImageFormat.Png);
|
|
||||||
CProfiles.LoadAvatars();
|
filename = filename + i + ".png";
|
||||||
_LoadAvatars(false);
|
_Snapshot.Save(filename, ImageFormat.Png);
|
||||||
|
|
||||||
_Snapshot = null;
|
_Snapshot = null;
|
||||||
CWebcam.Stop();
|
CWebcam.Stop();
|
||||||
CDraw.RemoveTexture(ref _WebcamTexture);
|
CDraw.RemoveTexture(ref _WebcamTexture);
|
||||||
|
|
||||||
CAvatar[] avatars = CProfiles.GetAvatars();
|
|
||||||
for (int j = 0; j < avatars.Length; j++)
|
|
||||||
{
|
|
||||||
if (Path.GetFileName(avatars[j].FileName) == (filename + i + ".png"))
|
|
||||||
{
|
|
||||||
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, avatars[j].ID);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_Buttons[_ButtonSaveSnapshot].Visible = false;
|
_Buttons[_ButtonSaveSnapshot].Visible = false;
|
||||||
_Buttons[_ButtonDiscardSnapshot].Visible = false;
|
_Buttons[_ButtonDiscardSnapshot].Visible = false;
|
||||||
_Buttons[_ButtonTakeSnapshot].Visible = false;
|
_Buttons[_ButtonTakeSnapshot].Visible = false;
|
||||||
_Buttons[_ButtonWebcam].Visible = true;
|
_Buttons[_ButtonWebcam].Visible = true;
|
||||||
|
|
||||||
|
int id = CProfiles.NewAvatar(filename);
|
||||||
|
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, id);
|
||||||
|
_LoadAvatars(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _OnWebcam()
|
private void _OnWebcam()
|
||||||
@@ -303,83 +364,37 @@ namespace Vocaluxe.Screens
|
|||||||
_Buttons[_ButtonWebcam].Visible = false;
|
_Buttons[_ButtonWebcam].Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool UpdateGame()
|
private void _NewProfile()
|
||||||
{
|
{
|
||||||
if (_ProfilesChanged)
|
_EditMode = EEditMode.None;
|
||||||
{
|
int id = CProfiles.NewProfile();
|
||||||
_LoadAvatars(true);
|
|
||||||
_LoadProfiles(true);
|
|
||||||
_ProfilesChanged = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_SelectSlides[_SelectSlideProfiles].Selection > -1)
|
|
||||||
{
|
|
||||||
_Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex);
|
|
||||||
if (_EditMode == EEditMode.PlayerName)
|
|
||||||
_Buttons[_ButtonPlayerName].Text.Text += "|";
|
|
||||||
|
|
||||||
_SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex);
|
|
||||||
_SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex);
|
|
||||||
_SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex);
|
|
||||||
|
|
||||||
int avatarID = CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex);
|
|
||||||
_SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(avatarID);
|
|
||||||
if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index != -1)
|
|
||||||
{
|
|
||||||
if (_Snapshot == null)
|
|
||||||
CWebcam.GetFrame(ref _WebcamTexture);
|
|
||||||
|
|
||||||
_Statics[_StaticAvatar].Texture = _WebcamTexture;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
_Statics[_StaticAvatar].Texture = CProfiles.GetAvatarTexture(avatarID);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnShow()
|
|
||||||
{
|
|
||||||
base.OnShow();
|
|
||||||
|
|
||||||
CProfiles.LoadProfiles();
|
|
||||||
_LoadAvatars(false);
|
|
||||||
_LoadProfiles(false);
|
_LoadProfiles(false);
|
||||||
UpdateGame();
|
_SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(id);
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnClose()
|
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex,
|
||||||
{
|
_SelectSlides[_SelectSlideAvatars].ValueIndex);
|
||||||
base.OnClose();
|
|
||||||
|
|
||||||
_OnDiscardSnapshot();
|
_SetInteractionToButton(_Buttons[_ButtonPlayerName]);
|
||||||
}
|
_EditMode = EEditMode.PlayerName;
|
||||||
|
|
||||||
private void _OnProfilesChanged()
|
|
||||||
{
|
|
||||||
_ProfilesChanged = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _SaveProfiles()
|
private void _SaveProfiles()
|
||||||
{
|
{
|
||||||
_EditMode = EEditMode.None;
|
_EditMode = EEditMode.None;
|
||||||
CProfiles.SaveProfiles();
|
CProfiles.SaveProfiles();
|
||||||
_LoadProfiles(true);
|
|
||||||
UpdateGame();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _DeleteProfile()
|
private void _DeleteProfile()
|
||||||
{
|
{
|
||||||
_EditMode = EEditMode.None;
|
_EditMode = EEditMode.None;
|
||||||
int selection = _SelectSlides[_SelectSlideProfiles].Selection;
|
|
||||||
CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex);
|
|
||||||
_LoadProfiles(false);
|
|
||||||
|
|
||||||
if (_SelectSlides[_SelectSlideProfiles].NumValues > selection)
|
CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex);
|
||||||
_SelectSlides[_SelectSlideProfiles].Selection = selection;
|
|
||||||
|
int selection = _SelectSlides[_SelectSlideProfiles].Selection;
|
||||||
|
if (_SelectSlides[_SelectSlideProfiles].NumValues - 1 > selection)
|
||||||
|
_SelectSlides[_SelectSlideProfiles].Selection = selection + 1;
|
||||||
else
|
else
|
||||||
_SelectSlides[_SelectSlideProfiles].Selection = selection - 1;
|
_SelectSlides[_SelectSlideProfiles].Selection = selection - 1;
|
||||||
UpdateGame();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _LoadProfiles(bool Keep)
|
private void _LoadProfiles(bool Keep)
|
||||||
@@ -401,7 +416,13 @@ namespace Vocaluxe.Screens
|
|||||||
|
|
||||||
if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0)
|
if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0)
|
||||||
{
|
{
|
||||||
|
if (selectedProfileID != -1)
|
||||||
_SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(selectedProfileID);
|
_SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(selectedProfileID);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_SelectSlides[_SelectSlideProfiles].Selection = 0;
|
||||||
|
selectedProfileID = _SelectSlides[_SelectSlideProfiles].ValueIndex;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Keep)
|
if (!Keep)
|
||||||
{
|
{
|
||||||
@@ -414,6 +435,7 @@ namespace Vocaluxe.Screens
|
|||||||
if (_EditMode == EEditMode.PlayerName)
|
if (_EditMode == EEditMode.PlayerName)
|
||||||
CProfiles.SetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex, name);
|
CProfiles.SetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex, name);
|
||||||
}
|
}
|
||||||
|
_ProfilesChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _LoadAvatars(bool Keep)
|
private void _LoadAvatars(bool Keep)
|
||||||
@@ -435,20 +457,8 @@ namespace Vocaluxe.Screens
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
_SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex));
|
_SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex));
|
||||||
}
|
|
||||||
|
|
||||||
private void _NewProfile()
|
_AvatarsChanged = false;
|
||||||
{
|
|
||||||
_EditMode = EEditMode.None;
|
|
||||||
int id = CProfiles.NewProfile();
|
|
||||||
_LoadProfiles(false);
|
|
||||||
_SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(id);
|
|
||||||
|
|
||||||
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex,
|
|
||||||
_SelectSlides[_SelectSlideAvatars].ValueIndex);
|
|
||||||
|
|
||||||
_SetInteractionToButton(_Buttons[_ButtonPlayerName]);
|
|
||||||
_EditMode = EEditMode.PlayerName;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,17 @@ namespace VocaluxeLib.Profile
|
|||||||
public string AvatarFileName;
|
public string AvatarFileName;
|
||||||
|
|
||||||
public EGameDifficulty Difficulty;
|
public EGameDifficulty Difficulty;
|
||||||
public CAvatar Avatar;
|
|
||||||
|
private CAvatar _Avatar;
|
||||||
|
public CAvatar Avatar
|
||||||
|
{
|
||||||
|
get { return _Avatar; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_Avatar = value;
|
||||||
|
AvatarFileName = _Avatar.FileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public EOffOn GuestProfile;
|
public EOffOn GuestProfile;
|
||||||
public EOffOn Active;
|
public EOffOn Active;
|
||||||
|
|||||||
Reference in new issue
Block a user