functional async profile adding

This commit is contained in:
Alexander Eckart committed 2013-05-07 19:18:46 +02:00
1 parent 2037e3edb4
commit 8ab93db26f
4 files changed
+83 -22

No files matched your search

+31 -6
View File
@@ -174,10 +174,20 @@ namespace Vocaluxe.Base
lock (_ProfileMutex) lock (_ProfileMutex)
{ {
List<string> knownFiles = new List<string>(); List<string> knownFiles = new List<string>();
foreach (int id in _Profiles.Keys) if (_Profiles.Count > 0)
{ {
_Profiles[id].LoadProfile(); int[] ids = new int[_Profiles.Keys.Count];
knownFiles.Add(_Profiles[id].FileName); _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>(); List<string> files = new List<string>();
@@ -211,10 +221,17 @@ namespace Vocaluxe.Base
lock (_AvatarMutex) lock (_AvatarMutex)
{ {
List<string> knownFiles = new List<string>(); List<string> knownFiles = new List<string>();
foreach (int id in _Avatars.Keys) if (_Avatars.Count > 0)
{ {
_Avatars[id].Reload(); int[] ids = new int[_Avatars.Keys.Count];
knownFiles.Add(_Avatars[id].FileName); _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>(); List<string> files = new List<string>();
@@ -241,6 +258,14 @@ namespace Vocaluxe.Base
_Notification(); _Notification();
} }
public static void SetPlayerName(int profileID, string PlayerName)
{
if (!ICProfileIDValid(profileID))
return;
_Profiles[profileID].PlayerName = PlayerName;
}
public static string AddGetPlayerName(int profileID, char chr) public static string AddGetPlayerName(int profileID, char chr)
{ {
if (!ICProfileIDValid(profileID)) if (!ICProfileIDValid(profileID))
+1
View File
@@ -161,6 +161,7 @@ namespace Vocaluxe.Base.Server
fs.Flush(); fs.Flush();
fs.Close(); fs.Close();
success = true; success = true;
CProfiles.LoadProfiles();
} }
catch {} catch {}
+46 -14
View File
@@ -62,6 +62,7 @@ namespace Vocaluxe.Screens
private const string _StaticAvatar = "StaticAvatar"; private const string _StaticAvatar = "StaticAvatar";
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;
@@ -76,6 +77,7 @@ namespace Vocaluxe.Screens
_ThemeStatics = new string[] {_StaticAvatar}; _ThemeStatics = new string[] {_StaticAvatar};
_EditMode = EEditMode.None; _EditMode = EEditMode.None;
CProfiles.AddNotificationCallback(_OnProfilesChanged);
} }
public override void LoadTheme(string xmlPath) public override void LoadTheme(string xmlPath)
@@ -269,7 +271,7 @@ namespace Vocaluxe.Screens
i++; i++;
_Snapshot.Save(Path.Combine(CSettings.FolderProfiles, filename + i + ".png"), ImageFormat.Png); _Snapshot.Save(Path.Combine(CSettings.FolderProfiles, filename + i + ".png"), ImageFormat.Png);
CProfiles.LoadAvatars(); CProfiles.LoadAvatars();
_LoadAvatars(); _LoadAvatars(false);
_Snapshot = null; _Snapshot = null;
CWebcam.Stop(); CWebcam.Stop();
CDraw.RemoveTexture(ref _WebcamTexture); CDraw.RemoveTexture(ref _WebcamTexture);
@@ -303,6 +305,13 @@ namespace Vocaluxe.Screens
public override bool UpdateGame() public override bool UpdateGame()
{ {
if (_ProfilesChanged)
{
_LoadAvatars(true);
_LoadProfiles(true);
_ProfilesChanged = false;
}
if (_SelectSlides[_SelectSlideProfiles].Selection > -1) if (_SelectSlides[_SelectSlideProfiles].Selection > -1)
{ {
_Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex); _Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex);
@@ -334,8 +343,8 @@ namespace Vocaluxe.Screens
base.OnShow(); base.OnShow();
CProfiles.LoadProfiles(); CProfiles.LoadProfiles();
_LoadAvatars(); _LoadAvatars(false);
_LoadProfiles(); _LoadProfiles(false);
UpdateGame(); UpdateGame();
} }
@@ -346,19 +355,25 @@ namespace Vocaluxe.Screens
_OnDiscardSnapshot(); _OnDiscardSnapshot();
} }
private void _OnProfilesChanged()
{
_ProfilesChanged = true;
}
private void _SaveProfiles() private void _SaveProfiles()
{ {
_EditMode = EEditMode.None; _EditMode = EEditMode.None;
CProfiles.SaveProfiles(); CProfiles.SaveProfiles();
_LoadProfiles(); _LoadProfiles(true);
UpdateGame(); UpdateGame();
} }
private void _DeleteProfile() private void _DeleteProfile()
{ {
_EditMode = EEditMode.None;
int selection = _SelectSlides[_SelectSlideProfiles].Selection; int selection = _SelectSlides[_SelectSlideProfiles].Selection;
CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex); CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex);
_LoadProfiles(); _LoadProfiles(false);
if (_SelectSlides[_SelectSlideProfiles].NumValues > selection) if (_SelectSlides[_SelectSlideProfiles].NumValues > selection)
_SelectSlides[_SelectSlideProfiles].Selection = selection; _SelectSlides[_SelectSlideProfiles].Selection = selection;
@@ -367,9 +382,12 @@ namespace Vocaluxe.Screens
UpdateGame(); UpdateGame();
} }
private void _LoadProfiles() private void _LoadProfiles(bool Keep)
{ {
_EditMode = EEditMode.None; string name = String.Empty;
if (_EditMode == EEditMode.PlayerName)
name = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex);
int selectedProfileID = _SelectSlides[_SelectSlideProfiles].ValueIndex; int selectedProfileID = _SelectSlides[_SelectSlideProfiles].ValueIndex;
_SelectSlides[_SelectSlideProfiles].Clear(); _SelectSlides[_SelectSlideProfiles].Clear();
@@ -384,14 +402,21 @@ namespace Vocaluxe.Screens
if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0) if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0)
{ {
_SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(selectedProfileID); _SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(selectedProfileID);
_SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(selectedProfileID);
_SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(selectedProfileID); if (!Keep)
_SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(selectedProfileID); {
_SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(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));
}
if (_EditMode == EEditMode.PlayerName)
CProfiles.SetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex, name);
} }
} }
private void _LoadAvatars() private void _LoadAvatars(bool Keep)
{ {
int selectedAvatarID = _SelectSlides[_SelectSlideAvatars].ValueIndex; int selectedAvatarID = _SelectSlides[_SelectSlideAvatars].ValueIndex;
_SelectSlides[_SelectSlideAvatars].Clear(); _SelectSlides[_SelectSlideAvatars].Clear();
@@ -402,14 +427,21 @@ namespace Vocaluxe.Screens
new STexture(-1), new STexture(-1),
avatars[i].ID, avatars[i].ID,
-1); -1);
_SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(selectedAvatarID);
if (Keep)
{
_SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(selectedAvatarID);
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, selectedAvatarID);
}
else
_SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex));
} }
private void _NewProfile() private void _NewProfile()
{ {
_EditMode = EEditMode.None; _EditMode = EEditMode.None;
int id = CProfiles.NewProfile(); int id = CProfiles.NewProfile();
_LoadProfiles(); _LoadProfiles(false);
_SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(id); _SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(id);
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex,
+5 -2
View File
@@ -28,10 +28,13 @@ namespace VocaluxeLib.Profile
return (Texture.Index != -1); return (Texture.Index != -1);
} }
public void Reload() public bool Reload()
{ {
CBase.Drawing.RemoveTexture(ref Texture); STexture oldTexture = Texture;
Texture = CBase.Drawing.AddTexture(FileName); Texture = CBase.Drawing.AddTexture(FileName);
CBase.Drawing.RemoveTexture(ref oldTexture);
return Texture.Index != -1;
} }
public void Unload() public void Unload()