From 1b0c40a20b3d44fe156312ab257df0f30ef980b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Fri, 29 Dec 2017 11:07:13 +0100 Subject: [PATCH] Fix: Handling of song-selection in challenge-mode --- .../PartyModeChallenge/CPartyModeChallenge.cs | 127 ++++++------------ Vocaluxe/Screens/CScreenSong.cs | 10 +- .../Menu/SongMenu/CSongMenuFramework.cs | 5 + VocaluxeLib/Menu/SongMenu/ISongMenu.cs | 1 + VocaluxeLib/PartyModes/CPartyModeNormal.cs | 1 + 5 files changed, 57 insertions(+), 87 deletions(-) diff --git a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs index 1271b434..a8cee26b 100644 --- a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs +++ b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs @@ -139,7 +139,6 @@ namespace VocaluxeLib.PartyModes.Challenge public int CurrentRoundNr; - public int[] CatSongIndices; public List Songs; } @@ -182,7 +181,6 @@ namespace VocaluxeLib.PartyModes.Challenge CategoryIndex = 0, GameMode = EGameMode.TR_GAMEMODE_NORMAL, NumMedleySongs = 5, - CatSongIndices = null, Results = null, Songs = new List() }; @@ -196,6 +194,7 @@ namespace VocaluxeLib.PartyModes.Challenge _ScreenSongOptions.Sorting.SongSorting = CBase.Config.GetSongSorting(); _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_OFF; _ScreenSongOptions.Selection.SongIndex = -1; + _ScreenSongOptions.Selection.CategoryIndex = -1; if (CBase.Config.GetTabs() == EOffOn.TR_CONFIG_ON && _ScreenSongOptions.Sorting.SongSorting != ESongSorting.TR_CONFIG_NONE) _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_ON; @@ -214,11 +213,7 @@ namespace VocaluxeLib.PartyModes.Challenge public override void UpdateGame() { - /* - if (CBase.Songs.IsInCategory() || _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) - _ScreenSongOptions.Selection.RandomOnly = true; - else - _ScreenSongOptions.Selection.RandomOnly = false;*/ + } private IMenu _GetNextScreen() @@ -321,85 +316,27 @@ namespace VocaluxeLib.PartyModes.Challenge public override SScreenSongOptions GetScreenSongOptions() { - _ScreenSongOptions.Selection.RandomOnly = true; - _ScreenSongOptions.Sorting.IgnoreArticles = CBase.Config.GetIgnoreArticles(); - - - switch (GameData.SongSource) - { - case ESongSource.TR_SONGSOURCE_ALLSONGS: - _ScreenSongOptions.Sorting.SongSorting = CBase.Config.GetSongSorting(); - _ScreenSongOptions.Sorting.Tabs = CBase.Config.GetTabs(); - _ScreenSongOptions.Sorting.FilterPlaylistID = -1; - - _ScreenSongOptions.Selection.CategoryChangeAllowed = true; - break; - - case ESongSource.TR_SONGSOURCE_CATEGORY: - _ScreenSongOptions.Sorting.SongSorting = GameData.Sorting; - _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_ON; - _ScreenSongOptions.Sorting.FilterPlaylistID = -1; - - if (GameData.CatSongIndices == null) - _CreateCatSongIndices(); - - _ScreenSongOptions.Selection.SongIndex = GameData.CatSongIndices[GameData.CategoryIndex]; - - _ScreenSongOptions.Selection.CategoryChangeAllowed = false; - break; - - case ESongSource.TR_SONGSOURCE_PLAYLIST: - _ScreenSongOptions.Sorting.SongSorting = CBase.Config.GetSongSorting(); - _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_OFF; - _ScreenSongOptions.Sorting.FilterPlaylistID = GameData.PlaylistID; - - _ScreenSongOptions.Selection.CategoryChangeAllowed = false; - break; - } return _ScreenSongOptions; } - // ReSharper disable RedundantAssignment public override void OnSongChange(int songIndex, ref SScreenSongOptions screenSongOptions) - // ReSharper restore RedundantAssignment { - _ScreenSongOptions.Selection.SongIndex = -1; - if (_ScreenSongOptions.Selection.SelectNextRandomSong && songIndex != -1) - { _ScreenSongOptions.Selection.SelectNextRandomSong = false; - _CreateCatSongIndices(); - if (GameData.CatSongIndices != null) - { - if (GameData.CatSongIndices[CBase.Songs.GetCurrentCategoryIndex()] == -1) - GameData.CatSongIndices[CBase.Songs.GetCurrentCategoryIndex()] = songIndex; - } - } + _ScreenSongOptions.Selection.SongIndex = songIndex; screenSongOptions = _ScreenSongOptions; } - // ReSharper disable RedundantAssignment public override void OnCategoryChange(int categoryIndex, ref SScreenSongOptions screenSongOptions) - // ReSharper restore RedundantAssignment { - if (GameData.CatSongIndices != null && categoryIndex != -1) - { - if (GameData.CatSongIndices[categoryIndex] == -1) - _ScreenSongOptions.Selection.SelectNextRandomSong = true; - else - _ScreenSongOptions.Selection.SongIndex = GameData.CatSongIndices[categoryIndex]; - } - - if (GameData.CatSongIndices == null && categoryIndex != -1) + if (categoryIndex != -1) _ScreenSongOptions.Selection.SelectNextRandomSong = true; + else + _ScreenSongOptions.Selection.SongIndex = -1; - if (categoryIndex == -1) - _ScreenSongOptions.Selection.RandomOnly = false; - - if (_ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_OFF || categoryIndex != -1) - _ScreenSongOptions.Selection.RandomOnly = true; + _ScreenSongOptions.Selection.CategoryIndex = categoryIndex; screenSongOptions = _ScreenSongOptions; } @@ -470,11 +407,42 @@ namespace VocaluxeLib.PartyModes.Challenge /// private void _PrepareSongSelection() { - _ScreenSongOptions.Selection.RandomOnly = _ScreenSongOptions.Sorting.Tabs != EOffOn.TR_CONFIG_ON; - _ScreenSongOptions.Selection.CategoryChangeAllowed = false; + _ScreenSongOptions.Selection.RandomOnly = true; + _ScreenSongOptions.Selection.SelectNextRandomSong = true; + + _ScreenSongOptions.Sorting.IgnoreArticles = CBase.Config.GetIgnoreArticles(); + + switch (GameData.SongSource) + { + case ESongSource.TR_SONGSOURCE_ALLSONGS: + _ScreenSongOptions.Sorting.SongSorting = CBase.Config.GetSongSorting(); + _ScreenSongOptions.Sorting.Tabs = CBase.Config.GetTabs(); + _ScreenSongOptions.Sorting.FilterPlaylistID = -1; + + _ScreenSongOptions.Selection.CategoryIndex = -1; + _ScreenSongOptions.Selection.CategoryChangeAllowed = true; + break; + + case ESongSource.TR_SONGSOURCE_CATEGORY: + _ScreenSongOptions.Sorting.SongSorting = GameData.Sorting; + _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_ON; + _ScreenSongOptions.Sorting.FilterPlaylistID = -1; + + _ScreenSongOptions.Selection.CategoryIndex = GameData.CategoryIndex; + _ScreenSongOptions.Selection.CategoryChangeAllowed = false; + break; + + case ESongSource.TR_SONGSOURCE_PLAYLIST: + _ScreenSongOptions.Sorting.SongSorting = CBase.Config.GetSongSorting(); + _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_OFF; + _ScreenSongOptions.Sorting.FilterPlaylistID = GameData.PlaylistID; + + _ScreenSongOptions.Selection.CategoryChangeAllowed = false; + break; + } + _SetNumJokers(); _SetTeamNames(); - GameData.CatSongIndices = null; } /// @@ -741,18 +709,5 @@ namespace VocaluxeLib.PartyModes.Challenge return result; } - - private void _CreateCatSongIndices() - { - if (GameData.CatSongIndices == null && CBase.Songs.GetNumCategories() > 0 && _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_ON) - { - GameData.CatSongIndices = new int[CBase.Songs.GetNumCategories()]; - for (int i = 1; i < GameData.CatSongIndices.Length; i++) - GameData.CatSongIndices[i] = CBase.Songs.GetNumSongsInCategory(i) + GameData.CatSongIndices[i - 1]; - } - - if (CBase.Songs.GetNumCategories() == 0 || _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) - GameData.CatSongIndices = null; - } } } \ No newline at end of file diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 6d2d8be6..6644bb8a 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -647,7 +647,15 @@ namespace Vocaluxe.Screens if (_Sso.Selection.CategoryIndex != CBase.Songs.GetCurrentCategoryIndex()) { _SelectedCategoryIndex = _Sso.Selection.CategoryIndex; - _SongMenu.EnterSelectedCategory(); + if (_SelectedCategoryIndex != -1) + { + _SongMenu.SetSelectedCategory(_SelectedCategoryIndex); + _SongMenu.EnterSelectedCategory(); + } + else + { + _SongMenu.LeaveSelectedCategory(); + } } _SearchActive = _Sso.Sorting.SearchActive; _SearchText = _Sso.Sorting.SearchString; diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index ecd41bb8..02cfac02 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -286,6 +286,11 @@ namespace VocaluxeLib.Menu.SongMenu _PreviewNr = _SelectionNr; } + public void LeaveSelectedCategory() + { + _LeaveCategory(); + } + public virtual void UnloadSkin() {} public virtual void LoadSkin() diff --git a/VocaluxeLib/Menu/SongMenu/ISongMenu.cs b/VocaluxeLib/Menu/SongMenu/ISongMenu.cs index 5d15a6a4..a37f50d0 100644 --- a/VocaluxeLib/Menu/SongMenu/ISongMenu.cs +++ b/VocaluxeLib/Menu/SongMenu/ISongMenu.cs @@ -40,6 +40,7 @@ namespace VocaluxeLib.Menu.SongMenu int GetSelectedCategory(); void SetSelectedCategory(int categoryNr); bool EnterSelectedCategory(); + void LeaveSelectedCategory(); // The song that is currently playing (set e.g. by clicking on a song) int GetPreviewSong(); diff --git a/VocaluxeLib/PartyModes/CPartyModeNormal.cs b/VocaluxeLib/PartyModes/CPartyModeNormal.cs index 6d01ff74..9c62e884 100644 --- a/VocaluxeLib/PartyModes/CPartyModeNormal.cs +++ b/VocaluxeLib/PartyModes/CPartyModeNormal.cs @@ -63,6 +63,7 @@ namespace VocaluxeLib.PartyModes _ScreenSongOptions.Selection.NumJokers = null; _ScreenSongOptions.Selection.TeamNames = null; _ScreenSongOptions.Selection.SongIndex = -1; + _ScreenSongOptions.Selection.CategoryIndex = -1; _ScreenSongOptions.Sorting.SearchString = String.Empty; _ScreenSongOptions.Sorting.SearchActive = false;