Fix a case where no songs will be available
Also some cleaner structure (no double storing of values)
This commit is contained in:
1 parent
5f96ac77b5
commit
4a63180600
3 files changed
+91
-122
No files matched your search
@@ -17,9 +17,11 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using VocaluxeLib.Menu;
|
||||
using VocaluxeLib.Songs;
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
@@ -161,10 +163,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
if (CBase.Config.GetTabs() == EOffOn.TR_CONFIG_ON && _ScreenSongOptions.Sorting.SongSorting != ESongSorting.TR_CONFIG_NONE)
|
||||
_ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_ON;
|
||||
|
||||
GameData.Songs = new List<int>();
|
||||
GameData.Rounds = new List<CRound>();
|
||||
GameData.PlayerTeam1 = new List<int>();
|
||||
GameData.PlayerTeam2 = new List<int>();
|
||||
GameData.Songs.Clear();
|
||||
GameData.Rounds.Clear();
|
||||
GameData.PlayerTeam1.Clear();
|
||||
GameData.PlayerTeam2.Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -215,7 +217,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
_CreateRounds();
|
||||
_SetNumJokers();
|
||||
_PreparePlayerList(0);
|
||||
_PrepareSongList();
|
||||
break;
|
||||
case EStage.Main:
|
||||
_Stage = EStage.Singing;
|
||||
@@ -224,7 +225,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
case EStage.Singing:
|
||||
_Stage = EStage.Main;
|
||||
GameData.Team = GameData.Team == 1 ? 0 : 1;
|
||||
_UpdateSongList();
|
||||
_UpdatePlayerList();
|
||||
break;
|
||||
default:
|
||||
@@ -431,10 +431,23 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
}
|
||||
}
|
||||
|
||||
private void _PrepareSongList()
|
||||
private static void _Shuffle<T>(IList<T> list)
|
||||
{
|
||||
var gm = EGameMode.TR_GAMEMODE_NORMAL;
|
||||
for (int n = list.Count - 1; n >= 1; n--)
|
||||
{
|
||||
int k = CBase.Game.GetRandom(n);
|
||||
T value = list[k];
|
||||
list[k] = list[n];
|
||||
list[n] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateSongList()
|
||||
{
|
||||
if (GameData.Songs.Count > 0)
|
||||
return;
|
||||
|
||||
EGameMode gm;
|
||||
switch (GameData.GameMode)
|
||||
{
|
||||
case EPartyGameMode.TR_GAMEMODE_NORMAL:
|
||||
@@ -448,61 +461,37 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
case EPartyGameMode.TR_GAMEMODE_SHORTSONG:
|
||||
gm = EGameMode.TR_GAMEMODE_SHORTSONG;
|
||||
break;
|
||||
|
||||
default:
|
||||
gm = EGameMode.TR_GAMEMODE_NORMAL;
|
||||
break;
|
||||
}
|
||||
|
||||
while (GameData.Songs.Count < (GameData.NumFields + GameData.NumJokerRandom[0] + GameData.NumJokerRandom[1]))
|
||||
switch (GameData.SongSource)
|
||||
{
|
||||
var songs = new List<int>();
|
||||
switch (GameData.SongSource)
|
||||
{
|
||||
case ESongSource.TR_PLAYLIST:
|
||||
for (int i = 0; i < CBase.Playlist.GetSongCount(GameData.PlaylistID); i++)
|
||||
{
|
||||
int id = CBase.Playlist.GetSong(GameData.PlaylistID, i).SongID;
|
||||
// ReSharper disable LoopCanBeConvertedToQuery
|
||||
foreach (EGameMode mode in CBase.Songs.GetSongByID(id).AvailableGameModes)
|
||||
// ReSharper restore LoopCanBeConvertedToQuery
|
||||
{
|
||||
if (mode == gm)
|
||||
songs.Add(id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ESongSource.TR_PLAYLIST:
|
||||
for (int i = 0; i < CBase.Playlist.GetSongCount(GameData.PlaylistID); i++)
|
||||
{
|
||||
int id = CBase.Playlist.GetSong(GameData.PlaylistID, i).SongID;
|
||||
if (CBase.Songs.GetSongByID(id).AvailableGameModes.Contains(gm))
|
||||
GameData.Songs.Add(id);
|
||||
}
|
||||
break;
|
||||
|
||||
case ESongSource.TR_ALLSONGS:
|
||||
for (int i = 0; i < CBase.Songs.GetNumSongs(); i++)
|
||||
{
|
||||
// ReSharper disable LoopCanBeConvertedToQuery
|
||||
foreach (EGameMode mode in CBase.Songs.GetSongByID(i).AvailableGameModes)
|
||||
// ReSharper restore LoopCanBeConvertedToQuery
|
||||
{
|
||||
if (mode == gm)
|
||||
songs.Add(i);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ESongSource.TR_ALLSONGS:
|
||||
ReadOnlyCollection<CSong> avSongs = CBase.Songs.GetSongs();
|
||||
GameData.Songs.AddRange(avSongs.Where(song => song.AvailableGameModes.Contains(gm)).Select(song => song.ID));
|
||||
break;
|
||||
|
||||
case ESongSource.TR_CATEGORY:
|
||||
CBase.Songs.SetCategory(GameData.CategoryID);
|
||||
for (int i = 0; i < CBase.Songs.GetNumSongsVisible(); i++)
|
||||
{
|
||||
// ReSharper disable LoopCanBeConvertedToQuery
|
||||
foreach (EGameMode mode in CBase.Songs.GetVisibleSong(i).AvailableGameModes)
|
||||
// ReSharper restore LoopCanBeConvertedToQuery
|
||||
{
|
||||
if (mode == gm)
|
||||
songs.Add(CBase.Songs.GetVisibleSong(i).ID);
|
||||
}
|
||||
}
|
||||
CBase.Songs.SetCategory(-1);
|
||||
break;
|
||||
}
|
||||
while (songs.Count > 0)
|
||||
{
|
||||
GameData.Songs.Add(songs[CBase.Game.GetRandom(songs.Count - 1)]);
|
||||
songs.Remove(GameData.Songs[GameData.Songs.Count - 1]);
|
||||
}
|
||||
case ESongSource.TR_CATEGORY:
|
||||
CBase.Songs.SetCategory(GameData.CategoryID);
|
||||
avSongs = CBase.Songs.GetVisibleSongs();
|
||||
GameData.Songs.AddRange(avSongs.Where(song => song.AvailableGameModes.Contains(gm)).Select(song => song.ID));
|
||||
|
||||
CBase.Songs.SetCategory(-1);
|
||||
break;
|
||||
}
|
||||
_Shuffle(GameData.Songs);
|
||||
}
|
||||
|
||||
private void _UpdatePlayerList()
|
||||
@@ -513,12 +502,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
_PreparePlayerList(2);
|
||||
}
|
||||
|
||||
private void _UpdateSongList()
|
||||
{
|
||||
if (GameData.Songs.Count == 0)
|
||||
_PrepareSongList();
|
||||
}
|
||||
|
||||
private void _StartRound(int roundNr)
|
||||
{
|
||||
CBase.Game.Reset();
|
||||
|
||||
@@ -23,12 +23,6 @@ using VocaluxeLib.Songs;
|
||||
|
||||
namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
{
|
||||
public class CField
|
||||
{
|
||||
public CRound Content;
|
||||
public CButton Button;
|
||||
}
|
||||
|
||||
public enum EStatus
|
||||
{
|
||||
FieldChoosing,
|
||||
@@ -73,7 +67,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
|
||||
private bool _ExitPopupVisible;
|
||||
|
||||
private List<CField> _Fields;
|
||||
private List<CButton> _Fields = new List<CButton>();
|
||||
private float _FieldFirstX = 25;
|
||||
private float _FieldFirstY = 25;
|
||||
private const int _FieldSpace = 10;
|
||||
@@ -97,8 +91,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
_ButtonJokerRetryT2
|
||||
};
|
||||
_ThemeStatics = new string[] {_StaticPopupBG, _StaticAvatarT1, _StaticAvatarT2};
|
||||
|
||||
_Fields = new List<CField>();
|
||||
}
|
||||
|
||||
public override void LoadTheme(string xmlPath)
|
||||
@@ -149,7 +141,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
switch (_Status)
|
||||
{
|
||||
case EStatus.FieldChoosing:
|
||||
if (_Fields[i].Button.Selected)
|
||||
if (_Fields[i].Selected)
|
||||
{
|
||||
_PartyMode.GameData.FieldNr = i;
|
||||
_FieldSelected();
|
||||
@@ -157,7 +149,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
break;
|
||||
|
||||
case EStatus.JokerRetry:
|
||||
if (_Fields[i].Button.Selected)
|
||||
if (_Fields[i].Selected)
|
||||
{
|
||||
_PartyMode.GameData.FieldNr = i;
|
||||
_FieldSelectedAgain();
|
||||
@@ -214,7 +206,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
switch (_Status)
|
||||
{
|
||||
case EStatus.FieldChoosing:
|
||||
if (_Fields[i].Button.Selected)
|
||||
if (_Fields[i].Selected)
|
||||
{
|
||||
_PartyMode.GameData.FieldNr = i;
|
||||
_FieldSelected();
|
||||
@@ -222,7 +214,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
break;
|
||||
|
||||
case EStatus.JokerRetry:
|
||||
if (_Fields[i].Button.Selected)
|
||||
if (_Fields[i].Selected)
|
||||
{
|
||||
_PartyMode.GameData.FieldNr = i;
|
||||
_FieldSelectedAgain();
|
||||
@@ -353,10 +345,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
{
|
||||
for (int i = 0; i < 25; i++)
|
||||
{
|
||||
var f = new CField {Button = GetNewButton(_Buttons[_ButtonField])};
|
||||
f.Button.Visible = false;
|
||||
f.Content = new CRound();
|
||||
_AddButton(f.Button);
|
||||
CButton f = GetNewButton(_Buttons[_ButtonField]);
|
||||
f.Visible = false;
|
||||
_AddButton(f);
|
||||
_Fields.Add(f);
|
||||
}
|
||||
}
|
||||
@@ -377,12 +368,12 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
{
|
||||
if (i < _PartyMode.GameData.NumFields)
|
||||
{
|
||||
_Fields[i].Button.W = _FieldSize;
|
||||
_Fields[i].Button.H = _FieldSize;
|
||||
_Fields[i].Button.X = x;
|
||||
_Fields[i].Button.Y = y;
|
||||
_Fields[i].Button.Visible = true;
|
||||
_Fields[i].Button.Selectable = true;
|
||||
_Fields[i].W = _FieldSize;
|
||||
_Fields[i].H = _FieldSize;
|
||||
_Fields[i].X = x;
|
||||
_Fields[i].Y = y;
|
||||
_Fields[i].Visible = true;
|
||||
_Fields[i].Selectable = true;
|
||||
column++;
|
||||
if ((i + 1) >= numOneRow * (row + 1))
|
||||
{
|
||||
@@ -396,8 +387,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
}
|
||||
else
|
||||
{
|
||||
_Fields[i].Button.Visible = false;
|
||||
_Fields[i].Button.Selectable = false;
|
||||
_Fields[i].Visible = false;
|
||||
_Fields[i].Selectable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -406,34 +397,33 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
{
|
||||
for (int i = 0; i < _PartyMode.GameData.Rounds.Count; i++)
|
||||
{
|
||||
_Fields[i].Button.Selectable = true;
|
||||
_Fields[i].Button.Texture = _Buttons[_ButtonField].Texture;
|
||||
_Fields[i].Button.Color = _Buttons[_ButtonField].Color;
|
||||
_Fields[i].Button.SelColor = _Buttons[_ButtonField].SelColor;
|
||||
_Fields[i].Content = _PartyMode.GameData.Rounds[i];
|
||||
if (_Fields[i].Content.Finished)
|
||||
_Fields[i].Selectable = true;
|
||||
_Fields[i].Texture = _Buttons[_ButtonField].Texture;
|
||||
_Fields[i].Color = _Buttons[_ButtonField].Color;
|
||||
_Fields[i].SelColor = _Buttons[_ButtonField].SelColor;
|
||||
if (_PartyMode.GameData.Rounds[i].Finished)
|
||||
{
|
||||
_Fields[i].Button.Selectable = false;
|
||||
_Fields[i].Button.Texture = CBase.Songs.GetSongByID(_Fields[i].Content.SongID).CoverTextureBig;
|
||||
_Fields[i].Button.Color = CBase.Themes.GetPlayerColor(_Fields[i].Content.Winner);
|
||||
_Fields[i].Button.SelColor = CBase.Themes.GetPlayerColor(_Fields[i].Content.Winner);
|
||||
_Fields[i].Selectable = false;
|
||||
_Fields[i].Texture = CBase.Songs.GetSongByID(_PartyMode.GameData.Rounds[i].SongID).CoverTextureBig;
|
||||
_Fields[i].Color = CBase.Themes.GetPlayerColor(_PartyMode.GameData.Rounds[i].Winner);
|
||||
_Fields[i].SelColor = CBase.Themes.GetPlayerColor(_PartyMode.GameData.Rounds[i].Winner);
|
||||
}
|
||||
if (_Status == EStatus.FieldSelected && _PartyMode.GameData.FieldNr == i)
|
||||
{
|
||||
_Fields[i].Button.Texture = CBase.Songs.GetSongByID(_Fields[i].Content.SongID).CoverTextureBig;
|
||||
_Fields[i].Button.Color = new SColorF(1, 1, 1, 1);
|
||||
_Fields[i].Button.SelColor = new SColorF(1, 1, 1, 1);
|
||||
_Fields[i].Button.Selectable = false;
|
||||
_Fields[i].Texture = CBase.Songs.GetSongByID(_PartyMode.GameData.Rounds[i].SongID).CoverTextureBig;
|
||||
_Fields[i].Color = new SColorF(1, 1, 1, 1);
|
||||
_Fields[i].SelColor = new SColorF(1, 1, 1, 1);
|
||||
_Fields[i].Selectable = false;
|
||||
}
|
||||
if (_Status == EStatus.JokerRetry && _Fields[i].Content.Finished)
|
||||
if (_Status == EStatus.JokerRetry && _PartyMode.GameData.Rounds[i].Finished)
|
||||
{
|
||||
_Fields[i].Button.SelColor = CBase.Themes.GetPlayerColor(_PartyMode.GameData.Team + 1);
|
||||
_Fields[i].Button.Selectable = true;
|
||||
_Fields[i].SelColor = CBase.Themes.GetPlayerColor(_PartyMode.GameData.Team + 1);
|
||||
_Fields[i].Selectable = true;
|
||||
}
|
||||
if (_Status == EStatus.JokerRetry && !_Fields[i].Content.Finished)
|
||||
_Fields[i].Button.Selectable = false;
|
||||
if (_Status == EStatus.JokerRetry && !_PartyMode.GameData.Rounds[i].Finished)
|
||||
_Fields[i].Selectable = false;
|
||||
if (_Status == EStatus.FieldSelected)
|
||||
_Fields[i].Button.Selectable = false;
|
||||
_Fields[i].Selectable = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,16 +450,12 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
|
||||
_UpdatePlayerInformation();
|
||||
}
|
||||
int songID = 0;
|
||||
if (_PartyMode.GameData.Songs.Count > 0)
|
||||
{
|
||||
songID = _PartyMode.GameData.Songs[0];
|
||||
_PartyMode.GameData.Songs.RemoveAt(0);
|
||||
}
|
||||
_PartyMode.UpdateSongList();
|
||||
int songID = _PartyMode.GameData.Songs[0];
|
||||
_PartyMode.GameData.Songs.RemoveAt(0);
|
||||
|
||||
_StartPreview(songID);
|
||||
_Status = EStatus.FieldSelected;
|
||||
_Fields[_PartyMode.GameData.FieldNr].Content.SongID = songID;
|
||||
_PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SongID = songID;
|
||||
_UpdateFieldContents();
|
||||
_UpdateJokerButtons();
|
||||
@@ -483,10 +469,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
|
||||
private void _FieldSelectedAgain()
|
||||
{
|
||||
int songID = _Fields[_PartyMode.GameData.FieldNr].Content.SongID;
|
||||
int songID = _PartyMode.GameData.Rounds[_OldSelectedField].SongID;
|
||||
_StartPreview(songID);
|
||||
_Status = EStatus.FieldSelected;
|
||||
_Fields[_PartyMode.GameData.FieldNr].Content.SongID = songID;
|
||||
_PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SongID = songID;
|
||||
_PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam1 = _PartyMode.GameData.Rounds[_OldSelectedField].SingerTeam1;
|
||||
_PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam2 = _PartyMode.GameData.Rounds[_OldSelectedField].SingerTeam2;
|
||||
@@ -588,8 +573,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
_Buttons[_ButtonJokerRetryT2].Visible = true;
|
||||
_Buttons[_ButtonJokerRetryT1].Text.Text = _PartyMode.GameData.NumJokerRetry[0].ToString();
|
||||
_Buttons[_ButtonJokerRetryT2].Text.Text = _PartyMode.GameData.NumJokerRetry[1].ToString();
|
||||
_Buttons[_ButtonJokerRetryT1].Selectable = _PartyMode.GameData.NumJokerRetry[0] > 0;
|
||||
_Buttons[_ButtonJokerRetryT2].Selectable = _PartyMode.GameData.NumJokerRetry[1] > 0;
|
||||
_Buttons[_ButtonJokerRetryT1].Selectable = _PartyMode.GameData.NumJokerRetry[0] > 0 && _PartyMode.GameData.CurrentRoundNr > 1;
|
||||
_Buttons[_ButtonJokerRetryT2].Selectable = _PartyMode.GameData.NumJokerRetry[1] > 0 && _PartyMode.GameData.CurrentRoundNr > 1;
|
||||
}
|
||||
|
||||
private void _NextRound()
|
||||
@@ -659,8 +644,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
var check = new List<int>();
|
||||
for (int j = 0; j < _Possibilities.GetLength(1); j++)
|
||||
{
|
||||
if (_Fields[_Possibilities[i, j]].Content.Winner > 0)
|
||||
check.Add(_Fields[_Possibilities[i, j]].Content.Winner);
|
||||
if (_PartyMode.GameData.Rounds[_Possibilities[i, j]].Winner > 0)
|
||||
check.Add(_PartyMode.GameData.Rounds[_Possibilities[i, j]].Winner);
|
||||
}
|
||||
if (check.Count != _Possibilities.GetLength(1))
|
||||
continue;
|
||||
|
||||
@@ -238,6 +238,7 @@ namespace VocaluxeLib
|
||||
|
||||
CSong GetVisibleSong(int visibleIndex);
|
||||
CSong GetSongByID(int songID);
|
||||
ReadOnlyCollection<CSong> GetSongs();
|
||||
ReadOnlyCollection<CSong> GetVisibleSongs();
|
||||
CCategory GetCategory(int index);
|
||||
|
||||
|
||||
Reference in new issue
Block a user