From b1225a1a97148b67616e3c60bc7e29437156fc81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Wed, 20 Dec 2017 18:40:21 +0100 Subject: [PATCH] Improved handling of next round in challenge-mode, also some documentation --- .../PartyModeChallenge/CPartyModeChallenge.cs | 93 ++++++++++++------- 1 file changed, 61 insertions(+), 32 deletions(-) diff --git a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs index d59f4ed8..c2f454d9 100644 --- a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs +++ b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs @@ -109,6 +109,7 @@ namespace VocaluxeLib.PartyModes.Challenge Songs, Names, Main, + SongSelection, Singing, MedleySinging } @@ -231,8 +232,9 @@ namespace VocaluxeLib.PartyModes.Challenge return _Screens["CPartyScreenChallengeNames"]; case EStage.Main: return _Screens["CPartyScreenChallengeMain"]; - case EStage.Singing: + case EStage.SongSelection: return CBase.Graphics.GetScreen(EScreen.Song); + case EStage.Singing: case EStage.MedleySinging: return CBase.Graphics.GetScreen(EScreen.Sing); default: @@ -265,10 +267,18 @@ namespace VocaluxeLib.PartyModes.Challenge break; case EStage.Main: if (GameData.GameMode == EGameMode.TR_GAMEMODE_MEDLEY) + { _Stage = EStage.MedleySinging; + _PrepareMedleyRound(); + } else - _Stage = EStage.Singing; - _StartNextRound(); + { + _Stage = EStage.SongSelection; + _PrepareSongSelection(); + } + break; + case EStage.SongSelection: + _Stage = EStage.Singing; break; case EStage.MedleySinging: case EStage.Singing: @@ -418,63 +428,76 @@ namespace VocaluxeLib.PartyModes.Challenge public override void SongSelected(int songID) { - _PrepareGame(new int[] { songID }); + _PrepareRound(new int[] { songID }); - CBase.Graphics.FadeTo(EScreen.Sing); + Next(); } public override void LeavingHighscore() { - CBase.Songs.AddPartySongSung(CBase.Game.GetSong(0).ID); + //Remember sung songs, so they don't will be selected a second time + for(int i = 0; i < CBase.Game.GetNumSongs(); i++) + CBase.Songs.AddPartySongSung(CBase.Game.GetSong(i).ID); + GameData.CurrentRoundNr++; + Next(); } - private void _StartNextRound() + /// + /// Start a new medley round based on song configuration + /// + private void _PrepareMedleyRound() { - if (GameData.GameMode == EGameMode.TR_GAMEMODE_MEDLEY) + //Select songs for medley + int[] songIDs = new int[GameData.NumMedleySongs]; + for (int i = 0; i < GameData.NumMedleySongs; i++) { - int[] songIDs = new int[GameData.NumMedleySongs]; - for (int i = 0; i < GameData.NumMedleySongs; i++) - { - if (GameData.Songs.Count == 0) - _UpdateSongList(); + if (GameData.Songs.Count == 0) + _UpdateSongList(); - songIDs[i] = GameData.Songs[0]; - GameData.Songs.RemoveAt(0); - } + songIDs[i] = GameData.Songs[0]; + GameData.Songs.RemoveAt(0); + } - _PrepareGame(songIDs); - } - else - { - _ScreenSongOptions.Selection.RandomOnly = _ScreenSongOptions.Sorting.Tabs != EOffOn.TR_CONFIG_ON; - _ScreenSongOptions.Selection.CategoryChangeAllowed = false; - _SetNumJokers(); - _SetTeamNames(); - GameData.CatSongIndices = null; - } + _PrepareRound(songIDs); } - private bool _PrepareGame(int[] songIDs) + /// + /// Setup options for song selection + /// + private void _PrepareSongSelection() { + _ScreenSongOptions.Selection.RandomOnly = _ScreenSongOptions.Sorting.Tabs != EOffOn.TR_CONFIG_ON; + _ScreenSongOptions.Selection.CategoryChangeAllowed = false; + _SetNumJokers(); + _SetTeamNames(); + GameData.CatSongIndices = null; + } + + /// + /// Prepare next game and fill song queue based on configuration and given songs. + /// + /// Array of SongIDs that are selected + /// false, if something can't setup correctly + private bool _PrepareRound(int[] songIDs) + { + //Reset game CBase.Game.Reset(); CBase.Game.ClearSongs(); #region PlayerNames CBase.Game.SetNumPlayer(GameData.NumPlayerAtOnce); SPlayer[] players = CBase.Game.GetPlayers(); - if (players == null) - return false; - - if (players.Length < GameData.NumPlayerAtOnce) + if (players == null || players.Length < GameData.NumPlayerAtOnce) return false; + //Get current round CRound c = GameData.Rounds[GameData.CurrentRoundNr - 1]; for (int i = 0; i < GameData.NumPlayerAtOnce; i++) { - //try to fill with the right data + //try to fill with correct player data if (c != null) players[i].ProfileID = GameData.ProfileIDs[c.Players[i]]; else @@ -483,6 +506,7 @@ namespace VocaluxeLib.PartyModes.Challenge #endregion PlayerNames #region SongQueue + //Add all songs with configure game mode to song queue for (int i = 0; i < songIDs.Length; i++) CBase.Game.AddSong(songIDs[i], GameData.GameMode); #endregion SongQueue @@ -533,6 +557,10 @@ namespace VocaluxeLib.PartyModes.Challenge _ScreenSongOptions.Selection.TeamNames[i] = CBase.Profiles.GetPlayerName(GameData.ProfileIDs[c.Players[i]]); } + /// + /// Fill song list based on song configuration. This is basically needed for singing medleys, + /// because we don't show song selection screen for these games. + /// private void _UpdateSongList() { if (GameData.Songs.Count > 0) @@ -555,6 +583,7 @@ namespace VocaluxeLib.PartyModes.Challenge break; case ESongSource.TR_SONGSOURCE_CATEGORY: + //Save old sorting to roll it back after getting songs for configured category ESongSorting oldSorting = CBase.Config.GetSongSorting(); CBase.Songs.SortSongs(GameData.Sorting, EOffOn.TR_CONFIG_ON, CBase.Config.GetIgnoreArticles() ,String.Empty, EDuetOptions.NoDuets, -1);