Better player handling with bugfix (selecting not available player number)

This commit is contained in:
Flamefire committed 2013-04-26 13:19:22 +02:00
1 parent 438068cf5d
commit 7cbae3d2db
5 files changed
+76 -164

No files matched your search

+2
View File
@@ -839,11 +839,13 @@ namespace Vocaluxe.Base
if (Players[j] == "") if (Players[j] == "")
continue; continue;
for (int i = 0; i < CProfiles.Profiles.Length; i++) for (int i = 0; i < CProfiles.Profiles.Length; i++)
{
if (Path.GetFileName(CProfiles.Profiles[i].ProfileFile) == Players[j] && CProfiles.Profiles[i].Active == EOffOn.TR_CONFIG_ON) if (Path.GetFileName(CProfiles.Profiles[i].ProfileFile) == Players[j] && CProfiles.Profiles[i].Active == EOffOn.TR_CONFIG_ON)
{ {
//Update Game-infos with player //Update Game-infos with player
CGame.Players[j].ProfileID = i; CGame.Players[j].ProfileID = i;
} }
}
} }
} }
} }
+30 -27
View File
@@ -66,7 +66,10 @@ namespace Vocaluxe.Base
{ {
if (IsProfileIDValid(profileID)) if (IsProfileIDValid(profileID))
return _Profiles[profileID].PlayerName; return _Profiles[profileID].PlayerName;
return (playerNum > 0) ? "Player " + playerNum : "Player"; string playerName = CLanguage.Translate("TR_SCREENNAMES_PLAYER");
if (playerNum > 0)
playerName += " " + playerNum;
return playerName;
} }
public static int NewProfile(string fileName = "") public static int NewProfile(string fileName = "")
@@ -253,32 +256,32 @@ namespace Vocaluxe.Base
return; return;
if (_Profiles[profileID].ProfileFile == "") if (_Profiles[profileID].ProfileFile == "")
return; return;
try try
{ {
//Check if profile saved in config //Check if profile saved in config
for (int i = 0; i < CConfig.Players.Length; i++) for (int i = 0; i < CConfig.Players.Length; i++)
{ {
if (CConfig.Players[i] == _Profiles[profileID].ProfileFile) if (CConfig.Players[i] == _Profiles[profileID].ProfileFile)
{ {
CConfig.Players[i] = string.Empty; CConfig.Players[i] = string.Empty;
CConfig.SaveConfig(); CConfig.SaveConfig();
} }
} }
File.Delete(_Profiles[profileID].ProfileFile); File.Delete(_Profiles[profileID].ProfileFile);
_Profiles.RemoveAt(profileID); _Profiles.RemoveAt(profileID);
//Check if profile is selected in game //Check if profile is selected in game
for (int i = 0; i < CGame.Players.Length; i++) for (int i = 0; i < CGame.Players.Length; i++)
{ {
if (CGame.Players[i].ProfileID > profileID) if (CGame.Players[i].ProfileID > profileID)
CGame.Players[i].ProfileID--; CGame.Players[i].ProfileID--;
else if (CGame.Players[i].ProfileID == profileID) else if (CGame.Players[i].ProfileID == profileID)
CGame.Players[i].ProfileID = -1; CGame.Players[i].ProfileID = -1;
} }
} }
catch (Exception) catch (Exception)
{ {
CLog.LogError("Can't delete Profile File " + _Profiles[profileID].ProfileFile + ".xml"); CLog.LogError("Can't delete Profile File " + _Profiles[profileID].ProfileFile + ".xml");
} }
} }
private static void _SortProfilesByName() private static void _SortProfilesByName()
+42 -133
View File
@@ -60,17 +60,13 @@ namespace Vocaluxe.Screens
private int _SelectingKeyboardPlayerNr; private int _SelectingKeyboardPlayerNr;
private int _SelectedPlayerNr; private int _SelectedPlayerNr;
private int[] _PlayerNr;
public override void Init() public override void Init()
{ {
base.Init(); base.Init();
List<string> statics = new List<string>(); List<string> statics = new List<string>();
foreach (string text in _StaticPlayer) statics.AddRange(_StaticPlayerAvatar);
statics.Add(text); statics.AddRange(_StaticPlayer);
foreach (string text in _StaticPlayerAvatar)
statics.Add(text);
statics.Add(_StaticWarningMics); statics.Add(_StaticWarningMics);
statics.Add(_StaticWarningProfiles); statics.Add(_StaticWarningProfiles);
_ThemeStatics = statics.ToArray(); _ThemeStatics = statics.ToArray();
@@ -82,8 +78,7 @@ namespace Vocaluxe.Screens
texts.Clear(); texts.Clear();
texts.Add(_TextWarningMics); texts.Add(_TextWarningMics);
texts.Add(_TextWarningProfiles); texts.Add(_TextWarningProfiles);
foreach (string text in _TextPlayer) texts.AddRange(_TextPlayer);
texts.Add(text);
_ThemeTexts = texts.ToArray(); _ThemeTexts = texts.ToArray();
texts.Clear(); texts.Clear();
@@ -108,10 +103,6 @@ namespace Vocaluxe.Screens
{ {
base.LoadTheme(xmlPath); base.LoadTheme(xmlPath);
_PlayerNr = new int[CSettings.MaxNumPlayer];
for (int i = 0; i < _PlayerNr.Length; i++)
_PlayerNr[i] = i;
for (int i = 0; i < CSettings.MaxNumPlayer; i++) for (int i = 0; i < CSettings.MaxNumPlayer; i++)
_OriginalPlayerAvatarTextures[i] = _Statics[_StaticPlayerAvatar[i]].Texture; _OriginalPlayerAvatarTextures[i] = _Statics[_StaticPlayerAvatar[i]].Texture;
@@ -164,6 +155,8 @@ namespace Vocaluxe.Screens
{ {
//Handle left/right/up/down //Handle left/right/up/down
_NameSelections[_NameSelection].HandleInput(keyEvent); _NameSelections[_NameSelection].HandleInput(keyEvent);
int numberPressed = -1;
bool resetSelection = false;
switch (keyEvent.Key) switch (keyEvent.Key)
{ {
case Keys.Enter: case Keys.Enter:
@@ -189,12 +182,7 @@ namespace Vocaluxe.Screens
if (_SelectingKeyboardUnendless) if (_SelectingKeyboardUnendless)
{ {
if (_SelectingKeyboardPlayerNr == CGame.NumPlayer) if (_SelectingKeyboardPlayerNr == CGame.NumPlayer)
{ resetSelection = true;
//Reset all values
_SelectingKeyboardPlayerNr = 0;
_SelectingKeyboardActive = false;
_NameSelections[_NameSelection].KeyboardSelection(false, -1);
}
else else
{ {
_SelectingKeyboardPlayerNr++; _SelectingKeyboardPlayerNr++;
@@ -202,117 +190,36 @@ namespace Vocaluxe.Screens
} }
} }
else else
{ resetSelection = true;
//Reset all values
_SelectingKeyboardPlayerNr = 0;
_SelectingKeyboardActive = false;
_NameSelections[_NameSelection].KeyboardSelection(false, -1);
}
break; break;
case Keys.D1: case Keys.D1:
case Keys.NumPad1: case Keys.NumPad1:
if (_SelectingKeyboardPlayerNr == 1) numberPressed = 1;
{
//Reset all values
_SelectingKeyboardPlayerNr = 0;
_SelectingKeyboardActive = false;
_NameSelections[_NameSelection].KeyboardSelection(false, -1);
}
else
{
_SelectingKeyboardPlayerNr = 1;
_NameSelections[_NameSelection].KeyboardSelection(true, 1);
}
_SelectingKeyboardUnendless = false;
break; break;
case Keys.D2: case Keys.D2:
case Keys.NumPad2: case Keys.NumPad2:
if (_SelectingKeyboardPlayerNr == 2) numberPressed = 2;
{
//Reset all values
_SelectingKeyboardPlayerNr = 0;
_SelectingKeyboardActive = false;
_NameSelections[_NameSelection].KeyboardSelection(false, -1);
}
else
{
_SelectingKeyboardPlayerNr = 2;
_NameSelections[_NameSelection].KeyboardSelection(true, 2);
}
_SelectingKeyboardUnendless = false;
break; break;
case Keys.D3: case Keys.D3:
case Keys.NumPad3: case Keys.NumPad3:
if (_SelectingKeyboardPlayerNr == 3) numberPressed = 3;
{
//Reset all values
_SelectingKeyboardPlayerNr = 0;
_SelectingKeyboardActive = false;
_NameSelections[_NameSelection].KeyboardSelection(false, -1);
}
else
{
_SelectingKeyboardPlayerNr = 3;
_NameSelections[_NameSelection].KeyboardSelection(true, 3);
}
_SelectingKeyboardUnendless = false;
break; break;
case Keys.D4: case Keys.D4:
case Keys.NumPad4: case Keys.NumPad4:
if (_SelectingKeyboardPlayerNr == 4) numberPressed = 4;
{
//Reset all values
_SelectingKeyboardPlayerNr = 0;
_SelectingKeyboardActive = false;
_NameSelections[_NameSelection].KeyboardSelection(false, -1);
}
else
{
_SelectingKeyboardPlayerNr = 4;
_NameSelections[_NameSelection].KeyboardSelection(true, 4);
}
_SelectingKeyboardUnendless = false;
break; break;
case Keys.D5: case Keys.D5:
case Keys.NumPad5: case Keys.NumPad5:
if (_SelectingKeyboardPlayerNr == 5) numberPressed = 5;
{
//Reset all values
_SelectingKeyboardPlayerNr = 0;
_SelectingKeyboardActive = false;
_NameSelections[_NameSelection].KeyboardSelection(false, -1);
}
else
{
_SelectingKeyboardPlayerNr = 5;
_NameSelections[_NameSelection].KeyboardSelection(true, 5);
}
_SelectingKeyboardUnendless = false;
break; break;
case Keys.D6: case Keys.D6:
case Keys.NumPad6: case Keys.NumPad6:
if (_SelectingKeyboardPlayerNr == 6) numberPressed = 6;
{
//Reset all values
_SelectingKeyboardPlayerNr = 0;
_SelectingKeyboardActive = false;
_NameSelections[_NameSelection].KeyboardSelection(false, -1);
}
else
{
_SelectingKeyboardPlayerNr = 6;
_NameSelections[_NameSelection].KeyboardSelection(true, 6);
}
_SelectingKeyboardUnendless = false;
break; break;
case Keys.Escape: case Keys.Escape:
//Reset all values resetSelection = true;
_SelectingKeyboardPlayerNr = 0;
_SelectingKeyboardActive = false;
_SelectingKeyboardUnendless = false;
_NameSelections[_NameSelection].KeyboardSelection(false, -1);
break; break;
case Keys.Delete: case Keys.Delete:
@@ -323,7 +230,7 @@ namespace Vocaluxe.Screens
CConfig.SaveConfig(); CConfig.SaveConfig();
//Update texture and name //Update texture and name
_Statics[_StaticPlayerAvatar[_SelectingKeyboardPlayerNr - 1]].Texture = _OriginalPlayerAvatarTextures[_SelectingKeyboardPlayerNr - 1]; _Statics[_StaticPlayerAvatar[_SelectingKeyboardPlayerNr - 1]].Texture = _OriginalPlayerAvatarTextures[_SelectingKeyboardPlayerNr - 1];
_Texts[_TextPlayer[_SelectingKeyboardPlayerNr - 1]].Text = CLanguage.Translate("TR_SCREENNAMES_PLAYER") + " " + _SelectingKeyboardPlayerNr; _Texts[_TextPlayer[_SelectingKeyboardPlayerNr - 1]].Text = CProfiles.GetPlayerName(-1, _SelectingKeyboardPlayerNr);
//Update profile-warning //Update profile-warning
_CheckPlayers(); _CheckPlayers();
//Reset all values //Reset all values
@@ -337,10 +244,8 @@ namespace Vocaluxe.Screens
case Keys.F10: case Keys.F10:
if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet) if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet)
{ {
if (_SelectSlides[_SelectSlideDuetPlayer[_SelectingKeyboardPlayerNr - 1]].Selection == 0) CSelectSlide selectSlideDuetPart = _SelectSlides[_SelectSlideDuetPlayer[_SelectingKeyboardPlayerNr - 1]];
_SelectSlides[_SelectSlideDuetPlayer[_SelectingKeyboardPlayerNr - 1]].Selection = 1; selectSlideDuetPart.Selection = (selectSlideDuetPart.Selection + 1) % 2;
else
_SelectSlides[_SelectSlideDuetPlayer[_SelectingKeyboardPlayerNr - 1]].Selection = 0;
//Reset all values //Reset all values
_SelectingKeyboardPlayerNr = 0; _SelectingKeyboardPlayerNr = 0;
_SelectingKeyboardActive = false; _SelectingKeyboardActive = false;
@@ -350,12 +255,27 @@ namespace Vocaluxe.Screens
} }
break; break;
} }
if (numberPressed > 0 || resetSelection)
{
if (numberPressed == _SelectingKeyboardPlayerNr || resetSelection)
{
//Reset all values
_SelectingKeyboardPlayerNr = 0;
_SelectingKeyboardActive = false;
_NameSelections[_NameSelection].KeyboardSelection(false, -1);
}
else if (numberPressed <= CConfig.NumPlayer)
{
_SelectingKeyboardPlayerNr = numberPressed;
_NameSelections[_NameSelection].KeyboardSelection(true, numberPressed);
}
_SelectingKeyboardUnendless = false;
}
} }
//Normal Keyboard handling //Normal Keyboard handling
else else
{ {
base.HandleInput(keyEvent); base.HandleInput(keyEvent);
bool processed = false;
switch (keyEvent.Key) switch (keyEvent.Key)
{ {
case Keys.Escape: case Keys.Escape:
@@ -366,15 +286,9 @@ namespace Vocaluxe.Screens
case Keys.Enter: case Keys.Enter:
if (_Buttons[_ButtonBack].Selected) if (_Buttons[_ButtonBack].Selected)
{
processed = true;
CGraphics.FadeTo(EScreens.ScreenSong); CGraphics.FadeTo(EScreens.ScreenSong);
}
else else
{
processed = true;
_StartSong(); _StartSong();
}
break; break;
@@ -407,10 +321,11 @@ namespace Vocaluxe.Screens
case Keys.NumPad6: case Keys.NumPad6:
_SelectingKeyboardPlayerNr = 6; _SelectingKeyboardPlayerNr = 6;
break; break;
default:
_UpdatePlayerNumber();
break;
} }
if (!processed)
_UpdatePlayerNumber();
if (_SelectingKeyboardPlayerNr > 0 && _SelectingKeyboardPlayerNr <= CConfig.NumPlayer) if (_SelectingKeyboardPlayerNr > 0 && _SelectingKeyboardPlayerNr <= CConfig.NumPlayer)
{ {
@@ -516,7 +431,7 @@ namespace Vocaluxe.Screens
CConfig.SaveConfig(); CConfig.SaveConfig();
//Update texture and name //Update texture and name
_Statics[_StaticPlayerAvatar[i]].Texture = _OriginalPlayerAvatarTextures[i]; _Statics[_StaticPlayerAvatar[i]].Texture = _OriginalPlayerAvatarTextures[i];
_Texts[_TextPlayer[i]].Text = CLanguage.Translate("TR_SCREENNAMES_PLAYER") + " " + (i + 1); _Texts[_TextPlayer[i]].Text = CProfiles.GetPlayerName(-1, i + 1);
//Update profile-warning //Update profile-warning
_CheckPlayers(); _CheckPlayers();
//Update Tiles-List //Update Tiles-List
@@ -564,16 +479,10 @@ namespace Vocaluxe.Screens
for (int i = 0; i < CSettings.MaxNumPlayer; i++) for (int i = 0; i < CSettings.MaxNumPlayer; i++)
{ {
if (CProfiles.IsProfileIDValid(CGame.Players[i].ProfileID)) _Statics[_StaticPlayerAvatar[i]].Texture = CProfiles.IsProfileIDValid(CGame.Players[i].ProfileID) ?
{ CProfiles.Profiles[CGame.Players[i].ProfileID].Avatar.Texture :
_Statics[_StaticPlayerAvatar[i]].Texture = CProfiles.Profiles[CGame.Players[i].ProfileID].Avatar.Texture; _OriginalPlayerAvatarTextures[i];
_Texts[_TextPlayer[i]].Text = CProfiles.GetPlayerName(CGame.Players[i].ProfileID); _Texts[_TextPlayer[i]].Text = CProfiles.GetPlayerName(CGame.Players[i].ProfileID, i + 1);
}
else
{
_Statics[_StaticPlayerAvatar[i]].Texture = _OriginalPlayerAvatarTextures[i];
_Texts[_TextPlayer[i]].Text = CLanguage.Translate("TR_SCREENNAMES_PLAYER") + " " + (i + 1).ToString();
}
if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet) if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet)
{ {
_SelectSlides[_SelectSlideDuetPlayer[i]].Clear(); _SelectSlides[_SelectSlideDuetPlayer[i]].Clear();
@@ -637,7 +546,7 @@ namespace Vocaluxe.Screens
_Statics["StaticPlayerAvatar" + i].Visible = true; _Statics["StaticPlayerAvatar" + i].Visible = true;
_Texts["TextPlayer" + i].Visible = true; _Texts["TextPlayer" + i].Visible = true;
if (_Texts["TextPlayer" + i].Text == "") if (_Texts["TextPlayer" + i].Text == "")
_Texts["TextPlayer" + i].Text = CLanguage.Translate("TR_SCREENNAMES_PLAYER") + " " + i; _Texts["TextPlayer" + i].Text = CProfiles.GetPlayerName(-1, i);
_Equalizers["EqualizerPlayer" + i].Visible = true; _Equalizers["EqualizerPlayer" + i].Visible = true;
if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet) if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet)
_SelectSlides["SelectSlideDuetPlayer" + i].Visible = true; _SelectSlides["SelectSlideDuetPlayer" + i].Visible = true;
+1 -3
View File
@@ -961,15 +961,13 @@ namespace Vocaluxe.Screens
float h = (float)(t * CSettings.RenderH); float h = (float)(t * CSettings.RenderH);
float w = CFonts.GetTextBounds(_Texts[_TextMedleyCountdown], h).Width; float w = CFonts.GetTextBounds(_Texts[_TextMedleyCountdown], h).Width;
float x = CSettings.RenderW / 2 - w / 2; float x = CSettings.RenderW / 2 - w / 2;
float y = CSettings.RenderH / 2 - h / 2 ; float y = CSettings.RenderH / 2 - h / 2;
_Texts[_TextMedleyCountdown].X = x; _Texts[_TextMedleyCountdown].X = x;
_Texts[_TextMedleyCountdown].Y = y; _Texts[_TextMedleyCountdown].Y = y;
_Texts[_TextMedleyCountdown].Height = h; _Texts[_TextMedleyCountdown].Height = h;
} }
else else
{
_Texts[_TextMedleyCountdown].Visible = false; _Texts[_TextMedleyCountdown].Visible = false;
}
} }
} }
+1 -1
View File
@@ -490,7 +490,7 @@ namespace VocaluxeLib.Menu
for (int p = 0; p < CBase.Game.GetNumPlayer(); p++) for (int p = 0; p < CBase.Game.GetNumPlayer(); p++)
{ {
//Don't show profile if is selected, but if selected and guest //Don't show profile if is selected, but if selected and guest
if (CBase.Game.GetPlayers()[p].ProfileID == i && CBase.Profiles.GetProfiles()[i].GuestProfile==EOffOn.TR_CONFIG_OFF) if (CBase.Game.GetPlayers()[p].ProfileID == i && CBase.Profiles.GetProfiles()[i].GuestProfile == EOffOn.TR_CONFIG_OFF)
visible = false; visible = false;
} }
} }