From 480e714afc84e16fde0aa4658428e87601802aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Thu, 27 Jun 2013 13:49:35 +0200 Subject: [PATCH] Improve profile-handling on names-screen, fixes #26 --- Vocaluxe/Base/CProfiles.cs | 5 ++ Vocaluxe/Screens/CScreenNames.cs | 82 ++++++++++-------------------- VocaluxeLib/Menu/CNameSelection.cs | 2 +- 3 files changed, 32 insertions(+), 57 deletions(-) diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index 5c7ec480..005eefe3 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -481,6 +481,11 @@ namespace Vocaluxe.Base return _Profiles[profileID].Avatar.ID; } + + public static int GetProfileID(int num) + { + return _Profiles[num].ID; + } #endregion profile properties #region avatar texture diff --git a/Vocaluxe/Screens/CScreenNames.cs b/Vocaluxe/Screens/CScreenNames.cs index 1f840fdd..a2cb0278 100644 --- a/Vocaluxe/Screens/CScreenNames.cs +++ b/Vocaluxe/Screens/CScreenNames.cs @@ -177,23 +177,12 @@ namespace Vocaluxe.Screens //Check, if a player is selected if (_NameSelections[_NameSelection].Selection > -1) { - CProfile[] profiles = CProfiles.GetProfiles(); _SelectedPlayerNr = _NameSelections[_NameSelection].Selection; - if (profiles.Length <= _SelectedPlayerNr) + if (CProfiles.NumProfiles <= _SelectedPlayerNr) return true; - //Update Game-infos with new player - CGame.Players[_SelectingFastPlayerNr - 1].ProfileID = profiles[_SelectedPlayerNr].ID; - //Update config for default players. - CConfig.Players[_SelectingFastPlayerNr - 1] = profiles[_SelectedPlayerNr].FileName; - CConfig.SaveConfig(); - //Update texture and name - _Statics[_StaticPlayerAvatar[_SelectingFastPlayerNr - 1]].Texture = profiles[_SelectedPlayerNr].Avatar.Texture; - _Texts[_TextPlayer[_SelectingFastPlayerNr - 1]].Text = profiles[_SelectedPlayerNr].PlayerName; - //Update profile-warning - _CheckPlayers(); - //Update Tiles-List - _NameSelections[_NameSelection].UpdateList(); + _UpdateSelectedProfile(_SelectingFastPlayerNr - 1, _SelectedPlayerNr); + _SetInteractionToButton(_Buttons[_ButtonStart]); } //Started selecting with 'P' @@ -449,22 +438,10 @@ namespace Vocaluxe.Screens _Texts[_TextPlayer[_SelectingSwitchNr]].Text = CProfiles.GetPlayerName(-1, (_SelectingSwitchNr + 1)); } - CProfile[] profiles = CProfiles.GetProfiles(); - if (profiles.Length <= _SelectedPlayerNr) + if (CProfiles.NumProfiles <= _SelectedPlayerNr) return true; - //Update Game-infos with new player - CGame.Players[i].ProfileID = profiles[_SelectedPlayerNr].ID; - //Update config for default players. - CConfig.Players[i] = profiles[_SelectedPlayerNr].FileName; - CConfig.SaveConfig(); - //Update texture and name - _Statics[_StaticPlayerAvatar[i]].Texture = _ChooseAvatarStatic.Texture; - _Texts[_TextPlayer[i]].Text = profiles[_SelectedPlayerNr].PlayerName; - //Update profile-warning - _CheckPlayers(); - //Update Tiles-List - _NameSelections[_NameSelection].UpdateList(); + _UpdateSelectedProfile(i, _SelectedPlayerNr); break; } //Selected player is dropped out of area @@ -494,22 +471,11 @@ namespace Vocaluxe.Screens _SelectedPlayerNr = _NameSelections[_NameSelection].TilePlayerNr(mouseEvent); if (_SelectedPlayerNr != -1) { - CProfile[] profiles = CProfiles.GetProfiles(); - if (profiles.Length <= _SelectedPlayerNr) + if (CProfiles.NumProfiles <= _SelectedPlayerNr) return true; - //Update Game-infos with new player - CGame.Players[_SelectingFastPlayerNr - 1].ProfileID = profiles[_SelectedPlayerNr].ID; - //Update config for default players. - CConfig.Players[_SelectingFastPlayerNr - 1] = profiles[_SelectedPlayerNr].FileName; - CConfig.SaveConfig(); - //Update texture and name - _Statics[_StaticPlayerAvatar[_SelectingFastPlayerNr - 1]].Texture = profiles[_SelectedPlayerNr].Avatar.Texture; - _Texts[_TextPlayer[_SelectingFastPlayerNr - 1]].Text = profiles[_SelectedPlayerNr].PlayerName; - //Update profile-warning - _CheckPlayers(); - //Update Tiles-List - _NameSelections[_NameSelection].UpdateList(); + _UpdateSelectedProfile(_SelectingFastPlayerNr - 1, _SelectedPlayerNr); + _SelectingFastPlayerNr++; if (_SelectingFastPlayerNr <= CGame.NumPlayer) _NameSelections[_NameSelection].FastSelection(true, _SelectingFastPlayerNr); @@ -541,22 +507,10 @@ namespace Vocaluxe.Screens { if (CGame.Players[i].ProfileID == -1) { - CProfile[] profiles = CProfiles.GetProfiles(); - if (profiles.Length <= _SelectedPlayerNr) + if (CProfiles.NumProfiles <= _SelectedPlayerNr) return true; - //Update Game-infos with new player - CGame.Players[i].ProfileID = profiles[_SelectedPlayerNr].ID; - //Update config for default players. - CConfig.Players[i] = profiles[_SelectedPlayerNr].FileName; - CConfig.SaveConfig(); - //Update texture and name - _Statics[_StaticPlayerAvatar[i]].Texture = profiles[_SelectedPlayerNr].Avatar.Texture; - _Texts[_TextPlayer[i]].Text = profiles[_SelectedPlayerNr].PlayerName; - //Update profile-warning - _CheckPlayers(); - //Update Tiles-List - _NameSelections[_NameSelection].UpdateList(); + _UpdateSelectedProfile(i, _SelectedPlayerNr); break; } } @@ -760,6 +714,22 @@ namespace Vocaluxe.Screens _CheckPlayers(); } + private void _UpdateSelectedProfile(int playerNum, int profileId) + { + //Update Game-infos with new player + CGame.Players[playerNum].ProfileID = profileId; + //Update config for default players. + CConfig.Players[playerNum] = CProfiles.GetProfileFileName(profileId); + CConfig.SaveConfig(); + //Update texture and name + _Statics[_StaticPlayerAvatar[playerNum]].Texture = CProfiles.GetAvatarTextureFromProfile(profileId); + _Texts[_TextPlayer[playerNum]].Text = CProfiles.GetPlayerName(profileId); + //Update profile-warning + _CheckPlayers(); + //Update Tiles-List + _NameSelections[_NameSelection].UpdateList(); + } + private void _ResetPlayerSelections() { for (int i = 0; i < CGame.NumPlayer; i++) diff --git a/VocaluxeLib/Menu/CNameSelection.cs b/VocaluxeLib/Menu/CNameSelection.cs index 5c3c043f..f427ed4c 100644 --- a/VocaluxeLib/Menu/CNameSelection.cs +++ b/VocaluxeLib/Menu/CNameSelection.cs @@ -515,7 +515,7 @@ namespace VocaluxeLib.Menu } } if (visible) - _VisibleProfiles.Add(i); + _VisibleProfiles.Add(profiles[i].ID); } }