More refactoring (mainly LINQ)
This commit is contained in:
1 parent
181490fa87
commit
b1e28ae7bc
43 files changed
+488
-662
No files matched your search
@@ -452,7 +452,7 @@ namespace VocaluxeLib.PartyModes.Challenge
|
||||
|
||||
public override void SongSelected(int songID)
|
||||
{
|
||||
EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL;
|
||||
const EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL;
|
||||
|
||||
CBase.Game.Reset();
|
||||
CBase.Game.ClearSongs();
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace VocaluxeLib.PartyModes.Challenge
|
||||
private SRectF _PlayerTableScrollArea;
|
||||
private int _RoundsTableOffset;
|
||||
private int _PlayerTableOffset;
|
||||
private int _NumPlayerVisible = 10;
|
||||
private const int _NumPlayerVisible = 10;
|
||||
private int _NumRoundsVisible = 3;
|
||||
|
||||
public CPartyScreenChallengeMain()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
{
|
||||
@@ -27,7 +28,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
private readonly Random _Rand;
|
||||
private readonly int _NumPlayer;
|
||||
|
||||
public List<CCombination> Rounds;
|
||||
public readonly List<CCombination> Rounds;
|
||||
|
||||
public CChallengeRounds(int numRounds, int numPlayer, int numPlayerAtOnce)
|
||||
{
|
||||
@@ -72,12 +73,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
numPlayed[playerIndex]++;
|
||||
}
|
||||
|
||||
int max = 0;
|
||||
foreach (int p in numPlayed)
|
||||
{
|
||||
if (p > max)
|
||||
max = p;
|
||||
}
|
||||
int max = numPlayed.Max();
|
||||
|
||||
int num = Rounds[0].Player.Count;
|
||||
List<int> result = new List<int>();
|
||||
@@ -162,28 +158,19 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
List<CCombination> combsFiltered = new List<CCombination>();
|
||||
if (playerNrDemand != null)
|
||||
{
|
||||
for (int i = 0; i < _Combs.Count; i++)
|
||||
{
|
||||
if (_Combs[i].IsAvailableAll(playerNrDemand))
|
||||
combsFiltered.Add(_Combs[i]);
|
||||
}
|
||||
combsFiltered.AddRange(_Combs.Where(t => t.IsAvailableAll(playerNrDemand)));
|
||||
}
|
||||
|
||||
//1st fallback
|
||||
if (playerNrDemand != null && combsFiltered.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < _Combs.Count; i++)
|
||||
{
|
||||
if (_Combs[i].IsAvailableSomeone(playerNrDemand))
|
||||
combsFiltered.Add(_Combs[i]);
|
||||
}
|
||||
combsFiltered.AddRange(_Combs.Where(t => t.IsAvailableSomeone(playerNrDemand)));
|
||||
}
|
||||
|
||||
//2nd fallback
|
||||
if (combsFiltered.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < _Combs.Count; i++)
|
||||
combsFiltered.Add(_Combs[i]);
|
||||
combsFiltered.AddRange(_Combs);
|
||||
}
|
||||
|
||||
int num = combsFiltered.Count;
|
||||
@@ -220,7 +207,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
|
||||
public class CCombination
|
||||
{
|
||||
public List<int> Player;
|
||||
public readonly List<int> Player;
|
||||
|
||||
public CCombination()
|
||||
{
|
||||
@@ -229,28 +216,17 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
|
||||
public bool IsAvailable(int playerIndex)
|
||||
{
|
||||
foreach (int p in Player)
|
||||
{
|
||||
if (p == playerIndex)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return Player.Any(p => p == playerIndex);
|
||||
}
|
||||
|
||||
public bool IsAvailableAll(IEnumerable<int> playerIndices)
|
||||
{
|
||||
bool result = true;
|
||||
foreach (int p in playerIndices)
|
||||
result &= IsAvailable(p);
|
||||
return result;
|
||||
return playerIndices.All(IsAvailable);
|
||||
}
|
||||
|
||||
public bool IsAvailableSomeone(IEnumerable<int> playerIndices)
|
||||
{
|
||||
bool result = false;
|
||||
foreach (int p in playerIndices)
|
||||
result |= IsAvailable(p);
|
||||
return result;
|
||||
return playerIndices.Any(IsAvailable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,6 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
public int Position;
|
||||
public int PlayerID;
|
||||
public int NumPlayed;
|
||||
public int NumRounds;
|
||||
public int NumWon;
|
||||
public int NumSingPoints;
|
||||
public int NumGamePoints;
|
||||
@@ -102,7 +101,6 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
public struct SFromScreenNames
|
||||
{
|
||||
public bool FadeToConfig;
|
||||
public bool FadeToMain;
|
||||
public List<int> ProfileIDs;
|
||||
}
|
||||
|
||||
@@ -518,8 +516,8 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
if (CBase.Songs.GetNumVisibleSongs() < _NumSongs)
|
||||
CBase.Songs.ResetPartySongSung();
|
||||
|
||||
EGameMode gm = EGameMode.TR_GAMEMODE_MEDLEY;
|
||||
List<int> iDs = new List<int>();
|
||||
const EGameMode gm = EGameMode.TR_GAMEMODE_MEDLEY;
|
||||
List<int> ids = new List<int>();
|
||||
|
||||
CSong[] visSongs = CBase.Songs.GetSongsNotSung();
|
||||
if (visSongs == null)
|
||||
@@ -534,11 +532,11 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
foreach (EGameMode mode in visSongs[i].AvailableGameModes)
|
||||
{
|
||||
if (mode == EGameMode.TR_GAMEMODE_MEDLEY)
|
||||
iDs.Add(visSongs[i].ID);
|
||||
ids.Add(visSongs[i].ID);
|
||||
}
|
||||
}
|
||||
|
||||
if (iDs.Count == 0)
|
||||
if (ids.Count == 0)
|
||||
{
|
||||
CBase.Log.LogError("CPartyChallengeMedleyMode Error: There are no medley songs!");
|
||||
CBase.Graphics.FadeTo(EScreens.ScreenParty);
|
||||
@@ -546,12 +544,12 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
}
|
||||
|
||||
int s = 0;
|
||||
while (s < _NumSongs && iDs.Count > 0)
|
||||
while (s < _NumSongs && ids.Count > 0)
|
||||
{
|
||||
int songID = iDs[CBase.Game.GetRandom(iDs.Count)];
|
||||
int songID = ids[CBase.Game.GetRandom(ids.Count)];
|
||||
CBase.Game.AddSong(songID, gm);
|
||||
CBase.Songs.AddPartySongSung(songID);
|
||||
iDs.Remove(songID);
|
||||
ids.Remove(songID);
|
||||
s++;
|
||||
}
|
||||
return true;
|
||||
@@ -630,7 +628,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
{
|
||||
for (int i = 0; i < _GameData.NumPlayer; i++)
|
||||
{
|
||||
CResultTableRow row = new CResultTableRow {PlayerID = _GameData.ProfileIDs[i], NumPlayed = 0, NumRounds = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0};
|
||||
CResultTableRow row = new CResultTableRow {PlayerID = _GameData.ProfileIDs[i], NumPlayed = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0};
|
||||
_GameData.ResultTable.Add(row);
|
||||
}
|
||||
|
||||
@@ -690,7 +688,6 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
|
||||
row.NumPlayed++;
|
||||
row.NumWon += points[i].Won;
|
||||
row.NumRounds += 1;
|
||||
row.NumSingPoints += points[i].SingPoints;
|
||||
row.NumGamePoints += points[i].GamePoints;
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
private SRectF _PlayerTableScrollArea;
|
||||
private int _RoundsTableOffset;
|
||||
private int _PlayerTableOffset;
|
||||
private int _NumPlayerVisible = 10;
|
||||
private const int _NumPlayerVisible = 10;
|
||||
private int _NumRoundsVisible = 3;
|
||||
|
||||
public CPartyScreenChallengeMedleyMain()
|
||||
@@ -598,7 +598,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
|
||||
row.Pos.Text = _GameState.ResultTable[i + _PlayerTableOffset].Position + ".";
|
||||
row.Name.Text = profiles[_GameState.ResultTable[i + _PlayerTableOffset].PlayerID].PlayerName;
|
||||
row.Rounds.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumRounds.ToString();
|
||||
row.Rounds.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumPlayed.ToString();
|
||||
row.Won.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumWon.ToString();
|
||||
row.SingPoints.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumSingPoints.ToString();
|
||||
row.GamePoints.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumGamePoints.ToString();
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
private const int _PlayerChooseButtonsFirstY = 105;
|
||||
private const int _PlayerChooseButtonsSpaceH = 15;
|
||||
private const int _PlayerChooseButtonsSpaceW = 25;
|
||||
private int _PlayerChooseButtonsOffset = 0;
|
||||
private const int _PlayerChooseButtonsOffset = 0;
|
||||
|
||||
private CStatic _ChooseAvatarStatic;
|
||||
private bool _SelectingMouseActive;
|
||||
@@ -88,7 +88,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
_ThemeButtons = new string[] {_ButtonBack, _ButtonNext, _ButtonPlayerDestination, _ButtonPlayerChoose};
|
||||
|
||||
_Data = new SDataFromScreen();
|
||||
SFromScreenNames names = new SFromScreenNames {FadeToConfig = false, FadeToMain = false, ProfileIDs = new List<int>()};
|
||||
SFromScreenNames names = new SFromScreenNames {FadeToConfig = false, ProfileIDs = new List<int>()};
|
||||
_Data.ScreenNames = names;
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
|
||||
private void _UpdateButtonPlayerChoose(int offset)
|
||||
{
|
||||
int numButtonPlayerChoose = _PlayerChooseButtonsNumW * _PlayerChooseButtonsNumH;
|
||||
const int numButtonPlayerChoose = _PlayerChooseButtonsNumW * _PlayerChooseButtonsNumH;
|
||||
if (offset < 0)
|
||||
offset = 0;
|
||||
|
||||
@@ -501,14 +501,12 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
|
||||
private void _Back()
|
||||
{
|
||||
_Data.ScreenNames.FadeToConfig = true;
|
||||
_Data.ScreenNames.FadeToMain = false;
|
||||
_PartyMode.DataFromScreen(ThemeName, _Data);
|
||||
}
|
||||
|
||||
private void _Next()
|
||||
{
|
||||
_Data.ScreenNames.FadeToConfig = false;
|
||||
_Data.ScreenNames.FadeToMain = true;
|
||||
_PartyMode.DataFromScreen(ThemeName, _Data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,8 +81,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
{
|
||||
public int CurrentRoundNr;
|
||||
public int Team;
|
||||
public int NumPlayerTeam1;
|
||||
public int NumPlayerTeam2;
|
||||
public int NumFields;
|
||||
public List<CRound> Rounds;
|
||||
public List<int> Songs;
|
||||
@@ -115,7 +113,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
public struct SFromScreenNames
|
||||
{
|
||||
public bool FadeToConfig;
|
||||
public bool FadeToMain;
|
||||
public List<int> ProfileIDsTeam1;
|
||||
public List<int> ProfileIDsTeam2;
|
||||
}
|
||||
@@ -380,8 +377,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
CBase.Songs.ResetPartySongSung();
|
||||
_GameData.CurrentRoundNr = 1;
|
||||
_ToScreenMain.CurrentRoundNr = 1;
|
||||
_ToScreenMain.NumPlayerTeam1 = _GameData.NumPlayerTeam1;
|
||||
_ToScreenMain.NumPlayerTeam2 = _GameData.NumPlayerTeam2;
|
||||
_ToScreenMain.NumFields = _GameData.NumFields;
|
||||
_ToScreenMain.ProfileIDsTeam1 = _GameData.ProfileIDsTeam1;
|
||||
_ToScreenMain.ProfileIDsTeam2 = _GameData.ProfileIDsTeam2;
|
||||
@@ -410,8 +405,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
_UpdateSongList();
|
||||
_UpdatePlayerList();
|
||||
_ToScreenMain.CurrentRoundNr = _GameData.CurrentRoundNr;
|
||||
_ToScreenMain.NumPlayerTeam1 = _GameData.NumPlayerTeam1;
|
||||
_ToScreenMain.NumPlayerTeam2 = _GameData.NumPlayerTeam2;
|
||||
_ToScreenMain.NumFields = _GameData.NumFields;
|
||||
_ToScreenMain.ProfileIDsTeam1 = _GameData.ProfileIDsTeam1;
|
||||
_ToScreenMain.ProfileIDsTeam2 = _GameData.ProfileIDsTeam2;
|
||||
@@ -588,23 +581,23 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
case 1:
|
||||
{
|
||||
//Prepare Player-IDs
|
||||
List<int> iDs = new List<int>();
|
||||
List<int> ids = new List<int>();
|
||||
//Add IDs to team-list
|
||||
while (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0] && iDs.Count == 0)
|
||||
while (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0] && ids.Count == 0)
|
||||
{
|
||||
if (iDs.Count == 0)
|
||||
if (ids.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < _GameData.NumPlayerTeam1; i++)
|
||||
iDs.Add(i);
|
||||
ids.Add(i);
|
||||
}
|
||||
if (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0])
|
||||
{
|
||||
int random = CBase.Game.GetRandom((iDs.Count - 1) * 10);
|
||||
int random = CBase.Game.GetRandom((ids.Count - 1) * 10);
|
||||
int num = (int)Math.Round((double)random / 10);
|
||||
if (num >= iDs.Count)
|
||||
num = iDs.Count - 1;
|
||||
_GameData.PlayerTeam1.Add(iDs[num]);
|
||||
iDs.RemoveAt(num);
|
||||
if (num >= ids.Count)
|
||||
num = ids.Count - 1;
|
||||
_GameData.PlayerTeam1.Add(ids[num]);
|
||||
ids.RemoveAt(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
private List<CField> _Fields;
|
||||
private float _FieldFirstX = 25;
|
||||
private float _FieldFirstY = 25;
|
||||
private int _FieldSpace = 10;
|
||||
private const int _FieldSpace = 10;
|
||||
private float _FieldSize = 100;
|
||||
|
||||
private int _PreviewStream = -1;
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
_ThemeButtons = new string[] {_ButtonBack, _ButtonNext, _ButtonPlayerDestination, _ButtonPlayerChoose, _ButtonPlayerChooseScrollUp, _ButtonPlayerChooseScrollDown};
|
||||
|
||||
_Data = new SDataFromScreen();
|
||||
SFromScreenNames names = new SFromScreenNames {FadeToConfig = false, FadeToMain = false, ProfileIDsTeam1 = new List<int>(), ProfileIDsTeam2 = new List<int>()};
|
||||
SFromScreenNames names = new SFromScreenNames {FadeToConfig = false, ProfileIDsTeam1 = new List<int>(), ProfileIDsTeam2 = new List<int>()};
|
||||
_Data.ScreenNames = names;
|
||||
}
|
||||
|
||||
@@ -403,7 +403,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
|
||||
private void _UpdateButtonPlayerChoose(int offset)
|
||||
{
|
||||
int numButtonPlayerChoose = _PlayerChooseButtonsNumW * _PlayerChooseButtonsNumH;
|
||||
const int numButtonPlayerChoose = _PlayerChooseButtonsNumW * _PlayerChooseButtonsNumH;
|
||||
if (offset < 0)
|
||||
offset = 0;
|
||||
|
||||
@@ -446,27 +446,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
//Show profile only if active
|
||||
if (CBase.Profiles.GetProfiles()[i].Active == EOffOn.TR_CONFIG_ON)
|
||||
{
|
||||
visible = true;
|
||||
|
||||
for (int p = 0; p < _Data.ScreenNames.ProfileIDsTeam1.Count; p++)
|
||||
{
|
||||
//Don't show profile if is selected
|
||||
if (_Data.ScreenNames.ProfileIDsTeam1[p] == i)
|
||||
{
|
||||
visible = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int p = 0; p < _Data.ScreenNames.ProfileIDsTeam2.Count; p++)
|
||||
{
|
||||
//Don't show profile if is selected
|
||||
if (_Data.ScreenNames.ProfileIDsTeam2[p] == i)
|
||||
{
|
||||
visible = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
visible = _Data.ScreenNames.ProfileIDsTeam1.All(t => t != i) && _Data.ScreenNames.ProfileIDsTeam2.All(t => t != i);
|
||||
}
|
||||
if (visible)
|
||||
_PlayerChooseButtonsVisibleProfiles.Add(i);
|
||||
@@ -642,14 +622,12 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
private void _Back()
|
||||
{
|
||||
_Data.ScreenNames.FadeToConfig = true;
|
||||
_Data.ScreenNames.FadeToMain = false;
|
||||
_PartyMode.DataFromScreen(ThemeName, _Data);
|
||||
}
|
||||
|
||||
private void _Next()
|
||||
{
|
||||
_Data.ScreenNames.FadeToConfig = false;
|
||||
_Data.ScreenNames.FadeToMain = true;
|
||||
_PartyMode.DataFromScreen(ThemeName, _Data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user