diff --git a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs index 5782df18..8479323b 100644 --- a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs +++ b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs @@ -459,11 +459,11 @@ namespace VocaluxeLib.PartyModes.Challenge CBase.Game.AddSong(songID, gm); CBase.Game.SetNumPlayer(_GameData.NumPlayerAtOnce); - SPlayer[] player = CBase.Game.GetPlayers(); - if (player == null) + SPlayer[] players = CBase.Game.GetPlayers(); + if (players == null) return; - if (player.Length < _GameData.NumPlayerAtOnce) + if (players.Length < _GameData.NumPlayerAtOnce) return; CCombination c = _GameData.Rounds.GetRound(_GameData.CurrentRoundNr - 1); @@ -472,9 +472,9 @@ namespace VocaluxeLib.PartyModes.Challenge { //try to fill with the right data if (c != null) - player[i].ProfileID = _GameData.ProfileIDs[c.Player[i]]; + players[i].ProfileID = _GameData.ProfileIDs[c.Player[i]]; else - player[i].ProfileID = -1; + players[i].ProfileID = -1; } CBase.Songs.AddPartySongSung(songID); diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index e733ddb3..89b4b1a0 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -482,11 +482,11 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley #region PlayerNames CBase.Game.SetNumPlayer(_GameData.NumPlayerAtOnce); - SPlayer[] player = CBase.Game.GetPlayers(); - if (player == null) + SPlayer[] players = CBase.Game.GetPlayers(); + if (players == null) return false; - if (player.Length < _GameData.NumPlayerAtOnce) + if (players.Length < _GameData.NumPlayerAtOnce) return false; CCombination c = _GameData.Rounds.GetRound(_GameData.CurrentRoundNr - 1); @@ -495,9 +495,9 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { //try to fill with the right data if (c != null) - player[i].ProfileID = _GameData.ProfileIDs[c.Player[i]]; + players[i].ProfileID = _GameData.ProfileIDs[c.Player[i]]; else - player[i].ProfileID = -1; + players[i].ProfileID = -1; } #endregion PlayerNames diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index 4dc7e99f..21e9f455 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -718,11 +718,11 @@ namespace VocaluxeLib.PartyModes.TicTacToe CBase.Game.SetNumPlayer(2); - SPlayer[] player = CBase.Game.GetPlayers(); - if (player == null) + SPlayer[] players = CBase.Game.GetPlayers(); + if (players == null) return; - if (player.Length < 2) + if (players.Length < 2) return; SProfile[] profiles = CBase.Profiles.GetProfiles(); @@ -732,7 +732,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe for (int i = 0; i < 2; i++) { //default values - player[i].ProfileID = -1; + players[i].ProfileID = -1; } //try to fill with the right data @@ -740,15 +740,15 @@ namespace VocaluxeLib.PartyModes.TicTacToe { if (_GameData.ProfileIDsTeam1[r.SingerTeam1] < profiles.Length) { - player[0].ProfileID = _GameData.ProfileIDsTeam1[r.SingerTeam1]; + players[0].ProfileID = _GameData.ProfileIDsTeam1[r.SingerTeam1]; if (isDuet) - player[0].LineNr = 0; + players[0].LineNr = 0; } if (_GameData.ProfileIDsTeam2[r.SingerTeam2] < profiles.Length) { - player[1].ProfileID = _GameData.ProfileIDsTeam2[r.SingerTeam2]; + players[1].ProfileID = _GameData.ProfileIDsTeam2[r.SingerTeam2]; if (isDuet) - player[1].LineNr = 1; + players[1].LineNr = 1; } SongSelected(r.SongID); } diff --git a/Vocaluxe/Base/CGame.cs b/Vocaluxe/Base/CGame.cs index d8403a9f..672ac815 100644 --- a/Vocaluxe/Base/CGame.cs +++ b/Vocaluxe/Base/CGame.cs @@ -246,15 +246,9 @@ namespace Vocaluxe.Base Players[p].SingLine.Add(new CLine()); CNote[] notes = lines[line].Notes; - int note = -1; - for (int j = 0; j < notes.Length; j++) - { - if (beat >= notes[j].StartBeat && beat <= notes[j].EndBeat) - { - note = j; - break; - } - } + int note = lines[line].FindPreviousNote(beat); + if (notes[note].EndBeat < beat) + note = -1; if (note >= 0) { diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index b2780e53..876464ed 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -52,7 +52,6 @@ namespace Vocaluxe.Base private static bool _SongsLoaded; private static bool _CoverLoaded; - private static int _CoverLoadIndex; private static int _CatIndex = -1; private static readonly List _CategoriesForRandom = new List(); @@ -157,20 +156,17 @@ namespace Vocaluxe.Base if (!SongsLoaded) return -1; - if (_CoverLoadIndex < _Songs.Count) + if (NumSongsWithCoverLoaded < _Songs.Count) { - song = _Songs[_CoverLoadIndex]; - _CoverLoadIndex++; - return _CoverLoadIndex; + song = _Songs[NumSongsWithCoverLoaded]; + NumSongsWithCoverLoaded++; + return NumSongsWithCoverLoaded; } return -2; } - public static int NumSongsWithCoverLoaded - { - get { return _CoverLoadIndex; } - } + public static int NumSongsWithCoverLoaded { get; private set; } public static void SetCoverSmall(int songIndex, STexture texture) { @@ -392,12 +388,11 @@ namespace Vocaluxe.Base foreach (string file in files) { CSong song = CSong.LoadSong(file); - if (song != null) - { - song.ID = _Songs.Count; - if (song.ReadNotes()) - _Songs.Add(song); - } + if (song == null) + continue; + song.ID = _Songs.Count; + if (song.ReadNotes()) + _Songs.Add(song); } CLog.StopBenchmark(2, "Read TXTs"); @@ -460,7 +455,7 @@ namespace Vocaluxe.Base foreach (CSong song in _Songs) { song.LoadSmallCover(); - _CoverLoadIndex++; + NumSongsWithCoverLoaded++; } GC.Collect(); _CoverLoaded = true; diff --git a/Vocaluxe/GameModes/CGameMode.cs b/Vocaluxe/GameModes/CGameMode.cs new file mode 100644 index 00000000..b14830cf --- /dev/null +++ b/Vocaluxe/GameModes/CGameMode.cs @@ -0,0 +1,24 @@ +using Vocaluxe.Base; +using VocaluxeLib.Menu.SongMenu; + +namespace Vocaluxe.GameModes +{ + abstract class CGameMode : IGameMode + { + private CSong _LastSong; + private int _LastSongID; + + public CSong GetSong(int songID) + { + if (songID != _LastSongID) + { + CSong song = CSongs.GetSong(songID); + _LastSong = _PrepareSong(song); + _LastSongID = songID; + } + return _LastSong; + } + + protected abstract CSong _PrepareSong(CSong song); + } +} \ No newline at end of file diff --git a/Vocaluxe/GameModes/CGameModes.cs b/Vocaluxe/GameModes/CGameModes.cs new file mode 100644 index 00000000..18b1b980 --- /dev/null +++ b/Vocaluxe/GameModes/CGameModes.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Vocaluxe.Base; +using VocaluxeLib.Menu; +using VocaluxeLib.Menu.SongMenu; + +namespace Vocaluxe.GameModes +{ + static class CGameModes + { + private static Dictionary _GameModes; + + public static void Init() + { + _GameModes = new Dictionary + { + {EGameMode.TR_GAMEMODE_NORMAL, new CGameModeNormal()}, + {EGameMode.TR_GAMEMODE_DUET, new CGameModeDuet()}, + {EGameMode.TR_GAMEMODE_SHORTSONG, new CGameModeShort()}, + {EGameMode.TR_GAMEMODE_MEDLEY, new CGameModeMedley()} + }; + } + + public static IGameMode Get(EGameMode gameMode) + { + if (_GameModes == null) + return null; + IGameMode result; + if (!_GameModes.TryGetValue(gameMode, out result)) + result = _GameModes[EGameMode.TR_GAMEMODE_NORMAL]; + return result; + } + } + + class CGameModeNormal : CGameMode + { + protected override CSong _PrepareSong(CSong song) + { + return song; + } + } + + class CGameModeDuet : CGameMode + { + protected override CSong _PrepareSong(CSong song) + { + return (song.IsDuet) ? song : null; + } + } + + class CGameModeShort : CGameMode + { + protected override CSong _PrepareSong(CSong song) + { + CSong newSong = new CSong(song) {Finish = CGame.GetTimeFromBeats(song.ShortEnd, song.BPM) + CSettings.DefaultMedleyFadeOutTime + song.Gap}; + // set lines to short mode + newSong.Notes.SetMedley(song.Notes.GetVoice(0).Lines[0].FirstNoteBeat, song.ShortEnd); + + return newSong; + } + } + + class CGameModeMedley : CGameMode + { + protected override CSong _PrepareSong(CSong song) + { + CSong newSong = new CSong(song) {Start = CGame.GetTimeFromBeats(song.Medley.StartBeat, song.BPM) - song.Medley.FadeInTime + song.Gap}; + if (newSong.Start < 0f) + newSong.Start = 0f; + + newSong.Finish = CGame.GetTimeFromBeats(song.Medley.EndBeat, song.BPM) + song.Medley.FadeOutTime + song.Gap; + + // set lines to medley mode + newSong.Notes.SetMedley(song.Medley.StartBeat, song.Medley.EndBeat); + + return newSong; + } + } +} \ No newline at end of file diff --git a/Vocaluxe/GameModes/IGameMode.cs b/Vocaluxe/GameModes/IGameMode.cs new file mode 100644 index 00000000..940bc1f1 --- /dev/null +++ b/Vocaluxe/GameModes/IGameMode.cs @@ -0,0 +1,9 @@ +using VocaluxeLib.Menu.SongMenu; + +namespace Vocaluxe.GameModes +{ + interface IGameMode + { + CSong GetSong(int songID); + } +} \ No newline at end of file diff --git a/Vocaluxe/Screens/CScreenHighscore.cs b/Vocaluxe/Screens/CScreenHighscore.cs index b8eb3d14..0f3bb0c4 100644 --- a/Vocaluxe/Screens/CScreenHighscore.cs +++ b/Vocaluxe/Screens/CScreenHighscore.cs @@ -219,12 +219,12 @@ namespace Vocaluxe.Screens for (int round = 0; round < points.NumRounds; round++) { - SPlayer[] player = points.GetPlayer(round, CGame.NumPlayer); + SPlayer[] players = points.GetPlayer(round, CGame.NumPlayer); - for (int p = 0; p < player.Length; p++) + for (int p = 0; p < players.Length; p++) { - if (player[p].Points > CSettings.MinScoreForDB && player[p].SongFinished && !CProfiles.IsGuestProfile(player[p].ProfileID)) - _NewEntryIDs.Add(CDataBase.AddScore(player[p])); + if (players[p].Points > CSettings.MinScoreForDB && players[p].SongFinished && !CProfiles.IsGuestProfile(players[p].ProfileID)) + _NewEntryIDs.Add(CDataBase.AddScore(players[p])); } } } diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index e02f912c..57764cac 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -127,31 +127,31 @@ namespace Vocaluxe.Screens public override bool UpdateGame() { - SPlayer[] player = new SPlayer[CGame.NumPlayer]; + SPlayer[] players = new SPlayer[CGame.NumPlayer]; if (_Round != 0) - player = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); + players = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); else { for (int i = 0; i < CGame.NumRounds; i++) { SPlayer[] points = _Points.GetPlayer(i, CGame.NumPlayer); - for (int p = 0; p < player.Length; p++) - player[p].Points += points[p].Points; + for (int p = 0; p < players.Length; p++) + players[p].Points += points[p].Points; } - for (int p = 0; p < player.Length; p++) - player[p].Points = (int)(player[p].Points / CGame.NumRounds); + for (int p = 0; p < players.Length; p++) + players[p].Points = (int)(players[p].Points / CGame.NumRounds); } - for (int p = 0; p < player.Length; p++) + for (int p = 0; p < players.Length; p++) { - if (_StaticPointsBarDrawnPoints[p] < player[p].Points) + if (_StaticPointsBarDrawnPoints[p] < players[p].Points) { if (CConfig.ScoreAnimationTime >= 1) { _StaticPointsBarDrawnPoints[p] = (_Timer.ElapsedMilliseconds / 1000f) / CConfig.ScoreAnimationTime * 10000; - if (_StaticPointsBarDrawnPoints[p] > player[p].Points) - _StaticPointsBarDrawnPoints[p] = player[p].Points; + if (_StaticPointsBarDrawnPoints[p] > players[p].Points) + _StaticPointsBarDrawnPoints[p] = players[p].Points; string direction = (string)_ScreenSettings[_ScreenSettingAnimationDirection].GetValue(); if (direction.ToLower() == "vertical") { @@ -260,7 +260,7 @@ namespace Vocaluxe.Screens private void _UpdateRatings() { CSong song = null; - SPlayer[] player = new SPlayer[CGame.NumPlayer]; + SPlayer[] players = new SPlayer[CGame.NumPlayer]; if (_Round != 0) { song = CGame.GetSong(_Round); @@ -270,7 +270,7 @@ namespace Vocaluxe.Screens _Texts[_TextSong].Text = song.Artist + " - " + song.Title; if (_Points.NumRounds > 1) _Texts[_TextSong].Text += " (" + _Round + "/" + _Points.NumRounds + ")"; - player = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); + players = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); } else { @@ -278,47 +278,47 @@ namespace Vocaluxe.Screens for (int i = 0; i < CGame.NumRounds; i++) { SPlayer[] points = _Points.GetPlayer(i, CGame.NumPlayer); - for (int p = 0; p < player.Length; p++) + for (int p = 0; p < players.Length; p++) { if (i < 1) - player[p].ProfileID = points[p].ProfileID; - player[p].Points += points[p].Points; + players[p].ProfileID = points[p].ProfileID; + players[p].Points += points[p].Points; } } - for (int p = 0; p < player.Length; p++) - player[p].Points = (int)Math.Round(player[p].Points / CGame.NumRounds); + for (int p = 0; p < players.Length; p++) + players[p].Points = (int)Math.Round(players[p].Points / CGame.NumRounds); } - for (int p = 0; p < player.Length; p++) + for (int p = 0; p < players.Length; p++) { - string name = CProfiles.GetPlayerName(player[p].ProfileID, p); + string name = CProfiles.GetPlayerName(players[p].ProfileID, p); if (song != null && song.IsDuet) { - if (player[p].LineNr == 0 && song.DuetPart1 != "Part 1") + if (players[p].LineNr == 0 && song.DuetPart1 != "Part 1") name += " (" + song.DuetPart1 + ")"; - else if (player[p].LineNr == 1 && song.DuetPart2 != "Part 2") + else if (players[p].LineNr == 1 && song.DuetPart2 != "Part 2") name += " (" + song.DuetPart2 + ")"; } _Texts[_TextNames[p, CGame.NumPlayer - 1]].Text = name; if (CGame.NumPlayer < (int)_ScreenSettings[_ScreenSettingShortScore].GetValue()) - _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = ((int)Math.Round(player[p].Points)).ToString("0000") + " " + CLanguage.Translate("TR_SCREENSCORE_POINTS"); + _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = ((int)Math.Round(players[p].Points)).ToString("0000") + " " + CLanguage.Translate("TR_SCREENSCORE_POINTS"); else - _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = ((int)Math.Round(player[p].Points)).ToString("0000"); + _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = ((int)Math.Round(players[p].Points)).ToString("0000"); if (CGame.NumPlayer < (int)_ScreenSettings[_ScreenSettingShortDifficulty].GetValue()) { _Texts[_TextDifficulty[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate("TR_SCREENSCORE_GAMEDIFFICULTY") + ": " + - CLanguage.Translate(CProfiles.GetDifficulty(player[p].ProfileID).ToString()); + CLanguage.Translate(CProfiles.GetDifficulty(players[p].ProfileID).ToString()); } else - _Texts[_TextDifficulty[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate(CProfiles.GetDifficulty(player[p].ProfileID).ToString()); + _Texts[_TextDifficulty[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate(CProfiles.GetDifficulty(players[p].ProfileID).ToString()); if (CGame.NumPlayer < (int)_ScreenSettings[_ScreenSettingShortRating].GetValue()) { _Texts[_TextRatings[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate("TR_SCREENSCORE_RATING") + ": " + - CLanguage.Translate(_GetRating((int)Math.Round(player[p].Points))); + CLanguage.Translate(_GetRating((int)Math.Round(players[p].Points))); } else - _Texts[_TextRatings[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate(_GetRating((int)Math.Round(player[p].Points))); + _Texts[_TextRatings[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate(_GetRating((int)Math.Round(players[p].Points))); _StaticPointsBarDrawnPoints[p] = 0.0; string direction = (string)_ScreenSettings[_ScreenSettingAnimationDirection].GetValue(); @@ -331,19 +331,19 @@ namespace Vocaluxe.Screens _Statics[_StaticPointsBarBG[p, CGame.NumPlayer - 1]].Rect.Y - _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H; } - if (CProfiles.IsProfileIDValid(player[p].ProfileID)) - _Statics[_StaticAvatar[p, CGame.NumPlayer - 1]].Texture = CProfiles.Profiles[player[p].ProfileID].Avatar.Texture; + if (CProfiles.IsProfileIDValid(players[p].ProfileID)) + _Statics[_StaticAvatar[p, CGame.NumPlayer - 1]].Texture = CProfiles.Profiles[players[p].ProfileID].Avatar.Texture; } if (CConfig.ScoreAnimationTime < 1) { for (int p = 0; p < CGame.NumPlayer; p++) { - _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H = ((float)player[p].Points) * (_Statics[_StaticPointsBarBG[p, CGame.NumPlayer - 1]].Rect.H / 10000); + _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H = ((float)players[p].Points) * (_Statics[_StaticPointsBarBG[p, CGame.NumPlayer - 1]].Rect.H / 10000); _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.Y = _Statics[_StaticPointsBarBG[p, CGame.NumPlayer - 1]].Rect.H + _Statics[_StaticPointsBarBG[p, CGame.NumPlayer - 1]].Rect.Y - _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H; - _StaticPointsBarDrawnPoints[p] = player[p].Points; + _StaticPointsBarDrawnPoints[p] = players[p].Points; } } diff --git a/Vocaluxe/SongQueue/CSongQueue.cs b/Vocaluxe/SongQueue/CSongQueue.cs index e8ad77f2..0217fc47 100644 --- a/Vocaluxe/SongQueue/CSongQueue.cs +++ b/Vocaluxe/SongQueue/CSongQueue.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using Vocaluxe.Base; +using Vocaluxe.GameModes; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -43,110 +44,77 @@ namespace Vocaluxe.SongQueue private CPoints _Points; #region Implementation - public virtual void Init() + public void Init() { _SongQueque = new List(); Reset(); + CGameModes.Init(); } - public virtual EGameMode GetCurrentGameMode() + public EGameMode GetCurrentGameMode() { if (_CurrentSong >= 0 && _CurrentSong < _SongQueque.Count) return _SongQueque[_CurrentSong].GameMode; return EGameMode.TR_GAMEMODE_NORMAL; } - public virtual bool AddVisibleSong(int visibleIndex, EGameMode gameMode) + public bool AddVisibleSong(int visibleIndex, EGameMode gameMode) { - if (CSongs.VisibleSongs.Length > visibleIndex) - { - int songID = CSongs.VisibleSongs[visibleIndex].ID; - if (gameMode == EGameMode.TR_GAMEMODE_DUET && !CSongs.GetSong(songID).IsDuet) - return false; + return CSongs.VisibleSongs.Length > visibleIndex && _AddSong(CSongs.VisibleSongs[visibleIndex].ID, gameMode); + } - _SongQueque.Add(new SSongQueueEntry(songID, gameMode)); + public bool AddSong(int absoluteIndex, EGameMode gameMode) + { + return CSongs.AllSongs.Length > absoluteIndex && _AddSong(CSongs.AllSongs[absoluteIndex].ID, gameMode); + } + + private bool _AddSong(int songID, EGameMode gameMode) + { + if (gameMode == EGameMode.TR_GAMEMODE_DUET && !CSongs.GetSong(songID).IsDuet) + return false; + + _SongQueque.Add(new SSongQueueEntry(songID, gameMode)); + return true; + } + + public bool RemoveVisibleSong(int visibleIndex) + { + return CSongs.VisibleSongs.Length > visibleIndex && _RemoveSong(CSongs.VisibleSongs[visibleIndex].ID); + } + + public bool RemoveSong(int absoluteIndex) + { + return CSongs.AllSongs.Length > absoluteIndex && _RemoveSong(CSongs.AllSongs[absoluteIndex].ID); + } + + private bool _RemoveSong(int songID) + { + for (int i = 0; i < _SongQueque.Count; i++) + { + if (_SongQueque[i].SongID != songID) + continue; + _SongQueque.RemoveAt(i); return true; } return false; } - public virtual bool AddSong(int absoluteIndex, EGameMode gameMode) - { - if (CSongs.AllSongs.Length > absoluteIndex) - { - int songID = CSongs.AllSongs[absoluteIndex].ID; - if (gameMode == EGameMode.TR_GAMEMODE_DUET && !CSongs.GetSong(songID).IsDuet) - return false; - - _SongQueque.Add(new SSongQueueEntry(songID, gameMode)); - return true; - } - return false; - } - - public virtual bool RemoveVisibleSong(int visibleIndex) - { - if (CSongs.VisibleSongs.Length > visibleIndex) - { - int index = -1; - int songID = CSongs.VisibleSongs[visibleIndex].ID; - for (int i = 0; i < _SongQueque.Count; i++) - { - if (_SongQueque[i].SongID == songID) - { - index = i; - break; - } - } - - if (index == -1) - return false; - - _SongQueque.RemoveAt(index); - return true; - } - return false; - } - - public virtual bool RemoveSong(int absoluteIndex) - { - if (CSongs.AllSongs.Length > absoluteIndex) - { - int index = -1; - int songID = CSongs.AllSongs[absoluteIndex].ID; - for (int i = 0; i < _SongQueque.Count; i++) - { - if (_SongQueque[i].SongID == songID) - { - index = i; - break; - } - } - if (index == -1) - return false; - - _SongQueque.RemoveAt(index); - return true; - } - return false; - } - - public virtual void ClearSongs() + public void ClearSongs() { _SongQueque.Clear(); } - public virtual void Reset() + public void Reset() { _CurrentSong = -1; } - public virtual void Start(SPlayer[] player) + public void Start(SPlayer[] players) { - _Points = new CPoints(_SongQueque.Count, player); + _Points = new CPoints(_SongQueque.Count, players); } - public virtual void NextRound(SPlayer[] player) + public void NextRound(SPlayer[] players) { if (_CurrentSong < _SongQueque.Count && _SongQueque.Count > 0) { @@ -155,7 +123,7 @@ namespace Vocaluxe.SongQueue _Points.SetPoints( _CurrentSong, _SongQueque[_CurrentSong].SongID, - player, + players, _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_MEDLEY, _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_DUET, _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_SHORTSONG); @@ -164,56 +132,29 @@ namespace Vocaluxe.SongQueue } } - public virtual bool IsFinished() + public bool IsFinished() { return _CurrentSong == _SongQueque.Count || _SongQueque.Count == 0; } - public virtual int GetCurrentRoundNr() + public int GetCurrentRoundNr() { return _CurrentSong + 1; } - public virtual CSong GetSong() + public CSong GetSong() { if (_CurrentSong >= 0 && _CurrentSong < _SongQueque.Count) - { - CSong song = CSongs.GetSong(_SongQueque[_CurrentSong].SongID); - song = new CSong(song); - - switch (GetCurrentGameMode()) - { - case EGameMode.TR_GAMEMODE_MEDLEY: - // set medley mode timings - song.Start = CGame.GetTimeFromBeats(song.Medley.StartBeat, song.BPM) - song.Medley.FadeInTime + song.Gap; - if (song.Start < 0f) - song.Start = 0f; - - song.Finish = CGame.GetTimeFromBeats(song.Medley.EndBeat, song.BPM) + song.Medley.FadeOutTime + song.Gap; - - // set lines to medley mode - song.Notes.SetMedley(song.Medley.StartBeat, song.Medley.EndBeat); - break; - - case EGameMode.TR_GAMEMODE_SHORTSONG: - song.Finish = CGame.GetTimeFromBeats(song.ShortEnd, song.BPM) + CSettings.DefaultMedleyFadeOutTime + song.Gap; - - // set lines to medley mode - song.Notes.SetMedley(song.Notes.GetVoice(0).Lines[0].FirstNoteBeat, song.ShortEnd); - break; - } - - return song; - } + CGameModes.Get(GetCurrentGameMode()).GetSong(_SongQueque[_CurrentSong].SongID); return null; } - public virtual int GetNumSongs() + public int GetNumSongs() { return _SongQueque.Count; } - public virtual CSong GetSong(int num) + public CSong GetSong(int num) { if (num - 1 < _SongQueque.Count && num > 0) return CSongs.GetSong(_SongQueque[num - 1].SongID); @@ -221,7 +162,7 @@ namespace Vocaluxe.SongQueue return null; } - public virtual EGameMode GetGameMode(int num) + public EGameMode GetGameMode(int num) { if (num - 1 < _SongQueque.Count && num > 0) return _SongQueque[num - 1].GameMode; @@ -229,7 +170,7 @@ namespace Vocaluxe.SongQueue return EGameMode.TR_GAMEMODE_NORMAL; } - public virtual CPoints GetPoints() + public CPoints GetPoints() { return _Points; } diff --git a/Vocaluxe/SongQueue/ISongQueue.cs b/Vocaluxe/SongQueue/ISongQueue.cs index 40bf808d..05d48111 100644 --- a/Vocaluxe/SongQueue/ISongQueue.cs +++ b/Vocaluxe/SongQueue/ISongQueue.cs @@ -35,8 +35,8 @@ namespace Vocaluxe.SongQueue void ClearSongs(); void Reset(); - void Start(SPlayer[] player); - void NextRound(SPlayer[] player); + void Start(SPlayer[] players); + void NextRound(SPlayer[] players); bool IsFinished(); int GetCurrentRoundNr(); diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 1e170ebb..e77012f6 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -198,7 +198,10 @@ Form + + + diff --git a/VocaluxeLib/Menu/CPoints.cs b/VocaluxeLib/Menu/CPoints.cs index b9ff4b41..f6ab17fb 100644 --- a/VocaluxeLib/Menu/CPoints.cs +++ b/VocaluxeLib/Menu/CPoints.cs @@ -80,23 +80,23 @@ namespace VocaluxeLib.Menu if (round >= NumRounds) return new SPlayer[1]; - SPlayer[] player = new SPlayer[numPlayer]; + SPlayer[] players = new SPlayer[numPlayer]; - for (int p = 0; p < player.Length; p++) + for (int p = 0; p < players.Length; p++) { - player[p].Points = _Rounds[round, p].Points; - player[p].PointsGoldenNotes = _Rounds[round, p].PointsGoldenNotes; - player[p].PointsLineBonus = _Rounds[round, p].PointsLineBonus; - player[p].SongID = _Rounds[round, p].SongID; - player[p].LineNr = _Rounds[round, p].LineNr; - player[p].Medley = _Rounds[round, p].Medley; - player[p].Duet = _Rounds[round, p].Duet; - player[p].ShortSong = _Rounds[round, p].ShortSong; - player[p].DateTicks = _Rounds[round, p].DateTicks; - player[p].SongFinished = _Rounds[round, p].SongFinished; - player[p].ProfileID = _Rounds[round, p].ProfileID; + players[p].Points = _Rounds[round, p].Points; + players[p].PointsGoldenNotes = _Rounds[round, p].PointsGoldenNotes; + players[p].PointsLineBonus = _Rounds[round, p].PointsLineBonus; + players[p].SongID = _Rounds[round, p].SongID; + players[p].LineNr = _Rounds[round, p].LineNr; + players[p].Medley = _Rounds[round, p].Medley; + players[p].Duet = _Rounds[round, p].Duet; + players[p].ShortSong = _Rounds[round, p].ShortSong; + players[p].DateTicks = _Rounds[round, p].DateTicks; + players[p].SongFinished = _Rounds[round, p].SongFinished; + players[p].ProfileID = _Rounds[round, p].ProfileID; } - return player; + return players; } } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/SingNotes/CNotes.cs b/VocaluxeLib/Menu/SingNotes/CNotes.cs index 0ba6dfb6..0de66cf3 100644 --- a/VocaluxeLib/Menu/SingNotes/CNotes.cs +++ b/VocaluxeLib/Menu/SingNotes/CNotes.cs @@ -423,6 +423,7 @@ namespace VocaluxeLib.Menu.SingNotes return _PerfectLine; } + //Find last note with StartBeat<=Beat public int FindPreviousNote(int beat) { //If no notes -> No previous note diff --git a/VocaluxeLib/Menu/SongMenu/CSong.cs b/VocaluxeLib/Menu/SongMenu/CSong.cs index 126a53c7..e4396d48 100644 --- a/VocaluxeLib/Menu/SongMenu/CSong.cs +++ b/VocaluxeLib/Menu/SongMenu/CSong.cs @@ -116,7 +116,6 @@ namespace VocaluxeLib.Menu.SongMenu { private bool _CoverSmallLoaded; private bool _CoverBigLoaded; - private bool _NotesLoaded; private STexture _CoverTextureSmall = new STexture(-1); private STexture _CoverTextureBig = new STexture(-1); @@ -140,18 +139,7 @@ namespace VocaluxeLib.Menu.SongMenu public EAspect VideoAspect = EAspect.Crop; - public bool CoverSmallLoaded - { - get { return _CoverSmallLoaded; } - } - public bool CoverBigLoaded - { - get { return _CoverBigLoaded; } - } - public bool NotesLoaded - { - get { return _NotesLoaded; } - } + public bool NotesLoaded { get; private set; } public STexture CoverTextureSmall { @@ -173,9 +161,7 @@ namespace VocaluxeLib.Menu.SongMenu { get { - if (_CoverBigLoaded) - return _CoverTextureBig; - return _CoverTextureSmall; + return _CoverBigLoaded ? _CoverTextureBig : _CoverTextureSmall; } set { @@ -278,7 +264,7 @@ namespace VocaluxeLib.Menu.SongMenu VideoAspect = song.VideoAspect; _CoverSmallLoaded = song._CoverSmallLoaded; _CoverBigLoaded = song._CoverBigLoaded; - _NotesLoaded = song._NotesLoaded; + NotesLoaded = song.NotesLoaded; Artist = song.Artist; Title = song.Title; @@ -619,7 +605,7 @@ namespace VocaluxeLib.Menu.SongMenu private bool _ReadNotes(string filePath, bool forceReload = false) { //Skip loading if already done and no reload is forced - if (_NotesLoaded && !forceReload) + if (NotesLoaded && !forceReload) return true; if (!File.Exists(filePath)) @@ -784,7 +770,7 @@ namespace VocaluxeLib.Menu.SongMenu { _FindRefrain(); _FindShortEnd(); - _NotesLoaded = true; + NotesLoaded = true; if (IsDuet) _CheckDuet(); }