Fixed and changed category handling and visible songs

This commit is contained in:
Flamefire committed 2013-04-28 17:19:22 +02:00
1 parent 3956fa17d1
commit 5172f17da7
20 files changed
+189 -336

No files matched your search

+1 -1
View File
@@ -505,7 +505,7 @@ namespace Vocaluxe.Base
bool popupVolumeControlAllowed = _CurrentScreen != EScreens.ScreenCredits && _CurrentScreen != EScreens.ScreenOptionsRecord;
//Hide volume control for bg-music if bg-music is disabled
if (popupVolumeControlAllowed && (_CurrentScreen != EScreens.ScreenSong || (_CurrentScreen == EScreens.ScreenSong && CSongs.Category == -1))
if (popupVolumeControlAllowed && (_CurrentScreen != EScreens.ScreenSong || CSongs.Category == -1)
&& _CurrentScreen != EScreens.ScreenSing && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF)
popupVolumeControlAllowed = false;
+8 -7
View File
@@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using Vocaluxe.Base.Font;
using VocaluxeLib.Menu;
@@ -568,9 +569,9 @@ namespace Vocaluxe.Base
return CSongs.NumAllSongs;
}
public int GetNumVisibleSongs()
public int GetNumSongsVisible()
{
return CSongs.NumVisibleSongs;
return CSongs.NumSongsVisible;
}
public int GetNumCategories()
@@ -618,14 +619,14 @@ namespace Vocaluxe.Base
return CSongs.GetSong(songID);
}
public CSong[] GetSongs()
public ReadOnlyCollection<CSong> GetSongs()
{
return CSongs.AllSongs;
}
public CSong[] GetSongsNotSung()
public ReadOnlyCollection<CSong> GetVisibleSongs()
{
return CSongs.SongsNotSung;
return CSongs.VisibleSongs;
}
public CCategory GetCategory(int index)
@@ -641,12 +642,12 @@ namespace Vocaluxe.Base
CSongs.AddPartySongSung(songID);
}
public void ResetPartySongSung()
public void ResetSongSung()
{
CSongs.ResetPartySongSung();
}
public void ResetPartySongSung(int catIndex)
public void ResetSongSung(int catIndex)
{
CSongs.ResetPartySongSung(catIndex);
}
+1 -1
View File
@@ -223,7 +223,7 @@ namespace Vocaluxe.Base
private static CPlaylistFile _ConvertUSDXPlaylist(string file)
{
CPlaylistFile pl = new CPlaylistFile();
CSong[] allSongs = CSongs.AllSongs;
var allSongs = CSongs.AllSongs;
if (!File.Exists(file))
return null;
+34 -39
View File
@@ -32,7 +32,7 @@ namespace Vocaluxe.Base
public CSongCategorizer()
{
CSongs.Filter.ObjectChanged += _HandleSortedSongsChanged;
CSongs.Sorter.ObjectChanged += _HandleSortedSongsChanged;
}
public List<CCategory> Categories
@@ -49,11 +49,10 @@ namespace Vocaluxe.Base
get { return _Tabs; }
set
{
if (value != _Tabs)
{
_Tabs = value;
_SetChanged();
}
if (value == _Tabs)
return;
_Tabs = value;
_SetChanged();
}
}
@@ -64,58 +63,55 @@ namespace Vocaluxe.Base
private void _CreateCategoriesLetter()
{
string category = "";
int notLetterCat = -1;
CCategory lastCategory = null;
CCategory notLetterCat = null;
for (int i = 0; i < CSongs.Sorter.SortedSongs.Length; i++)
{
Char firstLetter = Char.ToUpper(CSongs.Sorter.SortedSongs[i].SortString.Normalize(NormalizationForm.FormD)[0]);
if (!Char.IsLetter(firstLetter))
firstLetter = '#';
if (firstLetter.ToString() != category)
if (Char.IsLetter(firstLetter))
{
if (firstLetter != '#' || notLetterCat == -1)
if (lastCategory == null || CSongs.Sorter.SortedSongs[i].SortString != lastCategory.Name)
{
category = firstLetter.ToString();
_Categories.Add(new CCategory(category));
CSongs.Sorter.SortedSongs[i].CatIndex = _Categories.Count - 1;
if (firstLetter == '#')
notLetterCat = CSongs.Sorter.SortedSongs[i].CatIndex;
lastCategory = new CCategory(CSongs.Sorter.SortedSongs[i].SortString);
_Categories.Add(lastCategory);
}
else
CSongs.Sorter.SortedSongs[i].CatIndex = notLetterCat;
lastCategory.Songs.Add(CSongs.Sorter.SortedSongs[i]);
}
else
CSongs.Sorter.SortedSongs[i].CatIndex = _Categories.Count - 1;
{
if (notLetterCat == null)
{
notLetterCat = new CCategory("#");
_Categories.Add(notLetterCat);
}
notLetterCat.Songs.Add(CSongs.Sorter.SortedSongs[i]);
}
}
}
private void _CreateCategoriesNormal(string noCategoryName)
{
string category = "";
int noCategoryIndex = -1;
CCategory lastCategory = null;
CCategory noCategory = null;
for (int i = 0; i < CSongs.Sorter.SortedSongs.Length; i++)
{
if (CSongs.Sorter.SortedSongs[i].SortString != "")
{
if (CSongs.Sorter.SortedSongs[i].SortString != category)
if (lastCategory == null || CSongs.Sorter.SortedSongs[i].SortString != lastCategory.Name)
{
category = CSongs.Sorter.SortedSongs[i].SortString;
_Categories.Add(new CCategory(category));
lastCategory = new CCategory(CSongs.Sorter.SortedSongs[i].SortString);
_Categories.Add(lastCategory);
}
CSongs.Sorter.SortedSongs[i].CatIndex = _Categories.Count - 1;
lastCategory.Songs.Add(CSongs.Sorter.SortedSongs[i]);
}
else
{
if (noCategoryIndex < 0)
if (noCategory == null)
{
category = noCategoryName;
_Categories.Add(new CCategory(category));
noCategoryIndex = _Categories.Count - 1;
noCategory = new CCategory(noCategoryName);
_Categories.Add(noCategory);
}
CSongs.Sorter.SortedSongs[i].CatIndex = noCategoryIndex;
noCategory.Songs.Add(CSongs.Sorter.SortedSongs[i]);
}
}
}
@@ -172,15 +168,14 @@ namespace Vocaluxe.Base
_Categories.Clear();
if (_Tabs == EOffOn.TR_CONFIG_OFF)
if (_Tabs != EOffOn.TR_CONFIG_OFF)
_CreateCategories();
else
{
//No categories. So don't create them!
_Categories.Add(new CCategory(""));
for (int i = 0; i < CSongs.Sorter.SortedSongs.Length; i++)
CSongs.Sorter.SortedSongs[i].CatIndex = 0;
_Categories[0].Songs.AddRange(CSongs.Sorter.SortedSongs);
}
else
_CreateCategories();
foreach (CCategory cat in _Categories)
cat.CoverTextureSmall = CCover.Cover(cat.Name);
+11 -11
View File
@@ -27,7 +27,7 @@ namespace Vocaluxe.Base
{
class CSongSorter : CObservable
{
private SSongPointer[] _SortedSongs = new SSongPointer[0];
private CSongPointer[] _SortedSongs = new CSongPointer[0];
private EOffOn _IgnoreArticles = CConfig.IgnoreArticles;
private ESongSorting _SongSorting = CConfig.SongSorting;
@@ -36,7 +36,7 @@ namespace Vocaluxe.Base
CSongs.Filter.ObjectChanged += _HandleFilteredSongsChanged;
}
public SSongPointer[] SortedSongs
public CSongPointer[] SortedSongs
{
get
{
@@ -84,7 +84,7 @@ namespace Vocaluxe.Base
_SetChanged();
}
private int _SortByFieldArtistTitle(SSongPointer s1, SSongPointer s2)
private int _SortByFieldArtistTitle(CSongPointer s1, CSongPointer s2)
{
int res = String.Compare(s1.SortString, s2.SortString, StringComparison.OrdinalIgnoreCase);
if (res == 0)
@@ -100,7 +100,7 @@ namespace Vocaluxe.Base
return res;
}
private int _SortByFieldTitle(SSongPointer s1, SSongPointer s2)
private int _SortByFieldTitle(CSongPointer s1, CSongPointer s2)
{
int res = String.Compare(s1.SortString, s2.SortString, StringComparison.OrdinalIgnoreCase);
if (res == 0)
@@ -112,11 +112,11 @@ namespace Vocaluxe.Base
return res;
}
private List<SSongPointer> _CreateSortList(string fieldName)
private List<CSongPointer> _CreateSortList(string fieldName)
{
List<SSongPointer> sortList = new List<SSongPointer>();
List<CSongPointer> sortList = new List<CSongPointer>();
if (fieldName == "")
CSongs.Filter.FilteredSongs.ForEach(song => sortList.Add(new SSongPointer(song.ID, "")));
CSongs.Filter.FilteredSongs.ForEach(song => sortList.Add(new CSongPointer(song.ID, "")));
else
{
FieldInfo field = typeof(CSong).GetField(fieldName, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
@@ -132,16 +132,16 @@ namespace Vocaluxe.Base
{
object value = field.GetValue(song);
if (isString)
sortList.Add(new SSongPointer(song.ID, (String)value));
sortList.Add(new CSongPointer(song.ID, (String)value));
else
{
List<String> values = (List<String>)value;
if (values.Count == 0)
sortList.Add(new SSongPointer(song.ID, ""));
sortList.Add(new CSongPointer(song.ID, ""));
else
{
foreach (String sortString in values)
sortList.Add(new SSongPointer(song.ID, sortString));
sortList.Add(new CSongPointer(song.ID, sortString));
}
}
}
@@ -183,7 +183,7 @@ namespace Vocaluxe.Base
fieldName = "";
break;
}
List<SSongPointer> sortList = _CreateSortList(fieldName);
List<CSongPointer> sortList = _CreateSortList(fieldName);
switch (_SongSorting)
{
case ESongSorting.TR_CONFIG_ARTIST_LETTER:
+45 -128
View File
@@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using VocaluxeLib.Menu;
@@ -26,31 +27,11 @@ using VocaluxeLib.Menu.SongMenu;
namespace Vocaluxe.Base
{
public struct SSongPointer
{
public readonly int SongID;
public string SortString;
public int CatIndex;
public bool Visible;
public bool PartyHidden;
public SSongPointer(int id, string sortString)
{
SongID = id;
SortString = sortString;
CatIndex = -1;
Visible = false;
PartyHidden = false;
}
}
static class CSongs
{
private static readonly List<CSong> _Songs = new List<CSong>();
private static readonly List<CSong> _SongsForRandom = new List<CSong>();
private static bool _SongsLoaded;
private static bool _CoverLoaded;
private static int _CatIndex = -1;
private static readonly List<CCategory> _CategoriesForRandom = new List<CCategory>();
@@ -66,16 +47,13 @@ namespace Vocaluxe.Base
get { return _Songs; }
}
public static bool SongsLoaded
{
get { return _SongsLoaded; }
}
public static bool SongsLoaded { get; private set; }
public static bool CoverLoaded
{
get
{
if (_SongsLoaded && NumAllSongs == 0)
if (SongsLoaded && NumAllSongs == 0)
_CoverLoaded = true;
return _CoverLoaded;
}
@@ -86,14 +64,14 @@ namespace Vocaluxe.Base
get { return _Songs.Count; }
}
public static int NumVisibleSongs
public static int NumSongsVisible
{
get { return Sorter.SortedSongs.Count(sp => sp.Visible); }
get { return _CatIndex < 0 ? 0 : Categories[_CatIndex].Songs.Count(sp => !sp.IsSung); }
}
public static int NumCategories
{
get { return Categorizer.Categories.Count; }
get { return Categories.Count; }
}
public static int Category
@@ -101,13 +79,8 @@ namespace Vocaluxe.Base
get { return _CatIndex; }
set
{
if (value >= -1 && value < Categorizer.Categories.Count)
{
if (value == -1 || IsCatIndexValid(value))
_CatIndex = value;
for (int i = 0; i < Sorter.SortedSongs.Length; i++)
Sorter.SortedSongs[i].Visible = Sorter.SortedSongs[i].CatIndex == _CatIndex && !Sorter.SortedSongs[i].PartyHidden;
}
}
}
@@ -116,6 +89,11 @@ namespace Vocaluxe.Base
get { return _CatIndex >= 0; }
}
private static bool IsCatIndexValid(int catIndex)
{
return catIndex >= 0 && catIndex < Categories.Count;
}
/// <summary>
/// Returns the number of song in the category specified with CatIndex
/// </summary>
@@ -123,21 +101,12 @@ namespace Vocaluxe.Base
/// <returns></returns>
public static int NumSongsInCategory(int catIndex)
{
if (Categorizer.Categories.Count <= catIndex || catIndex < 0)
return 0;
int num = 0;
for (int i = 0; i < Sorter.SortedSongs.Length; i++)
{
if (Sorter.SortedSongs[i].CatIndex == catIndex && !Sorter.SortedSongs[i].PartyHidden)
num++;
}
return num;
return IsCatIndexValid(catIndex) ? Categories[catIndex].Songs.Count(sp => !sp.IsSung) : 0;
}
public static void NextCategory()
{
if (Category == Categorizer.Categories.Count - 1)
if (Category == Categories.Count - 1)
Category = 0;
else
Category++;
@@ -146,7 +115,7 @@ namespace Vocaluxe.Base
public static void PrevCategory()
{
if (Category == 0)
Category = Categorizer.Categories.Count - 1;
Category = Categories.Count - 1;
else
Category--;
}
@@ -168,29 +137,9 @@ namespace Vocaluxe.Base
public static int NumSongsWithCoverLoaded { get; private set; }
public static void SetCoverSmall(int songIndex, STexture texture)
{
if (!_SongsLoaded)
return;
if (songIndex < _Songs.Count)
_Songs[songIndex].CoverTextureSmall = texture;
}
public static void SetCoverBig(int songIndex, STexture texture)
{
if (!_SongsLoaded)
return;
if (songIndex < _Songs.Count)
_Songs[songIndex].CoverTextureBig = texture;
}
public static string GetCurrentCategoryName()
{
if ((Categorizer.Categories.Count > 0) && (_CatIndex >= 0) && (Categorizer.Categories.Count > _CatIndex))
return Categorizer.Categories[_CatIndex].Name;
return String.Empty;
return IsCatIndexValid(_CatIndex) ? Categories[_CatIndex].Name : "";
}
public static CSong GetSong(int songID)
@@ -200,43 +149,31 @@ namespace Vocaluxe.Base
public static void AddPartySongSung(int songID)
{
int cat = -1;
for (int i = 0; i < Sorter.SortedSongs.Length; i++)
foreach (CCategory category in Categories)
{
if (songID == Sorter.SortedSongs[i].SongID)
foreach (CSongPointer song in category.Songs.Where(song => song.SongID == songID))
{
Sorter.SortedSongs[i].PartyHidden = true;
Sorter.SortedSongs[i].Visible = false;
cat = Sorter.SortedSongs[i].CatIndex;
break;
song.IsSung = true;
int catIndex = _GetCategoryNumber(category);
if (NumSongsInCategory(catIndex) == 0)
ResetPartySongSung(catIndex);
return;
}
}
if (cat != -1)
{
if (NumSongsInCategory(cat) == 0)
ResetPartySongSung(cat);
}
}
public static void ResetPartySongSung()
{
for (int i = 0; i < Sorter.SortedSongs.Length; i++)
{
Sorter.SortedSongs[i].PartyHidden = false;
Sorter.SortedSongs[i].Visible = Sorter.SortedSongs[i].CatIndex == _CatIndex && !Sorter.SortedSongs[i].PartyHidden;
}
foreach (CSongPointer song in Sorter.SortedSongs)
song.IsSung = false;
}
public static void ResetPartySongSung(int catIndex)
{
for (int i = 0; i < Sorter.SortedSongs.Length; i++)
if (IsCatIndexValid(catIndex))
{
if (Sorter.SortedSongs[i].CatIndex == catIndex)
{
Sorter.SortedSongs[i].PartyHidden = false;
Sorter.SortedSongs[i].Visible = Sorter.SortedSongs[i].CatIndex == _CatIndex && !Sorter.SortedSongs[i].PartyHidden;
}
foreach (CSongPointer song in Categories[catIndex].Songs)
song.IsSung = false;
}
}
@@ -292,7 +229,7 @@ namespace Vocaluxe.Base
private static int _GetCategoryNumber(CCategory category)
{
for (int i = 0; i < Categories.Length; i++)
for (int i = 0; i < Categories.Count; i++)
{
if (Categories[i] == category)
return i;
@@ -300,59 +237,39 @@ namespace Vocaluxe.Base
return -1;
}
public static CSong[] AllSongs
public static ReadOnlyCollection<CSong> AllSongs
{
get { return _Songs.ToArray(); }
get { return _Songs.AsReadOnly(); }
}
public static CSong[] SongsNotSung
public static ReadOnlyCollection<CSong> VisibleSongs
{
get
{
List<CSong> songs = new List<CSong>();
foreach (SSongPointer sp in Sorter.SortedSongs)
if (IsCatIndexValid(_CatIndex))
{
if (sp.Visible)
songs.Add(_Songs[sp.SongID]);
foreach (CSongPointer sp in Categories[_CatIndex].Songs)
{
if (!sp.IsSung)
songs.Add(_Songs[sp.SongID]);
}
}
return songs.ToArray();
return songs.AsReadOnly();
}
}
public static CSong[] VisibleSongs
public static ReadOnlyCollection<CCategory> Categories
{
get
{
List<CSong> songs = new List<CSong>();
foreach (SSongPointer sp in Sorter.SortedSongs)
{
if (sp.Visible)
songs.Add(_Songs[sp.SongID]);
}
return songs.ToArray();
}
}
public static CCategory[] Categories
{
get { return Categorizer.Categories.ToArray(); }
get { return Categorizer.Categories.AsReadOnly(); }
}
public static CSong GetVisibleSongByIndex(int index)
{
if (index < 0)
return null;
foreach (SSongPointer sp in Sorter.SortedSongs)
{
if (sp.Visible)
{
if (index == 0)
return _Songs[sp.SongID];
index--;
}
}
return null;
var visSongs = VisibleSongs;
return (index < visSongs.Count) ? visSongs[index] : null;
}
private static void _HandleCategoriesChanged(object sender, EventArgs args)
@@ -371,7 +288,7 @@ namespace Vocaluxe.Base
public static void LoadSongs()
{
CLog.StartBenchmark(1, "Load Songs");
_SongsLoaded = false;
SongsLoaded = false;
_Songs.Clear();
CLog.StartBenchmark(2, "List Songs");
@@ -403,7 +320,7 @@ namespace Vocaluxe.Base
Categorizer.ObjectChanged += _HandleCategoriesChanged;
CLog.StopBenchmark(2, "Sort Songs");
Category = -1;
_SongsLoaded = true;
SongsLoaded = true;
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART)
{
+1 -1
View File
@@ -82,7 +82,7 @@ namespace Vocaluxe.Base.Font
point);
* */
Texture = CDraw.AddTexture(bmp);
bmp.Save("font/" + chr + CFonts.Style + ".png", ImageFormat.Png);
//bmp.Save("font/" + chr + CFonts.Style + ".png", ImageFormat.Png);
Width = (int)((1f + outline / 2f) * sizeB.Width * Texture.Width / factor / bmp.Width);
g.Dispose();
}
+1 -2
View File
@@ -155,9 +155,8 @@ namespace Vocaluxe.Lib.Playlist
xmlReader.TryGetEnumValue("//root/Songs/" + song + "/GameMode", ref gm);
CPlaylistSong playlistSong = new CPlaylistSong {SongID = -1};
CSong[] allSongs = CSongs.AllSongs;
foreach (CSong curSong in allSongs)
foreach (CSong curSong in CSongs.AllSongs)
{
if (curSong.Artist != artist || curSong.Title != title)
continue;
-5
View File
@@ -181,12 +181,7 @@ namespace Vocaluxe.Screens
CConfig.SaveConfig();
if (_OldCoverTheme != _SelectSlides[_SelectSlideCover].Selection)
{
CCover.ReloadCover();
CSongs.Filter.SearchString = String.Empty;
CSongs.Sorter.SetOptions(CConfig.SongSorting, CConfig.IgnoreArticles);
CSongs.Categorizer.Tabs = CConfig.Tabs;
}
if (_OldTheme != _SelectSlides[_SelectSlideTheme].Selection)
{
+39 -32
View File
@@ -213,7 +213,7 @@ namespace Vocaluxe.Screens
if (_Buttons[_ButtonStart].Selected)
_HandlePartySongSelection(_SongMenus[_SongMenu].GetSelectedSong());
}
if (CSongs.NumVisibleSongs > 0 && !_Sso.Selection.PartyMode)
if (CSongs.NumSongsVisible > 0 && !_Sso.Selection.PartyMode)
{
if (_SongMenus[_SongMenu].GetSelectedSong() != -1 && !_SongOptionsActive)
{
@@ -276,7 +276,7 @@ namespace Vocaluxe.Screens
break;
case Keys.S:
if (keyEvent.Mod == EModifier.Ctrl && CSongs.NumVisibleSongs > 0 && !_Sso.Selection.PartyMode)
if (keyEvent.Mod == EModifier.Ctrl && CSongs.NumSongsVisible > 0 && !_Sso.Selection.PartyMode)
_StartMedleySong(_SongMenus[_SongMenu].GetSelectedSong());
break;
@@ -442,7 +442,7 @@ namespace Vocaluxe.Screens
{
//TODO: Causes Bug if you select a song (e.g. with Select random song) and double click a normal button.
//E.g. clicking to fast on Select random song starts the next random song. is this OK?
if (CSongs.NumVisibleSongs > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1)
if (CSongs.NumSongsVisible > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1)
{
_ToggleSongOptions(ESongOptionsView.None);
_StartVisibleSong(_SongMenus[_SongMenu].GetActualSelection());
@@ -558,7 +558,7 @@ namespace Vocaluxe.Screens
}
}
if (CSongs.NumVisibleSongs > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1 && !_Sso.Selection.PartyMode)
if (CSongs.NumSongsVisible > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1 && !_Sso.Selection.PartyMode)
{
if (_SongMenus[_SongMenu].GetSelectedSong() != -1 && !_SongOptionsActive)
{
@@ -572,7 +572,7 @@ namespace Vocaluxe.Screens
if (mouseEvent.LBH)
{
if (!_DragAndDropActive && _Playlists[_Playlist].Visible && CSongs.NumVisibleSongs > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1)
if (!_DragAndDropActive && _Playlists[_Playlist].Visible && CSongs.NumSongsVisible > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1)
{
_DragAndDropCover = _SongMenus[_SongMenu].GetSelectedSongCover();
_DragAndDropCover.Rect.Z = CSettings.ZNear;
@@ -653,9 +653,9 @@ namespace Vocaluxe.Screens
CBackgroundMusic.Disabled = false;
int song = _SongMenus[_SongMenu].GetActualSelection();
if ((CSongs.Category >= 0 || CConfig.Tabs == EOffOn.TR_CONFIG_OFF) && song >= 0 && song < CSongs.VisibleSongs.Length)
if ((CSongs.Category >= 0 || CConfig.Tabs == EOffOn.TR_CONFIG_OFF) && song >= 0 && song < CSongs.VisibleSongs.Count)
_Texts[_TextSelection].Text = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title;
else if (!CSongs.IsInCategory && song >= 0 && song < CSongs.Categories.Length)
else if (!CSongs.IsInCategory && song >= 0 && song < CSongs.Categories.Count)
_Texts[_TextSelection].Text = CSongs.Categories[song].Name;
else
_Texts[_TextSelection].Text = String.Empty;
@@ -822,7 +822,7 @@ namespace Vocaluxe.Screens
private void _StartVisibleSong(int songNr)
{
if (CSongs.Category >= 0 && songNr >= 0 && CSongs.NumVisibleSongs > songNr)
if (CSongs.Category >= 0 && songNr >= 0 && CSongs.NumSongsVisible > songNr)
{
EGameMode gm = CSongs.VisibleSongs[songNr].IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL;
@@ -856,7 +856,7 @@ namespace Vocaluxe.Screens
CGame.ClearSongs();
List<int> ids = new List<int>();
for (int i = 0; i < CSongs.AllSongs.Length; i++)
for (int i = 0; i < CSongs.AllSongs.Count; i++)
ids.Add(i);
while (ids.Count > 0)
@@ -882,7 +882,7 @@ namespace Vocaluxe.Screens
CGame.ClearSongs();
List<int> ids = new List<int>();
for (int i = 0; i < CSongs.VisibleSongs.Length; i++)
for (int i = 0; i < CSongs.VisibleSongs.Count; i++)
ids.Add(CSongs.VisibleSongs[i].ID);
while (ids.Count > 0)
@@ -910,12 +910,12 @@ namespace Vocaluxe.Screens
List<int> ids = new List<int>();
if (allSongs)
{
for (int i = 0; i < CSongs.AllSongs.Length; i++)
for (int i = 0; i < CSongs.AllSongs.Count; i++)
ids.Add(i);
}
else
{
for (int i = 0; i < CSongs.VisibleSongs.Length; i++)
for (int i = 0; i < CSongs.VisibleSongs.Count; i++)
ids.Add(CSongs.VisibleSongs[i].ID);
}
int s = 0;
@@ -985,6 +985,21 @@ namespace Vocaluxe.Screens
return false;
}
private int _FindIndex<T>(IList<T> list, int start, Predicate<T> match)
{
for (int i = start; i < list.Count; i++)
{
if (match(list[i]))
return i;
}
for (int i = 0; i < start; i++)
{
if (match(list[i]))
return i;
}
return -1;
}
private void _JumpTo(char letter)
{
int start = 0;
@@ -992,29 +1007,21 @@ namespace Vocaluxe.Screens
if (CSongs.IsInCategory)
{
//TODO: Check and use sorting method
CSong[] songs = CSongs.VisibleSongs;
int ct = songs.Length;
if (curSelected >= 0 && curSelected < ct - 1)
{
CSong currentSong = CSongs.GetVisibleSongByIndex(curSelected);
if (currentSong != null && currentSong.Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase))
start = curSelected + 1;
}
int visibleID = Array.FindIndex(songs, start, ct - start, element => element.Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase));
if (visibleID < 0 && start > 1)
visibleID = Array.FindIndex(songs, 0, start - 1, element => element.Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase));
var songs = CSongs.VisibleSongs;
int ct = songs.Count;
if (curSelected >= 0 && curSelected < ct - 1 && songs[curSelected].Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase))
start = curSelected + 1;
int visibleID = _FindIndex(songs, start, element => element.Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase));
if (visibleID > -1)
_SongMenus[_SongMenu].SetSelectedSong(visibleID);
}
else
{
CCategory[] categories = CSongs.Categories;
int ct = categories.Length;
var categories = CSongs.Categories;
int ct = categories.Count;
if (curSelected >= 0 && curSelected < ct - 1 && categories[curSelected].Name.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase))
start = curSelected + 1;
int visibleID = Array.FindIndex(categories, start, ct - start, element => element.Name.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase));
if (visibleID < 0 && start > 1)
visibleID = Array.FindIndex(categories, 0, start - 1, element => element.Name.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase));
int visibleID = _FindIndex(categories, start, element => element.Name.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase));
if (visibleID > -1)
_SongMenus[_SongMenu].SetSelectedCategory(visibleID);
}
@@ -1030,7 +1037,7 @@ namespace Vocaluxe.Screens
int songIndex = _SongMenus[_SongMenu].GetSelectedSong();
int songID = -1;
if (songIndex != -1 && CSongs.NumVisibleSongs > 0 && CSongs.NumVisibleSongs > songIndex)
if (songIndex != -1 && CSongs.NumSongsVisible > 0 && CSongs.NumSongsVisible > songIndex)
songID = CSongs.VisibleSongs[songIndex].ID;
if (newFilterString == "" && _Sso.Sorting.Tabs == EOffOn.TR_CONFIG_ON)
@@ -1047,7 +1054,7 @@ namespace Vocaluxe.Screens
CSongs.Sort(_Sso.Sorting.SongSorting, _Sso.Sorting.Tabs, _Sso.Sorting.IgnoreArticles, newFilterString, _Sso.Sorting.DuetOptions);
if (songID == -1 || CSongs.NumVisibleSongs == 0 || CSongs.NumVisibleSongs <= songIndex || CSongs.GetVisibleSongByIndex(songIndex).ID != songID)
if (songID == -1 || CSongs.NumSongsVisible == 0 || CSongs.NumSongsVisible <= songIndex || CSongs.GetVisibleSongByIndex(songIndex).ID != songID)
refresh = true;
if (refresh)
@@ -1162,12 +1169,12 @@ namespace Vocaluxe.Screens
_SelectSlides[_SelectSlideOptionsNumMedleySongs].Clear();
if (CSongs.IsInCategory)
{
for (int i = 1; i <= CSongs.VisibleSongs.Length; i++)
for (int i = 1; i <= CSongs.VisibleSongs.Count; i++)
_SelectSlides[_SelectSlideOptionsNumMedleySongs].AddValue(i.ToString());
}
else
{
for (int i = 1; i <= CSongs.AllSongs.Length; i++)
for (int i = 1; i <= CSongs.AllSongs.Count; i++)
_SelectSlides[_SelectSlideOptionsNumMedleySongs].AddValue(i.ToString());
}
if (_SelectSlides[_SelectSlideOptionsNumMedleySongs].NumValues >= 5)
+4 -4
View File
@@ -60,12 +60,12 @@ namespace Vocaluxe.SongQueue
public bool AddVisibleSong(int visibleIndex, EGameMode gameMode)
{
return CSongs.VisibleSongs.Length > visibleIndex && _AddSong(CSongs.VisibleSongs[visibleIndex].ID, gameMode);
return CSongs.VisibleSongs.Count > visibleIndex && _AddSong(CSongs.VisibleSongs[visibleIndex].ID, gameMode);
}
public bool AddSong(int absoluteIndex, EGameMode gameMode)
{
return CSongs.AllSongs.Length > absoluteIndex && _AddSong(CSongs.AllSongs[absoluteIndex].ID, gameMode);
return CSongs.AllSongs.Count > absoluteIndex && _AddSong(CSongs.AllSongs[absoluteIndex].ID, gameMode);
}
private bool _AddSong(int songID, EGameMode gameMode)
@@ -79,12 +79,12 @@ namespace Vocaluxe.SongQueue
public bool RemoveVisibleSong(int visibleIndex)
{
return CSongs.VisibleSongs.Length > visibleIndex && _RemoveSong(CSongs.VisibleSongs[visibleIndex].ID);
return CSongs.VisibleSongs.Count > visibleIndex && _RemoveSong(CSongs.VisibleSongs[visibleIndex].ID);
}
public bool RemoveSong(int absoluteIndex)
{
return CSongs.AllSongs.Length > absoluteIndex && _RemoveSong(CSongs.AllSongs[absoluteIndex].ID);
return CSongs.AllSongs.Count > absoluteIndex && _RemoveSong(CSongs.AllSongs[absoluteIndex].ID);
}
private bool _RemoveSong(int songID)