From dc375de63200230531c7062af6b292864ad096fa Mon Sep 17 00:00:00 2001 From: z3ro01 Date: Mon, 21 Dec 2015 10:50:19 +0100 Subject: [PATCH] Fix: Crash after starting a second challenge mode #169 --- PartyModes/PartyModeChallenge/CPartyModeChallenge.cs | 12 +++++++++--- .../CPartyModeChallengeMedley.cs | 11 ++++++++--- PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs | 12 +++++++++--- Vocaluxe/Base/CParty.cs | 4 +++- VocaluxeLib/PartyModes/CPartyMode.cs | 5 +++++ VocaluxeLib/PartyModes/IPartyMode.cs | 1 + 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs index f92f2dea..e336d4de 100644 --- a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs +++ b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs @@ -153,10 +153,8 @@ namespace VocaluxeLib.PartyModes.Challenge GameData = new SData {NumPlayer = 4, NumPlayerAtOnce = 2, NumRounds = 12, NumJokers = 5, RefillJokers = true, CurrentRoundNr = 1, ProfileIDs = new List(), CatSongIndices = null, Results = null}; } - public override bool Init() + public override void SetDefaults() { - if (!base.Init()) - return false; _Stage = EStage.Config; _ScreenSongOptions.Sorting.IgnoreArticles = CBase.Config.GetIgnoreArticles(); @@ -168,7 +166,15 @@ namespace VocaluxeLib.PartyModes.Challenge _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_ON; GameData.ResultTable = new List(); + } + public override bool Init() + { + if (!base.Init()) + return false; + _Stage = EStage.Config; + + SetDefaults(); return true; } diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index 38c49aa8..78da5f05 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -168,14 +168,19 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley GameData = new SData {NumPlayer = 4, NumPlayerAtOnce = 2, NumRounds = 12, CurrentRoundNr = 1, ProfileIDs = new List(), NumSongs = 5, Songs = new List(), SongSource = ESongSource.TR_ALLSONGS, CatSongIndices = null, Results = null}; } + public override void SetDefaults() + { + _Stage = EStage.Config; + GameData.CurrentRoundNr = 1; + GameData.ResultTable = new List(); + } + public override bool Init() { if (!base.Init()) return false; - _Stage = EStage.Config; - - GameData.ResultTable = new List(); + SetDefaults(); return true; } diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index 81d3c308..6cf643e5 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -168,10 +168,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe }; } - public override bool Init() + public override void SetDefaults() { - if (!base.Init()) - return false; _Stage = EStage.Config; _ScreenSongOptions.Sorting.IgnoreArticles = CBase.Config.GetIgnoreArticles(); @@ -186,6 +184,14 @@ namespace VocaluxeLib.PartyModes.TicTacToe GameData.Rounds.Clear(); GameData.PlayerTeam1.Clear(); GameData.PlayerTeam2.Clear(); + } + + public override bool Init() + { + if (!base.Init()) + return false; + + SetDefaults(); return true; } diff --git a/Vocaluxe/Base/CParty.cs b/Vocaluxe/Base/CParty.cs index c3bffe57..f8e498c8 100644 --- a/Vocaluxe/Base/CParty.cs +++ b/Vocaluxe/Base/CParty.cs @@ -63,8 +63,10 @@ namespace Vocaluxe.Base get { return _CurrentPartyMode.ID; } set { - if (_CurrentPartyMode.ID == value) + if (_CurrentPartyMode.ID == value) { + _CurrentPartyMode.SetDefaults(); return; + } if (value != -1 && !_PartyModes.ContainsKey(value)) throw new ArgumentException("Partymode with ID=" + value + " does not exist!"); IPartyMode pm = _PartyModes[value].PartyMode; diff --git a/VocaluxeLib/PartyModes/CPartyMode.cs b/VocaluxeLib/PartyModes/CPartyMode.cs index 5a4d2b14..7fb529c0 100644 --- a/VocaluxeLib/PartyModes/CPartyMode.cs +++ b/VocaluxeLib/PartyModes/CPartyMode.cs @@ -48,6 +48,11 @@ namespace VocaluxeLib.PartyModes return true; } + public virtual void SetDefaults() + { + return; + } + public void LoadTheme() { string xmlPath = CBase.Themes.GetThemeScreensPath(ID); diff --git a/VocaluxeLib/PartyModes/IPartyMode.cs b/VocaluxeLib/PartyModes/IPartyMode.cs index d1aa7e1f..c2c431a2 100644 --- a/VocaluxeLib/PartyModes/IPartyMode.cs +++ b/VocaluxeLib/PartyModes/IPartyMode.cs @@ -99,6 +99,7 @@ namespace VocaluxeLib.PartyModes bool Init(); + void SetDefaults(); void LoadTheme(); void ReloadSkin(); void ReloadTheme();