From 271772301df8a148c0c41107f204a320a3e28d74 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Tue, 8 Oct 2013 18:01:08 +0200 Subject: [PATCH] Fix some bugs where round was actually roundNr Now round (0 based) is always used --- Vocaluxe/Base/CGame.cs | 2 +- Vocaluxe/Screens/CScreenHighscore.cs | 25 +++------ Vocaluxe/Screens/CScreenNames.cs | 12 ++--- Vocaluxe/Screens/CScreenScore.cs | 31 ++++++------ Vocaluxe/SongQueue/CSongQueue.cs | 76 ++++++++++++++++++---------- Vocaluxe/SongQueue/ISongQueue.cs | 12 ++--- VocaluxeLib/CHelper.cs | 9 ++++ 7 files changed, 92 insertions(+), 75 deletions(-) diff --git a/Vocaluxe/Base/CGame.cs b/Vocaluxe/Base/CGame.cs index d8ea972c..ada61872 100644 --- a/Vocaluxe/Base/CGame.cs +++ b/Vocaluxe/Base/CGame.cs @@ -131,7 +131,7 @@ namespace Vocaluxe.Base public static void NextRound() { - _SongQueue.NextRound(Players); + _SongQueue.StartNextRound(Players); } public static bool IsFinished() diff --git a/Vocaluxe/Screens/CScreenHighscore.cs b/Vocaluxe/Screens/CScreenHighscore.cs index ab44c452..411cd2cd 100644 --- a/Vocaluxe/Screens/CScreenHighscore.cs +++ b/Vocaluxe/Screens/CScreenHighscore.cs @@ -242,7 +242,7 @@ namespace Vocaluxe.Screens { _IsDuet = false; CPoints points = CGame.GetPoints(); - CSong song = CGame.GetSong(_Round + 1); + CSong song = CGame.GetSong(_Round); if (song == null) return; @@ -250,7 +250,7 @@ namespace Vocaluxe.Screens if (points.NumRounds > 1) _Texts[_TextSongName].Text += " (" + (_Round + 1) + "/" + points.NumRounds + ")"; - switch (CGame.GetGameMode(_Round + 1)) + switch (CGame.GetGameMode(_Round)) { case EGameMode.TR_GAMEMODE_NORMAL: _Texts[_TextSongMode].Text = "TR_GAMEMODE_NORMAL"; @@ -279,28 +279,15 @@ namespace Vocaluxe.Screens private void _ChangePos(int num) { - if (num > 0) - { - if (_Pos + num + _NumEntrys < _Scores[_Round].Count) - _Pos += num; - } - if (num < 0) - { - _Pos += num; - if (_Pos < 0) - _Pos = 0; - } + _Pos += num; + _Pos = _Pos.Clamp(0, _Scores[_Round].Count - 1); } private void _ChangeRound(int num) { CPoints points = CGame.GetPoints(); - if (_Round + num < points.NumRounds && _Round + num > -1) - _Round += num; - else if (_Round + num >= points.NumRounds) - _Round = points.NumRounds - 1; - else if (_Round + num < 0) - _Round = 0; + _Round += num; + _Round = _Round.Clamp(0, points.NumRounds - 1); _UpdateRound(); } diff --git a/Vocaluxe/Screens/CScreenNames.cs b/Vocaluxe/Screens/CScreenNames.cs index f1f548ab..6ad757c9 100644 --- a/Vocaluxe/Screens/CScreenNames.cs +++ b/Vocaluxe/Screens/CScreenNames.cs @@ -239,7 +239,7 @@ namespace Vocaluxe.Screens break; case Keys.F10: - if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet) + if (CGame.GetNumSongs() == 1 && CGame.GetSong(0).IsDuet) { CSelectSlide selectSlideDuetPart = _SelectSlides[_SelectSlideDuetPlayer[_SelectingFastPlayerNr - 1]]; selectSlideDuetPart.Selection = (selectSlideDuetPart.Selection + 1) % 2; @@ -603,12 +603,12 @@ namespace Vocaluxe.Screens CProfiles.GetAvatarTextureFromProfile(CGame.Players[i].ProfileID) : _OriginalPlayerAvatarTextures[i]; _Texts[_TextPlayer[i]].Text = CProfiles.GetPlayerName(CGame.Players[i].ProfileID, i + 1); - if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet) + if (CGame.GetNumSongs() == 1 && CGame.GetSong(0).IsDuet) { _SelectSlides[_SelectSlideDuetPlayer[i]].Clear(); _SelectSlides[_SelectSlideDuetPlayer[i]].Visible = i + 1 <= CGame.NumPlayer; - _SelectSlides[_SelectSlideDuetPlayer[i]].AddValue(CGame.GetSong(1).DuetPart1); - _SelectSlides[_SelectSlideDuetPlayer[i]].AddValue(CGame.GetSong(1).DuetPart2); + _SelectSlides[_SelectSlideDuetPlayer[i]].AddValue(CGame.GetSong(0).DuetPart1); + _SelectSlides[_SelectSlideDuetPlayer[i]].AddValue(CGame.GetSong(0).DuetPart2); _SelectSlides[_SelectSlideDuetPlayer[i]].Selection = i % 2; } else @@ -623,7 +623,7 @@ namespace Vocaluxe.Screens { for (int i = 0; i < CGame.NumPlayer; i++) { - if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet) + if (CGame.GetNumSongs() == 1 && CGame.GetSong(0).IsDuet) CGame.Players[i].VoiceNr = _SelectSlides[_SelectSlideDuetPlayer[i]].Selection; } @@ -652,7 +652,7 @@ namespace Vocaluxe.Screens if (_Texts["TextPlayer" + i].Text == "") _Texts["TextPlayer" + i].Text = CProfiles.GetPlayerName(-1, i); _Equalizers["EqualizerPlayer" + i].Visible = true; - if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet) + if (CGame.GetNumSongs() == 1 && CGame.GetSong(0).IsDuet) _SelectSlides["SelectSlideDuetPlayer" + i].Visible = true; } else diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index fac4c499..51cd0273 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -118,7 +118,8 @@ namespace Vocaluxe.Screens public override void OnShow() { base.OnShow(); - _Round = CGame.NumRounds > 1 ? 0 : 1; + //-1 --> Show average + _Round = CGame.NumRounds > 1 ? -1 : 0; _Points = CGame.GetPoints(); _SavePlayedSongs(); @@ -130,8 +131,8 @@ namespace Vocaluxe.Screens public override bool UpdateGame() { var players = new SPlayer[CGame.NumPlayer]; - if (_Round != 0) - players = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); + if (_Round >= 0) + players = _Points.GetPlayer(_Round, CGame.NumPlayer); else { for (int i = 0; i < CGame.NumRounds; i++) @@ -263,7 +264,7 @@ namespace Vocaluxe.Screens { CSong song = null; var players = new SPlayer[CGame.NumPlayer]; - if (_Round != 0) + if (_Round >= 0) { song = CGame.GetSong(_Round); if (song == null) @@ -271,8 +272,8 @@ namespace Vocaluxe.Screens _Texts[_TextSong].Text = song.Artist + " - " + song.Title; if (_Points.NumRounds > 1) - _Texts[_TextSong].Text += " (" + _Round + "/" + _Points.NumRounds + ")"; - players = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); + _Texts[_TextSong].Text += " (" + (_Round + 1) + "/" + _Points.NumRounds + ")"; + players = _Points.GetPlayer(_Round, CGame.NumPlayer); } else { @@ -386,16 +387,14 @@ namespace Vocaluxe.Screens private void _ChangeRound(int num) { - if ((_Round + num) <= _Points.NumRounds && (_Round + num > 0)) - { - _Round += num; - _UpdateRatings(); - } - else if (num < 0 && _Round == 1 && CGame.NumRounds > 1) - { - _Round = 0; - _UpdateRatings(); - } + if (_Points.NumRounds < 1) + return; + _Round += num; + _Round = _Round.Clamp(-1, _Points.NumRounds - 1); + if (_Round >= _Points.NumRounds) + _Round = _Points.NumRounds - 1; + + _UpdateRatings(); } private void _SavePlayedSongs() diff --git a/Vocaluxe/SongQueue/CSongQueue.cs b/Vocaluxe/SongQueue/CSongQueue.cs index d11aeb4c..3fb3169f 100644 --- a/Vocaluxe/SongQueue/CSongQueue.cs +++ b/Vocaluxe/SongQueue/CSongQueue.cs @@ -39,7 +39,7 @@ namespace Vocaluxe.SongQueue class CSongQueue : ISongQueue { private List _SongQueue; - private int _CurrentSong; + private int _CurrentRound; private CPoints _Points; #region Implementation @@ -52,9 +52,7 @@ namespace Vocaluxe.SongQueue public EGameMode GetCurrentGameMode() { - if (_CurrentSong >= 0 && _CurrentSong < _SongQueue.Count) - return _SongQueue[_CurrentSong].GameMode; - return EGameMode.TR_GAMEMODE_NORMAL; + return GetGameMode(_CurrentRound); } public bool AddVisibleSong(int visibleIndex, EGameMode gameMode) @@ -105,7 +103,7 @@ namespace Vocaluxe.SongQueue public void Reset() { - _CurrentSong = -1; + _CurrentRound = -1; } public void Start(SPlayer[] players) @@ -113,37 +111,51 @@ namespace Vocaluxe.SongQueue _Points = new CPoints(_SongQueue.Count, players); } - public void NextRound(SPlayer[] players) + public void StartNextRound(SPlayer[] players) { - if (_CurrentSong < _SongQueue.Count && _SongQueue.Count > 0) + if (IsFinished()) + return; + if (_CurrentRound > -1) { - if (_CurrentSong > -1) - { - _Points.SetPoints( - _CurrentSong, - _SongQueue[_CurrentSong].SongID, - players, - _SongQueue[_CurrentSong].GameMode); - } - _CurrentSong++; + _Points.SetPoints( + _CurrentRound, + _SongQueue[_CurrentRound].SongID, + players, + _SongQueue[_CurrentRound].GameMode); } + _CurrentRound++; } public bool IsFinished() { - return _CurrentSong == _SongQueue.Count || _SongQueue.Count == 0; + return _CurrentRound >= _SongQueue.Count || _SongQueue.Count == 0; } + /// + /// Get current round nr (1 ~ n) + /// + /// current round nr (1 ~ n) public int GetCurrentRoundNr() { - return _CurrentSong + 1; + return _CurrentRound + 1; } + /// + /// Returns current round + /// + /// Current round (0 based) + public int GetCurrentRound() + { + return _CurrentRound; + } + + /// + /// Get current song + /// + /// Song of current round or null if there is none/game finished public CSong GetSong() { - if (_CurrentSong >= 0 && _CurrentSong < _SongQueue.Count) - return CGameModes.Get(_SongQueue[_CurrentSong].GameMode).GetSong(_SongQueue[_CurrentSong].SongID); - return null; + return GetSong(_CurrentRound); } public int GetNumSongs() @@ -151,18 +163,28 @@ namespace Vocaluxe.SongQueue return _SongQueue.Count; } - public CSong GetSong(int num) + /// + /// Get song of specified round + /// + /// Round (0 based) + /// Current song or null if out of bounds + public CSong GetSong(int round) { - if (num - 1 < _SongQueue.Count && num > 0) - return CSongs.GetSong(_SongQueue[num - 1].SongID); + if (round < _SongQueue.Count && round >= 0) + return CSongs.GetSong(_SongQueue[round].SongID); return null; } - public EGameMode GetGameMode(int num) + /// + /// Get gameMode of specified round + /// + /// Round (0 based) + /// Current song or null if out of bounds + public EGameMode GetGameMode(int round) { - if (num - 1 < _SongQueue.Count && num > 0) - return _SongQueue[num - 1].GameMode; + if (round < _SongQueue.Count && round >= 0) + return _SongQueue[round].GameMode; return EGameMode.TR_GAMEMODE_NORMAL; } diff --git a/Vocaluxe/SongQueue/ISongQueue.cs b/Vocaluxe/SongQueue/ISongQueue.cs index c3e32f45..1831fd74 100644 --- a/Vocaluxe/SongQueue/ISongQueue.cs +++ b/Vocaluxe/SongQueue/ISongQueue.cs @@ -25,8 +25,6 @@ namespace Vocaluxe.SongQueue { void Init(); - EGameMode GetCurrentGameMode(); - bool AddVisibleSong(int visibleIndex, EGameMode gameMode); bool AddSong(int absoluteIndex, EGameMode gameMode); bool RemoveVisibleSong(int visibleIndex); @@ -35,15 +33,17 @@ namespace Vocaluxe.SongQueue void Reset(); void Start(SPlayer[] players); - void NextRound(SPlayer[] players); + void StartNextRound(SPlayer[] players); bool IsFinished(); - int GetCurrentRoundNr(); CPoints GetPoints(); int GetNumSongs(); + int GetCurrentRoundNr(); + CSong GetSong(); - CSong GetSong(int num); - EGameMode GetGameMode(int num); + CSong GetSong(int round); + EGameMode GetCurrentGameMode(); + EGameMode GetGameMode(int round); } } \ No newline at end of file diff --git a/VocaluxeLib/CHelper.cs b/VocaluxeLib/CHelper.cs index ad04b6db..04ea1a90 100644 --- a/VocaluxeLib/CHelper.cs +++ b/VocaluxeLib/CHelper.cs @@ -47,6 +47,15 @@ namespace VocaluxeLib return (int)result; } + public static T Clamp(this T val, T min, T max) where T : IComparable + { + if (val.CompareTo(min) < 0) + return min; + if (val.CompareTo(max) > 0) + return max; + return val; + } + /// /// Concat strings into one string with ", " as separator. ///