diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index 0803558d..aa743c90 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Runtime.InteropServices; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -504,7 +505,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley List ids = new List(); - var visibleSongs = CBase.Songs.GetVisibleSongs(); + ReadOnlyCollection visibleSongs = CBase.Songs.GetVisibleSongs(); if (visibleSongs.Count == 0) { CBase.Log.LogError("CPartyChallengeMedleyMode Error: There are no songs!"); diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 6b3781a8..e894da18 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -584,6 +584,11 @@ namespace Vocaluxe.Base return CSongs.NumSongsInCategory(categoryIndex); } + public bool IsInCategory() + { + return CSongs.IsInCategory; + } + public int GetCurrentCategoryIndex() { return CSongs.Category; diff --git a/Vocaluxe/Base/CPlaylists.cs b/Vocaluxe/Base/CPlaylists.cs index ca3e8e34..f057b26c 100644 --- a/Vocaluxe/Base/CPlaylists.cs +++ b/Vocaluxe/Base/CPlaylists.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Text; using Vocaluxe.Lib.Playlist; @@ -223,7 +224,7 @@ namespace Vocaluxe.Base private static CPlaylistFile _ConvertUSDXPlaylist(string file) { CPlaylistFile pl = new CPlaylistFile(); - var allSongs = CSongs.AllSongs; + ReadOnlyCollection allSongs = CSongs.AllSongs; if (!File.Exists(file)) return null; diff --git a/Vocaluxe/Base/CSongCategorizer.cs b/Vocaluxe/Base/CSongCategorizer.cs index 3e4e4706..d442bd20 100644 --- a/Vocaluxe/Base/CSongCategorizer.cs +++ b/Vocaluxe/Base/CSongCategorizer.cs @@ -52,6 +52,8 @@ namespace Vocaluxe.Base if (value == _Tabs) return; _Tabs = value; + if (_Tabs == EOffOn.TR_CONFIG_ON) + CSongs.Category = -1; _SetChanged(); } } diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index b52dbd36..3ce699ae 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -76,20 +76,25 @@ namespace Vocaluxe.Base public static int Category { - get { return _CatIndex; } + get + { + if (_CatIndex >= Categories.Count) + _CatIndex = -1; + return _CatIndex; + } set { - if (value == -1 || IsCatIndexValid(value)) + if (value == -1 || _IsCatIndexValid(value)) _CatIndex = value; } } public static bool IsInCategory { - get { return _CatIndex >= 0; } + get { return _IsCatIndexValid(_CatIndex); } } - private static bool IsCatIndexValid(int catIndex) + private static bool _IsCatIndexValid(int catIndex) { return catIndex >= 0 && catIndex < Categories.Count; } @@ -101,7 +106,7 @@ namespace Vocaluxe.Base /// public static int NumSongsInCategory(int catIndex) { - return IsCatIndexValid(catIndex) ? Categories[catIndex].Songs.Count(sp => !sp.IsSung) : 0; + return _IsCatIndexValid(catIndex) ? Categories[catIndex].Songs.Count(sp => !sp.IsSung) : 0; } public static void NextCategory() @@ -139,7 +144,7 @@ namespace Vocaluxe.Base public static string GetCurrentCategoryName() { - return IsCatIndexValid(_CatIndex) ? Categories[_CatIndex].Name : ""; + return _IsCatIndexValid(_CatIndex) ? Categories[_CatIndex].Name : ""; } public static CSong GetSong(int songID) @@ -170,7 +175,7 @@ namespace Vocaluxe.Base public static void ResetPartySongSung(int catIndex) { - if (IsCatIndexValid(catIndex)) + if (_IsCatIndexValid(catIndex)) { foreach (CSongPointer song in Categories[catIndex].Songs) song.IsSung = false; @@ -247,7 +252,7 @@ namespace Vocaluxe.Base get { List songs = new List(); - if (IsCatIndexValid(_CatIndex)) + if (_IsCatIndexValid(_CatIndex)) { foreach (CSongPointer sp in Categories[_CatIndex].Songs) { @@ -268,14 +273,13 @@ namespace Vocaluxe.Base { if (index < 0) return null; - var visSongs = VisibleSongs; + ReadOnlyCollection visSongs = VisibleSongs; return (index < visSongs.Count) ? visSongs[index] : null; } private static void _HandleCategoriesChanged(object sender, EventArgs args) { _CategoriesForRandom.Clear(); - Category = _CatIndex; } public static void Sort(ESongSorting sorting, EOffOn tabs, EOffOn ignoreArticles, String searchString, EDuetOptions duetOptions) diff --git a/Vocaluxe/Base/Font/CFonts.cs b/Vocaluxe/Base/Font/CFonts.cs index 85d7fde3..21922d7a 100644 --- a/Vocaluxe/Base/Font/CFonts.cs +++ b/Vocaluxe/Base/Font/CFonts.cs @@ -1,3 +1,22 @@ +#region license +// /* +// This file is part of Vocaluxe. +// +// Vocaluxe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Vocaluxe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Vocaluxe. If not, see . +// */ +#endregion + using System.Collections.Generic; using System.Drawing; using System.IO; diff --git a/Vocaluxe/Base/Font/CGlyph.cs b/Vocaluxe/Base/Font/CGlyph.cs index bca65ad9..c9cfe58b 100644 --- a/Vocaluxe/Base/Font/CGlyph.cs +++ b/Vocaluxe/Base/Font/CGlyph.cs @@ -1,3 +1,22 @@ +#region license +// /* +// This file is part of Vocaluxe. +// +// Vocaluxe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Vocaluxe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Vocaluxe. If not, see . +// */ +#endregion + using System; using System.Drawing; using System.Drawing.Drawing2D; diff --git a/Vocaluxe/GameModes/CGameMode.cs b/Vocaluxe/GameModes/CGameMode.cs index c246c3f0..31675f31 100644 --- a/Vocaluxe/GameModes/CGameMode.cs +++ b/Vocaluxe/GameModes/CGameMode.cs @@ -1,3 +1,22 @@ +#region license +// /* +// This file is part of Vocaluxe. +// +// Vocaluxe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Vocaluxe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Vocaluxe. If not, see . +// */ +#endregion + using Vocaluxe.Base; using VocaluxeLib.Menu.SongMenu; diff --git a/Vocaluxe/GameModes/CGameModes.cs b/Vocaluxe/GameModes/CGameModes.cs index 18b1b980..a29847a0 100644 --- a/Vocaluxe/GameModes/CGameModes.cs +++ b/Vocaluxe/GameModes/CGameModes.cs @@ -1,4 +1,23 @@ -using System; +#region license +// /* +// This file is part of Vocaluxe. +// +// Vocaluxe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Vocaluxe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Vocaluxe. If not, see . +// */ +#endregion + +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/Vocaluxe/GameModes/IGameMode.cs b/Vocaluxe/GameModes/IGameMode.cs index 940bc1f1..62277660 100644 --- a/Vocaluxe/GameModes/IGameMode.cs +++ b/Vocaluxe/GameModes/IGameMode.cs @@ -1,4 +1,23 @@ -using VocaluxeLib.Menu.SongMenu; +#region license +// /* +// This file is part of Vocaluxe. +// +// Vocaluxe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Vocaluxe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Vocaluxe. If not, see . +// */ +#endregion + +using VocaluxeLib.Menu.SongMenu; namespace Vocaluxe.GameModes { diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 6495e45a..49e62367 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -1007,7 +1008,7 @@ namespace Vocaluxe.Screens if (CSongs.IsInCategory) { //TODO: Check and use sorting method - var songs = CSongs.VisibleSongs; + ReadOnlyCollection songs = CSongs.VisibleSongs; int ct = songs.Count; if (curSelected >= 0 && curSelected < ct - 1 && songs[curSelected].Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)) start = curSelected + 1; @@ -1017,7 +1018,7 @@ namespace Vocaluxe.Screens } else { - var categories = CSongs.Categories; + ReadOnlyCollection categories = CSongs.Categories; int ct = categories.Count; if (curSelected >= 0 && curSelected < ct - 1 && categories[curSelected].Name.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)) start = curSelected + 1; diff --git a/VocaluxeLib/Menu/IMenu.cs b/VocaluxeLib/Menu/IMenu.cs index 979328e2..6c82b349 100644 --- a/VocaluxeLib/Menu/IMenu.cs +++ b/VocaluxeLib/Menu/IMenu.cs @@ -244,6 +244,7 @@ namespace VocaluxeLib.Menu int GetNumSongsVisible(); int GetNumCategories(); int NumSongsInCategory(int categoryIndex); + bool IsInCategory(); int GetCurrentCategoryIndex(); EOffOn GetTabs(); diff --git a/VocaluxeLib/Menu/SongMenu/CCategory.cs b/VocaluxeLib/Menu/SongMenu/CCategory.cs index c8a043e9..faa5a22a 100644 --- a/VocaluxeLib/Menu/SongMenu/CCategory.cs +++ b/VocaluxeLib/Menu/SongMenu/CCategory.cs @@ -1,4 +1,23 @@ -using System.Collections.Generic; +#region license +// /* +// This file is part of Vocaluxe. +// +// Vocaluxe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Vocaluxe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Vocaluxe. If not, see . +// */ +#endregion + +using System.Collections.Generic; namespace VocaluxeLib.Menu.SongMenu { diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index e3329358..8ff84dc1 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -559,7 +559,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (!_Initialized) return false; - if (CBase.Songs.GetCurrentCategoryIndex() >= 0 || _PreviewSelected < 0 || _PreviewSelected >= CBase.Songs.GetNumCategories()) + if (CBase.Songs.IsInCategory() || _PreviewSelected < 0 || _PreviewSelected >= CBase.Songs.GetNumCategories()) return false; _EnterCategory(_PreviewSelected); return true; @@ -582,7 +582,7 @@ namespace VocaluxeLib.Menu.SongMenu if (!_Initialized) return; - if (CBase.Songs.GetCurrentCategoryIndex() == -1) + if (!CBase.Songs.IsInCategory()) return; _Reset(); @@ -596,7 +596,7 @@ namespace VocaluxeLib.Menu.SongMenu protected void _SelectSong(int nr) { - if (CBase.Songs.GetCurrentCategoryIndex() >= 0 && (CBase.Songs.GetNumSongsVisible() > 0) && (nr >= 0) && ((_Actsong != nr) || (_Streams.Count == 0))) + if (CBase.Songs.IsInCategory() && (CBase.Songs.GetNumSongsVisible() > 0) && (nr >= 0) && ((_Actsong != nr) || (_Streams.Count == 0))) { _Streams.ForEach(soundStream => CBase.Sound.FadeAndStop(soundStream, 0f, 1f)); _Streams.Clear(); diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 35932a34..ccdc15bd 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -129,7 +129,7 @@ namespace VocaluxeLib.Menu.SongMenu public override void OnShow() { - if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0 && CBase.Songs.GetCurrentCategoryIndex() == -1) + if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0 && !CBase.Songs.IsInCategory()) _EnterCategory(0); _ActualSelection = -1; _Locked = -1; @@ -201,7 +201,7 @@ namespace VocaluxeLib.Menu.SongMenu switch (keyEvent.Key) { case Keys.Enter: - if (CBase.Songs.GetCurrentCategoryIndex() < 0) + if (!CBase.Songs.IsInCategory()) { _EnterCategory(_PreviewSelected); keyEvent.Handled = true; @@ -212,7 +212,7 @@ namespace VocaluxeLib.Menu.SongMenu case Keys.Escape: case Keys.Back: - if (CBase.Songs.GetCurrentCategoryIndex() > -1 && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && songOptions.Selection.CategoryChangeAllowed) + if (CBase.Songs.IsInCategory() && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && songOptions.Selection.CategoryChangeAllowed) { _ShowCategories(); keyEvent.Handled = true; @@ -234,7 +234,7 @@ namespace VocaluxeLib.Menu.SongMenu break; case Keys.Left: - if (_Locked > 0 && (!songOptions.Selection.RandomOnly || songOptions.Selection.CategoryChangeAllowed && CBase.Songs.GetCurrentCategoryIndex() < 0)) + if (_Locked > 0 && (!songOptions.Selection.RandomOnly || songOptions.Selection.CategoryChangeAllowed && !CBase.Songs.IsInCategory())) { _Locked--; _UpdateList(); @@ -242,7 +242,7 @@ namespace VocaluxeLib.Menu.SongMenu break; case Keys.Right: - if (CBase.Songs.GetCurrentCategoryIndex() < 0 && songOptions.Selection.CategoryChangeAllowed) + if (!CBase.Songs.IsInCategory() && songOptions.Selection.CategoryChangeAllowed) { if (_Locked < CBase.Songs.GetNumCategories() - 1) { @@ -252,7 +252,7 @@ namespace VocaluxeLib.Menu.SongMenu } else { - if (CBase.Songs.GetCurrentCategoryIndex() != -1 && _Locked < CBase.Songs.GetNumSongsVisible() - 1 && !songOptions.Selection.RandomOnly) + if (CBase.Songs.IsInCategory() && _Locked < CBase.Songs.GetNumSongsVisible() - 1 && !songOptions.Selection.RandomOnly) { _Locked++; _UpdateList(); @@ -268,7 +268,7 @@ namespace VocaluxeLib.Menu.SongMenu } if (_Locked > _NumW - 1 && - (!songOptions.Selection.RandomOnly || songOptions.Selection.CategoryChangeAllowed && CBase.Songs.GetCurrentCategoryIndex() < 0)) + (!songOptions.Selection.RandomOnly || songOptions.Selection.CategoryChangeAllowed && !CBase.Songs.IsInCategory())) { _Locked -= _NumW; _UpdateList(); @@ -282,7 +282,7 @@ namespace VocaluxeLib.Menu.SongMenu break; } - if (CBase.Songs.GetCurrentCategoryIndex() < 0 && songOptions.Selection.CategoryChangeAllowed) + if (!CBase.Songs.IsInCategory() && songOptions.Selection.CategoryChangeAllowed) { if (_Locked < CBase.Songs.GetNumCategories() - _NumW) { @@ -318,13 +318,13 @@ namespace VocaluxeLib.Menu.SongMenu bool sel = false; int lastselection = _ActualSelection; - if (!songOptions.Selection.RandomOnly || CBase.Songs.GetCurrentCategoryIndex() < 0 && songOptions.Selection.CategoryChangeAllowed) + if (!songOptions.Selection.RandomOnly || !CBase.Songs.IsInCategory() && songOptions.Selection.CategoryChangeAllowed) { foreach (CStatic tile in _Tiles) { if ((tile.Texture.Index != _CoverTexture.Index) && CHelper.IsInBounds(tile.Rect, mouseEvent) && !sel) { - if (mouseEvent.LB || CBase.Songs.GetCurrentCategoryIndex() == -1) + if (mouseEvent.LB || !CBase.Songs.IsInCategory()) { if (_PreviewSelected == i + _Offset) _Locked = _PreviewSelected; @@ -352,7 +352,7 @@ namespace VocaluxeLib.Menu.SongMenu if (!sel) _ActualSelection = -1; - if (mouseEvent.RB && (CBase.Songs.GetNumCategories() > 0) && CBase.Songs.GetCurrentCategoryIndex() >= 0 && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && + if (mouseEvent.RB && (CBase.Songs.GetNumCategories() > 0) && CBase.Songs.IsInCategory() && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && songOptions.Selection.CategoryChangeAllowed) { _ShowCategories(); @@ -366,7 +366,7 @@ namespace VocaluxeLib.Menu.SongMenu if (CHelper.IsInBounds(_CoverBig.Rect, mouseEvent) || CHelper.IsInBounds(_TextBG.Rect, mouseEvent)) _Locked = _PreviewSelected; } - else if (mouseEvent.LB && (CBase.Songs.GetCurrentCategoryIndex() == -1)) + else if (mouseEvent.LB && (!CBase.Songs.IsInCategory())) { foreach (CStatic tile in _Tiles) { @@ -380,7 +380,7 @@ namespace VocaluxeLib.Menu.SongMenu } if (mouseEvent.Wheel != 0 && CHelper.IsInBounds(_ScrollRect, mouseEvent) && - (!songOptions.Selection.RandomOnly || CBase.Songs.GetCurrentCategoryIndex() < 0 && songOptions.Selection.CategoryChangeAllowed)) + (!songOptions.Selection.RandomOnly || !CBase.Songs.IsInCategory() && songOptions.Selection.CategoryChangeAllowed)) _UpdateList(_Offset + _NumW * mouseEvent.Wheel); } @@ -389,17 +389,17 @@ namespace VocaluxeLib.Menu.SongMenu foreach (CStatic tile in _Tiles) { if (tile.Selected && _Active) - tile.Draw(1.2f, tile.Rect.Z - 0.1f, EAspect.Crop, false); + tile.Draw(1.2f, tile.Rect.Z - 0.1f, EAspect.Crop); else { if (tile.Texture.Index != _CoverTexture.Index) - tile.Draw(1f, tile.Rect.Z, EAspect.Crop, false); + tile.Draw(1f, tile.Rect.Z, EAspect.Crop); else - tile.Draw(1f, tile.Rect.Z, EAspect.Stretch, false); + tile.Draw(1f, tile.Rect.Z, EAspect.Stretch); } } - if (CBase.Songs.GetCurrentCategoryIndex() >= 0) + if (CBase.Songs.IsInCategory()) { int actsong = _PreviewSelected; if ((CBase.Songs.GetNumSongsVisible() > actsong) && (actsong >= 0)) @@ -490,7 +490,7 @@ namespace VocaluxeLib.Menu.SongMenu return new CStatic(_PartyModeID); } - protected void _SetSelectedTile(int itemNr) + private void _SetSelectedTile(int itemNr) { bool sel = _Tiles.Any(tile => tile.Selected); @@ -607,7 +607,7 @@ namespace VocaluxeLib.Menu.SongMenu private void _UpdateList(int offset, bool force = false) { - bool isInCategory = CBase.Songs.GetCurrentCategoryIndex() >= 0; + bool isInCategory = CBase.Songs.IsInCategory(); int itemCount = isInCategory ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories(); if (offset >= (itemCount / _NumW) * _NumW - (_NumW * (_NumH - 1)))