diff --git a/Output/Cover/Blue.xml b/Output/Cover/Blue.xml index bfa423a7..9befe7d3 100644 --- a/Output/Cover/Blue.xml +++ b/Output/Cover/Blue.xml @@ -5,230 +5,4 @@ Blue flokuep - - - NoCover - NoCover.png - - - A - A.png - - - B - B.png - - - C - C.png - - - D - D.png - - - E - E.png - - - F - F.png - - - G - G.png - - - H - H.png - - - I - I.png - - - J - J.png - - - K - K.png - - - L - L.png - - - M - M.png - - - N - N.png - - - O - O.png - - - P - P.png - - - Q - Q.png - - - R - R.png - - - S - S.png - - - T - T.png - - - U - U.png - - - V - V.png - - - W - W.png - - - X - X.png - - - Y - Y.png - - - Z - Z.png - - - # - #.png - - - No Year - NoYear.png - - - Ohne Jahr - OhneJahr.png - - - 1900 - 1909 - 1900er.png - - - 1910 - 1919 - 1910er.png - - - 1920 - 1929 - 20er.png - - - 1930 - 1939 - 30er.png - - - 1940 - 1949 - 40er.png - - - 1950 - 1959 - 50er.png - - - 1960 - 1969 - 60er.png - - - 1970 - 1979 - 70er.png - - - 1980 - 1989 - 80er.png - - - 1990 - 1999 - 90er.png - - - 2000 - 2009 - 2000er.png - - - 2010 - 2019 - 2010er.png - - - No Language - NoLanguage.png - - - Ohne Sprache - OhneSprache.png - - - German - German.png - - - English - English.png - - - French - French.png - - - Italian - Italian.png - - - Spanish - Spanish.png - - - Polish - Polish.png - - - No Edition - NoEdition.png - - - Ohne Edition - OhneEdition.png - - - No Genre - NoGenre.png - - - Ohne Genre - OhneGenre.png - - - All Songs - AllSongs.png - - - Alle Songs - AlleSongs.png - - diff --git a/Output/Cover/Blue/1900er.png b/Output/Cover/Blue/1900 - 1909.png similarity index 100% rename from Output/Cover/Blue/1900er.png rename to Output/Cover/Blue/1900 - 1909.png diff --git a/Output/Cover/Blue/1910er.png b/Output/Cover/Blue/1910 - 1919.png similarity index 100% rename from Output/Cover/Blue/1910er.png rename to Output/Cover/Blue/1910 - 1919.png diff --git a/Output/Cover/Blue/20er.png b/Output/Cover/Blue/1920 - 1929.png similarity index 100% rename from Output/Cover/Blue/20er.png rename to Output/Cover/Blue/1920 - 1929.png diff --git a/Output/Cover/Blue/30er.png b/Output/Cover/Blue/1930 - 1939.png similarity index 100% rename from Output/Cover/Blue/30er.png rename to Output/Cover/Blue/1930 - 1939.png diff --git a/Output/Cover/Blue/40er.png b/Output/Cover/Blue/1940 - 1949.png similarity index 100% rename from Output/Cover/Blue/40er.png rename to Output/Cover/Blue/1940 - 1949.png diff --git a/Output/Cover/Blue/50er.png b/Output/Cover/Blue/1950 - 1959.png similarity index 100% rename from Output/Cover/Blue/50er.png rename to Output/Cover/Blue/1950 - 1959.png diff --git a/Output/Cover/Blue/60er.png b/Output/Cover/Blue/1960 - 1969.png similarity index 100% rename from Output/Cover/Blue/60er.png rename to Output/Cover/Blue/1960 - 1969.png diff --git a/Output/Cover/Blue/70er.png b/Output/Cover/Blue/1970 - 1979.png similarity index 100% rename from Output/Cover/Blue/70er.png rename to Output/Cover/Blue/1970 - 1979.png diff --git a/Output/Cover/Blue/80er.png b/Output/Cover/Blue/1980 - 1989.png similarity index 100% rename from Output/Cover/Blue/80er.png rename to Output/Cover/Blue/1980 - 1989.png diff --git a/Output/Cover/Blue/90er.png b/Output/Cover/Blue/1990 - 1999.png similarity index 100% rename from Output/Cover/Blue/90er.png rename to Output/Cover/Blue/1990 - 1999.png diff --git a/Output/Cover/Blue/2000er.png b/Output/Cover/Blue/2000 - 2009.png similarity index 100% rename from Output/Cover/Blue/2000er.png rename to Output/Cover/Blue/2000 - 2009.png diff --git a/Output/Cover/Blue/2010er.png b/Output/Cover/Blue/2010 - 2019.png similarity index 100% rename from Output/Cover/Blue/2010er.png rename to Output/Cover/Blue/2010 - 2019.png diff --git a/Output/Cover/Blue/AllSongs.png b/Output/Cover/Blue/All Songs.png similarity index 100% rename from Output/Cover/Blue/AllSongs.png rename to Output/Cover/Blue/All Songs.png diff --git a/Output/Cover/Blue/AlleSongs.png b/Output/Cover/Blue/Alle Songs.png similarity index 100% rename from Output/Cover/Blue/AlleSongs.png rename to Output/Cover/Blue/Alle Songs.png diff --git a/Output/Cover/Blue/EmptyCover.png b/Output/Cover/Blue/EmptyCover.png new file mode 100644 index 00000000..048a8dc0 Binary files /dev/null and b/Output/Cover/Blue/EmptyCover.png differ diff --git a/Output/Cover/Blue/NoCover.png b/Output/Cover/Blue/No Cover.png similarity index 100% rename from Output/Cover/Blue/NoCover.png rename to Output/Cover/Blue/No Cover.png diff --git a/Output/Cover/Blue/NoEdition.png b/Output/Cover/Blue/No Edition.png similarity index 100% rename from Output/Cover/Blue/NoEdition.png rename to Output/Cover/Blue/No Edition.png diff --git a/Output/Cover/Blue/NoGenre.png b/Output/Cover/Blue/No Genre.png similarity index 100% rename from Output/Cover/Blue/NoGenre.png rename to Output/Cover/Blue/No Genre.png diff --git a/Output/Cover/Blue/NoLanguage.png b/Output/Cover/Blue/No Language.png similarity index 100% rename from Output/Cover/Blue/NoLanguage.png rename to Output/Cover/Blue/No Language.png diff --git a/Output/Cover/Blue/NoYear.png b/Output/Cover/Blue/No Year.png similarity index 100% rename from Output/Cover/Blue/NoYear.png rename to Output/Cover/Blue/No Year.png diff --git a/Output/Cover/Blue/OhneEdition.png b/Output/Cover/Blue/Ohne Edition.png similarity index 100% rename from Output/Cover/Blue/OhneEdition.png rename to Output/Cover/Blue/Ohne Edition.png diff --git a/Output/Cover/Blue/OhneGenre.png b/Output/Cover/Blue/Ohne Genre.png similarity index 100% rename from Output/Cover/Blue/OhneGenre.png rename to Output/Cover/Blue/Ohne Genre.png diff --git a/Output/Cover/Blue/OhneJahr.png b/Output/Cover/Blue/Ohne Jahr.png similarity index 100% rename from Output/Cover/Blue/OhneJahr.png rename to Output/Cover/Blue/Ohne Jahr.png diff --git a/Output/Cover/Blue/OhneSprache.png b/Output/Cover/Blue/Ohne Sprache.png similarity index 100% rename from Output/Cover/Blue/OhneSprache.png rename to Output/Cover/Blue/Ohne Sprache.png diff --git a/Output/Languages/English.xml b/Output/Languages/English.xml index 1cafa62a..6554f2dc 100644 --- a/Output/Languages/English.xml +++ b/Output/Languages/English.xml @@ -76,6 +76,7 @@ Own Music and Background Music No own Music Only own Music + Only selected song All Only names and avatars Nothing diff --git a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs index 46260c81..da2b74f7 100644 --- a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs +++ b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs @@ -270,7 +270,7 @@ namespace VocaluxeLib.PartyModes.Challenge public override void UpdateGame() { /* - if (CBase.Songs.GetCurrentCategoryIndex() != -1 || _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) + if (CBase.Songs.IsInCategory() || _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) _ScreenSongOptions.Selection.RandomOnly = true; else _ScreenSongOptions.Selection.RandomOnly = false;*/ @@ -475,12 +475,12 @@ namespace VocaluxeLib.PartyModes.Challenge players[i].ProfileID = -1; } - CBase.Songs.AddPartySongSung(songID); CBase.Graphics.FadeTo(EScreens.ScreenSing); } public override void LeavingHighscore() { + CBase.Songs.AddPartySongSung(CBase.Game.GetSong(0).ID); _GameData.CurrentRoundNr++; CBase.Graphics.FadeTo(EScreens.ScreenPartyDummy); } diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index b0975714..c6f0d619 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -275,7 +275,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public override void UpdateGame() { /* - if (CBase.Songs.GetCurrentCategoryIndex() != -1 || _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) + if (CBase.Songs.IsInCategory() || _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) _ScreenSongOptions.Selection.RandomOnly = true; else _ScreenSongOptions.Selection.RandomOnly = false;*/ @@ -457,6 +457,8 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public override void LeavingHighscore() { + for (int i = 0; i < CBase.Game.GetNumSongs();i++ ) + CBase.Songs.AddPartySongSung(CBase.Game.GetSong(i).ID); _GameData.CurrentRoundNr++; CBase.Graphics.FadeTo(EScreens.ScreenPartyDummy); } @@ -542,7 +544,6 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { int songID = ids[CBase.Game.GetRandom(ids.Count)]; CBase.Game.AddSong(songID, EGameMode.TR_GAMEMODE_MEDLEY); - CBase.Songs.AddPartySongSung(songID); ids.Remove(songID); s++; } diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index c695a1c7..1fcf18c2 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -329,7 +329,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe public override void UpdateGame() { /* - if (CBase.Songs.GetCurrentCategoryIndex() != -1 || _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) + if (CBase.Songs.IsInCategory() || _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) _ScreenSongOptions.Selection.RandomOnly = true; else _ScreenSongOptions.Selection.RandomOnly = false;*/ @@ -515,12 +515,12 @@ namespace VocaluxeLib.PartyModes.TicTacToe } CBase.Game.AddSong(songID, gm); - CBase.Songs.AddPartySongSung(songID); CBase.Graphics.FadeTo(EScreens.ScreenSing); } public override void LeavingHighscore() { + CBase.Songs.AddPartySongSung(CBase.Game.GetSong(0).ID); _UpdateScores(); CBase.Graphics.FadeTo(EScreens.ScreenPartyDummy); } @@ -655,9 +655,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe switch (_GameData.SongSource) { case ESongSource.TR_PLAYLIST: - for (int i = 0; i < CBase.Playlist.GetPlaylistSongCount(_GameData.PlaylistID); i++) + for (int i = 0; i < CBase.Playlist.GetSongCount(_GameData.PlaylistID); i++) { - int id = CBase.Playlist.GetPlaylistSong(_GameData.PlaylistID, i).SongID; + int id = CBase.Playlist.GetSong(_GameData.PlaylistID, i).SongID; // ReSharper disable LoopCanBeConvertedToQuery foreach (EGameMode mode in CBase.Songs.GetSongByID(id).AvailableGameModes) // ReSharper restore LoopCanBeConvertedToQuery diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs index 894f6386..f44f881c 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs @@ -180,11 +180,11 @@ namespace VocaluxeLib.PartyModes.TicTacToe _SelectSlides[_SelectSlideSongSource].Clear(); _SelectSlides[_SelectSlideSongSource].SetValues((int)_Data.ScreenConfig.SongSource); - List playlists = CBase.Playlist.GetPlaylistNames(); + List playlists = CBase.Playlist.GetNames(); _SelectSlides[_SelectSlidePlaylist].Clear(); for (int i = 0; i < playlists.Count; i++) { - string value = playlists[i] + " (" + CBase.Playlist.GetPlaylistSongCount(i) + " " + CBase.Language.Translate("TR_SONGS", _PartyModeID) + ")"; + string value = playlists[i] + " (" + CBase.Playlist.GetSongCount(i) + " " + CBase.Language.Translate("TR_SONGS", _PartyModeID) + ")"; _SelectSlides[_SelectSlidePlaylist].AddValue(value); } _SelectSlides[_SelectSlidePlaylist].Selection = _Data.ScreenConfig.PlaylistID; @@ -241,12 +241,12 @@ namespace VocaluxeLib.PartyModes.TicTacToe { if (CBase.Playlist.GetNumPlaylists() > 0) { - if (CBase.Playlist.GetPlaylistSongCount(_Data.ScreenConfig.PlaylistID) > 0) + if (CBase.Playlist.GetSongCount(_Data.ScreenConfig.PlaylistID) > 0) { _ConfigOk = false; - for (int i = 0; i < CBase.Playlist.GetPlaylistSongCount(_Data.ScreenConfig.PlaylistID); i++) + for (int i = 0; i < CBase.Playlist.GetSongCount(_Data.ScreenConfig.PlaylistID); i++) { - int id = CBase.Playlist.GetPlaylistSong(_Data.ScreenConfig.PlaylistID, i).SongID; + int id = CBase.Playlist.GetSong(_Data.ScreenConfig.PlaylistID, i).SongID; _ConfigOk = CBase.Songs.GetSongByID(id).AvailableGameModes.Any(mode => mode == gm); if (_ConfigOk) break; diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs index 2131cd14..1182b700 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs @@ -378,8 +378,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe public override void OnClose() { base.OnClose(); - CBase.BackgroundMusic.SetStatus(false); - CBase.Sound.FadeAndClose(_PreviewStream, 0f, 0.5f); + CBase.BackgroundMusic.SetDisabled(false); + CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close); } private void _CreateFields() @@ -501,7 +501,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe } CSong song = CBase.Songs.GetSongByID(songID); - CBase.BackgroundMusic.SetStatus(true); + CBase.BackgroundMusic.SetDisabled(true); _PreviewStream = CBase.Sound.Load(song.GetMP3()); CBase.Sound.SetPosition(_PreviewStream, song.Preview.StartTime); @@ -525,7 +525,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe { int songID = _Fields[_SelectedField].Content.SongID; CSong song = CBase.Songs.GetSongByID(songID); - CBase.BackgroundMusic.SetStatus(true); + CBase.BackgroundMusic.SetDisabled(true); _PreviewStream = CBase.Sound.Load(song.GetMP3()); CBase.Sound.SetPosition(_PreviewStream, song.Preview.StartTime); @@ -574,7 +574,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe { _GameData.NumJokerRandom[teamNr]--; if (!CBase.Sound.IsFinished(_PreviewStream)) - CBase.Sound.FadeAndClose(_PreviewStream, 0, 1); + CBase.Sound.Fade(_PreviewStream, 0, 1, EStreamAction.Close); _FieldSelected(true); } break; @@ -586,7 +586,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _GameData.NumJokerRetry[teamNr]--; _GameData.Team = teamNr; if (!CBase.Sound.IsFinished(_PreviewStream)) - CBase.Sound.FadeAndClose(_PreviewStream, 0, 1); + CBase.Sound.Fade(_PreviewStream, 0, 1, EStreamAction.Close); _Status = EStatus.JokerRetry; _OldSelectedField = _SelectedField; _SelectedField = -1; @@ -627,7 +627,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _NextRound() { - CBase.Sound.FadeAndClose(_PreviewStream, 0f, 0.5f); + CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close); _Data.ScreenMain.Rounds = _GameData.Rounds; _Data.ScreenMain.FadeToNameSelection = false; _Data.ScreenMain.FadeToSinging = true; @@ -640,7 +640,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _EndParty() { - CBase.Sound.FadeAndClose(_PreviewStream, 0f, 0.5f); + CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close); _FadeTo(EScreens.ScreenParty); } @@ -659,7 +659,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _Back() { - CBase.Sound.FadeAndClose(_PreviewStream, 0f, 0.5f); + CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close); _Data.ScreenMain.FadeToNameSelection = true; _Data.ScreenMain.FadeToSinging = false; _Data.ScreenMain.SingRoundNr = _SelectedField; diff --git a/ServerLib/CServer.cs b/ServerLib/CServer.cs index 2f5f0e78..e4c46301 100644 --- a/ServerLib/CServer.cs +++ b/ServerLib/CServer.cs @@ -16,7 +16,9 @@ #endregion using System; +#if WIN using System.Diagnostics; +#endif using System.ServiceModel; using System.ServiceModel.Web; using System.Net; @@ -160,7 +162,7 @@ namespace ServerLib catch (CommunicationException) { _Host.Abort(); - MessageBox.Show("Problem while initialization of webserver. You may use a different port (Change in config.xml)"); + MessageBox.Show("Problem while initialization of webserver. You may try a different port (Change it in config.xml)"); } } else @@ -187,8 +189,8 @@ namespace ServerLib ProcessStartInfo info = new ProcessStartInfo { FileName = "VocaluxeServerConfig.exe", - WorkingDirectory = Environment.CurrentDirectory, - Arguments = port + " " + (_Encrypted ? "true" : "false") + (reserve ? " reserve" : ""), + WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory, + Arguments = AppDomain.CurrentDomain.FriendlyName + " " + port + " " + (_Encrypted ? "true" : "false") + (reserve ? " true" : ""), UseShellExecute = true, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, @@ -198,10 +200,15 @@ namespace ServerLib using (Process p = Process.Start(info)) { p.WaitForExit(); + if (p.ExitCode != 0) + MessageBox.Show("Registering the Server failed (Code " + p.ExitCode + ")!\r\nThe Server might not work correctly."); p.Close(); } } - catch (Exception) {} + catch (Exception e) + { + MessageBox.Show("Registering the Server failed (" + e + ")!\r\nThe Server might not work correctly."); + } #else //Required? diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index b4be306f..d34d5432 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -22,6 +22,7 @@ using System.IO; using VocaluxeLib; using VocaluxeLib.Songs; using VocaluxeLib.Draw; +using VocaluxeLib.Utils.Player; namespace Vocaluxe.Base { @@ -29,89 +30,98 @@ namespace Vocaluxe.Base { private static bool _Initialized; + private static CSongPlayer _SongPlayer; + private static CSongPlayer _PreviewPlayer; + private static bool _OwnSongsAvailable; private static EBackgroundMusicSource _MusicSource; private static bool _VideoEnabled; private static CPlaylistElement _CurrentPlaylistElement; //Currently played music - private static int _CurrentMusicStream = -1; //Current active music stream - private static int _PreviousMusicIndex; //Index of _CurrentPlaylistElement in _PreviousFiles (kept for performance) + private static int _PreviousMusicIndex = -1; private static readonly List _BGMusicFiles = new List(); //Background music files private static readonly List _NotPlayedFiles = new List(); //Not played files private static readonly List _PreviousFiles = new List(); //Played files - private static int _Video = -1; - private static CTexture _CurrentVideoTexture; - private static CFading _VideoFading; - private static bool _OwnMusicAdded; private static bool _BackgroundMusicAdded; private static bool _Disabled; + private static bool _PlaysPreview; public static bool VideoEnabled { - get { return _VideoEnabled; } - set - { - if (_VideoEnabled == value) - return; - _VideoEnabled = value; - if (_VideoEnabled) - _LoadVideo(); - else if (_Video != -1) - { - CVideo.Close(_Video); - CDraw.RemoveTexture(ref _CurrentVideoTexture); - _Video = -1; - } + get { return _PlaysPreview ? _PreviewPlayer.VideoEnabled : _SongPlayer.VideoEnabled; } + set { + if(_PlaysPreview) + _PreviewPlayer.VideoEnabled = value; + else + _SongPlayer.VideoEnabled = value; } } - public static bool CanSing { get; private set; } + public static bool CanSing + { + get + { + if (_PlaysPreview) + return false; + else + if (_BGMusicFiles.Contains(_CurrentPlaylistElement)) + return false; + else return true; + } + } public static bool Disabled { get { return _Disabled; } set { + if (Disabled == value) + return; _Disabled = value; - if (_Disabled) - Pause(); - else - Play(); + Pause(); } } - public static bool RepeatSong { get; set; } + public static bool RepeatSong { + get { return _SongPlayer.RepeatSong; } + set { _SongPlayer.RepeatSong = value; } + } public static int SongID { - get { return _CurrentPlaylistElement == null ? -1 : _CurrentPlaylistElement.SongID; } + get { return _SongPlayer.SongID; } } public static bool SongHasVideo { - get { return _CurrentPlaylistElement != null && File.Exists(_CurrentPlaylistElement.VideoFilePath); } + get { return _SongPlayer.SongHasVideo; } } - public static bool IsPlaying { get; private set; } + public static bool IsPlaying { get { return _PlaysPreview ? _PreviewPlayer.IsPlaying : _SongPlayer.IsPlaying; } } + + public static bool IsPlayingPreview { get { return _PlaysPreview; } } public static string ArtistAndTitle { - get - { - if (_CurrentPlaylistElement == null) - return ""; - if (_CurrentPlaylistElement.Artist != "" && _CurrentPlaylistElement.Title != "") - return _CurrentPlaylistElement.Artist + " - " + _CurrentPlaylistElement.Title; - return Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath); + get { + if (_PlaysPreview) + return _PreviewPlayer.ArtistAndTitle; + else + return _BGMusicFiles.Contains(_CurrentPlaylistElement) ? Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath) : _SongPlayer.ArtistAndTitle; } } + public static float Length + { + get { return _PlaysPreview ? _PreviewPlayer.Length : _SongPlayer.Length; } + } + public static CTexture Cover { - get { return _CurrentPlaylistElement == null ? CCover.NoCover : _CurrentPlaylistElement.Cover; } + get { return _PlaysPreview ? _PreviewPlayer.Cover : _SongPlayer.Cover; } } //Use this to set whether own songs are available for access @@ -135,7 +145,7 @@ namespace Vocaluxe.Base if (_Initialized) return; - List soundFiles = CHelper.ListSoundFiles(CSettings.FolderBackgroundMusic, true, true); + List soundFiles = CHelper.ListSoundFiles(CSettings.FolderNameBackgroundMusic, true, true); foreach (string path in soundFiles) _BGMusicFiles.Add(new CPlaylistElement(path)); @@ -143,8 +153,13 @@ namespace Vocaluxe.Base _MusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC; _AddBackgroundMusic(); - _PreviousMusicIndex = -1; - IsPlaying = false; + _SongPlayer = new CSongPlayer(); + _SongPlayer.Volume = CConfig.BackgroundMusicVolume; + + _PreviewPlayer = new CSongPlayer(); + _PreviewPlayer.Volume = CConfig.PreviewMusicVolume; + _PreviewPlayer.RepeatSong = true; + _VideoEnabled = (CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON && CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON); SetMusicSource(CConfig.BackgroundMusicSource); _Initialized = true; @@ -152,42 +167,29 @@ namespace Vocaluxe.Base public static void Close() { - if (_CurrentMusicStream >= 0) - { - CSound.Close(_CurrentMusicStream); - _CurrentMusicStream = -1; - } - if (_Video != -1) - { - CVideo.Close(_Video); - CDraw.RemoveTexture(ref _CurrentVideoTexture); - _Video = -1; - } + _SongPlayer.Stop(); + _PreviewPlayer.Stop(); + _BGMusicFiles.Clear(); _NotPlayedFiles.Clear(); _PreviousFiles.Clear(); - IsPlaying = false; _Initialized = false; } public static void Play() { - if (IsPlaying || CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF) + if (IsPlaying || (CConfig.BackgroundMusic != EBackgroundMusicOffOn.TR_CONFIG_ON && !_PlaysPreview)) return; - if (_CurrentMusicStream != -1) - { - //Resume - CSound.SetStreamVolume(_CurrentMusicStream, 0f); - CSound.Fade(_CurrentMusicStream, 100f, CSettings.BackgroundMusicFadeTime); - CSound.Play(_CurrentMusicStream); - if (_VideoEnabled && _Video != -1) - CVideo.Resume(_Video); - IsPlaying = true; - } - else - Next(); + if (_PlaysPreview) + _PreviewPlayer.Play(); + else if(CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_OFF) + if (_SongPlayer.SongLoaded) + //Resume + _SongPlayer.TogglePause(); + else + Next(); } public static void Stop() @@ -195,121 +197,103 @@ namespace Vocaluxe.Base if (!IsPlaying) return; - if (_Video != -1) + if (_PlaysPreview) { - CVideo.Close(_Video); - CDraw.RemoveTexture(ref _CurrentVideoTexture); - _Video = -1; + _PreviewPlayer.Stop(); + _PlaysPreview = false; + Pause(); + } + else + { + _SongPlayer.Stop(); + _CurrentPlaylistElement = null; } - CSound.FadeAndClose(_CurrentMusicStream, 0f, CSettings.BackgroundMusicFadeTime); - _CurrentMusicStream = -1; - - _CurrentPlaylistElement = null; - IsPlaying = false; } public static void Pause() { - if (!IsPlaying) - return; - - if (_Video != -1) + if (_PlaysPreview) { - CVideo.Pause(_Video); - CVideo.Skip(_Video, CSound.GetPosition(_CurrentMusicStream) + CSettings.BackgroundMusicFadeTime, _CurrentPlaylistElement.VideoGap); + if (!_PreviewPlayer.SongLoaded) + return; + _PreviewPlayer.TogglePause(); + } + else if (CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON) + { + if (!_SongPlayer.SongLoaded) + Next(); + else + _SongPlayer.TogglePause(); } - CSound.FadeAndPause(_CurrentMusicStream, 0f, CSettings.BackgroundMusicFadeTime); - IsPlaying = false; } public static void Next() { - Stop(); //stop last song if any - if (_PreviousMusicIndex < _PreviousFiles.Count - 2) + if (!_PlaysPreview) { - //We are in the previous list and next element exists - _PreviousMusicIndex++; - _CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex]; - } - else - { - //We are not in the previous list (anymore) - if (_NotPlayedFiles.Count == 0) + Stop(); //stop last song if any + if (_PreviousMusicIndex < _PreviousFiles.Count - 2) { - if (_PreviousFiles.Count == 0) - return; //No songs to play - _NotPlayedFiles.AddRange(_PreviousFiles); + //We are in the previous list and next element exists + _PreviousMusicIndex++; + _CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex]; } + else + { + //We are not in the previous list (anymore) + if (_NotPlayedFiles.Count == 0) + { + if (_PreviousFiles.Count == 0) + return; //No songs to play + _NotPlayedFiles.AddRange(_PreviousFiles); + } - _CurrentPlaylistElement = _NotPlayedFiles[CGame.Rand.Next(_NotPlayedFiles.Count)]; - _NotPlayedFiles.Remove(_CurrentPlaylistElement); + _CurrentPlaylistElement = _NotPlayedFiles[CGame.Rand.Next(_NotPlayedFiles.Count)]; + _NotPlayedFiles.Remove(_CurrentPlaylistElement); - _PreviousFiles.Add(_CurrentPlaylistElement); - _PreviousMusicIndex = _PreviousFiles.Count - 1; + _PreviousFiles.Add(_CurrentPlaylistElement); + _PreviousMusicIndex = _PreviousFiles.Count - 1; + } + _StartSong(); } - _StartSong(); - CanSing = !_IsBackgroundFile(_CurrentPlaylistElement); } public static void Previous() { - if (_PreviousMusicIndex < 0) - return; - Debug.Assert(_CurrentMusicStream != -1 && _CurrentPlaylistElement != null); - if (CSound.GetPosition(_CurrentMusicStream) <= 1.5f && _PreviousMusicIndex > 0) + if (!_PlaysPreview) { - Stop(); //stop last song - _PreviousMusicIndex--; + if (_PreviousMusicIndex < 0) + return; + Debug.Assert(_CurrentPlaylistElement != null); + if (_SongPlayer.Position <= 1.5f && _PreviousMusicIndex > 0) + { + Stop(); //stop last song + _PreviousMusicIndex--; - _CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex]; - CanSing = !_IsBackgroundFile(_CurrentPlaylistElement); + _CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex]; + } + _StartSong(); } - _StartSong(); } public static void Update() { - if (!IsPlaying) + if (!IsPlaying && (!_SongPlayer.SongLoaded || !_PreviewPlayer.SongLoaded) ) return; - Debug.Assert(_CurrentMusicStream != -1 && _CurrentPlaylistElement != null); - float timeToPlay; - if (Math.Abs(_CurrentPlaylistElement.Finish) < 0.001) + if (_PlaysPreview) + _PreviewPlayer.Update(); + else { - //No End-Tag defined - float len = CSound.GetLength(_CurrentMusicStream); - timeToPlay = (len > 0f) ? len - CSound.GetPosition(_CurrentMusicStream) : CSettings.BackgroundMusicFadeTime + 1f; - } - else //End-Tag found - timeToPlay = _CurrentPlaylistElement.Finish - CSound.GetPosition(_CurrentMusicStream); - - bool finished = CSound.IsFinished(_CurrentMusicStream); - if (timeToPlay <= CSettings.BackgroundMusicFadeTime || finished) - { - if (RepeatSong) - _StartSong(); - else + _SongPlayer.Update(); + if (_SongPlayer.IsFinished) Next(); } } public static CTexture GetVideoTexture() { - if (_Video == -1) - return null; - float vtime; - if (CVideo.GetFrame(_Video, ref _CurrentVideoTexture, CSound.GetPosition(_CurrentMusicStream), out vtime)) - { - if (_VideoFading != null) - { - bool finished; - _CurrentVideoTexture.Color.A = _VideoFading.GetValue(out finished); - if (finished) - _VideoFading = null; - } - return _CurrentVideoTexture; - } - return null; + return _PlaysPreview ? _PreviewPlayer.GetVideoTexture() : _SongPlayer.GetVideoTexture(); } public static void SetMusicSource(EBackgroundMusicSource source) @@ -335,37 +319,74 @@ namespace Vocaluxe.Base } } + public static void LoadPreview(CSong song, float start = 0f) + { + if (!_PlaysPreview) + Pause(); + else + StopPreview(); + + if (song == null) + return; + + if (start == 0f) + start = song.Preview.StartTime; + + _PlaysPreview = true; + _PreviewPlayer.Load(song, start); + + float startposition = song.Preview.StartTime; + + float length = _PreviewPlayer.Length; + + if (song.Preview.Source == EDataSource.None) + startposition = length / 4f; + else if (startposition > length - 5f) + startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f)); + + if (startposition >= 0.5f) + startposition -= 0.5f; + + _PreviewPlayer.Position = startposition; + + Play(); + } + + public static void PlayPreview(float start = -1f) + { + if (start > -1f) + _PreviewPlayer.Position = start; + + Play(); + } + + public static void StopPreview() + { + _PreviewPlayer.Stop(); + _PlaysPreview = false; + } + /// /// (Re-)Starts the _CurrentPlaylistElement /// private static void _StartSong() { Debug.Assert(_CurrentPlaylistElement != null); - //If we have an active stream, reuse it - if (_CurrentMusicStream < 0) - { - //otherwhise load - _CurrentMusicStream = CSound.Load(_CurrentPlaylistElement.MusicFilePath); - if (_CurrentMusicStream < 0) - return; - CSound.SetStreamVolume(_CurrentMusicStream, 0f); - CSound.Fade(_CurrentMusicStream, 100f, CSettings.BackgroundMusicFadeTime); - } - //Seek to #Start-Tag, if found - if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) - CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start); - if (_VideoEnabled) + //If current song same as loaded restart only + if (_CurrentPlaylistElement.SongID == _SongPlayer.SongID && _SongPlayer.SongLoaded) + _SongPlayer.Play(); + + //otherwhise load + if (_BGMusicFiles.Contains(_CurrentPlaylistElement)) + _SongPlayer.LoadFile(_CurrentPlaylistElement.MusicFilePath, 0f, true); + else { - if (_Video != -1) - { - if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) - CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap + _CurrentPlaylistElement.Start); - else - CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap); - } - else - _LoadVideo(); + //Seek to #Start-Tag, if found + float start = 0f; + if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) + start = _CurrentPlaylistElement.Start; + _SongPlayer.Load(CBase.Songs.GetSongByID(_CurrentPlaylistElement.SongID), start, true); } } @@ -419,16 +440,5 @@ namespace Vocaluxe.Base return _BGMusicFiles.Contains(element); } - private static void _LoadVideo() - { - if (_Video != -1 || String.IsNullOrEmpty(_CurrentPlaylistElement.VideoFilePath)) - return; - _Video = CVideo.Load(_CurrentPlaylistElement.VideoFilePath); - if (CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) - CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap + _CurrentPlaylistElement.Start); //Use gap, otherwhise we will overwrite position in GetVideoTexture - else - CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap); - _VideoFading = new CFading(0f, 1f, 3f); - } } } \ No newline at end of file diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index d6265f3c..5b42d5aa 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -46,11 +46,9 @@ namespace Vocaluxe.Base private static bool _Initialized; // Base file and folder names (formerly from CSettings but they can be changed) - private const string _FolderProfiles = "Profiles"; //Use ProfileFolders for access - private const string _FolderSongs = "Songs"; //Use SongFolders for access - public static string FolderPlaylists = "Playlists"; - public static string FileHighscoreDB = "HighscoreDB.sqlite"; - private static string _FileConfig = "Config.xml"; + public static string FolderPlaylists = Path.Combine(CSettings.DataFolder, "Playlists"); + public static string FileHighscoreDB = Path.Combine(CSettings.DataFolder, "HighscoreDB.sqlite"); + private static string _FileConfig = Path.Combine(CSettings.DataFolder, "Config.xml"); // Debug public static EDebugLevel DebugLevel = EDebugLevel.TR_CONFIG_OFF; @@ -99,7 +97,7 @@ namespace Vocaluxe.Base public static EBufferSize AudioBufferSize = EBufferSize.B2048; public static int AudioLatency; private static int _BackgroundMusicVolume = 30; - public static EOffOn BackgroundMusic = EOffOn.TR_CONFIG_ON; + public static EBackgroundMusicOffOn BackgroundMusic = EBackgroundMusicOffOn.TR_CONFIG_ON; public static EBackgroundMusicSource BackgroundMusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC; public static EOffOn BackgroundMusicUseStart = EOffOn.TR_CONFIG_ON; private static int _PreviewMusicVolume = 50; @@ -108,10 +106,10 @@ namespace Vocaluxe.Base //Folders public static readonly List SongFolders = new List { - Path.Combine(Directory.GetCurrentDirectory(), _FolderSongs) + Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameSongs) #if INSTALLER - ,Path.Combine(CSettings.DataPath, CSettings.FolderSongs); + ,Path.Combine(CSettings.DataFolder, CSettings.FolderNameSongs); #endif }; /// @@ -121,9 +119,9 @@ namespace Vocaluxe.Base public static readonly List ProfileFolders = new List { #if INSTALLER - Path.Combine(Environment.CurrentDirectory, CSettings.FolderProfiles), + Path.Combine(Environment.CurrentDirectory, CSettings.FolderNameProfiles), #endif - Path.Combine(CSettings.DataPath, _FolderProfiles) + Path.Combine(CSettings.DataFolder, CSettings.FolderNameProfiles) }; // Game @@ -202,7 +200,7 @@ namespace Vocaluxe.Base return; // Init config file - if (!File.Exists(Path.Combine(CSettings.DataPath, _FileConfig))) + if (!File.Exists(_FileConfig)) SaveConfig(); else _LoadConfig(); @@ -212,7 +210,7 @@ namespace Vocaluxe.Base private static void _LoadConfig() { - CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.DataPath, _FileConfig)); + CXMLReader xmlReader = CXMLReader.OpenFile(_FileConfig); if (xmlReader == null) return; @@ -357,7 +355,7 @@ namespace Vocaluxe.Base XmlWriter writer = null; try { - writer = XmlWriter.Create(Path.Combine(CSettings.DataPath, _FileConfig), XMLSettings); + writer = XmlWriter.Create(_FileConfig, XMLSettings); writer.WriteStartDocument(); writer.WriteStartElement("root"); @@ -373,7 +371,7 @@ namespace Vocaluxe.Base writer.WriteElementString("Screens", Screen.AllScreens.Length.ToString()); writer.WriteElementString("PrimaryScreenResolution", Screen.PrimaryScreen.Bounds.Size.ToString()); - writer.WriteElementString("Directory", Environment.CurrentDirectory); + writer.WriteElementString("Directory", CSettings.ProgramFolder); writer.WriteEndElement(); @@ -480,8 +478,8 @@ namespace Vocaluxe.Base writer.WriteComment("AudioLatency from -500 to 500 ms"); writer.WriteElementString("AudioLatency", AudioLatency.ToString()); - writer.WriteComment("Background Music: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("BackgroundMusic", Enum.GetName(typeof(EOffOn), BackgroundMusic)); + writer.WriteComment("Background Music: " + CHelper.ListStrings(Enum.GetNames(typeof(EBackgroundMusicOffOn)))); + writer.WriteElementString("BackgroundMusic", Enum.GetName(typeof(EBackgroundMusicOffOn), BackgroundMusic)); writer.WriteComment("Background Music Volume from 0 to 100"); writer.WriteElementString("BackgroundMusicVolume", BackgroundMusicVolume.ToString()); @@ -806,10 +804,8 @@ namespace Vocaluxe.Base //Check each parameter for (int i = 0; i < _Params.Count; i++) { - //Switch parameter as lower case - string param = _Params[i]; - - param = param.ToLower(); + //Switch parameter to lower case + string param = _Params[i].ToLower(); string value = _Values[i]; diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index 26eb6866..ac9cc10c 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -143,7 +143,7 @@ namespace Vocaluxe.Base { _CoverThemes.Clear(); - const string path = CSettings.FolderCover; + string path = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover); List files = CHelper.ListFiles(path, "*.xml"); foreach (string file in files) @@ -179,23 +179,23 @@ namespace Vocaluxe.Base var ignoreList = new List(); - string coverPath = Path.Combine(CSettings.FolderCover, coverTheme.Folder); + string coverPath = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover, coverTheme.Folder); List files = CHelper.ListImageFiles(coverPath, true, true); - CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.FolderCover, coverTheme.File)); + CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover, coverTheme.File)); lock (_Covers) { if (xmlReader != null) { _Covers.Clear(); - List cover = xmlReader.GetValues("Cover"); + List cover = xmlReader.GetNames("//root/Cover/*"); foreach (string coverName in cover) { string name; string filePath; xmlReader.GetValue("//root/Cover/" + coverName + "/Name", out name, String.Empty); xmlReader.GetValue("//root/Cover/" + coverName + "/Path", out filePath, String.Empty); - string coverFilePath = Path.Combine(CSettings.FolderCover, Path.Combine(coverTheme.Folder, filePath)); + string coverFilePath = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover, coverTheme.Folder, filePath); if (!File.Exists(coverFilePath)) continue; diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index 065e7170..6297433e 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -32,9 +32,9 @@ namespace Vocaluxe.Base public static bool Init() { - _HighscoreDB = new CHighscoreDB(Path.Combine(Environment.CurrentDirectory, CConfig.FileHighscoreDB)); - _CoverDB = new CCoverDB(Path.Combine(Environment.CurrentDirectory, CSettings.FileCoverDB)); - _ResourceDB = new CResourceDB(Path.Combine(Environment.CurrentDirectory, CSettings.FileCreditsRessourcesDB)); + _HighscoreDB = new CHighscoreDB(CConfig.FileHighscoreDB); + _CoverDB = new CCoverDB(Path.Combine(CSettings.DataFolder, CSettings.FileNameCoverDB)); + _ResourceDB = new CResourceDB(Path.Combine(CSettings.ProgramFolder, CSettings.FileNameCreditsRessourcesDB)); if (!_HighscoreDB.Init()) { diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index 837cd713..69bf1c51 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -60,6 +60,11 @@ namespace Vocaluxe.Base get { return _CurrentScreen; } } + public static EScreens NextScreen + { + get { return _NextScreen; } + } + #region public methods public static void Init() { @@ -335,7 +340,7 @@ namespace Vocaluxe.Base bool popupVolumeControlAllowed = _CurrentScreen != EScreens.ScreenCredits && _CurrentScreen != EScreens.ScreenOptionsRecord; //Hide volume control for bg-music if bg-music is disabled if (popupVolumeControlAllowed && (_CurrentScreen != EScreens.ScreenSong || CSongs.Category == -1) - && _CurrentScreen != EScreens.ScreenSing && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF) + && _CurrentScreen != EScreens.ScreenSing && CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_OFF) popupVolumeControlAllowed = false; @@ -348,8 +353,7 @@ namespace Vocaluxe.Base if (!eventsAvailable) keyEvent = inputKeyEvent; - if (keyEvent.Key == Keys.Left || keyEvent.Key == Keys.Right || keyEvent.Key == Keys.Up || keyEvent.Key == Keys.Down || keyEvent.Key == Keys.NumPad0 || - keyEvent.Key == Keys.D0) + if (keyEvent.IsArrowKey() || keyEvent.Key == Keys.NumPad0 || keyEvent.Key == Keys.D0) { _Cursor.Deactivate(); @@ -392,13 +396,13 @@ namespace Vocaluxe.Base if (popupPlayerControlAllowed && keyEvent.Key == Keys.Tab) { - if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) + if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON) ShowPopup(EPopupScreens.PopupPlayerControl); else HidePopup(EPopupScreens.PopupPlayerControl); } - if (popupPlayerControlAllowed && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) + if (popupPlayerControlAllowed && CConfig.BackgroundMusic != EBackgroundMusicOffOn.TR_CONFIG_OFF) { if (keyEvent.Key == Keys.MediaNextTrack) CBackgroundMusic.Next(); @@ -498,7 +502,7 @@ namespace Vocaluxe.Base bool isOverPopupPlayerControl = CHelper.IsInBounds(_PopupScreens[(int)EPopupScreens.PopupPlayerControl].ScreenArea, mouseEvent); if (popupPlayerControlAllowed && isOverPopupPlayerControl) { - if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) + if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON) ShowPopup(EPopupScreens.PopupPlayerControl); } diff --git a/Vocaluxe/Base/CLanguage.cs b/Vocaluxe/Base/CLanguage.cs index c3828223..a86faf0f 100644 --- a/Vocaluxe/Base/CLanguage.cs +++ b/Vocaluxe/Base/CLanguage.cs @@ -74,7 +74,7 @@ namespace Vocaluxe.Base _Languages = new List(); var files = new List(); - files.AddRange(CHelper.ListFiles(CSettings.FolderLanguages, "*.xml", true, true)); + files.AddRange(CHelper.ListFiles(CSettings.FolderNameLanguages, "*.xml", true, true)); foreach (string file in files) _LoadLanguageFile(file); @@ -168,7 +168,7 @@ namespace Vocaluxe.Base private static bool _LoadLanguageEntries(CXMLReader xmlReader, out Dictionary texts) { texts = new Dictionary(); - IEnumerable names = xmlReader.GetAttributes("resources", "name"); + IEnumerable names = xmlReader.GetAttributes("//resources/string", "name"); foreach (string name in names) { string value; @@ -214,7 +214,7 @@ namespace Vocaluxe.Base private static void _LoadLanguageFile(string fileName) { - var lang = new SLanguage {LanguageFilePath = Path.Combine(CSettings.FolderLanguages, fileName)}; + var lang = new SLanguage {LanguageFilePath = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameLanguages, fileName)}; CXMLReader xmlReader = CXMLReader.OpenFile(lang.LanguageFilePath); if (xmlReader == null) diff --git a/Vocaluxe/Base/CLog.cs b/Vocaluxe/Base/CLog.cs index f90b7043..31d26f5a 100644 --- a/Vocaluxe/Base/CLog.cs +++ b/Vocaluxe/Base/CLog.cs @@ -42,7 +42,7 @@ namespace Vocaluxe.Base { if (_LogFile != null) return; - _LogFile = new StreamWriter(Path.Combine(CSettings.DataPath, _LogFileName), false, Encoding.UTF8); + _LogFile = new StreamWriter(Path.Combine(CSettings.DataFolder, _LogFileName), false, Encoding.UTF8); _LogFile.WriteLine(_LogName + " " + CSettings.GetFullVersionText() + " " + DateTime.Now); _LogFile.WriteLine("----------------------------------------"); @@ -117,11 +117,11 @@ namespace Vocaluxe.Base public static void Init() { - _ErrorLog = new CErrorLogFile(CSettings.FileErrorLog, "Error-Log"); - _PerformanceLog = new CLogFile(CSettings.FilePerformanceLog, "Performance-Log"); - _BenchmarkLog = new CLogFile(CSettings.FileBenchmarkLog, "Benchmark-Log"); - _DebugLog = new CLogFile(CSettings.FileDebugLog, "Debug-Log"); - _SongInfoLog = new CLogFile(CSettings.FileSongInfoLog, "Song-Information-Log"); + _ErrorLog = new CErrorLogFile(CSettings.FileNameErrorLog, "Error-Log"); + _PerformanceLog = new CLogFile(CSettings.FileNamePerformanceLog, "Performance-Log"); + _BenchmarkLog = new CLogFile(CSettings.FileNameBenchmarkLog, "Benchmark-Log"); + _DebugLog = new CLogFile(CSettings.FileNameDebugLog, "Debug-Log"); + _SongInfoLog = new CLogFile(CSettings.FileNameSongInfoLog, "Song-Information-Log"); _BenchmarkTimer = new Stopwatch[_MaxBenchmarks]; for (int i = 0; i < _BenchmarkTimer.Length; i++) diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index a47c74a7..68bdb588 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -76,6 +76,11 @@ namespace Vocaluxe.Base return CConfig.BackgroundMusicVolume; } + public EBackgroundMusicOffOn GetBackgroundMusicStatus() + { + return CConfig.BackgroundMusic; + } + public int GetPreviewMusicVolume() { return CConfig.PreviewMusicVolume; @@ -231,7 +236,7 @@ namespace Vocaluxe.Base public string GetDataPath() { - return CSettings.DataPath; + return CSettings.DataFolder; } public float GetSlideShowImageTime() @@ -243,6 +248,11 @@ namespace Vocaluxe.Base { return CSettings.SlideShowFadeTime; } + + public float GetSoundPlayerFadeTime() + { + return CSettings.SoundPlayerFadeTime; + } } class CBtheme : ITheme @@ -335,11 +345,21 @@ namespace Vocaluxe.Base return CBackgroundMusic.VideoEnabled; } - public void SetStatus(bool disabled) + public bool IsPlayingPreview() + { + return CBackgroundMusic.IsPlayingPreview; + } + + public void SetDisabled(bool disabled) { CBackgroundMusic.Disabled = disabled; } + public float GetLength() + { + return CBackgroundMusic.Length; + } + public void Next() { CBackgroundMusic.Next(); @@ -360,6 +380,26 @@ namespace Vocaluxe.Base CBackgroundMusic.Play(); } + public void Stop() + { + CBackgroundMusic.Stop(); + } + + public void LoadPreview(CSong song, float start = 0f) + { + CBackgroundMusic.LoadPreview(song, start); + } + + public void PlayPreview(float start = -1f) + { + CBackgroundMusic.PlayPreview(start); + } + + public void StopPreview() + { + CBackgroundMusic.StopPreview(); + } + public CTexture GetVideoTexture() { return CBackgroundMusic.GetVideoTexture(); @@ -430,6 +470,11 @@ namespace Vocaluxe.Base { return CGraphics.GlobalAlpha; } + + public EScreens GetNextScreen() + { + return CGraphics.NextScreen; + } } class CBlog : ILog @@ -577,6 +622,16 @@ namespace Vocaluxe.Base { return CGame.GetNumSongs(); } + + public CSong GetSong() + { + return CGame.GetSong(); + } + + public CSong GetSong(int round) + { + return CGame.GetSong(round); + } } class CBprofiles : IProfiles @@ -774,6 +829,16 @@ namespace Vocaluxe.Base { CVideo.SetLoop(streamID, loop); } + + public void Pause(int streamID) + { + CVideo.Pause(streamID); + } + + public void Resume(int streamID) + { + CVideo.Resume(streamID); + } } class CBsound : ISound @@ -793,9 +858,14 @@ namespace Vocaluxe.Base CSound.Play(soundStream); } - public void Fade(int soundStream, float targetVolume, float duration) + public void Fade(int soundStream, float targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing) { - CSound.Fade(soundStream, targetVolume, duration); + CSound.Fade(soundStream, targetVolume, duration, afterFadeAction); + } + + public void Close(int soundStream) + { + CSound.Close(soundStream); } public bool IsFinished(int soundStream) @@ -813,11 +883,6 @@ namespace Vocaluxe.Base return CSound.GetLength(soundStream); } - public void FadeAndClose(int soundStream, float targetVolume, float duration) - { - CSound.FadeAndClose(soundStream, targetVolume, duration); - } - public void SetStreamVolume(int soundStream, float volume) { CSound.SetStreamVolume(soundStream, volume); @@ -855,29 +920,34 @@ namespace Vocaluxe.Base class CBplaylist : IPlaylist { - public void SetPlaylistName(int playlistID, string name) + public void SetName(int playlistID, string name) { - CPlaylists.SetPlaylistName(playlistID, name); + CPlaylists.SetName(playlistID, name); } - public List GetPlaylistNames() + public List GetNames() { - return CPlaylists.PlaylistNames; + return CPlaylists.Names; } - public string GetPlaylistName(int playlistID) + public bool Exists(int playlistID) { - return CPlaylists.GetPlaylistName(playlistID); + return CPlaylists.Get(playlistID) != null; } - public void DeletePlaylist(int playlistID) + public string GetName(int playlistID) { - CPlaylists.DeletePlaylist(playlistID); + return CPlaylists.GetName(playlistID); } - public void SavePlaylist(int playlistID) + public void Delete(int playlistID) { - CPlaylists.SavePlaylist(playlistID); + CPlaylists.Delete(playlistID); + } + + public void Save(int playlistID) + { + CPlaylists.Save(playlistID); } public int GetNumPlaylists() @@ -885,49 +955,49 @@ namespace Vocaluxe.Base return CPlaylists.NumPlaylists; } - public void AddPlaylistSong(int playlistID, int songID) + public void AddSong(int playlistID, int songID) { - CPlaylists.AddPlaylistSong(playlistID, songID); + CPlaylists.AddSong(playlistID, songID); } - public void AddPlaylistSong(int playlistID, int songID, EGameMode gameMode) + public void AddSong(int playlistID, int songID, EGameMode gameMode) { - CPlaylists.AddPlaylistSong(playlistID, songID, gameMode); + CPlaylists.AddSong(playlistID, songID, gameMode); } - public void InsertPlaylistSong(int playlistID, int positionIndex, int songID, EGameMode gameMode) + public void InsertSong(int playlistID, int positionIndex, int songID, EGameMode gameMode) { - CPlaylists.InsertPlaylistSong(playlistID, positionIndex, songID, gameMode); + CPlaylists.InsertSong(playlistID, positionIndex, songID, gameMode); } - public void MovePlaylistSong(int playlistID, int sourceIndex, int destIndex) + public void MoveSong(int playlistID, int sourceIndex, int destIndex) { - CPlaylists.MovePlaylistSong(playlistID, sourceIndex, destIndex); + CPlaylists.MoveSong(playlistID, sourceIndex, destIndex); } - public void MovePlaylistSongDown(int playlistID, int songIndex) + public void MoveSongDown(int playlistID, int songIndex) { - CPlaylists.MovePlaylistSongDown(playlistID, songIndex); + CPlaylists.MovePSongDown(playlistID, songIndex); } - public void MovePlaylistSongUp(int playlistID, int songIndex) + public void MoveSongUp(int playlistID, int songIndex) { - CPlaylists.MovePlaylistSongUp(playlistID, songIndex); + CPlaylists.MoveSongUp(playlistID, songIndex); } - public void DeletePlaylistSong(int playlistID, int songIndex) + public void DeleteSong(int playlistID, int songIndex) { - CPlaylists.DeletePlaylistSong(playlistID, songIndex); + CPlaylists.DeleteSong(playlistID, songIndex); } - public int GetPlaylistSongCount(int playlistID) + public int GetSongCount(int playlistID) { - return CPlaylists.GetPlaylistSongCount(playlistID); + return CPlaylists.GetSongCount(playlistID); } - public CPlaylistSong GetPlaylistSong(int playlistID, int songIndex) + public CPlaylistSong GetSong(int playlistID, int songIndex) { - return CPlaylists.GetPlaylistSong(playlistID, songIndex); + return CPlaylists.GetSong(playlistID, songIndex); } } } \ No newline at end of file diff --git a/Vocaluxe/Base/CParty.cs b/Vocaluxe/Base/CParty.cs index 2fd180c1..22bc3b33 100644 --- a/Vocaluxe/Base/CParty.cs +++ b/Vocaluxe/Base/CParty.cs @@ -218,7 +218,7 @@ namespace Vocaluxe.Base private static void _LoadPartyModes() { var files = new List(); - files.AddRange(CHelper.ListFiles(CSettings.FolderPartyModes, "*.xml", false, true)); + files.AddRange(CHelper.ListFiles(CSettings.FolderNamePartyModes, "*.xml", false, true)); foreach (string file in files) { @@ -246,10 +246,10 @@ namespace Vocaluxe.Base loaded &= xmlReader.GetValue("//root/Info/Author", out pm.Author, "ERROR Author"); loaded &= xmlReader.GetValue("//root/Info/Folder", out pm.Folder, "ERROR Folder"); loaded &= xmlReader.GetValue("//root/Info/PartyModeFile", out pm.PartyModeFile, "ERROR PartyModeFile"); - loaded &= xmlReader.GetInnerValues("PartyScreens", ref pm.ScreenFiles); loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMajor", ref pm.PartyModeVersionMajor); loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMinor", ref pm.PartyModeVersionMinor); loaded &= xmlReader.GetValue("//root/Info/TargetAudience", out pm.TargetAudience, "ERROR TargetAudience"); + loaded &= xmlReader.GetValues("//root/PartyScreens/*", ref pm.ScreenFiles); if (!loaded) { @@ -269,7 +269,8 @@ namespace Vocaluxe.Base return pm; } - string pathToCode = Path.Combine(Path.Combine(CSettings.FolderPartyModes, pm.Folder), CSettings.FolderPartyModeCode); + string pathToPm = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNamePartyModes, pm.Folder); + string pathToCode = Path.Combine(pathToPm, CSettings.FolderNamePartyModeCode); var filesToCompile = new List(); filesToCompile.AddRange(CHelper.ListFiles(pathToCode, "*.cs", false, true)); @@ -278,7 +279,7 @@ namespace Vocaluxe.Base if (output == null) return pm; - if (!CLanguage.LoadPartyLanguageFiles(pm.PartyModeID, Path.Combine(Path.Combine(CSettings.FolderPartyModes, pm.Folder), CSettings.FolderPartyModeLanguages))) + if (!CLanguage.LoadPartyLanguageFiles(pm.PartyModeID, Path.Combine(pathToPm, CSettings.FolderNamePartyModeLanguages))) { CLog.LogError("Error loading language files for PartyMode: " + file); return pm; @@ -301,9 +302,9 @@ namespace Vocaluxe.Base return pm; } pm.PartyMode.Initialize(); - pm.PartyMode.SetFolder(Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.FolderPartyModes, pm.Folder))); + pm.PartyMode.SetFolder(pathToPm); - if (!CTheme.AddTheme(Path.Combine(pm.PartyMode.GetFolder(), "Theme.xml"), pm.PartyModeID)) + if (!CTheme.AddTheme(Path.Combine(pathToPm, "Theme.xml"), pm.PartyModeID)) return pm; int themeIndex = CTheme.GetThemeIndex(pm.PartyModeID); @@ -318,7 +319,7 @@ namespace Vocaluxe.Base foreach (string screenfile in pm.ScreenFiles) { - string xmlPath = Path.Combine(Path.Combine(CSettings.FolderPartyModes, pm.Folder), CSettings.FolderPartyModeScreens); + string xmlPath = Path.Combine(pathToPm, CSettings.FolderNamePartyModeScreens); CMenuParty screen = _GetPartyScreenInstance(output, screenfile, pm.Folder); if (screen != null) diff --git a/Vocaluxe/Base/CPlaylists.cs b/Vocaluxe/Base/CPlaylists.cs index 5d928c7c..2189fee2 100644 --- a/Vocaluxe/Base/CPlaylists.cs +++ b/Vocaluxe/Base/CPlaylists.cs @@ -31,15 +31,16 @@ namespace Vocaluxe.Base static class CPlaylists { private static List _Playlists; + private static int _NextID; - public static CPlaylistFile[] Playlists + public static IEnumerable Playlists { - get { return _Playlists.ToArray(); } + get { return _Playlists.AsReadOnly(); } } - public static List PlaylistNames + public static List Names { - get { return _Playlists.Select(t => t.PlaylistName).ToList(); } + get { return _Playlists.Select(t => t.Name).ToList(); } } public static int NumPlaylists @@ -49,176 +50,169 @@ namespace Vocaluxe.Base public static void Init() { - LoadPlaylists(); + Load(); _ConvertUSDXPlaylists(); - _SortPlaylistsByName(); + _SortByName(); } private static void _ConvertUSDXPlaylists() { var files = new List(); - files.AddRange(CHelper.ListFiles(Path.Combine(CSettings.DataPath, CConfig.FolderPlaylists), "*.upl", true, true)); + files.AddRange(CHelper.ListFiles(Path.Combine(CSettings.DataFolder, CConfig.FolderPlaylists), "*.upl", true, true)); foreach (string file in files) { CPlaylistFile playlist = _ConvertUSDXPlaylist(file); - playlist.SavePlaylist(); + playlist.Save(); _Playlists.Add(playlist); } } - public static void LoadPlaylists() + public static void Load() { _Playlists = new List(); var files = new List(); - files.AddRange(CHelper.ListFiles(Path.Combine(CSettings.DataPath, CConfig.FolderPlaylists), "*.xml", true, true)); + files.AddRange(CHelper.ListFiles(Path.Combine(CSettings.DataFolder, CConfig.FolderPlaylists), "*.xml", true, true)); foreach (string file in files) { - CPlaylistFile playlist = new CPlaylistFile(file, files.IndexOf(file)); + CPlaylistFile playlist = new CPlaylistFile(files.IndexOf(file), file); _Playlists.Add(playlist); } } - public static string GetPlaylistName(int playlistID) + public static CPlaylistFile Get(int playlistID) { - if (playlistID >= _Playlists.Count || playlistID < 0) - return "Error: Can't find Playlist"; - - return _Playlists[playlistID].PlaylistName; + return _Playlists.FirstOrDefault(pl => pl.Id == playlistID); } - public static void SetPlaylistName(int playlistID, string name) + public static string GetName(int playlistID) { - if (playlistID >= _Playlists.Count || playlistID < 0) - return; - - _Playlists[playlistID].PlaylistName = name; + CPlaylistFile pl = Get(playlistID); + return pl == null ? "Error: Can't find Playlist" : pl.Name; } - public static void DeletePlaylist(int playlistID) + public static void SetName(int playlistID, string name) { - if (playlistID < 0 || playlistID >= _Playlists.Count) + CPlaylistFile pl = Get(playlistID); + + if (pl != null) + pl.Name = name; + } + + public static void Delete(int playlistID) + { + CPlaylistFile pl = Get(playlistID); + if (pl == null) return; - if (_Playlists[playlistID].PlaylistFile != "") + if (pl.File != "" && File.Exists(pl.File)) { try { - File.Delete(_Playlists[playlistID].PlaylistFile); + File.Delete(pl.File); } catch (Exception) { - CLog.LogError("Can't delete Playlist File " + _Playlists[playlistID].PlaylistFile + ".xml"); + CLog.LogError("Can't delete Playlist File " + _Playlists[playlistID].File + ".xml"); } } - _Playlists.RemoveAt(playlistID); + _Playlists.Remove(pl); } - public static void SavePlaylist(int playlistID) + public static void Save(int playlistID) { - if (playlistID < 0 || playlistID >= _Playlists.Count) - return; - _Playlists[playlistID].SavePlaylist(); + CPlaylistFile pl = Get(playlistID); + if (pl != null) + pl.Save(); } - public static int NewPlaylist() + public static int NewPlaylist(string name = "New Playlist") { - CPlaylistFile pl = new CPlaylistFile {PlaylistName = "New Playlist", Id = _Playlists.Count}; + CPlaylistFile pl = new CPlaylistFile(_NextID++) {Name = name}; _Playlists.Add(pl); - return _Playlists.Count - 1; + return pl.Id; } - public static void AddPlaylistSong(int playlistID, int songID) + public static void AddSong(int playlistID, int songID) { - if (playlistID >= _Playlists.Count || playlistID < 0) - return; - - _Playlists[playlistID].AddSong(songID); + CPlaylistFile pl = Get(playlistID); + if (pl != null) + pl.AddSong(songID); } - public static void AddPlaylistSong(int playlistID, int songID, EGameMode gameMode) + public static void AddSong(int playlistID, int songID, EGameMode gameMode) { - if (playlistID >= _Playlists.Count || playlistID < 0) - return; - - _Playlists[playlistID].AddSong(songID, gameMode); + CPlaylistFile pl = Get(playlistID); + if (pl != null) + pl.AddSong(songID, gameMode); } - public static void InsertPlaylistSong(int playlistID, int positionIndex, int songID, EGameMode gameMode) + public static void InsertSong(int playlistID, int positionIndex, int songID, EGameMode gameMode) { - if (playlistID >= _Playlists.Count || playlistID < 0) - return; - - _Playlists[playlistID].SongInsert(positionIndex, songID, gameMode); + CPlaylistFile pl = Get(playlistID); + if (pl != null) + pl.InsertSong(positionIndex, songID, gameMode); } - public static void MovePlaylistSong(int playlistID, int sourceIndex, int destIndex) + public static void MoveSong(int playlistID, int sourceIndex, int destIndex) { - if (playlistID >= _Playlists.Count || playlistID < 0) - return; - - _Playlists[playlistID].SongMove(sourceIndex, destIndex); + CPlaylistFile pl = Get(playlistID); + if (pl != null) + pl.MoveSong(sourceIndex, destIndex); } - public static void MovePlaylistSongDown(int playlistID, int songIndex) + public static void MovePSongDown(int playlistID, int songIndex) { - if (playlistID >= _Playlists.Count || playlistID < 0) - return; - - _Playlists[playlistID].SongDown(songIndex); + CPlaylistFile pl = Get(playlistID); + if (pl != null) + pl.MoveSongDown(songIndex); } - public static void MovePlaylistSongUp(int playlistID, int songIndex) + public static void MoveSongUp(int playlistID, int songIndex) { - if (playlistID >= _Playlists.Count || playlistID < 0) - return; - - _Playlists[playlistID].SongUp(songIndex); + CPlaylistFile pl = Get(playlistID); + if (pl != null) + pl.MoveSongUp(songIndex); } - public static void DeletePlaylistSong(int playlistID, int songIndex) + public static void DeleteSong(int playlistID, int songIndex) { - if (playlistID >= _Playlists.Count || playlistID < 0) - return; - - _Playlists[playlistID].DeleteSong(songIndex); + CPlaylistFile pl = Get(playlistID); + if (pl != null) + pl.DeleteSong(songIndex); } - public static int GetPlaylistSongCount(int playlistID) + public static int GetSongCount(int playlistID) { - if (playlistID >= _Playlists.Count || playlistID < 0) - return 0; - - return _Playlists[playlistID].Songs.Count; + CPlaylistFile pl = Get(playlistID); + return pl != null ? pl.Songs.Count : -1; } - public static CPlaylistSong GetPlaylistSong(int playlistID, int songIndex) + public static CPlaylistSong GetSong(int playlistID, int songIndex) { - if (playlistID >= _Playlists.Count || playlistID < 0) + CPlaylistFile pl = Get(playlistID); + if (pl == null || songIndex >= pl.Songs.Count) return null; - if (songIndex >= _Playlists[playlistID].Songs.Count) - return null; - - return _Playlists[playlistID].Songs[songIndex]; + return pl.Songs[songIndex]; } #region private methods - private static void _SortPlaylistsByName() + private static void _SortByName() { - _Playlists.Sort(_CompareByPlaylistName); + _Playlists.Sort(_CompareByName); } - private static int _CompareByPlaylistName(CPlaylistFile a, CPlaylistFile b) + private static int _CompareByName(CPlaylistFile a, CPlaylistFile b) { - return String.CompareOrdinal(a.PlaylistName, b.PlaylistName); + return String.CompareOrdinal(a.Name, b.Name); } private static CPlaylistFile _ConvertUSDXPlaylist(string file) { - var pl = new CPlaylistFile(); + var pl = new CPlaylistFile(_NextID++); ReadOnlyCollection allSongs = CSongs.AllSongs; if (!File.Exists(file)) @@ -234,30 +228,23 @@ namespace Vocaluxe.Base int pos = line.IndexOf(":", StringComparison.Ordinal); if (pos <= 0) continue; - //Name or comment if (line[0] == '#') { + //Name or comment string identifier = line.Substring(1, pos - 1).Trim(); string value = line.Substring(pos + 1, line.Length - pos - 1).Trim(); if (identifier.ToUpper() == "NAME") - pl.PlaylistName = value; + pl.Name = value; } - //Song else { + //Song string artist = line.Substring(0, pos - 1).Trim(); string title = line.Substring(pos + 1, line.Length - pos - 1).Trim(); - bool found = false; - foreach (CSong song in allSongs) - { - if (song.Artist == artist && song.Title == title) - { - pl.AddSong(song.ID); - found = true; - break; - } - } - if (!found) + CSong plSong = allSongs.FirstOrDefault(song => song.Artist == artist && song.Title == title); + if (plSong != null) + pl.AddSong(plSong.ID); + else CLog.LogError("Can't find song '" + title + "' from '" + artist + "' in playlist file: " + file); } } diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index 3de72e98..b419e7b1 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -71,45 +71,51 @@ namespace Vocaluxe.Base public const int VertexBufferElements = 10000; + public static readonly string ProgramFolder = AppDomain.CurrentDomain.BaseDirectory; + #if INSTALLER - public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Vocaluxe"); + public static readonly string DataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Vocaluxe"); #else - public static readonly string DataPath = Environment.CurrentDirectory; + public static readonly string DataFolder = ProgramFolder; #endif - public const string Icon = "Vocaluxe.ico"; - public const string Logo = "Logo.png"; public const string FallbackLanguage = "English"; - public const string FileFonts = "Fonts.xml"; - public const string FileOldHighscoreDB = "Ultrastar.db"; - public const string FileCoverDB = "CoverDB.sqlite"; - public const string FileCreditsRessourcesDB = "CreditsRessourcesDB.sqlite"; - public const string FilePerformanceLog = "Performance.log"; - public const string FileErrorLog = "Error.log"; - public const string FileBenchmarkLog = "Benchmark.log"; - public const string FileDebugLog = "Debug.log"; - public const string FileSongInfoLog = "SongInformation.log"; + public const string FileNameIcon = "Vocaluxe.ico"; + public const string FileNameLogo = "Logo.png"; + public const string FileNameFonts = "Fonts.xml"; - public const string SoundT440 = "440Hz.mp3"; + public const string FileNameOldHighscoreDB = "Ultrastar.db"; + public const string FileNameCoverDB = "CoverDB.sqlite"; + public const string FileNameCreditsRessourcesDB = "CreditsRessourcesDB.sqlite"; - public const string FolderCover = "Cover"; - public const string FolderGraphics = "Graphics"; - public const string FolderFonts = "Fonts"; - public const string FolderThemes = "Themes"; - public const string FolderThemeFonts = "Fonts"; - public const string FolderScreens = "Screens"; - public const string FolderPhotos = "Photos"; - public const string FolderSounds = "Sounds"; - public const string FolderLanguages = "Languages"; - public const string FolderScreenshots = "Screenshots"; - public const string FolderBackgroundMusic = "BackgroundMusic"; + public const string FileNamePerformanceLog = "Performance.log"; + public const string FileNameErrorLog = "Error.log"; + public const string FileNameBenchmarkLog = "Benchmark.log"; + public const string FileNameDebugLog = "Debug.log"; + public const string FileNameSongInfoLog = "SongInformation.log"; - public const string FolderPartyModes = "PartyModes"; - public const string FolderPartyModeCode = "Code"; - public const string FolderPartyModeScreens = "Screens"; - public const string FolderPartyModeLanguages = "Languages"; - public const string FolderPartyModeFonts = "Fonts"; + public const string FileNameSoundT440 = "440Hz.mp3"; + + public const string FolderNameSongs = "Songs"; + public const string FolderNameProfiles = "Profiles"; + public const string FolderNameCover = "Cover"; + public const string FolderNameGraphics = "Graphics"; + public const string FolderNameFonts = "Fonts"; + public const string FolderNameThemes = "Themes"; + public const string FolderNameThemeFonts = "Fonts"; + public const string FolderNameScreens = "Screens"; + public const string FolderNamePhotos = "Photos"; + public const string FolderNameSounds = "Sounds"; + public const string FolderNameLanguages = "Languages"; + public const string FolderNameScreenshots = "Screenshots"; + public const string FolderNameBackgroundMusic = "BackgroundMusic"; + + public const string FolderNamePartyModes = "PartyModes"; + public const string FolderNamePartyModeCode = "Code"; + public const string FolderNamePartyModeScreens = "Screens"; + public const string FolderNamePartyModeLanguages = "Languages"; + public const string FolderNamePartyModeFonts = "Fonts"; public const string LinkAndroidApp = "https://build.phonegap.com/apps/639714/download/android/?qr_key=uY98ymvTr6K144RyTdhs"; public const string LinkSymbianApp = "https://build.phonegap.com/apps/639714/download/symbian/?qr_key=uY98ymvTr6K144RyTdhs"; @@ -145,6 +151,8 @@ namespace Vocaluxe.Base public const float BackgroundMusicFadeTime = 0.5f; public const float PauseResetTime = 1f; + public const float SoundPlayerFadeTime = 0.5f; + public const float SlideShowImageTime = 3500f; public const float SlideShowFadeTime = 500f; @@ -211,12 +219,12 @@ namespace Vocaluxe.Base { var folders = new List { - Path.Combine(Environment.CurrentDirectory, FolderCover), - Path.Combine(Environment.CurrentDirectory, FolderFonts), - Path.Combine(DataPath, FolderScreenshots), - Path.Combine(Environment.CurrentDirectory, FolderBackgroundMusic), - Path.Combine(Environment.CurrentDirectory, FolderSounds), - Path.Combine(DataPath, CConfig.FolderPlaylists) + Path.Combine(ProgramFolder, FolderNameCover), + Path.Combine(ProgramFolder, FolderNameFonts), + Path.Combine(DataFolder, FolderNameScreenshots), + Path.Combine(ProgramFolder, FolderNameBackgroundMusic), + Path.Combine(ProgramFolder, FolderNameSounds), + Path.Combine(DataFolder, CConfig.FolderPlaylists) }; folders.AddRange(CConfig.ProfileFolders); folders.AddRange(CConfig.SongFolders); diff --git a/Vocaluxe/Base/CSongCategorizer.cs b/Vocaluxe/Base/CSongCategorizer.cs index 282e62a7..4c16bf3a 100644 --- a/Vocaluxe/Base/CSongCategorizer.cs +++ b/Vocaluxe/Base/CSongCategorizer.cs @@ -71,7 +71,7 @@ namespace Vocaluxe.Base { if (songPointer.SortString != "") { - if (lastCategory == null || songPointer.SortString != lastCategory.Name) + if (lastCategory == null || String.Compare(songPointer.SortString, lastCategory.Name, StringComparison.CurrentCultureIgnoreCase) != 0) { lastCategory = new CCategory(songPointer.SortString); _Categories.Add(lastCategory); diff --git a/Vocaluxe/Base/CSongSorter.cs b/Vocaluxe/Base/CSongSorter.cs index f1703224..f521118f 100644 --- a/Vocaluxe/Base/CSongSorter.cs +++ b/Vocaluxe/Base/CSongSorter.cs @@ -155,7 +155,7 @@ namespace Vocaluxe.Base list.Add(new CSongPointer(song.ID, value)); else { - if (list.Count == 0) + if (values.Count == 0) list.Add(new CSongPointer(song.ID, "")); else list.AddRange(values.Select(val => new CSongPointer(song.ID, val))); diff --git a/Vocaluxe/Base/CSound.cs b/Vocaluxe/Base/CSound.cs index 9d7f65dd..d20061f2 100644 --- a/Vocaluxe/Base/CSound.cs +++ b/Vocaluxe/Base/CSound.cs @@ -85,7 +85,7 @@ namespace Vocaluxe.Base } #region Stream Handling - public static int Load(string media, bool loop=false, bool prescan=false) + public static int Load(string media, bool loop = false, bool prescan = false) { return _Playback.Load(media, loop, prescan); } @@ -176,11 +176,11 @@ namespace Vocaluxe.Base #region Sounds public static int PlaySound(ESounds sound, bool fade = true) { - string file = Path.Combine(Environment.CurrentDirectory, CSettings.FolderSounds); + string file = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameSounds); switch (sound) { case ESounds.T440: - file = Path.Combine(file, CSettings.SoundT440); + file = Path.Combine(file, CSettings.FileNameSoundT440); break; default: return -1; diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index 4f9dd431..520353a4 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -266,13 +266,13 @@ namespace Vocaluxe.Base { CFonts.LoadThemeFonts( _Themes[themeIndex].Name, - Path.Combine(Path.Combine(_Themes[themeIndex].Path, _Themes[themeIndex].SkinFolder), CSettings.FolderThemeFonts), + Path.Combine(Path.Combine(_Themes[themeIndex].Path, _Themes[themeIndex].SkinFolder), CSettings.FolderNameThemeFonts), xmlReader); } else { CFonts.LoadPartyModeFonts(_Themes[themeIndex].PartyModeID, - Path.Combine(_Themes[themeIndex].Path, CSettings.FolderPartyModeFonts), + Path.Combine(_Themes[themeIndex].Path, CSettings.FolderNamePartyModeFonts), xmlReader); } return true; @@ -385,11 +385,11 @@ namespace Vocaluxe.Base { _Themes.Clear(); - string path = Path.Combine(Directory.GetCurrentDirectory(), CSettings.FolderThemes); - List files = CHelper.ListFiles(path, "*.xml"); + string path = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameThemes); + List files = CHelper.ListFiles(path, "*.xml", false, true); foreach (string file in files) - AddTheme(Path.Combine(path, file), -1); + AddTheme(file, -1); } public static bool AddTheme(string filePath, int partyModeID) @@ -485,12 +485,12 @@ namespace Vocaluxe.Base skin.PartyModeID = theme.PartyModeID; skin.SkinList = new Dictionary(); - List names = xmlReader.GetValues("Skins"); + List names = xmlReader.GetNames("//root/Skins/*"); foreach (string str in names) skin.SkinList[str] = new CSkinElement(); skin.VideoList = new Dictionary(); - names = xmlReader.GetValues("Videos"); + names = xmlReader.GetNames("//root/Videos/*"); foreach (string str in names) skin.VideoList[str] = new CVideoSkinElement(); _Skins.Add(skin); @@ -546,7 +546,7 @@ namespace Vocaluxe.Base if (themeIndex != -1) { path = Path.Combine(_Themes[themeIndex].Path, _Themes[themeIndex].SkinFolder); - path = Path.Combine(path, CSettings.FolderScreens); + path = Path.Combine(path, CSettings.FolderNameScreens); } else CLog.LogError("Can't find current Theme"); @@ -665,7 +665,7 @@ namespace Vocaluxe.Base } var colorScheme = new List(); - List names = xmlReader.GetValues("ColorSchemes"); + List names = xmlReader.GetNames("//root/ColorSchemes/*"); foreach (string str in names) { var scheme = new SColorScheme {Name = str}; diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index 5bb596e9..3d57cbd3 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -15,8 +15,6 @@ // along with Vocaluxe. If not, see . #endregion -using System.Diagnostics; -using System.Drawing; using Vocaluxe.Lib.Video; using VocaluxeLib; using VocaluxeLib.Draw; @@ -115,94 +113,4 @@ namespace Vocaluxe.Base #endregion VideoDecoder } - - class CVideoPlayer - { - private CTexture _VideoTexture; - private int _VideoStream; - private readonly Stopwatch _VideoTimer = new Stopwatch(); - private bool _Finished; - private bool _Loaded; - - public bool IsFinished - { - get { return _Finished || !_Loaded; } - } - - public bool Loop - { - set { CVideo.SetLoop(_VideoStream, value); } - } - - public void Load(string videoName) - { - _VideoStream = CVideo.Load(CTheme.GetVideoFilePath(videoName, -1)); - _Loaded = true; - CVideo.Pause(_VideoStream); - } - - public void Start() - { - _VideoTimer.Reset(); - _Finished = false; - //CVideo.VdSkip(_VideoStream, 0f, 0f); - _VideoTimer.Start(); - CVideo.Resume(_VideoStream); - } - - public void Pause() - { - CVideo.Pause(_VideoStream); - _VideoTimer.Stop(); - } - - public void Resume() - { - CVideo.Resume(_VideoStream); - _VideoTimer.Start(); - } - - public void Draw() - { - if (!_Finished) - { - float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f; - _Finished = CVideo.Finished(_VideoStream); - - CVideo.GetFrame(_VideoStream, ref _VideoTexture, videoTime, out videoTime); - } - if (_VideoTexture == null) - return; - var bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH); - RectangleF rect; - CHelper.SetRect(bounds, out rect, _VideoTexture.OrigAspect, EAspect.Crop); - - CDraw.DrawTexture(_VideoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CSettings.ZFar / 4)); - } - - public void PreLoad() - { - bool paused = _VideoTimer.IsRunning; - if (paused) - CVideo.Resume(_VideoStream); - float videoTime = 0f; - while (_VideoTexture == null && videoTime < 1f) - { - float dummy; - CVideo.GetFrame(_VideoStream, ref _VideoTexture, 0, out dummy); - videoTime += 0.05f; - } - if (paused) - CVideo.Pause(_VideoStream); - } - - public void Close() - { - CVideo.Close(_VideoStream); - CDraw.RemoveTexture(ref _VideoTexture); - _Loaded = false; - _Finished = false; - _VideoTimer.Reset(); - } - } } \ No newline at end of file diff --git a/Vocaluxe/Base/CVideoPlayer.cs b/Vocaluxe/Base/CVideoPlayer.cs new file mode 100644 index 00000000..8dd47d4b --- /dev/null +++ b/Vocaluxe/Base/CVideoPlayer.cs @@ -0,0 +1,97 @@ +using System.Diagnostics; +using System.Drawing; +using VocaluxeLib; +using VocaluxeLib.Draw; + +namespace Vocaluxe.Base +{ + class CVideoPlayer + { + private CTexture _VideoTexture; + private int _VideoStream; + private readonly Stopwatch _VideoTimer = new Stopwatch(); + private bool _Finished; + private bool _Loaded; + + public bool IsFinished + { + get { return _Finished || !_Loaded; } + } + + public bool Loop + { + set { CVideo.SetLoop(_VideoStream, value); } + } + + public void Load(string videoName) + { + _VideoStream = CVideo.Load(CTheme.GetVideoFilePath(videoName, -1)); + _Loaded = true; + CVideo.Pause(_VideoStream); + } + + public void Start() + { + _VideoTimer.Reset(); + _Finished = false; + //CVideo.VdSkip(_VideoStream, 0f, 0f); + _VideoTimer.Start(); + CVideo.Resume(_VideoStream); + } + + public void Pause() + { + CVideo.Pause(_VideoStream); + _VideoTimer.Stop(); + } + + public void Resume() + { + CVideo.Resume(_VideoStream); + _VideoTimer.Start(); + } + + public void Draw() + { + if (!_Finished) + { + float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f; + _Finished = CVideo.Finished(_VideoStream); + + CVideo.GetFrame(_VideoStream, ref _VideoTexture, videoTime, out videoTime); + } + if (_VideoTexture == null) + return; + var bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH); + RectangleF rect; + CHelper.SetRect(bounds, out rect, _VideoTexture.OrigAspect, EAspect.Crop); + + CDraw.DrawTexture(_VideoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CSettings.ZFar / 4)); + } + + public void PreLoad() + { + bool paused = _VideoTimer.IsRunning; + if (paused) + CVideo.Resume(_VideoStream); + float videoTime = 0f; + while (_VideoTexture == null && videoTime < 1f) + { + float dummy; + CVideo.GetFrame(_VideoStream, ref _VideoTexture, 0, out dummy); + videoTime += 0.05f; + } + if (paused) + CVideo.Pause(_VideoStream); + } + + public void Close() + { + CVideo.Close(_VideoStream); + CDraw.RemoveTexture(ref _VideoTexture); + _Loaded = false; + _Finished = false; + _VideoTimer.Reset(); + } + } +} \ No newline at end of file diff --git a/Vocaluxe/Base/Fonts/CFonts.cs b/Vocaluxe/Base/Fonts/CFonts.cs index 2c838aac..1fa9ee31 100644 --- a/Vocaluxe/Base/Fonts/CFonts.cs +++ b/Vocaluxe/Base/Fonts/CFonts.cs @@ -341,11 +341,11 @@ namespace Vocaluxe.Base.Fonts /// private static void _LoadFontList() { - CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.FolderFonts, CSettings.FileFonts)); + CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts, CSettings.FileNameFonts)); if (xmlReader == null) return; - _LoadFontFiles(xmlReader, Path.Combine(Directory.GetCurrentDirectory(), CSettings.FolderFonts)); + _LoadFontFiles(xmlReader, Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts)); } /// diff --git a/Vocaluxe/Base/Server/CVocaluxeServer.cs b/Vocaluxe/Base/Server/CVocaluxeServer.cs index c25462d0..e0afa162 100644 --- a/Vocaluxe/Base/Server/CVocaluxeServer.cs +++ b/Vocaluxe/Base/Server/CVocaluxeServer.cs @@ -342,7 +342,7 @@ namespace Vocaluxe.Base.Server return false; string name = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); - string filePath = _SaveImage(photoData.Photo, name, CSettings.FolderPhotos); + string filePath = _SaveImage(photoData.Photo, name, CSettings.FolderNamePhotos); if (!string.IsNullOrEmpty(filePath)) { _PhotosOfThisRound.Add(filePath); @@ -461,20 +461,20 @@ namespace Vocaluxe.Base.Server private static SPlaylistInfo _GetPlaylist(int playlistId) { - if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0) + if (CPlaylists.Get(playlistId) == null) throw new ArgumentException("invalid playlistId"); - return _GetPlaylistInfo(CPlaylists.Playlists[playlistId]); + return _GetPlaylistInfo(CPlaylists.Get(playlistId)); } private static void _AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates) { - if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0) + if (CPlaylists.Get(playlistId) == null) throw new ArgumentException("invalid playlistId"); if (allowDuplicates || !_PlaylistContainsSong(songId, playlistId)) { - CPlaylists.AddPlaylistSong(playlistId, songId); - CPlaylists.SavePlaylist(playlistId); + CPlaylists.AddSong(playlistId, songId); + CPlaylists.Save(playlistId); } else throw new ArgumentException("song exists in this playlist"); @@ -482,45 +482,49 @@ namespace Vocaluxe.Base.Server private static void _RemoveSongFromPlaylist(int position, int playlistId, int songId) { - if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0) + CPlaylistFile pl = CPlaylists.Get(playlistId); + if (pl == null) throw new ArgumentException("invalid playlistId"); if (!_PlaylistContainsSong(songId, playlistId)) throw new ArgumentException("invalid songId"); - if (position < 0 || CPlaylists.Playlists[playlistId].Songs.Count <= position - || CPlaylists.Playlists[playlistId].Songs[position].SongID != songId) + if (position < 0 || pl.Songs.Count <= position + || pl.Songs[position].SongID != songId) throw new ArgumentException("invalid position"); - CPlaylists.Playlists[playlistId].DeleteSong(position); - CPlaylists.SavePlaylist(playlistId); + pl.DeleteSong(position); + pl.Save(); } private static void _MoveSongInPlaylist(int newPosition, int playlistId, int songId) { - if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0) + CPlaylistFile pl = CPlaylists.Get(playlistId); + if (pl == null) throw new ArgumentException("invalid playlistId"); if (!_PlaylistContainsSong(songId, playlistId)) throw new ArgumentException("invalid songId"); - if (CPlaylists.Playlists[playlistId].Songs.Count < newPosition) + if (pl.Songs.Count < newPosition) throw new ArgumentException("invalid newPosition"); - int oldPosition = CPlaylists.Playlists[playlistId].Songs.FindIndex(s => s.SongID == songId); - CPlaylists.MovePlaylistSong(playlistId, oldPosition, newPosition); - CPlaylists.SavePlaylist(playlistId); + int oldPosition = pl.Songs.FindIndex(s => s.SongID == songId); + pl.MoveSong(oldPosition, newPosition); + pl.Save(); } private static bool _PlaylistContainsSong(int songId, int playlistId) { - if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0) + CPlaylistFile pl = CPlaylists.Get(playlistId); + if (pl == null) throw new ArgumentException("invalid playlistId"); - return CPlaylists.Playlists[playlistId].Songs.Any(s => s.SongID == songId); + return pl.Songs.Any(s => s.SongID == songId); } private static SPlaylistSongInfo[] _GetPlaylistSongs(int playlistId) { - if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0) + CPlaylistFile pl = CPlaylists.Get(playlistId); + if (pl == null) throw new ArgumentException("invalid playlistId"); - return _GetPlaylistSongInfos(CPlaylists.Playlists[playlistId]); + return _GetPlaylistSongInfos(pl); } private static SPlaylistSongInfo _GetPlaylistSongInfo(CPlaylistSong playlistSong, int playlistId, int playlistPos) @@ -549,7 +553,7 @@ namespace Vocaluxe.Base.Server return new SPlaylistInfo { PlaylistId = playlist.Id, - PlaylistName = playlist.PlaylistName, + PlaylistName = playlist.Name, SongCount = playlist.Songs.Count, LastChanged = DateTime.Now.ToLongDateString() }; @@ -557,16 +561,15 @@ namespace Vocaluxe.Base.Server private static void _RemovePlaylist(int playlistId) { - if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0) + if (CPlaylists.Get(playlistId) == null) throw new ArgumentException("invalid playlistId"); - CPlaylists.DeletePlaylist(playlistId); + CPlaylists.Delete(playlistId); } private static int _AddPlaylist(string playlistName) { - int newPlaylistId = CPlaylists.NewPlaylist(); - CPlaylists.Playlists[newPlaylistId].PlaylistName = playlistName; - CPlaylists.SavePlaylist(newPlaylistId); + int newPlaylistId = CPlaylists.NewPlaylist(playlistName); + CPlaylists.Save(newPlaylistId); return newPlaylistId; } @@ -682,19 +685,10 @@ namespace Vocaluxe.Base.Server if (!Directory.Exists(folder)) Directory.CreateDirectory(folder); - string filename = Path.Combine(folder, name); - if (File.Exists(filename + "." + extension)) - { - int i = 0; - while (File.Exists(filename + "_" + i + "." + extension)) - i++; - filename = filename + "_" + i + "." + extension; - } - else - filename = filename + "." + extension; + string file = CHelper.GetUniqueFileName(folder, name + "." + extension); - avatarImage.Save(filename); - return filename; + avatarImage.Save(file); + return file; } } } \ No newline at end of file diff --git a/Vocaluxe/CSplashScreen.cs b/Vocaluxe/CSplashScreen.cs index cf31ae7b..bba2749c 100644 --- a/Vocaluxe/CSplashScreen.cs +++ b/Vocaluxe/CSplashScreen.cs @@ -29,7 +29,7 @@ namespace Vocaluxe public CSplashScreen() { - string path = Path.Combine(Environment.CurrentDirectory, Path.Combine(CSettings.FolderGraphics, CSettings.Logo)); + string path = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameGraphics, CSettings.FileNameLogo); if (File.Exists(path)) { try @@ -45,7 +45,7 @@ namespace Vocaluxe else CLog.LogError("Can't find " + path); - path = Path.Combine(Environment.CurrentDirectory, CSettings.Icon); + path = Path.Combine(CSettings.ProgramFolder, CSettings.FileNameIcon); if (File.Exists(path)) { try diff --git a/Vocaluxe/Lib/Database/CHighscoreDB.cs b/Vocaluxe/Lib/Database/CHighscoreDB.cs index 43d25424..5e9b20ce 100644 --- a/Vocaluxe/Lib/Database/CHighscoreDB.cs +++ b/Vocaluxe/Lib/Database/CHighscoreDB.cs @@ -47,7 +47,7 @@ namespace Vocaluxe.Lib.Database public override bool Init() { - string oldDBFilePath = Path.Combine(Environment.CurrentDirectory, CSettings.FileOldHighscoreDB); + string oldDBFilePath = Path.Combine(CSettings.DataFolder, CSettings.FileNameOldHighscoreDB); if (File.Exists(oldDBFilePath)) { if (File.Exists(_FilePath)) diff --git a/Vocaluxe/Lib/Database/CResourceDB.cs b/Vocaluxe/Lib/Database/CResourceDB.cs index 51e07bf5..4891a19e 100644 --- a/Vocaluxe/Lib/Database/CResourceDB.cs +++ b/Vocaluxe/Lib/Database/CResourceDB.cs @@ -119,7 +119,7 @@ namespace Vocaluxe.Lib.Database { foreach (string file in _FilesV1) { - string filePath = Path.Combine(Environment.CurrentDirectory, file); + string filePath = Path.Combine(CSettings.ProgramFolder, file); if (!_AddImageToCreditsDB(filePath, transaction)) { transaction.Rollback(); diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 032d952b..1c04f6fd 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -84,7 +84,7 @@ namespace Vocaluxe.Lib.Draw /// public CDirect3D() { - Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon)); + Icon = new Icon(Path.Combine(CSettings.ProgramFolder, CSettings.FileNameIcon)); //Fill Queue with 100000 IDs for (int i = 0; i < _MaxID; i++) @@ -320,7 +320,6 @@ namespace Vocaluxe.Lib.Draw } else _DoResize(); - ; } /// @@ -731,18 +730,13 @@ namespace Vocaluxe.Lib.Draw /// public void MakeScreenShot() { - const string file = "Screenshot_"; - string path = Path.Combine(CSettings.DataPath, CSettings.FolderScreenshots); - - int i = 0; - while (File.Exists(Path.Combine(path, file + i.ToString("00000") + ".bmp"))) - i++; + string file = CHelper.GetUniqueFileName(Path.Combine(CSettings.DataFolder, CSettings.FolderNameScreenshots), "Screenshot.bmp"); //create a surface of the frame using (Surface surface = _Device.GetBackBuffer(0, 0)) { var screen = new Bitmap(Surface.ToStream(surface, ImageFileFormat.Bmp)); - screen.Save(Path.Combine(path, file + i.ToString("00000") + ".bmp"), ImageFormat.Bmp); + screen.Save(file, ImageFormat.Bmp); screen.Dispose(); } } diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index c1fd96b9..08720117 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -51,7 +51,7 @@ namespace Vocaluxe.Lib.Draw public CDrawWinForm() { - Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon)); + Icon = new Icon(Path.Combine(CSettings.ProgramFolder, CSettings.FileNameIcon)); _Keys = new CKeys(); _Mouse = new CMouse(); @@ -304,14 +304,9 @@ namespace Vocaluxe.Lib.Draw public void MakeScreenShot() { - const string file = "Screenshot_"; - string path = Path.Combine(CSettings.DataPath, CSettings.FolderScreenshots); + string file = CHelper.GetUniqueFileName(Path.Combine(CSettings.DataFolder, CSettings.FolderNameScreenshots), "Screenshot.bmp"); - int i = 0; - while (File.Exists(Path.Combine(path, file + i.ToString("00000") + ".png"))) - i++; - - _Backbuffer.Save(Path.Combine(path, file + i.ToString("00000") + ".png"), ImageFormat.Png); + _Backbuffer.Save(file, ImageFormat.Png); } public void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 5b7e19ae..43ba70c2 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -111,7 +111,7 @@ namespace Vocaluxe.Lib.Draw public COpenGL() { - Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon)); + Icon = new Icon(Path.Combine(CSettings.ProgramFolder, CSettings.FileNameIcon)); for (int i = 1; i < _MaxID; i++) _IDs.Enqueue(i); @@ -534,12 +534,7 @@ namespace Vocaluxe.Lib.Draw public void MakeScreenShot() { - const string file = "Screenshot_"; - string path = Path.Combine(CSettings.DataPath, CSettings.FolderScreenshots); - - int i = 0; - while (File.Exists(Path.Combine(path, file + i.ToString("00000") + ".bmp"))) - i++; + string file = CHelper.GetUniqueFileName(Path.Combine(CSettings.DataFolder, CSettings.FolderNameScreenshots), "Screenshot.bmp"); int width = GetScreenWidth(); int height = GetScreenHeight(); @@ -552,7 +547,7 @@ namespace Vocaluxe.Lib.Draw screen.UnlockBits(bmpData); screen.RotateFlip(RotateFlipType.RotateNoneFlipY); - screen.Save(Path.Combine(path, file + i.ToString("00000") + ".bmp"), ImageFormat.Bmp); + screen.Save(file, ImageFormat.Bmp); } } diff --git a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs index ef439692..ff86215f 100644 --- a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs +++ b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Xml; using Vocaluxe.Base; using VocaluxeLib; @@ -28,31 +29,26 @@ namespace Vocaluxe.Lib.Playlist { public class CPlaylistFile { - public string PlaylistName; - public string PlaylistFile; - public int Id = -1; + public string Name = ""; + public string File; + public readonly int Id = -1; public List Songs = new List(); - public CPlaylistFile() - { - PlaylistName = string.Empty; - PlaylistFile = string.Empty; - } - - public CPlaylistFile(string file, int id) + public CPlaylistFile(int id, string file = "") { Id = id; - PlaylistFile = file; - _LoadPlaylist(); + File = file; + if (File != "") + _Load(); } - public void SavePlaylist() + public void Save() { - if (PlaylistFile == "") + if (File == "") { string filename = string.Empty; // ReSharper disable LoopCanBeConvertedToQuery - foreach (char chr in PlaylistName) + foreach (char chr in Name) // ReSharper restore LoopCanBeConvertedToQuery { if (char.IsLetter(chr)) @@ -62,25 +58,17 @@ namespace Vocaluxe.Lib.Playlist if (filename == "") filename = "1"; - int i = 0; - while (File.Exists(Path.Combine(CSettings.DataPath, CConfig.FolderPlaylists, filename + ".xml"))) - { - i++; - if (!File.Exists(Path.Combine(CSettings.DataPath, CConfig.FolderPlaylists, filename + i + ".xml"))) - filename += i; - } - - PlaylistFile = Path.Combine(CSettings.DataPath, CConfig.FolderPlaylists, filename + ".xml"); + File = CHelper.GetUniqueFileName(Path.Combine(CSettings.DataFolder, CConfig.FolderPlaylists), filename + ".xml"); } XmlWriter writer; try { - writer = XmlWriter.Create(PlaylistFile, CConfig.XMLSettings); + writer = XmlWriter.Create(File, CConfig.XMLSettings); } catch (Exception e) { - CLog.LogError("Error creating/opening Playlist File " + PlaylistFile + ": " + e.Message); + CLog.LogError("Error creating/opening Playlist File " + File + ": " + e.Message); return; } @@ -90,7 +78,7 @@ namespace Vocaluxe.Lib.Playlist writer.WriteStartElement("root"); writer.WriteStartElement("Info"); - writer.WriteElementString("PlaylistName", PlaylistName); + writer.WriteElementString("PlaylistName", Name); writer.WriteEndElement(); writer.WriteStartElement("Songs"); @@ -121,51 +109,42 @@ namespace Vocaluxe.Lib.Playlist } } - private void _LoadPlaylist() + private void _Load() { - CXMLReader xmlReader = CXMLReader.OpenFile(PlaylistFile); + CXMLReader xmlReader = CXMLReader.OpenFile(File); if (xmlReader == null) return; - string value = String.Empty; - if (xmlReader.GetValue("//root/Info/PlaylistName", out value, value)) + string value; + if (xmlReader.GetValue("//root/Info/PlaylistName", out value, "")) { - PlaylistName = value; + Name = value; Songs = new List(); - List songs = xmlReader.GetValues("Songs"); - var gm = EGameMode.TR_GAMEMODE_NORMAL; + List songs = xmlReader.GetNames("//root/Songs/*"); - foreach (string song in songs) + foreach (string songEntry in songs) { string artist; string title; - xmlReader.GetValue("//root/Songs/" + song + "/Artist", out artist, String.Empty); - xmlReader.GetValue("//root/Songs/" + song + "/Title", out title, String.Empty); - xmlReader.TryGetEnumValue("//root/Songs/" + song + "/GameMode", ref gm); + xmlReader.GetValue("//root/Songs/" + songEntry + "/Artist", out artist, String.Empty); + xmlReader.GetValue("//root/Songs/" + songEntry + "/Title", out title, String.Empty); + EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; + xmlReader.TryGetEnumValue("//root/Songs/" + songEntry + "/GameMode", ref gm); - var playlistSong = new CPlaylistSong {SongID = -1}; - - foreach (CSong curSong in CSongs.AllSongs) + CSong plSong = CSongs.AllSongs.FirstOrDefault(song => song.Artist == artist && song.Title == title); + if (plSong != null) { - if (curSong.Artist != artist || curSong.Title != title) - continue; - playlistSong.SongID = curSong.ID; - break; - } - - if (playlistSong.SongID != -1) - { - playlistSong.GameMode = gm; + var playlistSong = new CPlaylistSong(plSong.ID, gm); Songs.Add(playlistSong); } else - CLog.LogError("Can't find song '" + title + "' from '" + artist + "' in playlist file: " + PlaylistFile); + CLog.LogError("Can't find song '" + title + "' from '" + artist + "' in playlist file: " + File); } } else - CLog.LogError("Can't find PlaylistName in Playlist File: " + PlaylistFile); + CLog.LogError("Can't find PlaylistName in Playlist File: " + File); } public void AddSong(int songID) @@ -181,7 +160,7 @@ namespace Vocaluxe.Lib.Playlist public void AddSong(int songID, EGameMode gm) { - var song = new CPlaylistSong {SongID = songID, GameMode = gm}; + var song = new CPlaylistSong(songID, gm); Songs.Add(song); } @@ -191,31 +170,31 @@ namespace Vocaluxe.Lib.Playlist Songs.RemoveAt(songNr); } - public void SongUp(int songNr) + public void MoveSongUp(int songNr) { - if (songNr < Songs.Count - 1 && songNr > 0) + if (songNr < Songs.Count && songNr > 0) Songs.Reverse(songNr - 1, 2); } - public void SongDown(int songNr) + public void MoveSongDown(int songNr) { if (songNr < Songs.Count - 1 && songNr >= 0) Songs.Reverse(songNr, 2); } - public void SongMove(int sourceNr, int destNr) + public void MoveSong(int sourceNr, int destNr) { - if (sourceNr < 0 || destNr < 0 || sourceNr == destNr || sourceNr > Songs.Count - 1 || destNr > Songs.Count - 1) + if (sourceNr < 0 || destNr < 0 || sourceNr == destNr || sourceNr >= Songs.Count || destNr >= Songs.Count) return; - var ps = new CPlaylistSong(Songs[sourceNr]); + CPlaylistSong song = Songs[sourceNr]; Songs.RemoveAt(sourceNr); - Songs.Insert(destNr, ps); + Songs.Insert(destNr, song); } - public void SongInsert(int destNr, int songID, EGameMode gm) + public void InsertSong(int destNr, int songID, EGameMode gm) { - if (destNr < 0 || destNr > Songs.Count - 1) + if (destNr < 0 || destNr >= Songs.Count) return; CPlaylistSong ps = new CPlaylistSong(songID, gm); diff --git a/Vocaluxe/Lib/Sound/Playback/CPlaybackBase.cs b/Vocaluxe/Lib/Sound/Playback/CPlaybackBase.cs index 05f5a35f..a9ce5959 100644 --- a/Vocaluxe/Lib/Sound/Playback/CPlaybackBase.cs +++ b/Vocaluxe/Lib/Sound/Playback/CPlaybackBase.cs @@ -142,10 +142,7 @@ namespace Vocaluxe.Lib.Sound.Playback { int index = _GetStreamIndex(streamID); if (index >= 0) - { _Streams[index].Close(); - _Streams.RemoveAt(index); - } } } diff --git a/Vocaluxe/Lib/Sound/Playback/IAudioStream.cs b/Vocaluxe/Lib/Sound/Playback/IAudioStream.cs index 8ec763fe..15d88270 100644 --- a/Vocaluxe/Lib/Sound/Playback/IAudioStream.cs +++ b/Vocaluxe/Lib/Sound/Playback/IAudioStream.cs @@ -16,6 +16,7 @@ #endregion using System; +using VocaluxeLib; namespace Vocaluxe.Lib.Sound.Playback { diff --git a/Vocaluxe/Lib/Sound/Playback/IPlayback.cs b/Vocaluxe/Lib/Sound/Playback/IPlayback.cs index 04d9be75..a022d455 100644 --- a/Vocaluxe/Lib/Sound/Playback/IPlayback.cs +++ b/Vocaluxe/Lib/Sound/Playback/IPlayback.cs @@ -15,15 +15,10 @@ // along with Vocaluxe. If not, see . #endregion +using VocaluxeLib; + namespace Vocaluxe.Lib.Sound.Playback { - public enum EStreamAction - { - Nothing, - Pause, - Stop, - Close - } interface IPlayback { diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index de49bff9..b4720e87 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -301,6 +301,7 @@ namespace Vocaluxe if (args.Name.IndexOf(".resources", StringComparison.Ordinal) >= 0) return null; + Assembly assembly = null; string[] arr = args.Name.Split(new char[] {','}); if (arr.Length > 0) { @@ -311,27 +312,25 @@ namespace Vocaluxe #if ARCH_X64 string path = "x64"; #endif - path = Path.Combine(path, arr[0] + ".dll"); + path = Path.Combine(CSettings.ProgramFolder, path, arr[0] + ".dll"); try { - Assembly assembly; + assembly = Assembly.LoadFrom(path); + } + catch (FileLoadException e1) + { + //possibly loading from network, this would work always but better use the normal LoadFrom for more specific errors try { - assembly = Assembly.LoadFrom(path); - } - catch (FileLoadException) - { - //possibly loading from network, this would work always but better use the normal LoadFrom for more specific errors assembly = Assembly.Load(File.ReadAllBytes(path)); } - return assembly; - } - catch (Exception e) - { - CLog.LogError("Cannot load assembly " + args.Name + " from " + path + ": " + e); + catch (Exception e) + { + CLog.LogError("Cannot load assembly " + args.Name + " from " + path + ": " + e + "\r\nOuter Error: " + e1); + } } } - return null; + return assembly; } private static readonly Mutex _Mutex = new Mutex(false, Application.ProductName + "-SingleInstanceMutex"); diff --git a/Vocaluxe/Screens/CPopupScreenPlayerControl.cs b/Vocaluxe/Screens/CPopupScreenPlayerControl.cs index 9ffe1779..e0c1cdf2 100644 --- a/Vocaluxe/Screens/CPopupScreenPlayerControl.cs +++ b/Vocaluxe/Screens/CPopupScreenPlayerControl.cs @@ -115,7 +115,7 @@ namespace Vocaluxe.Screens if (_Buttons[_ButtonPrevious].Selected) CBackgroundMusic.Previous(); if (_Buttons[_ButtonPlay].Selected) - CBackgroundMusic.Play(); + CBackgroundMusic.Pause(); if (_Buttons[_ButtonPause].Selected) CBackgroundMusic.Pause(); if (_Buttons[_ButtonRepeat].Selected) @@ -143,7 +143,7 @@ namespace Vocaluxe.Screens if (_Buttons[_ButtonPrevious].Selected) CBackgroundMusic.Previous(); if (_Buttons[_ButtonPlay].Selected) - CBackgroundMusic.Play(); + CBackgroundMusic.Pause(); if (_Buttons[_ButtonPause].Selected) CBackgroundMusic.Pause(); if (_Buttons[_ButtonRepeat].Selected) @@ -168,6 +168,17 @@ namespace Vocaluxe.Screens return true; } + public override void OnShow() + { + base.OnShow(); + _Buttons[_ButtonNext].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonPause].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonPlay].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonPrevious].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonRepeat].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonSing].Visible = !CBackgroundMusic.IsPlayingPreview; + } + public override bool UpdateGame() { _Statics[_StaticCover].Visible = !_VideoPreviewInt || !CBackgroundMusic.SongHasVideo; diff --git a/Vocaluxe/Screens/CPopupScreenServerQR.cs b/Vocaluxe/Screens/CPopupScreenServerQR.cs index a961edd9..febb08a2 100644 --- a/Vocaluxe/Screens/CPopupScreenServerQR.cs +++ b/Vocaluxe/Screens/CPopupScreenServerQR.cs @@ -15,6 +15,7 @@ // along with Vocaluxe. If not, see . #endregion +using System.Windows.Forms; using Vocaluxe.Base; using Vocaluxe.Base.Server; using VocaluxeLib; @@ -75,7 +76,7 @@ namespace Vocaluxe.Screens public override bool HandleMouse(SMouseEvent mouseEvent) { - if (mouseEvent.LB) + if (mouseEvent.LB || mouseEvent.RB) { CGraphics.HidePopup(EPopupScreens.PopupServerQR); return true; @@ -83,6 +84,18 @@ namespace Vocaluxe.Screens return false; } + public override bool HandleInput(SKeyEvent keyEvent) + { + switch (keyEvent.Key) + { + case Keys.Escape: + case Keys.Back: + CGraphics.HidePopup(EPopupScreens.PopupServerQR); + return true; + } + return base.HandleInput(keyEvent); + } + public override bool UpdateGame() { return true; diff --git a/Vocaluxe/Screens/CScreenHighscore.cs b/Vocaluxe/Screens/CScreenHighscore.cs index 01848911..010a3cce 100644 --- a/Vocaluxe/Screens/CScreenHighscore.cs +++ b/Vocaluxe/Screens/CScreenHighscore.cs @@ -284,7 +284,7 @@ namespace Vocaluxe.Screens else { _Pos += num; - _Pos = _Pos.Clamp(0, _Scores[_Round].Count - 1); + _Pos = _Pos.Clamp(0, _Scores[_Round].Count - 1, true); } } diff --git a/Vocaluxe/Screens/CScreenLoad.cs b/Vocaluxe/Screens/CScreenLoad.cs index 5bcc054d..50c57008 100644 --- a/Vocaluxe/Screens/CScreenLoad.cs +++ b/Vocaluxe/Screens/CScreenLoad.cs @@ -152,6 +152,9 @@ namespace Vocaluxe.Screens { CBackgroundMusic.OwnSongsAvailable = true; + if (CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON || CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON) + CBackgroundMusic.VideoEnabled = true; + CBackgroundMusic.Play(); } diff --git a/Vocaluxe/Screens/CScreenOptionsSound.cs b/Vocaluxe/Screens/CScreenOptionsSound.cs index 502f4c28..0d711fd0 100644 --- a/Vocaluxe/Screens/CScreenOptionsSound.cs +++ b/Vocaluxe/Screens/CScreenOptionsSound.cs @@ -52,7 +52,7 @@ namespace Vocaluxe.Screens public override void LoadTheme(string xmlPath) { base.LoadTheme(xmlPath); - _SelectSlides[_SelectSlideBackgroundMusic].SetValues((int)CConfig.BackgroundMusic); + _SelectSlides[_SelectSlideBackgroundMusic].SetValues((int)CConfig.BackgroundMusic); _SelectSlides[_SelectSlideBackgroundMusicVolume].AddValues(new string[] {"0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "100"}); _SelectSlides[_SelectSlideBackgroundMusicVolume].Selection = CConfig.BackgroundMusicVolume / 5; @@ -150,14 +150,14 @@ namespace Vocaluxe.Screens { CConfig.GameMusicVolume = _SelectSlides[_SelectSlideGameMusicVolume].Selection * 5; CConfig.PreviewMusicVolume = _SelectSlides[_SelectSlidePreviewMusicVolume].Selection * 5; - CConfig.BackgroundMusic = (EOffOn)_SelectSlides[_SelectSlideBackgroundMusic].Selection; + CConfig.BackgroundMusic = (EBackgroundMusicOffOn)_SelectSlides[_SelectSlideBackgroundMusic].Selection; CConfig.BackgroundMusicSource = (EBackgroundMusicSource)_SelectSlides[_SelectSlideBackgroundMusicSource].Selection; CConfig.BackgroundMusicVolume = _SelectSlides[_SelectSlideBackgroundMusicVolume].Selection * 5; CConfig.SaveConfig(); CBackgroundMusic.SetMusicSource(CConfig.BackgroundMusicSource); CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume); - if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) + if (CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON) CBackgroundMusic.Play(); else CBackgroundMusic.Pause(); diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index 2c29383d..c8fdacfb 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -345,13 +345,8 @@ namespace Vocaluxe.Screens private void _OnSaveSnapshot() { - string filename = Path.Combine(CSettings.DataPath, CConfig.ProfileFolders[0], "snapshot"); - int i = 0; - while (File.Exists(filename + i + ".png")) - i++; - - filename = filename + i + ".png"; - _Snapshot.Save(filename, ImageFormat.Png); + string file = CHelper.GetUniqueFileName(Path.Combine(CSettings.DataFolder, CConfig.ProfileFolders[0]), "snapshot.png"); + _Snapshot.Save(file, ImageFormat.Png); _Snapshot = null; CDraw.RemoveTexture(ref _WebcamTexture); @@ -361,7 +356,7 @@ namespace Vocaluxe.Screens _Buttons[_ButtonTakeSnapshot].Visible = false; _Buttons[_ButtonWebcam].Visible = CWebcam.IsDeviceAvailable(); - int id = CProfiles.NewAvatar(filename); + int id = CProfiles.NewAvatar(file); CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, id); _LoadAvatars(false); } diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index db70f56e..bbf4aaf4 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -123,6 +123,8 @@ namespace Vocaluxe.Screens public override void OnShow() { + CBackgroundMusic.Disabled = false; + base.OnShow(); //-1 --> Show average _Round = CGame.NumRounds > 1 ? -1 : 0; @@ -396,12 +398,8 @@ namespace Vocaluxe.Screens private void _ChangeRound(int num) { - if (_Points.NumRounds < 1) - return; _Round += num; _Round = _Round.Clamp(-1, _Points.NumRounds - 1); - if (_Round >= _Points.NumRounds) - _Round = _Points.NumRounds - 1; _UpdateRatings(); } diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index d39a6202..ff4416f8 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -433,7 +433,6 @@ namespace Vocaluxe.Screens _UpdateAvatars(); _UpdateNames(); - CBackgroundMusic.Disabled = true; _CloseSong(); CSound.SetGlobalVolume(CConfig.GameMusicVolume); } @@ -441,6 +440,7 @@ namespace Vocaluxe.Screens public override void OnShowFinish() { base.OnShowFinish(); + CBackgroundMusic.Disabled = true; CGame.Start(); _LoadNextSong(); @@ -537,8 +537,6 @@ namespace Vocaluxe.Screens _CloseSong(); if (_Webcam) CWebcam.Stop(); - CBackgroundMusic.Disabled = false; - CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume); } private void _CloseSong() @@ -569,6 +567,8 @@ namespace Vocaluxe.Screens _Texts[_TextSongName].Text = String.Empty; _Texts[_TextDuetName1].Text = String.Empty; _Texts[_TextDuetName2].Text = String.Empty; + _Texts[_TextMedleyCountdown].Visible = false; + _Texts[_TextMedleyCountdown].Text = String.Empty; } private void _LoadNextSong() diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 996f427c..ace7503d 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -23,6 +23,7 @@ using System.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib; using VocaluxeLib.Menu; +using VocaluxeLib.Menu.SongMenu; using VocaluxeLib.PartyModes; using VocaluxeLib.Songs; @@ -70,15 +71,15 @@ namespace Vocaluxe.Screens private const string _StaticSearchBar = "StaticSearchBar"; private const string _StaticOptionsBG = "StaticOptionsBG"; - private const string _SongMenu = "SongMenu"; - private const string _Playlist = "Playlist"; + private const string _SongMenuName = "SongMenu"; + private const string _PlaylistName = "Playlist"; private string _SearchText = String.Empty; private bool _SearchActive; private readonly List _ButtonsJoker = new List(); private readonly List _TextsPlayer = new List(); - private bool _SongOptionsActive; + private ESongOptionsView _CurSongOptionsView; private bool _PlaylistActive; private readonly List _AvailableGameModes; private SScreenSongOptions _Sso; @@ -91,6 +92,9 @@ namespace Vocaluxe.Screens private int _SelectedSongID; private int _SelectedCategoryIndex; + private CSongMenu _SongMenu; + private CPlaylist _Playlist; + public CScreenSong() { _AvailableGameModes = new List(); @@ -133,19 +137,20 @@ namespace Vocaluxe.Screens _ThemeTexts = tlist.ToArray(); _ThemeButtons = blist.ToArray(); _ThemeSelectSlides = new string[] {_SelectSlideOptionsMode, _SelectSlideOptionsPlaylistAdd, _SelectSlideOptionsPlaylistOpen, _SelectSlideOptionsNumMedleySongs}; - _ThemeSongMenus = new string[] {_SongMenu}; - _ThemePlaylists = new string[] {_Playlist}; + _ThemeSongMenus = new string[] {_SongMenuName}; + _ThemePlaylists = new string[] {_PlaylistName}; } public override void LoadTheme(string xmlPath) { base.LoadTheme(xmlPath); + _SongMenu = _SongMenus[_SongMenuName]; + _Playlist = _Playlists[_PlaylistName]; _ToggleSongOptions(ESongOptionsView.None); - _Playlists[_Playlist].Visible = false; - _DragAndDropCover = GetNewStatic(); - _Playlists[_Playlist].Init(); + _Playlist.Init(); + _Playlist.Visible = false; _AvailableGameModes.Clear(); } @@ -158,11 +163,11 @@ namespace Vocaluxe.Screens if (_PlaylistActive) { - _Playlists[_Playlist].HandleInput(keyEvent); + _Playlist.HandleInput(keyEvent); return true; } - if (!_SongOptionsActive) + if (_CurSongOptionsView == ESongOptionsView.None) { if (keyEvent.KeyPressed && !Char.IsControl(keyEvent.Unicode) && keyEvent.Mod != EModifier.Ctrl) { @@ -176,8 +181,8 @@ namespace Vocaluxe.Screens } else { - _SongMenus[_SongMenu].HandleInput(ref keyEvent, _Sso); - _UpdatePartyModeOptions(); + if (_SongMenu.HandleInput(ref keyEvent, _Sso)) + keyEvent.Handled = true; if (keyEvent.Handled) return true; @@ -210,32 +215,31 @@ namespace Vocaluxe.Screens } } if (_Buttons[_ButtonStart].Selected) - _HandlePartySongSelection(_SongMenus[_SongMenu].GetSelectedSong()); + _HandlePartySongSelection(_SongMenu.GetPreviewSongNr()); } if (CSongs.NumSongsVisible > 0 && !_Sso.Selection.PartyMode) { - if (_SongMenus[_SongMenu].GetSelectedSong() != -1 && !_SongOptionsActive) - { - if (!_Sso.Selection.PartyMode) - _ToggleSongOptions(ESongOptionsView.Song); - } + if (_SongMenu.GetPreviewSongNr() != -1) + _ToggleSongOptions(ESongOptionsView.Song); } break; case Keys.Tab: - if (_Playlists[_Playlist].Visible) + if (_Playlist.Visible) { _PlaylistActive = !_PlaylistActive; - _Playlists[_Playlist].Selected = _PlaylistActive; - _SongMenus[_SongMenu].SetActive(!_PlaylistActive); + _Playlist.Selected = _PlaylistActive; + _SongMenu.Active = !_PlaylistActive; } break; case Keys.Back: - if (_SearchActive && _SearchText != "") - _ApplyNewSearchFilter(_SearchText.Remove(_SearchText.Length - 1)); - - if ((CSongs.Category < 0 || _Sso.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) && !_Sso.Selection.PartyMode && !_SearchActive) + if (_SearchActive) + { + if (_SearchText != "") + _ApplyNewSearchFilter(_SearchText.Remove(_SearchText.Length - 1)); + } + else if ((!CSongs.IsInCategory || _Sso.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) && !_Sso.Selection.PartyMode) CGraphics.FadeTo(EScreens.ScreenMain); break; @@ -276,7 +280,12 @@ namespace Vocaluxe.Screens case Keys.S: if (keyEvent.Mod == EModifier.Ctrl && CSongs.NumSongsVisible > 0 && !_Sso.Selection.PartyMode) - _StartMedleySong(_SongMenus[_SongMenu].GetSelectedSong()); + _StartMedleySong(_SongMenu.GetPreviewSongNr()); + break; + + case Keys.F: + if (keyEvent.Mod == EModifier.Ctrl) + _SearchActive = true; break; case Keys.D1: @@ -322,7 +331,7 @@ namespace Vocaluxe.Screens else if (_Buttons[_ButtonOptionsSing].Selected) { _ToggleSongOptions(ESongOptionsView.None); - _StartSong(_SongMenus[_SongMenu].GetSelectedSong()); + _StartSong(_SongMenu.GetPreviewSongNr()); } else if (_Buttons[_ButtonOptionsPlaylist].Selected) { @@ -332,9 +341,9 @@ namespace Vocaluxe.Screens else if (_Buttons[_ButtonOptionsRandom].Selected) { if (CSongs.IsInCategory) - _SongMenus[_SongMenu].SetSelectedSong(CSongs.GetRandomSong()); + _SongMenu.SetSelectedSong(CSongs.GetRandomSong()); else - _SongMenus[_SongMenu].SetSelectedCategory(CSongs.GetRandomCategory()); + _SongMenu.SetSelectedCategory(CSongs.GetRandomCategory()); } else if (_Buttons[_ButtonOptionsSingAll].Selected) _StartRandomAllSongs(); @@ -397,31 +406,31 @@ namespace Vocaluxe.Screens _OldMousePosX = mouseEvent.X; _OldMousePosY = mouseEvent.Y; - if (_Playlists[_Playlist].Visible && _Playlists[_Playlist].IsMouseOver(mouseEvent)) + if (_Playlist.Visible && _Playlist.IsMouseOver(mouseEvent)) { _PlaylistActive = true; - _Playlists[_Playlist].Selected = _PlaylistActive; - _SongMenus[_SongMenu].SetActive(!_PlaylistActive); + _Playlist.Selected = _PlaylistActive; + _SongMenu.Active = !_PlaylistActive; _ToggleSongOptions(ESongOptionsView.None); } - else if (CHelper.IsInBounds(_SongMenus[_SongMenu].Rect, mouseEvent.X, mouseEvent.Y)) + else if (CHelper.IsInBounds(_SongMenu.Rect, mouseEvent.X, mouseEvent.Y)) { _PlaylistActive = false; - _Playlists[_Playlist].Selected = _PlaylistActive; - _SongMenus[_SongMenu].SetActive(!_PlaylistActive); + _Playlist.Selected = _PlaylistActive; + _SongMenu.Active = !_PlaylistActive; } - if (_Playlists[_Playlist].Visible && _PlaylistActive) + if (_Playlist.Visible && _PlaylistActive) { - if (_Playlists[_Playlist].HandleMouse(mouseEvent)) + if (_Playlist.HandleMouse(mouseEvent)) return true; } if (mouseEvent.RB) { - if (_SongOptionsActive) + if (_CurSongOptionsView != ESongOptionsView.None) { _ToggleSongOptions(ESongOptionsView.None); return true; @@ -447,19 +456,23 @@ namespace Vocaluxe.Screens if (mouseEvent.LD && !_Sso.Selection.PartyMode) { - if (CSongs.NumSongsVisible > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1 && _SongMenus[_SongMenu].IsMouseOverActualSelection(mouseEvent)) + if (CSongs.NumSongsVisible > 0 && _SongMenu.GetPreviewSongNr() != -1 && _SongMenu.IsMouseOverSelectedSong(mouseEvent)) { _ToggleSongOptions(ESongOptionsView.None); - _StartVisibleSong(_SongMenus[_SongMenu].GetActualSelection()); + _StartVisibleSong(_SongMenu.GetPreviewSongNr()); return true; } } - _SongMenus[_SongMenu].HandleMouse(ref mouseEvent, _Sso); - _UpdatePartyModeOptions(); + if (_SongMenu.HandleMouse(ref mouseEvent, _Sso)) + mouseEvent.Handled = true; if (mouseEvent.Handled) + { + if (_CurSongOptionsView != ESongOptionsView.None) + _ToggleSongOptions(ESongOptionsView.None); return true; + } if (mouseEvent.LB) { @@ -478,7 +491,7 @@ namespace Vocaluxe.Screens if (_Buttons[_ButtonOptionsSing].Selected) { _ToggleSongOptions(ESongOptionsView.None); - _StartSong(_SongMenus[_SongMenu].GetSelectedSong()); + _StartSong(_SongMenu.GetPreviewSongNr()); return true; } if (_Buttons[_ButtonOptionsPlaylist].Selected) @@ -491,7 +504,7 @@ namespace Vocaluxe.Screens { if (CSongs.IsInCategory) { - _SongMenus[_SongMenu].SetSelectedSong(CSongs.GetRandomSong()); + _SongMenu.SetSelectedSong(CSongs.GetRandomSong()); return true; } } @@ -499,7 +512,7 @@ namespace Vocaluxe.Screens { if (!CSongs.IsInCategory) { - _SongMenus[_SongMenu].SetSelectedCategory(CSongs.GetRandomCategory()); + _SongMenu.SetSelectedCategory(CSongs.GetRandomCategory()); return true; } } @@ -545,7 +558,7 @@ namespace Vocaluxe.Screens { if (_Buttons[_ButtonStart].Selected) { - _HandlePartySongSelection(_SongMenus[_SongMenu].GetSelectedSong()); + _HandlePartySongSelection(_SongMenu.GetPreviewSongNr()); return true; } @@ -563,25 +576,20 @@ namespace Vocaluxe.Screens } } - if (CSongs.NumSongsVisible > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1 && !_Sso.Selection.PartyMode) + if (_SongMenu.GetPreviewSongNr() != -1 && !_Sso.Selection.PartyMode && _SongMenu.IsMouseOverSelectedSong(mouseEvent)) { - if (_SongMenus[_SongMenu].GetSelectedSong() != -1 && !_SongOptionsActive) - { - _ToggleSongOptions(ESongOptionsView.Song); - return true; - } - _ToggleSongOptions(ESongOptionsView.None); + _ToggleSongOptions(ESongOptionsView.Song); return true; } } if (mouseEvent.LBH) { - if (!_DragAndDropActive && _Playlists[_Playlist].Visible && CSongs.NumSongsVisible > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1) + if (!_DragAndDropActive && _Playlist.Visible && CSongs.NumSongsVisible > 0 && _SongMenu.GetSelectedSongNr() != -1) { - _DragAndDropCover = _SongMenus[_SongMenu].GetSelectedSongCover(); + _DragAndDropCover = _SongMenu.GetSelectedSongCover(); _DragAndDropCover.Rect.Z = CSettings.ZNear; - _Playlists[_Playlist].DragAndDropSongID = CSongs.VisibleSongs[_SongMenus[_SongMenu].GetActualSelection()].ID; + _Playlist.DragAndDropSongID = CSongs.VisibleSongs[_SongMenu.GetSelectedSongNr()].ID; _DragAndDropActive = true; return true; } @@ -591,7 +599,7 @@ namespace Vocaluxe.Screens if (!mouseEvent.LBH && _DragAndDropActive) { _DragAndDropActive = false; - _Playlists[_Playlist].DragAndDropSongID = -1; + _Playlist.DragAndDropSongID = -1; return true; } @@ -608,7 +616,7 @@ namespace Vocaluxe.Screens else if (_Sso.Selection.CategoryChangeAllowed) { _ToggleSongOptions(ESongOptionsView.None); - _SongMenus[_SongMenu].EnterCurrentCategory(); + _SongMenu.EnterSelectedCategory(); } } @@ -625,7 +633,7 @@ namespace Vocaluxe.Screens _SearchText = _Sso.Sorting.SearchString; CGame.Reset(); - _SongMenus[_SongMenu].OnShow(); + _SongMenu.OnShow(); if (_Sso.Selection.PartyMode) _PlaylistActive = false; @@ -633,14 +641,14 @@ namespace Vocaluxe.Screens if (_Sso.Selection.PartyMode) _ToggleSongOptions(ESongOptionsView.None); - _SongMenus[_SongMenu].SetActive(!_PlaylistActive); - _SongMenus[_SongMenu].SetSmallView(_Playlists[_Playlist].Visible); + _SongMenu.Active = !_PlaylistActive; + _SongMenu.SmallView = _Playlist.Visible; - if (_Playlists[_Playlist].ActivePlaylistID != -1) - _Playlists[_Playlist].LoadPlaylist(_Playlists[_Playlist].ActivePlaylistID); + if (_Playlist.ActivePlaylistID != -1) + _Playlist.LoadPlaylist(_Playlist.ActivePlaylistID); _DragAndDropActive = false; - _Playlists[_Playlist].DragAndDropSongID = -1; + _Playlist.DragAndDropSongID = -1; UpdateGame(); if (CSongs.IsInCategory) @@ -649,23 +657,25 @@ namespace Vocaluxe.Screens public override bool UpdateGame() { - if (_SongMenus[_SongMenu].IsSmallView()) - CheckPlaylist(); + if (_PlaylistActive) + _CheckPlaylist(); _Texts[_TextCategory].Text = CSongs.GetCurrentCategoryName(); - if (CSongs.Category > -1 || CConfig.Tabs == EOffOn.TR_CONFIG_OFF) - CBackgroundMusic.Disabled = true; + string selectionText = ""; + if (CSongs.IsInCategory) + { + int song = _SongMenu.GetSelectedSongNr(); + if (song >= 0 && song < CSongs.VisibleSongs.Count) + selectionText = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title; + } else - CBackgroundMusic.Disabled = false; - - int song = _SongMenus[_SongMenu].GetActualSelection(); - if ((CSongs.IsInCategory || CConfig.Tabs == EOffOn.TR_CONFIG_OFF) && song >= 0 && song < CSongs.VisibleSongs.Count) - _Texts[_TextSelection].Text = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title; - else if (!CSongs.IsInCategory && song >= 0 && song < CSongs.Categories.Count) - _Texts[_TextSelection].Text = CSongs.Categories[song].Name; - else - _Texts[_TextSelection].Text = String.Empty; + { + int cat = _SongMenu.GetSelectedCategory(); + if (!CSongs.IsInCategory && cat >= 0 && cat < CSongs.Categories.Count) + _Texts[_TextSelection].Text = CSongs.Categories[cat].Name; + } + _Texts[_TextSelection].Text = selectionText; _Texts[_TextSearchBar].Text = _SearchText; if (_SearchActive) @@ -701,14 +711,19 @@ namespace Vocaluxe.Screens public override void OnClose() { base.OnClose(); - CBackgroundMusic.Disabled = false; - CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume); - _SongMenus[_SongMenu].OnHide(); + + _SongMenu.OnHide(); + + if (CGraphics.NextScreen != EScreens.ScreenNames) + { + CBackgroundMusic.Disabled = false; + CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume); + } } private void _HandlePartySongSelection(int songNr) { - if ((CSongs.Category >= 0) && (songNr >= 0)) + if (CSongs.IsInCategory && (songNr >= 0)) { CSong song = CSongs.VisibleSongs[songNr]; if (song != null) @@ -730,12 +745,12 @@ namespace Vocaluxe.Screens _SelectNextRandomSong(); if (_Sso.Selection.SongIndex != -1) - _SongMenus[_SongMenu].SetSelectedSong(_Sso.Selection.SongIndex); + _SongMenu.SetSelectedSong(_Sso.Selection.SongIndex); } - if (_SelectedSongID != _SongMenus[_SongMenu].GetSelectedSong() && CSongs.Category > -1) + if (_SelectedSongID != _SongMenu.GetPreviewSongNr() && CSongs.IsInCategory) { - _SelectedSongID = _SongMenus[_SongMenu].GetSelectedSong(); + _SelectedSongID = _SongMenu.GetPreviewSongNr(); CParty.OnSongChange(_SelectedSongID, ref _Sso); } @@ -752,14 +767,13 @@ namespace Vocaluxe.Screens _ToggleSongOptions(ESongOptionsView.None); } - _SongMenus[_SongMenu].Update(_Sso); + _SongMenu.Update(_Sso); if (_Sso.Selection.RandomOnly && _Sso.Selection.NumJokers != null) { _Buttons[_ButtonStart].Visible = true; - if (!_SongMenus[_SongMenu].IsSmallView()) - _SongMenus[_SongMenu].SetSmallView(true); + _SongMenu.SmallView = true; for (int i = 0; i < CSettings.MaxNumPlayer; i++) { @@ -791,8 +805,8 @@ namespace Vocaluxe.Screens } else { - if (_Sso.Selection.PartyMode && _SongMenus[_SongMenu].IsSmallView()) - _SongMenus[_SongMenu].SetSmallView(false); + if (_Sso.Selection.PartyMode) + _SongMenu.SmallView = false; for (int i = 0; i < CSettings.MaxNumPlayer; i++) { @@ -806,7 +820,7 @@ namespace Vocaluxe.Screens private void _StartSong(int songNr) { - if ((CSongs.Category >= 0) && (songNr >= 0)) + if (CSongs.IsInCategory && (songNr >= 0)) { EGameMode gm; if (_AvailableGameModes.Count >= _SelectSlides[_SelectSlideOptionsMode].Selection) @@ -824,7 +838,7 @@ namespace Vocaluxe.Screens private void _StartVisibleSong(int songNr) { - if (CSongs.Category >= 0 && songNr >= 0 && CSongs.NumSongsVisible > songNr) + if (CSongs.IsInCategory && songNr >= 0 && CSongs.NumSongsVisible > songNr) { EGameMode gm = CSongs.VisibleSongs[songNr].IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL; @@ -838,7 +852,7 @@ namespace Vocaluxe.Screens private void _StartMedleySong(int songNr) { - if ((CSongs.Category >= 0) && (songNr >= 0)) + if (CSongs.IsInCategory && (songNr >= 0)) { if (!CSongs.VisibleSongs[songNr].IsGameModeAvailable(EGameMode.TR_GAMEMODE_MEDLEY)) return; @@ -964,7 +978,7 @@ namespace Vocaluxe.Screens if (CSongs.IsInCategory) { _ToggleSongOptions(ESongOptionsView.None); - _SongMenus[_SongMenu].SetSelectedSong(CSongs.GetRandomSong()); + _SongMenu.SetSelectedSong(CSongs.GetRandomSong()); return true; } return false; @@ -975,7 +989,7 @@ namespace Vocaluxe.Screens if (!CSongs.IsInCategory) { _ToggleSongOptions(ESongOptionsView.None); - _SongMenus[_SongMenu].SetSelectedCategory(CSongs.GetRandomCategory()); + _SongMenu.SetSelectedCategory(CSongs.GetRandomCategory()); return true; } return false; @@ -999,7 +1013,7 @@ namespace Vocaluxe.Screens private void _JumpTo(char letter) { int start = 0; - int curSelected = _SongMenus[_SongMenu].GetActualSelection(); + int curSelected = CSongs.IsInCategory ? _SongMenu.GetSelectedSongNr() : _SongMenu.GetSelectedCategory(); bool firstLevel = CConfig.Tabs == EOffOn.TR_CONFIG_OFF && CSongs.IsInCategory; bool secondSort = CConfig.Tabs == EOffOn.TR_CONFIG_ON && (CConfig.SongSorting == ESongSorting.TR_CONFIG_ARTIST || @@ -1042,7 +1056,7 @@ namespace Vocaluxe.Screens break; } if (visibleID > -1) - _SongMenus[_SongMenu].SetSelectedSong(visibleID); + _SongMenu.SetSelectedSong(visibleID); } else if (secondSort && CSongs.IsInCategory) { @@ -1066,7 +1080,7 @@ namespace Vocaluxe.Screens break; } if (visibleID > -1) - _SongMenus[_SongMenu].SetSelectedSong(visibleID); + _SongMenu.SetSelectedSong(visibleID); } else if (!CSongs.IsInCategory) { @@ -1076,7 +1090,7 @@ namespace Vocaluxe.Screens start = curSelected + 1; int visibleID = _FindIndex(categories, start, element => element.Name.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)); if (visibleID > -1) - _SongMenus[_SongMenu].SetSelectedCategory(visibleID); + _SongMenu.SetSelectedCategory(visibleID); } } @@ -1088,9 +1102,9 @@ namespace Vocaluxe.Screens bool refresh = false; _SearchText = newFilterString; - int songIndex = _SongMenus[_SongMenu].GetSelectedSong(); + int songIndex = _SongMenu.GetSelectedSongNr(); int songID = -1; - if (songIndex != -1 && CSongs.NumSongsVisible > 0 && CSongs.NumSongsVisible > songIndex) + if (songIndex != -1) songID = CSongs.VisibleSongs[songIndex].ID; if (newFilterString == "" && _Sso.Sorting.Tabs == EOffOn.TR_CONFIG_ON) @@ -1107,13 +1121,13 @@ namespace Vocaluxe.Screens CSongs.Sort(_Sso.Sorting.SongSorting, _Sso.Sorting.Tabs, _Sso.Sorting.IgnoreArticles, newFilterString, _Sso.Sorting.DuetOptions); - if (songID == -1 || CSongs.NumSongsVisible == 0 || CSongs.NumSongsVisible <= songIndex || CSongs.GetVisibleSongByIndex(songIndex).ID != songID) + if (songID == -1 || CSongs.NumSongsVisible <= songIndex || CSongs.GetVisibleSongByIndex(songIndex).ID != songID) refresh = true; if (refresh) - _SongMenus[_SongMenu].OnHide(); + _SongMenu.OnHide(); - _SongMenus[_SongMenu].OnShow(); + _SongMenu.OnShow(); } private void _ToggleSongOptions(ESongOptionsView view) @@ -1137,13 +1151,13 @@ namespace Vocaluxe.Screens _Buttons[_ButtonOpenOptions].Visible = true; if (view == ESongOptionsView.None) - _SongOptionsActive = false; + _CurSongOptionsView = view; else if (CSongs.IsInCategory) - _SongOptionsActive = CSongs.VisibleSongs.Count > 0; + _CurSongOptionsView = CSongs.VisibleSongs.Count > 0 ? view : ESongOptionsView.None; else - _SongOptionsActive = CSongs.Categories.Count > 0; + _CurSongOptionsView = CSongs.Categories.Count > 0 ? view : ESongOptionsView.None; - if (!_SongOptionsActive) + if (_CurSongOptionsView == ESongOptionsView.None) return; //Has to be done here otherwhise changed playlist names will not appear until OnShow is called! @@ -1163,7 +1177,7 @@ namespace Vocaluxe.Screens private void _CheckAndAddGameMode(EGameMode gameMode) { - if (CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].IsGameModeAvailable(gameMode)) + if (CSongs.VisibleSongs[_SongMenu.GetPreviewSongNr()].IsGameModeAvailable(gameMode)) { _SelectSlides[_SelectSlideOptionsMode].AddValue(Enum.GetName(typeof(EGameMode), gameMode)); _AvailableGameModes.Add(gameMode); @@ -1243,31 +1257,30 @@ namespace Vocaluxe.Screens } #region Playlist Actions - public void CheckPlaylist() + private void _CheckPlaylist() { - if (_Playlists[_Playlist].ActivePlaylistID == -1 && _PlaylistActive) + if (_Playlist.ActivePlaylistID == -1 && _PlaylistActive) _ClosePlaylist(); } private void _OpenPlaylist(int playlistID) { - if (CPlaylists.Playlists.Length > playlistID && playlistID >= 0) + if (_Playlist.LoadPlaylist(playlistID)) { - _Playlists[_Playlist].LoadPlaylist(playlistID); - _SongMenus[_SongMenu].SetSmallView(true); - _Playlists[_Playlist].Visible = true; + _SongMenu.SmallView = true; + _Playlist.Visible = true; } } private void _ClosePlaylist() { - if (_Playlists[_Playlist].Visible || _PlaylistActive) + if (_Playlist.Visible || _PlaylistActive) { - _SongMenus[_SongMenu].SetSmallView(false); + _SongMenu.SmallView = false; _PlaylistActive = false; - _Playlists[_Playlist].Selected = _PlaylistActive; - _SongMenus[_SongMenu].SetActive(!_PlaylistActive); - _Playlists[_Playlist].ClosePlaylist(); + _Playlist.Selected = _PlaylistActive; + _SongMenu.Active = !_PlaylistActive; + _Playlist.ClosePlaylist(); } } @@ -1275,22 +1288,22 @@ namespace Vocaluxe.Screens { _SelectSlides[_SelectSlideOptionsPlaylistAdd].Clear(); _SelectSlides[_SelectSlideOptionsPlaylistAdd].AddValue("TR_SCREENSONG_NEWPLAYLIST"); - _SelectSlides[_SelectSlideOptionsPlaylistAdd].AddValues(CPlaylists.PlaylistNames); + _SelectSlides[_SelectSlideOptionsPlaylistAdd].AddValues(CPlaylists.Names); _SelectSlides[_SelectSlideOptionsPlaylistOpen].Clear(); - _SelectSlides[_SelectSlideOptionsPlaylistOpen].AddValues(CPlaylists.PlaylistNames); + _SelectSlides[_SelectSlideOptionsPlaylistOpen].AddValues(CPlaylists.Names); } private void _OpenAndAddPlaylistAction() { - //Open an existing playlist and add song - if (_Playlists[_Playlist].ActivePlaylistID != (_SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1) && + if (_Playlist.ActivePlaylistID != (_SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1) && (_SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1) != -1) { + //Open an existing playlist and add song //Check selected game-mode EGameMode gm; if (_AvailableGameModes.Count >= _SelectSlides[_SelectSlideOptionsMode].Selection) gm = _AvailableGameModes[_SelectSlides[_SelectSlideOptionsMode].Selection]; - else if (CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].IsDuet) + else if (CSongs.VisibleSongs[_SongMenu.GetPreviewSongNr()].IsDuet) gm = EGameMode.TR_GAMEMODE_DUET; else gm = EGameMode.TR_GAMEMODE_NORMAL; @@ -1298,63 +1311,63 @@ namespace Vocaluxe.Screens //Check if Playlist really exists if (_SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1 >= 0) { - _Playlists[_Playlist].ActivePlaylistID = _SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1; + _Playlist.ActivePlaylistID = _SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1; //Add song to playlist - CPlaylists.Playlists[_Playlists[_Playlist].ActivePlaylistID].AddSong(CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].ID, gm); + CPlaylists.AddSong(_Playlist.ActivePlaylistID, CSongs.VisibleSongs[_SongMenu.GetPreviewSongNr()].ID, gm); //Open playlist - _OpenPlaylist(_Playlists[_Playlist].ActivePlaylistID); + _OpenPlaylist(_Playlist.ActivePlaylistID); - _Playlists[_Playlist].ScrollToBottom(); + _Playlist.ScrollToBottom(); } } - //Create a new playlist and add song else if ((_SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1) == -1) { + //Create a new playlist and add song //Check selected game-mode EGameMode gm; if (_AvailableGameModes.Count >= _SelectSlides[_SelectSlideOptionsMode].Selection) gm = _AvailableGameModes[_SelectSlides[_SelectSlideOptionsMode].Selection]; - else if (CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].IsDuet) + else if (CSongs.VisibleSongs[_SongMenu.GetPreviewSongNr()].IsDuet) gm = EGameMode.TR_GAMEMODE_DUET; else gm = EGameMode.TR_GAMEMODE_NORMAL; //Create new playlist - _Playlists[_Playlist].ActivePlaylistID = CPlaylists.NewPlaylist(); + _Playlist.ActivePlaylistID = CPlaylists.NewPlaylist(); //Add song to playlist - CPlaylists.Playlists[_Playlists[_Playlist].ActivePlaylistID].AddSong(CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].ID, gm); + CPlaylists.AddSong(_Playlist.ActivePlaylistID, CSongs.VisibleSongs[_SongMenu.GetPreviewSongNr()].ID, gm); //Open playlist - _OpenPlaylist(_Playlists[_Playlist].ActivePlaylistID); + _OpenPlaylist(_Playlist.ActivePlaylistID); //Add new playlist to select-slide - _SelectSlides[_SelectSlideOptionsPlaylistAdd].AddValue(CPlaylists.Playlists[_Playlists[_Playlist].ActivePlaylistID].PlaylistName); - _SelectSlides[_SelectSlideOptionsPlaylistOpen].AddValue(CPlaylists.Playlists[_Playlists[_Playlist].ActivePlaylistID].PlaylistName); + _SelectSlides[_SelectSlideOptionsPlaylistAdd].AddValue(CPlaylists.GetName(_Playlist.ActivePlaylistID)); + _SelectSlides[_SelectSlideOptionsPlaylistOpen].AddValue(CPlaylists.GetName(_Playlist.ActivePlaylistID)); } - //Add song to loaded playlist else { + //Add song to loaded playlist //Check selected game-mode EGameMode gm; if (_AvailableGameModes.Count >= _SelectSlides[_SelectSlideOptionsMode].Selection) gm = _AvailableGameModes[_SelectSlides[_SelectSlideOptionsMode].Selection]; - else if (CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].IsDuet) + else if (CSongs.VisibleSongs[_SongMenu.GetPreviewSongNr()].IsDuet) gm = EGameMode.TR_GAMEMODE_DUET; else gm = EGameMode.TR_GAMEMODE_NORMAL; - CPlaylists.Playlists[_Playlists[_Playlist].ActivePlaylistID].AddSong(CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].ID, gm); - _Playlists[_Playlist].UpdatePlaylist(); - _Playlists[_Playlist].ScrollToBottom(); + CPlaylists.AddSong(_Playlist.ActivePlaylistID, CSongs.VisibleSongs[_SongMenu.GetPreviewSongNr()].ID, gm); + _Playlist.UpdatePlaylist(); + _Playlist.ScrollToBottom(); } } private void _SetSelectSlidePlaylistToCurrentPlaylist() { - if (_Playlists[_Playlist].ActivePlaylistID > -1) - _SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection = _Playlists[_Playlist].ActivePlaylistID + 1; + if (_Playlist.ActivePlaylistID > -1) + _SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection = _Playlist.ActivePlaylistID + 1; else _SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection = 0; } diff --git a/Vocaluxe/SongQueue/CSongQueue.cs b/Vocaluxe/SongQueue/CSongQueue.cs index cbfa7acf..969013c9 100644 --- a/Vocaluxe/SongQueue/CSongQueue.cs +++ b/Vocaluxe/SongQueue/CSongQueue.cs @@ -41,6 +41,7 @@ namespace Vocaluxe.SongQueue private List _SongQueue; private int _CurrentRound; private CPoints _Points; + private CSong _CurrentSong; #region Implementation public void Init() @@ -124,6 +125,7 @@ namespace Vocaluxe.SongQueue _SongQueue[_CurrentRound].GameMode); } _CurrentRound++; + _CurrentSong = IsFinished() ? null : CGameModes.Get(GetCurrentGameMode()).GetSong(_SongQueue[_CurrentRound].SongID); } public bool IsFinished() @@ -155,7 +157,7 @@ namespace Vocaluxe.SongQueue /// Song of current round or null if there is none/game finished public CSong GetSong() { - return GetSong(_CurrentRound); + return _CurrentSong; } public int GetNumSongs() @@ -170,6 +172,8 @@ namespace Vocaluxe.SongQueue /// Current song or null if out of bounds public CSong GetSong(int round) { + if (round == _CurrentRound) + return _CurrentSong; if (round < _SongQueue.Count && round >= 0) return CSongs.GetSong(_SongQueue[round].SongID); diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index db1858e6..b8276467 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -218,6 +218,7 @@ + diff --git a/VocaluxeLib/CHelper.cs b/VocaluxeLib/CHelper.cs index 9d37b818..411d39ec 100644 --- a/VocaluxeLib/CHelper.cs +++ b/VocaluxeLib/CHelper.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Globalization; using System.IO; @@ -63,8 +64,18 @@ namespace VocaluxeLib return (int)result; } + /// + /// Makes sure val is between min and max + /// Asserts that min<=max + /// + /// + /// + /// + /// + /// Clamped value public static T Clamp(this T val, T min, T max) where T : IComparable { + Debug.Assert(min.CompareTo(max) <= 0); if (val.CompareTo(min) < 0) return min; if (val.CompareTo(max) > 0) @@ -72,6 +83,27 @@ namespace VocaluxeLib return val; } + /// + /// Makes sure val is between min and max but also handles the case where min>max + /// + /// + /// + /// + /// + /// + /// Clamped value + public static T Clamp(this T val, T min, T max, bool preferMin) where T : IComparable + { + if (min.CompareTo(max) > 0) + { + if (preferMin) + max = min; + else + min = max; + } + return Clamp(val, min, max); + } + /// /// Concat strings into one string with ", " as separator. /// @@ -88,30 +120,13 @@ namespace VocaluxeLib return result; } - public static int TryReadInt(StreamReader sr) + public static void SetRect(SRectF bounds, out SRectF rect, float rectAspect, EAspect aspect) { - string value = String.Empty; + var bounds2 = new RectangleF(bounds.X, bounds.Y, bounds.W, bounds.H); + RectangleF rect2; + SetRect(bounds2, out rect2, rectAspect, aspect); - try - { - int tmp = sr.Peek(); - //Check for ' ', ?, ?, \n, \r, E - while (tmp != 32 && tmp != 19 && tmp != 16 && tmp != 13 && tmp != 10 && tmp != 69) - { - if (sr.EndOfStream) - break; - - var chr = (char)sr.Read(); - value += chr.ToString(); - tmp = sr.Peek(); - } - } - catch (Exception) - { - return 0; - } - int result; - return Int32.TryParse(value, out result) ? result : 0; + rect = new SRectF(rect2.X, rect2.Y, rect2.Width, rect2.Height, bounds.Z); } public static void SetRect(RectangleF bounds, out RectangleF rect, float rectAspect, EAspect aspect) @@ -264,6 +279,29 @@ namespace VocaluxeLib { return (bounds.X <= x) && (bounds.X + bounds.W >= x) && (bounds.Y <= y) && (bounds.Y + bounds.H >= y); } + + /// + /// Returns a filename that is unique in that path + /// + /// Path in which the file should be stored + /// filename (including extension) + /// Whether the fullpath or only the filename should be returned + /// + public static string GetUniqueFileName(string path, string filename, bool withPath = true) + { + string ext = Path.GetExtension(filename); + filename = Path.GetFileNameWithoutExtension(filename) ?? "1"; + if (File.Exists(Path.Combine(path, filename + ext))) + { + int i = 1; + while (File.Exists(Path.Combine(path, filename + "_" + i + ext))) + i++; + filename += "_" + i; + } + if (withPath) + filename = Path.Combine(path, filename); + return filename + ext; + } } static class CEncoding diff --git a/VocaluxeLib/CXMLReader.cs b/VocaluxeLib/CXMLReader.cs index 6d4a14af..1603af81 100644 --- a/VocaluxeLib/CXMLReader.cs +++ b/VocaluxeLib/CXMLReader.cs @@ -57,52 +57,44 @@ namespace VocaluxeLib } } - public bool TryGetEnumValue(string cast, ref T value) + public bool TryGetEnumValue(string xPath, ref T value) where T : struct { string val; - if (GetValue(cast, out val, Enum.GetName(typeof(T), value))) - { - CHelper.TryParse(val, out value, true); - return true; - } + if (GetValue(xPath, out val, Enum.GetName(typeof(T), value))) + return CHelper.TryParse(val, out value, true); return false; } - public bool TryGetIntValue(string cast, ref int value) + public bool TryGetIntValue(string xPath, ref int value) { string val; - if (GetValue(cast, out val, value.ToString())) + if (GetValue(xPath, out val, value.ToString())) return int.TryParse(val, out value); return false; } - public bool TryGetIntValueRange(string cast, ref int value, int min = 0, int max = 100) + public bool TryGetIntValueRange(string xPath, ref int value, int min = 0, int max = 100) { - bool result = TryGetIntValue(cast, ref value); + bool result = TryGetIntValue(xPath, ref value); if (result) - { - if (value < min) - value = min; - else if (value > max) - value = max; - } + value = value.Clamp(min, max); return result; } - public bool TryGetFloatValue(string cast, ref float value) + public bool TryGetFloatValue(string xPath, ref float value) { string val; - return GetValue(cast, out val, value.ToString()) && CHelper.TryParse(val, out value); + return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value); } - public bool GetValue(string cast, out string value, string defaultValue) + public bool GetValue(string xPath, out string value, string defaultValue) { int resultCt = 0; string val = string.Empty; - _Navigator.MoveToFirstChild(); - XPathNodeIterator iterator = _Navigator.Select(cast); + _Navigator.MoveToRoot(); + XPathNodeIterator iterator = _Navigator.Select(xPath); while (iterator.MoveNext()) { @@ -119,77 +111,45 @@ namespace VocaluxeLib return true; } - public List GetValues(string cast) + public List GetNames(string xPath) { var values = new List(); _Navigator.MoveToRoot(); - _Navigator.MoveToFirstChild(); - _Navigator.MoveToFirstChild(); - - while (_Navigator.Name != cast) - _Navigator.MoveToNext(); - - _Navigator.MoveToFirstChild(); - - values.Add(_Navigator.LocalName); - while (_Navigator.MoveToNext()) - values.Add(_Navigator.LocalName); - - return values; - } - - public IEnumerable GetAttributes(string cast, string attribute) - { - var values = new List(); - - _Navigator.MoveToRoot(); - _Navigator.MoveToFirstChild(); - - while (_Navigator.Name != cast) - _Navigator.MoveToNext(); - - _Navigator.MoveToFirstChild(); - - values.Add(_Navigator.LocalName); - while (_Navigator.MoveToNext()) - values.Add(_Navigator.GetAttribute(attribute, "")); - - return values; - } - - public bool GetInnerValues(string cast, ref List values) - { - _Navigator.MoveToRoot(); - _Navigator.MoveToFirstChild(); - _Navigator.MoveToFirstChild(); - - while (_Navigator.Name != cast) - _Navigator.MoveToNext(); - - _Navigator.MoveToFirstChild(); - - values.Add(_Navigator.Value); - while (_Navigator.MoveToNext()) - values.Add(_Navigator.Value); - - return true; - } - - public bool ItemExists(string cast) - { - int results = 0; - - _Navigator.MoveToFirstChild(); - XPathNodeIterator iterator = _Navigator.Select(cast); - + XPathNodeIterator iterator = _Navigator.Select(xPath); while (iterator.MoveNext()) - results++; + values.Add(iterator.Current.LocalName); - if (results == 0) - return false; + return values; + } + + public IEnumerable GetAttributes(string xPath, string attribute) + { + var values = new List(); + + _Navigator.MoveToRoot(); + XPathNodeIterator iterator = _Navigator.Select(xPath); + while (iterator.MoveNext()) + values.Add(iterator.Current.GetAttribute(attribute, "")); + + return values; + } + + public bool GetValues(string xPath, ref List values) + { + _Navigator.MoveToRoot(); + XPathNodeIterator iterator = _Navigator.Select(xPath); + while (iterator.MoveNext()) + values.Add(iterator.Current.Value); return true; } + + public bool ItemExists(string xPath) + { + _Navigator.MoveToRoot(); + + return _Navigator.Select(xPath).MoveNext(); + } } } \ No newline at end of file diff --git a/VocaluxeLib/Enums.cs b/VocaluxeLib/Enums.cs index 0df1d888..4db6424c 100644 --- a/VocaluxeLib/Enums.cs +++ b/VocaluxeLib/Enums.cs @@ -248,6 +248,13 @@ namespace VocaluxeLib // ReSharper restore InconsistentNaming } + public enum EBackgroundMusicOffOn + { + TR_CONFIG_OFF, + TR_CONFIG_ONLY_SONG, + TR_CONFIG_ON + } + public enum EPlayerInfo { // ReSharper disable InconsistentNaming @@ -288,6 +295,14 @@ namespace VocaluxeLib } #endregion Config + public enum EStreamAction + { + Nothing, + Pause, + Stop, + Close + } + public enum EProgramState { Start, diff --git a/VocaluxeLib/Extensions.cs b/VocaluxeLib/Extensions.cs index 4cc4fe2e..f04d5f40 100644 --- a/VocaluxeLib/Extensions.cs +++ b/VocaluxeLib/Extensions.cs @@ -124,5 +124,15 @@ namespace VocaluxeLib { return value.ToString("F", NumberFormatInfo.InvariantInfo); } + + public static SRectF Scale(this SRectF rect, float scale) + { + return new SRectF( + rect.X - rect.W * (scale - 1f), + rect.Y - rect.H * (scale - 1f), + rect.W + 2 * rect.W * (scale - 1f), + rect.H + 2 * rect.H * (scale - 1f), + rect.Z); + } } } \ No newline at end of file diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index 9d84374d..d88a4ea7 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -35,6 +35,8 @@ namespace VocaluxeLib void SetBackgroundMusicVolume(int newVolume); int GetBackgroundMusicVolume(); + EBackgroundMusicOffOn GetBackgroundMusicStatus(); + int GetPreviewMusicVolume(); EOffOn GetVideosToBackground(); @@ -89,6 +91,8 @@ namespace VocaluxeLib float GetSlideShowImageTime(); float GetSlideShowFadeTime(); + + float GetSoundPlayerFadeTime(); } public interface ITheme @@ -115,16 +119,24 @@ namespace VocaluxeLib { bool IsDisabled(); bool IsPlaying(); + bool IsPlayingPreview(); bool SongHasVideo(); bool VideoEnabled(); + float GetLength(); - void SetStatus(bool disabled); + void SetDisabled(bool disabled); void Next(); void Previous(); void Pause(); void Play(); + void Stop(); CTexture GetVideoTexture(); + + void LoadPreview(CSong song, float start = 0f); + void PlayPreview(float start = -1f); + void StopPreview(); + } public interface IDrawing @@ -148,6 +160,8 @@ namespace VocaluxeLib void FadeTo(EScreens nextScreen); float GetGlobalAlpha(); + + EScreens GetNextScreen(); } public interface ILog @@ -196,6 +210,8 @@ namespace VocaluxeLib void Reset(); void ClearSongs(); int GetNumSongs(); + CSong GetSong(); + CSong GetSong(int round); } public interface IRecording @@ -253,6 +269,8 @@ namespace VocaluxeLib bool IsFinished(int streamID); bool Close(int streamID); void SetLoop(int streamID, bool loop = true); + void Resume(int streamID); + void Pause(int streamID); } public interface ISound @@ -260,12 +278,12 @@ namespace VocaluxeLib int Load(string soundFile, bool loop = false, bool prescan = false); void SetPosition(int soundStream, float newPosition); void Play(int soundStream); - void Fade(int soundStream, float targetVolume, float duration); + void Fade(int soundStream, float targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing); + void Close(int soundStream); bool IsFinished(int soundStream); float GetPosition(int soundStream); float GetLength(int soundStream); - void FadeAndClose(int soundStream, float targetVolume, float duration); void SetStreamVolume(int soundStream, float volume); } @@ -288,24 +306,38 @@ namespace VocaluxeLib public interface IPlaylist { - string GetPlaylistName(int playlistID); - List GetPlaylistNames(); + bool Exists(int playlistID); + string GetName(int playlistID); + List GetNames(); - void SetPlaylistName(int playlistID, string name); - void DeletePlaylist(int playlistID); - void SavePlaylist(int playlistID); + void SetName(int playlistID, string name); + void Delete(int playlistID); + void Save(int playlistID); int GetNumPlaylists(); - void AddPlaylistSong(int playlistID, int songID); - void AddPlaylistSong(int playlistID, int songID, EGameMode gameMode); - void InsertPlaylistSong(int playlistID, int positionIndex, int songID, EGameMode gameMode); + void AddSong(int playlistID, int songID); + void AddSong(int playlistID, int songID, EGameMode gameMode); + void InsertSong(int playlistID, int positionIndex, int songID, EGameMode gameMode); - void MovePlaylistSong(int playlistID, int sourceIndex, int destIndex); - void MovePlaylistSongDown(int playlistID, int songIndex); - void MovePlaylistSongUp(int playlistID, int songIndex); - void DeletePlaylistSong(int playlistID, int songIndex); + void MoveSong(int playlistID, int sourceIndex, int destIndex); + void MoveSongDown(int playlistID, int songIndex); + void MoveSongUp(int playlistID, int songIndex); + void DeleteSong(int playlistID, int songIndex); + + int GetSongCount(int playlistID); + CPlaylistSong GetSong(int playlistID, int songIndex); + } + + public interface IPreviewPlayer + { + void Play(float start = -1); + void Load(CSong song, float start = 0f); + void Stop(); + void TogglePause(); + CTexture GetCover(); + CTexture GetVideoTexture(); + bool IsPlaying(); + float GetLength(); - int GetPlaylistSongCount(int playlistID); - CPlaylistSong GetPlaylistSong(int playlistID, int songIndex); } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index 7138d3f3..67ba0755 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -194,7 +194,7 @@ namespace VocaluxeLib.Menu if (!String.IsNullOrEmpty(_Theme.TextureName) && (_Theme.Type == EBackgroundTypes.Texture || - (_Theme.Type == EBackgroundTypes.Video && (CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF || !ok)))) + (_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF))) ok = _DrawTexture(); if (_Theme.Type == EBackgroundTypes.Color || _Theme.Type == EBackgroundTypes.Texture && !ok || diff --git a/VocaluxeLib/Menu/CMenu.cs b/VocaluxeLib/Menu/CMenu.cs index af2e5443..01fcb9ab 100644 --- a/VocaluxeLib/Menu/CMenu.cs +++ b/VocaluxeLib/Menu/CMenu.cs @@ -339,6 +339,7 @@ namespace VocaluxeLib.Menu foreach (CNameSelection ns in _NameSelections) ns.UnloadTextures(); + foreach (CPlaylist pls in _Playlists) pls.UnloadTextures(); diff --git a/VocaluxeLib/Menu/CPlaylist.cs b/VocaluxeLib/Menu/CPlaylist.cs index 1e71a262..428955d0 100644 --- a/VocaluxeLib/Menu/CPlaylist.cs +++ b/VocaluxeLib/Menu/CPlaylist.cs @@ -176,7 +176,7 @@ namespace VocaluxeLib.Menu { if (EditMode == EEditMode.ChangeOrder && _ChangeOrderSource != -1 && _PlaylistElements.Count > _ChangeOrderSource) { - CBase.Playlist.DeletePlaylistSong(ActivePlaylistID, _PlaylistElements[_ChangeOrderSource].Content); + CBase.Playlist.DeleteSong(ActivePlaylistID, _PlaylistElements[_ChangeOrderSource].Content); UpdatePlaylist(); } _ChangeOrderSource = -1; @@ -503,13 +503,13 @@ namespace VocaluxeLib.Menu switch (keyEvent.Key) { case Keys.Enter: - CBase.Playlist.SetPlaylistName(ActivePlaylistID, _Theme.ButtonPlaylistName.Text.Text); - CBase.Playlist.SavePlaylist(ActivePlaylistID); + CBase.Playlist.SetName(ActivePlaylistID, _Theme.ButtonPlaylistName.Text.Text); + CBase.Playlist.Save(ActivePlaylistID); EditMode = EEditMode.None; _Theme.ButtonPlaylistName.EditMode = false; break; case Keys.Escape: - _Theme.ButtonPlaylistName.Text.Text = CBase.Playlist.GetPlaylistName(ActivePlaylistID); + _Theme.ButtonPlaylistName.Text.Text = CBase.Playlist.GetName(ActivePlaylistID); EditMode = EEditMode.None; _Theme.ButtonPlaylistName.EditMode = false; break; @@ -600,7 +600,7 @@ namespace VocaluxeLib.Menu break; case Keys.Delete: - CBase.Playlist.DeletePlaylistSong(ActivePlaylistID, _PlaylistElements[CurrentPlaylistElement].Content); + CBase.Playlist.DeleteSong(ActivePlaylistID, _PlaylistElements[CurrentPlaylistElement].Content); UpdatePlaylist(); if (Offset > 0) @@ -626,7 +626,7 @@ namespace VocaluxeLib.Menu case Keys.Add: //move the selected song up if (_PlaylistElementContents.Count > 1 && (CurrentPlaylistElement > 0 || Offset > 0)) { - CBase.Playlist.MovePlaylistSongUp(ActivePlaylistID, CurrentPlaylistElement + Offset); + CBase.Playlist.MoveSongUp(ActivePlaylistID, CurrentPlaylistElement + Offset); UpdatePlaylist(); var key = new SKeyEvent {Key = Keys.Up}; @@ -655,7 +655,7 @@ namespace VocaluxeLib.Menu case Keys.Subtract: //move the selected song down if (_PlaylistElementContents.Count > 1 && CurrentPlaylistElement + Offset < _PlaylistElementContents.Count - 1) { - CBase.Playlist.MovePlaylistSongDown(ActivePlaylistID, CurrentPlaylistElement + Offset); + CBase.Playlist.MoveSongDown(ActivePlaylistID, CurrentPlaylistElement + Offset); UpdatePlaylist(); var key = new SKeyEvent {Key = Keys.Down}; @@ -724,7 +724,7 @@ namespace VocaluxeLib.Menu if (CurrentPlaylistElement != -1) { - CBase.Playlist.GetPlaylistSong(ActivePlaylistID, CurrentPlaylistElement + Offset).GameMode = + CBase.Playlist.GetSong(ActivePlaylistID, CurrentPlaylistElement + Offset).GameMode = _PlaylistElementContents[CurrentPlaylistElement + Offset].Modes[_PlaylistElements[CurrentPlaylistElement].SelectSlide.Selection]; UpdatePlaylist(); } @@ -736,7 +736,7 @@ namespace VocaluxeLib.Menu if (CurrentPlaylistElement != -1) { - CBase.Playlist.GetPlaylistSong(ActivePlaylistID, CurrentPlaylistElement + Offset).GameMode = + CBase.Playlist.GetSong(ActivePlaylistID, CurrentPlaylistElement + Offset).GameMode = _PlaylistElementContents[CurrentPlaylistElement + Offset].Modes[_PlaylistElements[CurrentPlaylistElement].SelectSlide.Selection]; UpdatePlaylist(); } @@ -764,10 +764,10 @@ namespace VocaluxeLib.Menu else if (_Theme.ButtonPlaylistSing.Selected) _StartPlaylistSongs(); else if (_Theme.ButtonPlaylistSave.Selected) - CBase.Playlist.SavePlaylist(ActivePlaylistID); + CBase.Playlist.Save(ActivePlaylistID); else if (_Theme.ButtonPlaylistDelete.Selected) { - CBase.Playlist.DeletePlaylist(ActivePlaylistID); + CBase.Playlist.Delete(ActivePlaylistID); ClosePlaylist(); } else if (_Theme.ButtonPlaylistName.Selected) @@ -888,7 +888,7 @@ namespace VocaluxeLib.Menu //Delete Entry with RB if (CHelper.IsInBounds(_PlaylistElements[i].Background.Rect, mouseEvent) && mouseEvent.RB && _PlaylistElements[i].Content != -1) { - CBase.Playlist.DeletePlaylistSong(ActivePlaylistID, _PlaylistElements[i].Content); + CBase.Playlist.DeleteSong(ActivePlaylistID, _PlaylistElements[i].Content); UpdatePlaylist(); return true; } @@ -906,7 +906,7 @@ namespace VocaluxeLib.Menu { if (CurrentPlaylistElement != -1) { - CBase.Playlist.GetPlaylistSong(ActivePlaylistID, CurrentPlaylistElement + Offset).GameMode = + CBase.Playlist.GetSong(ActivePlaylistID, CurrentPlaylistElement + Offset).GameMode = _PlaylistElementContents[CurrentPlaylistElement + Offset].Modes[_PlaylistElements[CurrentPlaylistElement].SelectSlide.Selection]; UpdatePlaylist(); } @@ -922,12 +922,12 @@ namespace VocaluxeLib.Menu } if (_Theme.ButtonPlaylistSave.Selected) { - CBase.Playlist.SavePlaylist(ActivePlaylistID); + CBase.Playlist.Save(ActivePlaylistID); return true; } if (_Theme.ButtonPlaylistDelete.Selected) { - CBase.Playlist.DeletePlaylist(ActivePlaylistID); + CBase.Playlist.Delete(ActivePlaylistID); ClosePlaylist(); return true; } @@ -981,14 +981,14 @@ namespace VocaluxeLib.Menu if (CurrentPlaylistElement != -1) { - CBase.Playlist.InsertPlaylistSong(ActivePlaylistID, CurrentPlaylistElement + Offset, DragAndDropSongID, gm); + CBase.Playlist.InsertSong(ActivePlaylistID, CurrentPlaylistElement + Offset, DragAndDropSongID, gm); UpdatePlaylist(); } else { if (mouseEvent.Y < _PlaylistElements[0].Background.Rect.Y && Offset == 0) { - CBase.Playlist.InsertPlaylistSong(ActivePlaylistID, 0, DragAndDropSongID, gm); + CBase.Playlist.InsertSong(ActivePlaylistID, 0, DragAndDropSongID, gm); UpdatePlaylist(); } else @@ -1007,7 +1007,7 @@ namespace VocaluxeLib.Menu if (mouseEvent.Y > min) { - CBase.Playlist.AddPlaylistSong(ActivePlaylistID, DragAndDropSongID, gm); + CBase.Playlist.AddSong(ActivePlaylistID, DragAndDropSongID, gm); UpdatePlaylist(); ScrollToBottom(); } @@ -1028,8 +1028,8 @@ namespace VocaluxeLib.Menu { if (_Theme.ButtonPlaylistName.Selected) { - CBase.Playlist.SetPlaylistName(ActivePlaylistID, _Theme.ButtonPlaylistName.Text.Text); - CBase.Playlist.SavePlaylist(ActivePlaylistID); + CBase.Playlist.SetName(ActivePlaylistID, _Theme.ButtonPlaylistName.Text.Text); + CBase.Playlist.Save(ActivePlaylistID); EditMode = EEditMode.None; return true; } @@ -1038,7 +1038,7 @@ namespace VocaluxeLib.Menu { if (_Theme.ButtonPlaylistName.Selected) { - _Theme.ButtonPlaylistName.Text.Text = CBase.Playlist.GetPlaylistName(ActivePlaylistID); + _Theme.ButtonPlaylistName.Text.Text = CBase.Playlist.GetName(ActivePlaylistID); EditMode = EEditMode.None; _Theme.ButtonPlaylistName.EditMode = false; return true; @@ -1058,13 +1058,13 @@ namespace VocaluxeLib.Menu { if (CurrentPlaylistElement != -1 && CurrentPlaylistElement + Offset != _ChangeOrderSource) { - CBase.Playlist.MovePlaylistSong(ActivePlaylistID, _ChangeOrderSource, CurrentPlaylistElement + Offset); + CBase.Playlist.MoveSong(ActivePlaylistID, _ChangeOrderSource, CurrentPlaylistElement + Offset); UpdatePlaylist(); } else if (CurrentPlaylistElement == -1) { if (mouseEvent.Y < _PlaylistElements[0].Background.Rect.Y && Offset == 0) - CBase.Playlist.MovePlaylistSong(ActivePlaylistID, _ChangeOrderSource, 0); + CBase.Playlist.MoveSong(ActivePlaylistID, _ChangeOrderSource, 0); else { if (_PlaylistElements.Count + Offset >= _PlaylistElementContents.Count) @@ -1080,7 +1080,7 @@ namespace VocaluxeLib.Menu } if (mouseEvent.Y > min) - CBase.Playlist.MovePlaylistSong(ActivePlaylistID, _ChangeOrderSource, _PlaylistElementContents.Count - 1); + CBase.Playlist.MoveSong(ActivePlaylistID, _ChangeOrderSource, _PlaylistElementContents.Count - 1); } } @@ -1134,35 +1134,33 @@ namespace VocaluxeLib.Menu public bool LoadPlaylist(int playlistID) { - if (playlistID > -1 && playlistID < CBase.Playlist.GetNumPlaylists()) + if (!CBase.Playlist.Exists(playlistID)) + return false; + ActivePlaylistID = playlistID; + _Theme.ButtonPlaylistName.Text.Text = CBase.Playlist.GetName(ActivePlaylistID); + _PlaylistElementContents.Clear(); + for (int i = 0; i < CBase.Playlist.GetSongCount(ActivePlaylistID); i++) { - ActivePlaylistID = playlistID; - _Theme.ButtonPlaylistName.Text.Text = CBase.Playlist.GetPlaylistName(ActivePlaylistID); - _PlaylistElementContents.Clear(); - for (int i = 0; i < CBase.Playlist.GetPlaylistSongCount(ActivePlaylistID); i++) - { - var pec = new CPlaylistElementContent - { - SongID = CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).SongID, - Modes = CBase.Songs.GetSongByID(CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).SongID).AvailableGameModes, - Mode = CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).GameMode - }; - _PlaylistElementContents.Add(pec); - } - Update(); - return true; + var pec = new CPlaylistElementContent + { + SongID = CBase.Playlist.GetSong(ActivePlaylistID, i).SongID, + Modes = CBase.Songs.GetSongByID(CBase.Playlist.GetSong(ActivePlaylistID, i).SongID).AvailableGameModes, + Mode = CBase.Playlist.GetSong(ActivePlaylistID, i).GameMode + }; + _PlaylistElementContents.Add(pec); } - return false; + Update(); + return true; } public void UpdatePlaylist() { _PlaylistElementContents.Clear(); - for (int i = 0; i < CBase.Playlist.GetPlaylistSongCount(ActivePlaylistID); i++) + for (int i = 0; i < CBase.Playlist.GetSongCount(ActivePlaylistID); i++) { - var pec = new CPlaylistElementContent {SongID = CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).SongID}; + var pec = new CPlaylistElementContent {SongID = CBase.Playlist.GetSong(ActivePlaylistID, i).SongID}; pec.Modes = CBase.Songs.GetSongByID(pec.SongID).AvailableGameModes; - pec.Mode = CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).GameMode; + pec.Mode = CBase.Playlist.GetSong(ActivePlaylistID, i).GameMode; _PlaylistElementContents.Add(pec); } @@ -1181,10 +1179,10 @@ namespace VocaluxeLib.Menu CBase.Game.Reset(); CBase.Game.ClearSongs(); - if (ActivePlaylistID > -1 && ActivePlaylistID < CBase.Playlist.GetNumPlaylists()) + if (CBase.Playlist.Exists(ActivePlaylistID)) { - for (int i = 0; i < CBase.Playlist.GetPlaylistSongCount(ActivePlaylistID); i++) - CBase.Game.AddSong(CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).SongID, CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).GameMode); + for (int i = 0; i < CBase.Playlist.GetSongCount(ActivePlaylistID); i++) + CBase.Game.AddSong(CBase.Playlist.GetSong(ActivePlaylistID, i).SongID, CBase.Playlist.GetSong(ActivePlaylistID, i).GameMode); if (CBase.Game.GetNumSongs() > 0) CBase.Graphics.FadeTo(EScreens.ScreenNames); //TODO: What is if someone uses that in PartyMode? } @@ -1195,7 +1193,7 @@ namespace VocaluxeLib.Menu CBase.Game.Reset(); CBase.Game.ClearSongs(); - CBase.Game.AddSong(CBase.Playlist.GetPlaylistSong(ActivePlaylistID, selected).SongID, CBase.Playlist.GetPlaylistSong(ActivePlaylistID, selected).GameMode); + CBase.Game.AddSong(CBase.Playlist.GetSong(ActivePlaylistID, selected).SongID, CBase.Playlist.GetSong(ActivePlaylistID, selected).GameMode); if (CBase.Game.GetNumSongs() > 0) CBase.Graphics.FadeTo(EScreens.ScreenNames); @@ -1203,7 +1201,7 @@ namespace VocaluxeLib.Menu public void Update() { - if (ActivePlaylistID > -1 && ActivePlaylistID < CBase.Playlist.GetNumPlaylists()) + if (CBase.Playlist.Exists(ActivePlaylistID)) { for (int i = 0; i < _PlaylistElements.Count; i++) { diff --git a/VocaluxeLib/Menu/CStatic.cs b/VocaluxeLib/Menu/CStatic.cs index 24b9b56c..327dfc14 100644 --- a/VocaluxeLib/Menu/CStatic.cs +++ b/VocaluxeLib/Menu/CStatic.cs @@ -188,43 +188,20 @@ namespace VocaluxeLib.Menu public void Draw(bool forceDraw = false) { - Draw(1f, Rect.Z, Aspect, forceDraw); + Draw(Aspect, 1f, 0f, forceDraw); } - public void Draw(EAspect aspect) - { - Draw(1f, Rect.Z, aspect); - } - - public void Draw(float scale, EAspect aspect) - { - Draw(scale, Rect.Z, aspect); - } - - public void Draw(float scale, float z, EAspect aspect, bool forceDraw = false) + public void Draw(EAspect aspect, float scale = 1f, float zModify = 0f, bool forceDraw = false) { CTexture texture = Texture ?? new CTexture((int)Rect.W, (int)Rect.H); - var bounds = new SRectF( - Rect.X - Rect.W * (scale - 1f), - Rect.Y - Rect.H * (scale - 1f), - Rect.W + 2 * Rect.W * (scale - 1f), - Rect.H + 2 * Rect.H * (scale - 1f), - z); - - SRectF rect = bounds; - + SRectF bounds = Rect.Scale(scale); + SRectF rect; if (aspect != EAspect.Stretch) - { - var bounds2 = new RectangleF(bounds.X, bounds.Y, bounds.W, bounds.H); - RectangleF rect2; - CHelper.SetRect(bounds2, out rect2, texture.OrigAspect, aspect); - - rect.X = rect2.X; - rect.Y = rect2.Y; - rect.W = rect2.Width; - rect.H = rect2.Height; - } + CHelper.SetRect(bounds, out rect, texture.OrigAspect, aspect); + else + rect = bounds; + rect.Z = Rect.Z + zModify; var color = new SColorF(Color.R, Color.G, Color.B, Color.A * Alpha); if (Visible || forceDraw || (CBase.Settings.GetProgramState() == EProgramState.EditTheme)) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenu.cs b/VocaluxeLib/Menu/SongMenu/CSongMenu.cs index 84e729b6..74bac712 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenu.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenu.cs @@ -33,16 +33,29 @@ namespace VocaluxeLib.Menu.SongMenu _CreateSongMenu(); } + #region ISongMenu public bool Selected { - get { return _SongMenu.IsSelected(); } - set { _SongMenu.SetSelected(value); } + get { return _SongMenu.Selected; } + set { _SongMenu.Selected = value; } } public bool Visible { - get { return _SongMenu.IsVisible(); } - set { _SongMenu.SetVisible(value); } + get { return _SongMenu.Visible; } + set { _SongMenu.Visible = value; } + } + + public bool Active + { + get { return _SongMenu.Active; } + set { _SongMenu.Active = value; } + } + + public bool SmallView + { + get { return _SongMenu.SmallView; } + set { _SongMenu.SmallView = value; } } public SRectF Rect @@ -50,7 +63,6 @@ namespace VocaluxeLib.Menu.SongMenu get { return _SongMenu.Rect; } } - #region ISongMenu public void Update(SScreenSongOptions songOptions) { _SongMenu.Update(songOptions); @@ -66,14 +78,14 @@ namespace VocaluxeLib.Menu.SongMenu _SongMenu.OnHide(); } - public void HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions songOptions) + public bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options) { - _SongMenu.HandleInput(ref keyEvent, songOptions); + return _SongMenu.HandleInput(ref keyEvent, options); } - public void HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions) + public bool HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions) { - _SongMenu.HandleMouse(ref mouseEvent, songOptions); + return _SongMenu.HandleMouse(ref mouseEvent, songOptions); } public void Draw() @@ -81,24 +93,19 @@ namespace VocaluxeLib.Menu.SongMenu _SongMenu.Draw(); } - public bool IsActive() + public bool IsMouseOverSelectedSong(SMouseEvent mEvent) { - return _SongMenu.IsActive(); + return _SongMenu.IsMouseOverSelectedSong(mEvent); } - public void SetActive(bool active) + public int GetPreviewSongNr() { - _SongMenu.SetActive(active); + return _SongMenu.GetPreviewSongNr(); } - public bool IsMouseOverActualSelection(SMouseEvent mEvent) + public int GetSelectedSongNr() { - return _SongMenu.IsMouseOverActualSelection(mEvent); - } - - public int GetSelectedSong() - { - return _SongMenu.GetSelectedSong(); + return _SongMenu.GetSelectedSongNr(); } public CStatic GetSelectedSongCover() @@ -121,44 +128,14 @@ namespace VocaluxeLib.Menu.SongMenu _SongMenu.SetSelectedCategory(categoryNr); } - public bool EnterCurrentCategory() + public bool EnterSelectedCategory() { - return _SongMenu.EnterCurrentCategory(); + return _SongMenu.EnterSelectedCategory(); } - public int GetActualSelection() + public int GetPreviewSong() { - return _SongMenu.GetActualSelection(); - } - - public bool IsSelected() - { - return _SongMenu.IsSelected(); - } - - public void SetSelected(bool selected) - { - _SongMenu.SetSelected(selected); - } - - public bool IsVisible() - { - return _SongMenu.IsVisible(); - } - - public void SetVisible(bool visible) - { - _SongMenu.SetVisible(visible); - } - - public bool IsSmallView() - { - return _SongMenu.IsSmallView(); - } - - public void SetSmallView(bool smallView) - { - _SongMenu.SetSmallView(smallView); + return _SongMenu.GetPreviewSong(); } #endregion ISongMenu diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuBook.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuBook.cs index f1a372fa..a7b0510c 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuBook.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuBook.cs @@ -15,11 +15,33 @@ // along with Vocaluxe. If not, see . #endregion +using VocaluxeLib.PartyModes; + namespace VocaluxeLib.Menu.SongMenu { class CSongMenuBook : CSongMenuFramework { public CSongMenuBook(int partyModeID) : base(partyModeID) {} + + public override float SelectedTileZoomFactor + { + get { return 1.2f; } + } + + public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options) + { + return false; + } + + public override bool HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions) + { + return false; + } + + public override CStatic GetSelectedSongCover() + { + return null; + } } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuDreidel.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuDreidel.cs index 14a668ed..318b053b 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuDreidel.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuDreidel.cs @@ -15,6 +15,8 @@ // along with Vocaluxe. If not, see . #endregion +using VocaluxeLib.PartyModes; + namespace VocaluxeLib.Menu.SongMenu { class CSongMenuDreidel : CSongMenuFramework @@ -30,13 +32,6 @@ namespace VocaluxeLib.Menu.SongMenu private CText _Artist; private CText _Title; private CText _SongLength; - - private int _actualSelection = -1; - - public override int GetActualSelection() - { - return _actualSelection; - } */ public CSongMenuDreidel(int partyModeID) @@ -59,5 +54,25 @@ namespace VocaluxeLib.Menu.SongMenu } // ReSharper restore RedundantOverridenMember + + public override float SelectedTileZoomFactor + { + get { return 1.2f; } + } + + public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options) + { + return false; + } + + public override bool HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions) + { + return false; + } + + public override CStatic GetSelectedSongCover() + { + return null; + } } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index e7f260f9..7ab54122 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -16,7 +16,7 @@ #endregion using System; -using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Xml; using VocaluxeLib.Draw; @@ -98,81 +98,65 @@ namespace VocaluxeLib.Menu.SongMenu protected SThemeSongMenu _Theme; private bool _ThemeLoaded; - private CFading _VideoFading; - private readonly List _Streams = new List(); - protected CTexture _Vidtex; - protected bool _Initialized; - protected int _LastKnownNumSongs; - protected int _LastKnownCategory = -1; - protected SColorF _Color; - - protected bool _Active; - - protected float _MaxVolume = 100f; - - //the real selected song for singing - protected int _Locked { get; set; } - - protected int _PreviewIdInternal = -1; - protected virtual int _PreviewId + private int _PreviewNrInternal = -1; + protected virtual int _PreviewNr { - get { return _PreviewIdInternal; } + get { return _PreviewNrInternal; } set { - //Do this first, otherwhise song will restart - _PlaySong(value); - _PreviewIdInternal = value; + if (_PreviewNrInternal == value) + return; + if (CBase.Songs.IsInCategory()) + { + if (value >= CBase.Songs.GetNumSongsVisible()) + value = -1; + _PlaySong(value); + } + else if (value >= CBase.Songs.GetNumCategories()) + { + value = -1; + CBase.BackgroundMusic.Stop(); + } + + _PreviewNrInternal = value; } } - protected int _PreviewSongStream { get; private set; } + private SColorF _ColorInternal; + protected SColorF _Color + { + get { return _ColorInternal; } + } - protected int _PreviewVideoStream { get; private set; } + public int GetPreviewSong() + { + return _PreviewNr; + } public SRectF Rect { get; protected set; } - - public SColorF Color - { - get { return _Color; } - } - - public virtual int GetActualSelection() - { - return -1; - } - + public bool Active { get; set; } private bool _Selected; - private bool _Visible = true; - - public bool IsSelected() + public bool Selected { - return _Selected; - } - - public void SetSelected(bool selected) - { - _Selected = selected; - SetActive(selected); - } - - public bool IsVisible() - { - return _Visible; - } - - public void SetVisible(bool visible) - { - _Visible = visible; + get { return _Selected; } + set + { + _Selected = value; + Active = value; + } } + public bool Visible { get; set; } + public virtual bool SmallView { get; set; } + public abstract float SelectedTileZoomFactor { get; } + // This is the nr of the current selection (song or category) + protected virtual int _SelectionNr { get; set; } protected CSongMenuFramework(int partyModeID) { + Visible = true; _PartyModeID = partyModeID; - _PreviewVideoStream = -1; - _PreviewSongStream = -1; - _Locked = -1; _Theme = new SThemeSongMenu { SongMenuTileBoard = @@ -190,6 +174,7 @@ namespace VocaluxeLib.Menu.SongMenu }; } + #region Theme public string GetThemeName() { return _Theme.Name; @@ -208,13 +193,13 @@ namespace VocaluxeLib.Menu.SongMenu _ThemeLoaded &= xmlReader.GetValue(item + "/MedleyTagIcon", out _Theme.MedleyTagIcon, String.Empty); if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) - _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out _Color); + _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out _ColorInternal); else { - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/R", ref _Color.R); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/G", ref _Color.G); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/B", ref _Color.B); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/A", ref _Color.A); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/R", ref _ColorInternal.R); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/G", ref _ColorInternal.G); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/B", ref _ColorInternal.B); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/A", ref _ColorInternal.A); } #region SongMenuTileBoard @@ -352,115 +337,88 @@ namespace VocaluxeLib.Menu.SongMenu } return false; } + #endregion Theme public virtual void Init() { - _Reset(); + _ResetPreview(false); _Initialized = true; } - public void UpdateRect(SRectF rect) - { - Rect = rect; - Init(); - } - public virtual void Update(SScreenSongOptions songOptions) { if (!_Initialized) return; - - if (_Streams.Count <= 0 || _PreviewVideoStream == -1) - return; - - if (CBase.Video.IsFinished(_PreviewVideoStream) || CBase.Sound.IsFinished(_PreviewSongStream)) - { - CBase.Video.Close(_PreviewVideoStream); - _PreviewVideoStream = -1; - return; - } - - float time = CBase.Sound.GetPosition(_PreviewSongStream); - - float vtime; - if (CBase.Video.GetFrame(_PreviewVideoStream, ref _Vidtex, time, out vtime)) - { - if (_Vidtex != null) - { - if (_VideoFading != null) - { - bool finished; - _Vidtex.Color.A = _VideoFading.GetValue(out finished); - if (finished) - _VideoFading = null; - } - } - } - } - - public virtual void OnShow() - { - _PreviewSongStream = -1; - _Vidtex = null; } + public virtual void OnShow() {} + public virtual void OnHide() { - _Reset(); + if(CBase.Graphics.GetNextScreen() != EScreens.ScreenNames) + _ResetPreview(); } - public virtual void HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions songOptions) {} + public abstract bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options); - public virtual void HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions) {} + public abstract bool HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions); public virtual void Draw() { - if (!_Initialized || !_Visible) + if (!_Initialized || !Visible) return; - if (_PreviewVideoStream != -1) - CBase.Drawing.DrawTexture(_Vidtex, new SRectF(0, 0, 1280, 720, 0)); + if (CBase.BackgroundMusic.IsPlaying()) + CBase.Drawing.DrawTexture(CBase.BackgroundMusic.GetVideoTexture(), new SRectF(0, 0, 1280, 720, 0)); } - public virtual bool IsActive() + public bool IsMouseOverSelectedSong(SMouseEvent mEvent) { - return _Active; + CStatic selCov = GetSelectedSongCover(); + return selCov != null && CHelper.IsInBounds(selCov.Rect.Scale(SelectedTileZoomFactor), mEvent); } - public virtual void SetActive(bool active) - { - _Active = active; - } - - public virtual bool IsMouseOverActualSelection(SMouseEvent mEvent) - { - return false; - } - - public virtual int GetSelectedSong() + public int GetPreviewSongNr() { + if (CBase.Songs.IsInCategory()) + return _PreviewNr; return -1; } - public virtual CStatic GetSelectedSongCover() - { - return new CStatic(_PartyModeID); - } - - public virtual int GetSelectedCategory() + public int GetSelectedSongNr() { + if (CBase.Songs.IsInCategory()) + return _SelectionNr; return -1; } - public virtual void SetSelectedSong(int visibleSongNr) {} + public abstract CStatic GetSelectedSongCover(); - public virtual void SetSelectedCategory(int categoryNr) {} - - public virtual void SetSmallView(bool smallView) {} - - public virtual bool IsSmallView() + public int GetSelectedCategory() { - return false; + if (!CBase.Songs.IsInCategory()) + return _SelectionNr; + return -1; + } + + public void SetSelectedSong(int visibleSongNr) + { + Debug.Assert(CBase.Songs.IsInCategory()); + if (visibleSongNr >= 0 && visibleSongNr < CBase.Songs.GetNumSongsVisible()) + _SelectionNr = visibleSongNr; + else + _SelectionNr = -1; + _PreviewNr = _SelectionNr; + } + + public void SetSelectedCategory(int categoryNr) + { + Debug.Assert(!CBase.Songs.IsInCategory()); + if (categoryNr >= 0 && categoryNr < CBase.Songs.GetNumCategories()) + _SelectionNr = categoryNr; + else + _SelectionNr = -1; + _PreviewNr = _SelectionNr; } public virtual void UnloadTextures() {} @@ -470,7 +428,7 @@ namespace VocaluxeLib.Menu.SongMenu Init(); if (!String.IsNullOrEmpty(_Theme.ColorName)) - _Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); + _ColorInternal = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); } public void ReloadTextures() @@ -479,29 +437,29 @@ namespace VocaluxeLib.Menu.SongMenu LoadTextures(); } - public bool EnterCurrentCategory() + public bool EnterSelectedCategory() { if (!_Initialized) return false; - if (CBase.Songs.IsInCategory() || _PreviewId < 0 || _PreviewId >= CBase.Songs.GetNumCategories()) + if (CBase.Songs.IsInCategory() || GetSelectedCategory() < 0 || GetSelectedCategory() >= CBase.Songs.GetNumCategories()) return false; - _EnterCategory(_PreviewId); + _EnterCategory(GetSelectedCategory()); return true; } - protected virtual void _EnterCategory(int category) + protected virtual void _EnterCategory(int categoryNr) { if (!_Initialized) return; - if (category >= CBase.Songs.GetNumCategories()) + if (categoryNr >= CBase.Songs.GetNumCategories()) return; - _Reset(); - CBase.Songs.SetCategory(category); + _ResetPreview(false); + CBase.Songs.SetCategory(categoryNr); } - protected virtual void _ShowCategories() + protected virtual void _LeaveCategory() { if (!_Initialized) return; @@ -509,74 +467,50 @@ namespace VocaluxeLib.Menu.SongMenu if (!CBase.Songs.IsInCategory()) return; - _Reset(); + _ResetPreview(); CBase.Songs.SetCategory(-1); } - protected void _PlaySong(int nr) + private void _PlaySong(int nr) { - if (CBase.Songs.IsInCategory() && (_PreviewId != nr || _Streams.Count == 0)) - { - _Reset(); + _PreviewNrInternal = -1; - CSong song = CBase.Songs.GetVisibleSong(nr); - if (song == null) - return; + CSong song = CBase.Songs.GetVisibleSong(nr); + if (song == null) + return; - //TODO: Using prescan here causes Vocaluxe to hang a bit on loading the song but we need the length below - int stream = CBase.Sound.Load(Path.Combine(song.Folder, song.MP3FileName), true, true); - - float startposition = song.Preview.StartTime; - float length = CBase.Sound.GetLength(stream); - - if (song.Preview.Source == EDataSource.None) - startposition = length / 4f; - else if (startposition > length - 5f) - startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f)); - - if (startposition >= 0.5f) - startposition -= 0.5f; - - CBase.Sound.SetPosition(stream, startposition); - CBase.Sound.Play(stream); - CBase.Sound.SetStreamVolume(stream, 0f); - CBase.Sound.Fade(stream, 100f, 3f); - _Streams.Add(stream); - _PreviewSongStream = stream; - - _PreviewIdInternal = nr; - - if (song.VideoFileName != "" && CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON) - { - _PreviewVideoStream = CBase.Video.Load(Path.Combine(song.Folder, song.VideoFileName)); - if (_PreviewVideoStream == -1) - return; - CBase.Video.SetLoop(_PreviewVideoStream); - CBase.Video.Skip(_PreviewVideoStream, startposition, song.VideoGap); - _VideoFading = new CFading(0f, 1f, 3f); - } - } + CBase.BackgroundMusic.LoadPreview(song); } - protected void _Reset() + protected void _ResetPreview(bool playBGagain = true) { - foreach (int stream in _Streams) - CBase.Sound.FadeAndClose(stream, 0f, 0.75f); - _Streams.Clear(); + if (_PreviewNrInternal == -1) + return; - CBase.Video.Close(_PreviewVideoStream); - _PreviewVideoStream = -1; + CBase.BackgroundMusic.StopPreview(); - CBase.Drawing.RemoveTexture(ref _Vidtex); + if (playBGagain) + CBase.BackgroundMusic.Play(); + + //Make sure we don't have a preview here otherwise a change won't be recognized + //(e.g. leave a category with one song and set preview to 0 --> previewOld=previewNew=0 --> No change --> Old data shown + //Use internal nr because this function gets called from withing setPreviewNr + _PreviewNrInternal = -1; } #region ThemeEdit + private void _UpdateRect(SRectF rect) + { + Rect = rect; + Init(); + } + public void MoveElement(int stepX, int stepY) { SRectF rect = Rect; rect.X += stepX; rect.Y += stepY; - UpdateRect(rect); + _UpdateRect(rect); } public void ResizeElement(int stepW, int stepH) @@ -591,7 +525,7 @@ namespace VocaluxeLib.Menu.SongMenu if (rect.H < 100) rect.H = 100; - UpdateRect(rect); + _UpdateRect(rect); } #endregion ThemeEdit } diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuList.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuList.cs index 655fa404..9c5b7a6e 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuList.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuList.cs @@ -15,11 +15,30 @@ // along with Vocaluxe. If not, see . #endregion +using VocaluxeLib.PartyModes; + namespace VocaluxeLib.Menu.SongMenu { class CSongMenuList : CSongMenuFramework { public CSongMenuList(int partyModeID) : base(partyModeID) {} + + public override float SelectedTileZoomFactor + { + get { return 1.2f; } + } + + public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options) + { + return false; + } + + public override bool HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions) { return false; } + + public override CStatic GetSelectedSongCover() + { + return null; + } } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 1fef5094..b33a1d16 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -37,8 +37,8 @@ namespace VocaluxeLib.Menu.SongMenu private CStatic _MedleyCalcIcon; private CStatic _MedleyTagIcon; - private CTexture _CoverBigTexture; - private CTexture _CoverTexture; + private CTexture _CoverBigBGTexture; + private CTexture _CoverBGTexture; private CText _Artist; private CText _Title; @@ -53,63 +53,80 @@ namespace VocaluxeLib.Menu.SongMenu private int _TileW; private int _TileH; - private int _Offset = -1; - private int _ActualSelection = -1; - - private bool _SmallView; + // Offset is the song or categoryNr of the tile in the left upper corner + private int _Offset; private float _Length = -1f; + private int _LastKnownElements; + private int _LastKnownCategory; + + private bool _MouseWasInRect; + + public override float SelectedTileZoomFactor + { + get { return 1.2f; } + } + + protected override int _SelectionNr + { + set + { + int max = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories(); + base._SelectionNr = value.Clamp(-1, max - 1, true); + //Update list in case we scrolled + _UpdateList(); + + _UpdateTileSelection(); + } + } + + private void _UpdateTileSelection() + { + foreach (CStatic tile in _Tiles) + tile.Selected = false; + int tileNr = _SelectionNr - _Offset; + if (tileNr >= 0 && tileNr < _Tiles.Count) + _Tiles[tileNr].Selected = true; + } + + public override bool SmallView + { + set + { + if (SmallView == value) + return; + base.SmallView = value; + _InitTiles(); + _UpdateList(true); + _UpdateTileSelection(); + } + } public CSongMenuTileBoard(int partyModeID) : base(partyModeID) {} - protected override int _PreviewId + protected override int _PreviewNr { set { - if (value == base._PreviewId) + if (value == base._PreviewNr) + { + if (!CBase.BackgroundMusic.IsPlaying() && value != -1) + CBase.BackgroundMusic.PlayPreview(); return; - base._PreviewId = value; + } + base._PreviewNr = value; _UpdatePreview(); } } - public override int GetActualSelection() - { - return _ActualSelection; - } - public override void Init() { base.Init(); - Rect = _Theme.SongMenuTileBoard.TileRect; - - _NumW = _Theme.SongMenuTileBoard.NumW; - _NumH = _Theme.SongMenuTileBoard.NumH; _SpaceW = _Theme.SongMenuTileBoard.SpaceW; _SpaceH = _Theme.SongMenuTileBoard.SpaceH; - _TileW = (int)((_Theme.SongMenuTileBoard.TileRect.W - _SpaceW * (_NumW - 1)) / _NumW); - _TileH = (int)((_Theme.SongMenuTileBoard.TileRect.H - _SpaceH * (_NumH - 1)) / _NumH); - - _CoverTexture = CBase.Theme.GetSkinTexture(_Theme.CoverBackgroundName, _PartyModeID); - _CoverBigTexture = CBase.Theme.GetSkinTexture(_Theme.CoverBigBackgroundName, _PartyModeID); - - _Tiles = new List(); - for (int i = 0; i < _NumH; i++) - { - for (int j = 0; j < _NumW; j++) - { - var rect = new SRectF(_Theme.SongMenuTileBoard.TileRect.X + j * (_TileW + _SpaceW), - _Theme.SongMenuTileBoard.TileRect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, Rect.Z); - var tile = new CStatic(_PartyModeID, _CoverTexture, Color, rect); - _Tiles.Add(tile); - } - } - - _ScrollRect = new SRectF(0, 0, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), _Theme.SongMenuTileBoard.TileRect.Z); - _CoverBig = _Theme.SongMenuTileBoard.StaticCoverBig; _TextBG = _Theme.SongMenuTileBoard.StaticTextBG; _DuetIcon = _Theme.SongMenuTileBoard.StaticDuetIcon; @@ -121,8 +138,42 @@ namespace VocaluxeLib.Menu.SongMenu _Title = _Theme.SongMenuTileBoard.TextTitle; _SongLength = _Theme.SongMenuTileBoard.TextSongLength; - _PreviewId = -1; - _Offset = 0; + _PreviewNr = -1; + _InitTiles(); + } + + private void _InitTiles() + { + if (SmallView) + { + _NumH = _Theme.SongMenuTileBoard.NumHsmall; + _NumW = _Theme.SongMenuTileBoard.NumWsmall; + Rect = _Theme.SongMenuTileBoard.TileRectSmall; + } + else + { + _NumH = _Theme.SongMenuTileBoard.NumH; + _NumW = _Theme.SongMenuTileBoard.NumW; + Rect = _Theme.SongMenuTileBoard.TileRect; + } + + _TileW = (int)((Rect.W - _SpaceW * (_NumW - 1)) / _NumW); + _TileH = (int)((Rect.H - _SpaceH * (_NumH - 1)) / _NumH); + + _CoverBGTexture = CBase.Theme.GetSkinTexture(_Theme.CoverBackgroundName, _PartyModeID); + _CoverBigBGTexture = CBase.Theme.GetSkinTexture(_Theme.CoverBigBackgroundName, _PartyModeID); + + _Tiles = new List(); + for (int i = 0; i < _NumH; i++) + { + for (int j = 0; j < _NumW; j++) + { + var rect = new SRectF(Rect.X + j * (_TileW + _SpaceW), Rect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, Rect.Z); + var tile = new CStatic(_PartyModeID, _CoverBGTexture, _Color, rect); + _Tiles.Add(tile); + } + } + _ScrollRect = new SRectF(0, 0, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), Rect.Z); } public override void Update(SScreenSongOptions songOptions) @@ -130,21 +181,16 @@ namespace VocaluxeLib.Menu.SongMenu base.Update(songOptions); if (songOptions.Selection.RandomOnly) - { - _Locked = _PreviewId; - _ActualSelection = _PreviewId; - for (int i = 0; i < _Tiles.Count; i++) - _Tiles[i].Selected = _Locked == i + _Offset; - } + _PreviewNr = _SelectionNr; - if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.Sound.GetLength(_PreviewSongStream) > 0) - _UpdateLength(CBase.Songs.GetVisibleSong(_PreviewId)); + if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.BackgroundMusic.GetLength() > 0) + _UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr)); } private void _UpdatePreview() { //First hide everything so we just have to set what we actually want - _CoverBig.Texture = _CoverBigTexture; + _CoverBig.Texture = _CoverBigBGTexture; _Artist.Text = String.Empty; _Title.Text = String.Empty; _SongLength.Text = String.Empty; @@ -155,12 +201,12 @@ namespace VocaluxeLib.Menu.SongMenu _Length = -1f; //Check if nothing is selected (for preview) - if (_PreviewId < 0) + if (_PreviewNr < 0) return; if (CBase.Songs.IsInCategory()) { - CSong song = CBase.Songs.GetVisibleSong(_PreviewId); + CSong song = CBase.Songs.GetVisibleSong(_PreviewNr); //Check if we have a valid song (song still visible, index >=0 etc is checked by framework) if (song == null) { @@ -185,7 +231,7 @@ namespace VocaluxeLib.Menu.SongMenu } else { - CCategory category = CBase.Songs.GetCategory(_PreviewId); + CCategory category = CBase.Songs.GetCategory(_PreviewNr); //Check if we have a valid category if (category == null) return; @@ -202,7 +248,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (song == null) return; - float time = CBase.Sound.GetLength(_PreviewSongStream); + float time = CBase.BackgroundMusic.GetLength(); if (Math.Abs(song.Finish) > 0.001) time = song.Finish; @@ -221,272 +267,223 @@ namespace VocaluxeLib.Menu.SongMenu public override void OnShow() { - if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0 && !CBase.Songs.IsInCategory()) - _EnterCategory(0); - _ActualSelection = -1; - _Locked = -1; - _UpdateList(0, true); - //AfterCategoryChange(); - SetSelectedSong(_PreviewId); - _AfterCategoryChange(); - - if (_PreviewId < 0) + _LastKnownElements = -1; //Force refresh of list + if (!CBase.Songs.IsInCategory()) { - _PreviewId = 0; - _Locked = 0; - } - - if (CBase.Songs.GetNumSongsVisible() == 0 && CBase.Songs.GetSearchFilter() != "") - { - _PreviewId = -1; - _Locked = -1; + if ((CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0) || CBase.Songs.GetNumCategories() == 1) + _EnterCategory(0); } + if (CBase.Songs.IsInCategory()) + SetSelectedSong(_SelectionNr < 0 ? 0 : _SelectionNr); + else + SetSelectedCategory(_SelectionNr < 0 ? 0 : _SelectionNr); + _PreviewNr = _SelectionNr; + _UpdateListIfRequired(); } - public override void HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions songOptions) + public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options) { - base.HandleInput(ref keyEvent, songOptions); + if (keyEvent.KeyPressed) + return false; - if (!keyEvent.KeyPressed) + bool moveAllowed = !options.Selection.RandomOnly || (options.Selection.CategoryChangeAllowed && !CBase.Songs.IsInCategory()); + bool catChangePossible = CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && options.Selection.CategoryChangeAllowed; + + //If nothing selected set a reasonable default value + if (keyEvent.IsArrowKey() && moveAllowed && _SelectionNr < 0) + _SelectionNr = (_PreviewNr < 0) ? _Offset : _PreviewNr; + + switch (keyEvent.Key) { - if (!(keyEvent.Key == Keys.Left || keyEvent.Key == Keys.Right || keyEvent.Key == Keys.Up || keyEvent.Key == Keys.Down || - keyEvent.Key == Keys.Escape || keyEvent.Key == Keys.Back || keyEvent.Key == Keys.Enter || - keyEvent.Key == Keys.PageDown || keyEvent.Key == Keys.PageUp)) - return; - - bool sel = _Tiles.Any(tile => tile.Selected); - - if ((_Locked == -1 || !sel) && - (keyEvent.Key != Keys.Escape && keyEvent.Key != Keys.Back && keyEvent.Key != Keys.PageUp && keyEvent.Key != Keys.PageDown)) - { - if (_PreviewId > -1) - _Locked = _PreviewId; + case Keys.Enter: + if (CBase.Songs.IsInCategory()) + { + if (_SelectionNr >= 0 && _PreviewNr != _SelectionNr) + { + _PreviewNr = _SelectionNr; + keyEvent.Handled = true; + } + } else { - _Locked = 0; - _ActualSelection = 0; - _PreviewId = 0; - _UpdateList(0, true); + _EnterCategory(_PreviewNr); + keyEvent.Handled = true; } - } - else - { - switch (keyEvent.Key) + break; + + case Keys.Escape: + case Keys.Back: + if (CBase.Songs.IsInCategory() && catChangePossible) { - case Keys.Enter: - if (!CBase.Songs.IsInCategory()) - { - _EnterCategory(_PreviewId); - keyEvent.Handled = true; - } - else if (_ActualSelection > -1 && _PreviewId >= 0) - _Locked = _ActualSelection; - break; - - case Keys.Escape: - case Keys.Back: - if (CBase.Songs.IsInCategory() && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && songOptions.Selection.CategoryChangeAllowed) - { - _ShowCategories(); - keyEvent.Handled = true; - } - //else if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF) - //{ - // CGraphics.FadeTo(EScreens.ScreenMain); - //} - break; - - case Keys.PageUp: - if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && songOptions.Selection.CategoryChangeAllowed) - _PrevCategory(); - break; - - case Keys.PageDown: - if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && songOptions.Selection.CategoryChangeAllowed) - _NextCategory(); - break; - - case Keys.Left: - if (_Locked > 0 && (!songOptions.Selection.RandomOnly || songOptions.Selection.CategoryChangeAllowed && !CBase.Songs.IsInCategory())) - { - _Locked--; - _UpdateList(); - } - break; - - case Keys.Right: - if (!CBase.Songs.IsInCategory() && songOptions.Selection.CategoryChangeAllowed) - { - if (_Locked < CBase.Songs.GetNumCategories() - 1) - { - _Locked++; - _UpdateList(); - } - } - else - { - if (CBase.Songs.IsInCategory() && _Locked < CBase.Songs.GetNumSongsVisible() - 1 && !songOptions.Selection.RandomOnly) - { - _Locked++; - _UpdateList(); - } - } - break; - - case Keys.Up: - if (keyEvent.ModShift && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && songOptions.Selection.CategoryChangeAllowed) - { - _PrevCategory(); - break; - } - - if (_Locked > _NumW - 1 && - (!songOptions.Selection.RandomOnly || songOptions.Selection.CategoryChangeAllowed && !CBase.Songs.IsInCategory())) - { - _Locked -= _NumW; - _UpdateList(); - } - break; - - case Keys.Down: - if (keyEvent.ModShift && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && songOptions.Selection.CategoryChangeAllowed) - { - _NextCategory(); - break; - } - - if (!CBase.Songs.IsInCategory() && songOptions.Selection.CategoryChangeAllowed) - { - if (_Locked < CBase.Songs.GetNumCategories() - _NumW) - { - _Locked += _NumW; - _UpdateList(); - } - } - else if (_Locked < CBase.Songs.GetNumSongsVisible() - _NumW && !songOptions.Selection.RandomOnly) - { - _Locked += _NumW; - _UpdateList(); - } - break; + _LeaveCategory(); + keyEvent.Handled = true; } - } + break; - if (!keyEvent.Handled) - { - _ActualSelection = _Locked; - _PreviewId = _Locked; + case Keys.PageUp: + if (catChangePossible) + { + _PrevCategory(); + keyEvent.Handled = true; + } + break; - for (int i = 0; i < _Tiles.Count; i++) - _Tiles[i].Selected = _Locked == i + _Offset; - } + case Keys.PageDown: + if (catChangePossible) + { + _NextCategory(); + keyEvent.Handled = true; + } + break; + + case Keys.Left: + //Check for >0 so we do not allow selection of nothing (-1) + if (_SelectionNr > 0 && moveAllowed) + { + _SelectionNr--; + keyEvent.Handled = true; + } + break; + + case Keys.Right: + if (moveAllowed) + { + _SelectionNr++; + keyEvent.Handled = true; + } + break; + + case Keys.Up: + if (keyEvent.ModShift) + { + if (catChangePossible) + { + _PrevCategory(); + keyEvent.Handled = true; + } + } + else if (_SelectionNr >= _NumW && moveAllowed) + { + _SelectionNr -= _NumW; + keyEvent.Handled = true; + } + break; + + case Keys.Down: + if (keyEvent.ModShift) + { + if (catChangePossible) + { + _NextCategory(); + keyEvent.Handled = true; + } + } + else if (moveAllowed) + { + _SelectionNr += _NumW; + keyEvent.Handled = true; + } + break; } + if (!CBase.Songs.IsInCategory()) + _PreviewNr = _SelectionNr; + return keyEvent.Handled; } - public override void HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions) + public override bool HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions) { - base.HandleMouse(ref mouseEvent, songOptions); - - int i = 0; - bool sel = false; - int lastselection = _ActualSelection; - if (!songOptions.Selection.RandomOnly || (!CBase.Songs.IsInCategory() && songOptions.Selection.CategoryChangeAllowed)) { + if (mouseEvent.Wheel != 0 && CHelper.IsInBounds(_ScrollRect, mouseEvent)) + _UpdateList(_Offset + _NumW * mouseEvent.Wheel); + + int lastSelection = _SelectionNr; + int i = 0; + bool somethingSelected = false; foreach (CStatic tile in _Tiles) { - if (tile.Texture != _CoverTexture && CHelper.IsInBounds(tile.Rect, mouseEvent) && !sel) + if (tile.Texture != _CoverBGTexture && CHelper.IsInBounds(tile.Rect, mouseEvent)) { - if (mouseEvent.LB || !CBase.Songs.IsInCategory()) - { - if (_PreviewId == i + _Offset) - _Locked = _PreviewId; - else - { - _PreviewId = i + _Offset; - _Locked = -1; - } - } - tile.Selected = true; - _ActualSelection = i + _Offset; - sel = true; + somethingSelected = true; + _SelectionNr = i + _Offset; + if (!CBase.Songs.IsInCategory()) + _PreviewNr = i + _Offset; + break; } - else - tile.Selected = false; i++; } + //Reset selection only if we moved out of the rect to avoid loosing it when selecting random songs + if (_MouseWasInRect && !somethingSelected) + _SelectionNr = -1; + if (mouseEvent.Sender == ESender.WiiMote && _SelectionNr != lastSelection && _SelectionNr != -1) + CBase.Controller.SetRumble(0.050f); } - else - sel = true; + _MouseWasInRect = CHelper.IsInBounds(Rect, mouseEvent); - if (mouseEvent.Sender == ESender.WiiMote && _ActualSelection != lastselection && _ActualSelection != -1) - CBase.Controller.SetRumble(0.050f); - - if (!sel) - _ActualSelection = -1; - - if (mouseEvent.RB && (CBase.Songs.GetNumCategories() > 0) && CBase.Songs.IsInCategory() && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && - songOptions.Selection.CategoryChangeAllowed) + if (mouseEvent.RB) { - _ShowCategories(); - mouseEvent.Handled = true; - return; - } - if (mouseEvent.RB && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && !songOptions.Selection.PartyMode) - CBase.Graphics.FadeTo(EScreens.ScreenMain); - else if (_PreviewId != -1 && mouseEvent.LB && CBase.Songs.GetCurrentCategoryIndex() != -1 && !songOptions.Selection.PartyMode) - { - if (CHelper.IsInBounds(_CoverBig.Rect, mouseEvent) || CHelper.IsInBounds(_TextBG.Rect, mouseEvent)) - _Locked = _PreviewId; - } - else if (mouseEvent.LB && (!CBase.Songs.IsInCategory())) - { - foreach (CStatic tile in _Tiles) + if (CBase.Songs.IsInCategory() && CBase.Songs.GetNumCategories() > 0 && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && + songOptions.Selection.CategoryChangeAllowed) { - if (tile.Texture != _CoverTexture && CHelper.IsInBounds(tile.Rect, mouseEvent)) - { - _EnterCategory(_PreviewId); - mouseEvent.Handled = true; - return; - } + _LeaveCategory(); + return true; + } + if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && !songOptions.Selection.PartyMode) + { + CBase.Graphics.FadeTo(EScreens.ScreenMain); + return true; } } - - if (mouseEvent.Wheel != 0 && CHelper.IsInBounds(_ScrollRect, mouseEvent) && - (!songOptions.Selection.RandomOnly || !CBase.Songs.IsInCategory() && songOptions.Selection.CategoryChangeAllowed)) - _UpdateList(_Offset + _NumW * mouseEvent.Wheel); + else if (mouseEvent.LB) + { + if (_SelectionNr >= 0 && _MouseWasInRect) + { + if (CBase.Songs.IsInCategory()) + { + if (_PreviewNr == _SelectionNr) + return false; + _PreviewNr = _SelectionNr; + } + else + EnterSelectedCategory(); + return true; + } + } + return false; } public override void Draw() { foreach (CStatic tile in _Tiles) { - if (tile.Selected && _Active) - tile.Draw(1.2f, tile.Rect.Z - 0.1f, EAspect.Crop); + if (tile.Selected && Active) + tile.Draw(EAspect.Crop, SelectedTileZoomFactor, -0.1f); else { - EAspect aspect = (tile.Texture != _CoverTexture) ? EAspect.Crop : EAspect.Stretch; - tile.Draw(1f, tile.Rect.Z, aspect); + EAspect aspect = (tile.Texture != _CoverBGTexture) ? EAspect.Crop : EAspect.Stretch; + tile.Draw(aspect); } } _TextBG.Draw(); - if (_Vidtex != null && _PreviewVideoStream != -1) + CTexture vidtex = CBase.BackgroundMusic.IsPlayingPreview() ? CBase.BackgroundMusic.GetVideoTexture() : null; + + if (vidtex != null) { - if (_Vidtex.Color.A < 1) - _CoverBig.Draw(1f, EAspect.Crop); + if (vidtex.Color.A < 1) + _CoverBig.Draw(EAspect.Crop); var bounds = new RectangleF(_CoverBig.Rect.X, _CoverBig.Rect.Y, _CoverBig.Rect.W, _CoverBig.Rect.H); RectangleF rect; - CHelper.SetRect(bounds, out rect, _Vidtex.OrigAspect, EAspect.Crop); + CHelper.SetRect(bounds, out rect, vidtex.OrigAspect, EAspect.Crop); var vidRect = new SRectF(rect.X, rect.Y, rect.Width, rect.Height, _CoverBig.Rect.Z); var vidRectBounds = new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f); - CBase.Drawing.DrawTexture(_Vidtex, vidRect, _Vidtex.Color, vidRectBounds); - CBase.Drawing.DrawTextureReflection(_Vidtex, vidRect, _Vidtex.Color, vidRectBounds, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight); + CBase.Drawing.DrawTexture(vidtex, vidRect, vidtex.Color, vidRectBounds); + CBase.Drawing.DrawTextureReflection(vidtex, vidRect, vidtex.Color, vidRectBounds, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight); } else - _CoverBig.Draw(1f, EAspect.Crop); + _CoverBig.Draw(EAspect.Crop); _Artist.Draw(); @@ -498,104 +495,30 @@ namespace VocaluxeLib.Menu.SongMenu _MedleyTagIcon.Draw(); } - public override int GetSelectedSong() - { - return _Locked; - } - - public override bool IsMouseOverActualSelection(SMouseEvent mEvent) - { - CStatic selCov = GetSelectedSongCover(); - if (selCov.Texture == null) - return false; - var rect = new SRectF(selCov.Rect.X - selCov.Rect.W * 0.2f, selCov.Rect.Y - selCov.Rect.H * 0.2f, selCov.Rect.W * 1.2f, selCov.Rect.H * 1.2f, selCov.Rect.Z); - return CHelper.IsInBounds(rect, mEvent); - } - public override CStatic GetSelectedSongCover() { - foreach (CStatic tile in _Tiles) - { - if (tile.Selected) - return new CStatic(tile); - } - return new CStatic(_PartyModeID); + return _Tiles.FirstOrDefault(tile => tile.Selected); } - private void _SetSelectedTile(int itemNr) + protected override void _EnterCategory(int categoryNr) { - bool sel = _Tiles.Any(tile => tile.Selected); + base._EnterCategory(categoryNr); - if (_Locked == -1 || !sel) - { - if (_PreviewId > -1) - _Locked = _PreviewId; - else - { - _Locked = 0; - _ActualSelection = 0; - _PreviewId = 0; - _UpdateList(0, true); - } - } - - foreach (CStatic tile in _Tiles) - tile.Selected = false; - - _PreviewId = itemNr; - _Locked = itemNr; - - _UpdateList(true); - - _PreviewId = _Locked; - _ActualSelection = _Locked; - - if (_Locked - _Offset >= 0) - _Tiles[_Locked - _Offset].Selected = true; + SetSelectedSong(0); + _UpdateListIfRequired(); } - public override void SetSelectedSong(int visibleSongNr) + protected override void _LeaveCategory() { - _PlaySong(visibleSongNr); - base.SetSelectedSong(visibleSongNr); + base._LeaveCategory(); - if (visibleSongNr >= 0 && visibleSongNr < CBase.Songs.GetNumSongsVisible()) - _SetSelectedTile(visibleSongNr); - } - - public override void SetSelectedCategory(int categoryNr) - { - base.SetSelectedCategory(categoryNr); - - if (categoryNr >= 0 && categoryNr < CBase.Songs.GetNumCategories()) - _SetSelectedTile(categoryNr); - } - - protected override void _EnterCategory(int cat) - { - base._EnterCategory(cat); - - _PreviewId = 0; - _Locked = -1; - _ActualSelection = 0; - _AfterCategoryChange(); - _Locked = 0; - } - - protected override void _ShowCategories() - { - base._ShowCategories(); - - _PreviewId = 0; - _Locked = -1; - _ActualSelection = 0; - _AfterCategoryChange(); - _Locked = 0; + SetSelectedCategory(0); + _UpdateListIfRequired(); } private void _NextCategory() { - if (CBase.Songs.GetCurrentCategoryIndex() > -1) + if (CBase.Songs.IsInCategory()) { CBase.Songs.NextCategory(); _EnterCategory(CBase.Songs.GetCurrentCategoryIndex()); @@ -604,33 +527,40 @@ namespace VocaluxeLib.Menu.SongMenu private void _PrevCategory() { - if (CBase.Songs.GetCurrentCategoryIndex() > -1) + if (CBase.Songs.IsInCategory()) { CBase.Songs.PrevCategory(); _EnterCategory(CBase.Songs.GetCurrentCategoryIndex()); } } - private void _AfterCategoryChange() + private void _UpdateListIfRequired() { - foreach (CStatic tile in _Tiles) - tile.Selected = false; - - if (_ActualSelection >= 0 && _ActualSelection < _Tiles.Count) - _Tiles[_ActualSelection].Selected = true; - - if ((_LastKnownNumSongs == CBase.Songs.GetNumSongsVisible()) && (_LastKnownCategory == CBase.Songs.GetCurrentCategoryIndex())) + int curElements = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories(); + if ((_LastKnownElements == curElements) && (_LastKnownCategory == CBase.Songs.GetCurrentCategoryIndex())) return; _LastKnownCategory = CBase.Songs.GetCurrentCategoryIndex(); - _LastKnownNumSongs = CBase.Songs.GetNumSongsVisible(); - _UpdateList(0, true); + _LastKnownElements = curElements; CBase.Songs.UpdateRandomSongList(); + _UpdateList(true); + } + + private int _GetOffsetForPosition(int index, int rowNum = 0) + { + return (index / _NumW) * _NumW - (_NumW * rowNum.Clamp(0, _NumH - 1, true)); } private void _UpdateList(bool force = false) { - _UpdateList((_Locked / _NumW) * _NumW - (_NumW * (_NumH - 2)), force); + int offset; + if (_SelectionNr < _Offset && _SelectionNr >= 0) + offset = _GetOffsetForPosition(_SelectionNr); + else if (_SelectionNr >= _Offset + _NumW * _NumH) + offset = _GetOffsetForPosition(_SelectionNr, _NumH); + else + offset = _Offset; + _UpdateList(offset, force); } private void _UpdateList(int offset, bool force = false) @@ -638,11 +568,7 @@ namespace VocaluxeLib.Menu.SongMenu bool isInCategory = CBase.Songs.IsInCategory(); int itemCount = isInCategory ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories(); - if (offset >= (itemCount / _NumW) * _NumW - (_NumW * (_NumH - 1))) - offset = (itemCount / _NumW) * _NumW - (_NumW * (_NumH - 1)); - - if (offset < 0) - offset = 0; + offset = offset.Clamp(0, _GetOffsetForPosition(itemCount, _NumH - 1), true); if (offset == _Offset && !force) return; @@ -656,58 +582,13 @@ namespace VocaluxeLib.Menu.SongMenu } else { - _Tiles[i].Texture = _CoverTexture; + _Tiles[i].Texture = _CoverBGTexture; _Tiles[i].Color = _Color; } } _Offset = offset; } - public override void SetSmallView(bool smallView) - { - base.SetSmallView(smallView); - - _SmallView = smallView; - - if (_SmallView) - { - _NumH = _Theme.SongMenuTileBoard.NumHsmall; - _NumW = _Theme.SongMenuTileBoard.NumWsmall; - Rect = _Theme.SongMenuTileBoard.TileRectSmall; - } - else - { - _NumH = _Theme.SongMenuTileBoard.NumH; - _NumW = _Theme.SongMenuTileBoard.NumW; - Rect = _Theme.SongMenuTileBoard.TileRect; - } - - _TileW = (int)((Rect.W - _SpaceW * (_NumW - 1)) / _NumW); - _TileH = (int)((Rect.H - _SpaceH * (_NumH - 1)) / _NumH); - - _CoverTexture = CBase.Theme.GetSkinTexture(_Theme.CoverBackgroundName, _PartyModeID); - _CoverBigTexture = CBase.Theme.GetSkinTexture(_Theme.CoverBigBackgroundName, _PartyModeID); - - _Tiles = new List(); - for (int i = 0; i < _NumH; i++) - { - for (int j = 0; j < _NumW; j++) - { - var rect = new SRectF(Rect.X + j * (_TileW + _SpaceW), Rect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, Rect.Z); - var tile = new CStatic(_PartyModeID, _CoverTexture, Color, rect); - _Tiles.Add(tile); - } - } - - _ScrollRect = new SRectF(0, 0, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), Rect.Z); - _UpdateList(true); - } - - public override bool IsSmallView() - { - return _SmallView; - } - public override void LoadTextures() { base.LoadTextures(); diff --git a/VocaluxeLib/Menu/SongMenu/ISongMenu.cs b/VocaluxeLib/Menu/SongMenu/ISongMenu.cs index e1ea8998..fbd9a116 100644 --- a/VocaluxeLib/Menu/SongMenu/ISongMenu.cs +++ b/VocaluxeLib/Menu/SongMenu/ISongMenu.cs @@ -25,34 +25,30 @@ namespace VocaluxeLib.Menu.SongMenu void OnShow(); void OnHide(); - void HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions songOptions); - void HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions); + bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options); + bool HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions); void Draw(); - int GetSelectedSong(); + // The selected song is the song, where the mouse is hovering over + // The number is refering to the index in the visible songs array + int GetPreviewSongNr(); + int GetSelectedSongNr(); CStatic GetSelectedSongCover(); void SetSelectedSong(int visibleSongNr); + bool IsMouseOverSelectedSong(SMouseEvent mEvent); - bool IsActive(); - void SetActive(bool active); - - bool IsMouseOverActualSelection(SMouseEvent mEvent); - + // Same for categories int GetSelectedCategory(); void SetSelectedCategory(int categoryNr); - int GetActualSelection(); + bool EnterSelectedCategory(); - bool EnterCurrentCategory(); - - bool IsSelected(); - void SetSelected(bool selected); - - bool IsVisible(); - void SetVisible(bool visible); - - bool IsSmallView(); - void SetSmallView(bool smallView); + // The song that is currently playing (set e.g. by clicking on a song) + int GetPreviewSong(); SRectF Rect { get; } + bool Active { get; set; } + bool Selected { get; set; } + bool Visible { get; set; } + bool SmallView { get; set; } } } \ No newline at end of file diff --git a/VocaluxeLib/PartyModes/IPartyMode.cs b/VocaluxeLib/PartyModes/IPartyMode.cs index d71e8135..71c30c9a 100644 --- a/VocaluxeLib/PartyModes/IPartyMode.cs +++ b/VocaluxeLib/PartyModes/IPartyMode.cs @@ -44,7 +44,7 @@ namespace VocaluxeLib.PartyModes public struct SSelectionOptions { /// - /// If != -1, the SongMenu should set the song selection on the provided song index (visible index) if possible + /// If != -1, the SongMenu should set the song selection to the provided song index (visible index) if possible /// public int SongIndex; diff --git a/VocaluxeLib/Profile/CProfile.cs b/VocaluxeLib/Profile/CProfile.cs index ca8de4d6..24c9de70 100644 --- a/VocaluxeLib/Profile/CProfile.cs +++ b/VocaluxeLib/Profile/CProfile.cs @@ -120,20 +120,9 @@ namespace VocaluxeLib.Profile if (filename == "") filename = "1"; - int i = 0; - while (File.Exists(Path.Combine(FilePath, filename + ".xml"))) - { - i++; - if (!File.Exists(Path.Combine(FilePath, filename + i + ".xml"))) - filename += i; - } - - FileName = filename + ".xml"; + FileName = CHelper.GetUniqueFileName(FilePath, filename + ".xml", false); } - if (FileName == String.Empty) - return; - XmlWriter writer; try { diff --git a/VocaluxeLib/Songs/CSong.cs b/VocaluxeLib/Songs/CSong.cs index 26d1d6fd..665beac4 100644 --- a/VocaluxeLib/Songs/CSong.cs +++ b/VocaluxeLib/Songs/CSong.cs @@ -458,7 +458,10 @@ namespace VocaluxeLib.Songs if (Preview.Source == EDataSource.None) { if (Medley.Source != EDataSource.None) + { Preview.StartTime = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM); + Preview.Source = EDataSource.Calculated; + } } } diff --git a/VocaluxeLib/Songs/CSongLoader.cs b/VocaluxeLib/Songs/CSongLoader.cs index 7c18a981..cd4cf834 100644 --- a/VocaluxeLib/Songs/CSongLoader.cs +++ b/VocaluxeLib/Songs/CSongLoader.cs @@ -240,7 +240,7 @@ namespace VocaluxeLib.Songs break; case "LANGUAGE": if (value.Length > 1) - _Song.Languages.Add(value); + _Song.Languages.Add(_UnifyLanguage(value)); else _LogWarning("Invalid language"); break; @@ -416,6 +416,7 @@ namespace VocaluxeLib.Songs { //PreviewStart is not set or <=0 _Song.Preview.StartTime = (headerFlags & EHeaderFlags.MedleyStartBeat) != 0 ? CBase.Game.GetTimeFromBeats(_Song.Medley.StartBeat, _Song.BPM) : 0f; + _Song.Preview.Source = _Song.Preview.StartTime == 0 ? EDataSource.None : EDataSource.Calculated; } if ((headerFlags & EHeaderFlags.MedleyStartBeat) != 0 && (headerFlags & EHeaderFlags.MedleyEndBeat) != 0) @@ -449,6 +450,27 @@ namespace VocaluxeLib.Songs return true; } + private static string _UnifyLanguage(string lang) + { + if (lang != "") + { + lang = Char.ToUpperInvariant(lang[0]) + lang.Substring(1).ToLowerInvariant(); + switch (lang) + { + case "Englisch": + lang = "English"; + break; + case "Deutsch": + lang = "German"; + break; + case "Spanisch": + lang = "Spanish"; + break; + } + } + return lang; + } + private enum ENoteReadMode { Normal, diff --git a/VocaluxeLib/Structs.cs b/VocaluxeLib/Structs.cs index 13ee20ca..d0c73628 100644 --- a/VocaluxeLib/Structs.cs +++ b/VocaluxeLib/Structs.cs @@ -132,6 +132,15 @@ namespace VocaluxeLib if (ctrl) Mod |= EModifier.Ctrl; } + + /// + /// Returns true if this is about an arrow key (left, right, up down) + /// + /// True if Key is an arrow key + public bool IsArrowKey() + { + return Key == Keys.Left || Key == Keys.Right || Key == Keys.Up || Key == Keys.Down; + } } public struct SMouseEvent diff --git a/VocaluxeLib/Utils/Player/CSongPlayer.cs b/VocaluxeLib/Utils/Player/CSongPlayer.cs new file mode 100644 index 00000000..078be067 --- /dev/null +++ b/VocaluxeLib/Utils/Player/CSongPlayer.cs @@ -0,0 +1,185 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; + +using VocaluxeLib.Draw; +using VocaluxeLib.Songs; + +namespace VocaluxeLib.Utils.Player +{ + public class CSongPlayer : CSoundPlayer + { + private CSong _Song; + private bool _VideoEnabled; + private int _Video = -1; + private CTexture _CurrentVideoTexture; + private CFading _VideoFading; + + public bool VideoEnabled + { + get { return _VideoEnabled; } + set + { + if (_VideoEnabled == value) + return; + _VideoEnabled = value; + if (_VideoEnabled) + _LoadVideo(); + else if (_Video != -1) + { + CBase.Video.Close(_Video); + CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture); + _Video = -1; + } + } + } + public int SongID + { + get { return _Song == null ? -1 : _Song.ID; } + } + public bool SongHasVideo + { + get { return _Song != null && File.Exists(Path.Combine(_Song.Folder,_Song.VideoFileName)); } + } + + public string ArtistAndTitle + { + get + { + if (_Song == null) + return ""; + if (_Song.Artist != "" && _Song.Title != "") + return _Song.Artist + " - " + _Song.Title; + return Path.GetFileNameWithoutExtension(_Song.MP3FileName); + } + } + + public CTexture Cover + { + get { return _Song == null ? CBase.Cover.GetNoCover() : _Song.CoverTextureBig; } + } + + public bool SongLoaded + { + get { return _StreamID != -1; } + } + + + public CSongPlayer(bool loop = false) : base(loop) { } + + public CSongPlayer(CSong song, bool loop = false, float position = 0f, bool autoplay = false) + : base(Path.Combine(song.Folder,song.MP3FileName), loop, position, autoplay) + { + _Song = song; + _LoadVideo(); + } + + public CSongPlayer(string file, bool loop = false, float position = 0f, bool autoplay = false) + : base(file, loop, position, autoplay) + { + _Song = null; + } + + public CTexture GetVideoTexture() + { + if (_Video == -1 || _Song == null) + return null; + float vtime; + if (CBase.Video.GetFrame(_Video, ref _CurrentVideoTexture, CBase.Sound.GetPosition(_StreamID), out vtime)) + { + if (_VideoFading != null) + { + bool finished; + _CurrentVideoTexture.Color.A = _VideoFading.GetValue(out finished); + if (finished) + _VideoFading = null; + } + return _CurrentVideoTexture; + } + return null; + } + + public void Load(CSong song, float position = 0f, bool autoplay = false) + { + if (song == null) + return; + + Stop(); + + _Song = song; + + base.Load(Path.Combine(song.Folder, song.MP3FileName), position, false); + _LoadVideo(); + + if (autoplay) + Play(); + } + + public void LoadFile(string file, float position = 0f, bool autoplay = false) + { + if (String.IsNullOrEmpty(file)) + return; + + Stop(); + + base.Load(file, position, autoplay); + } + + public new void Play() + { + CBase.Sound.SetPosition(_StreamID, _StartPosition); + CBase.Video.Skip(_Video, _StartPosition, _Song.VideoGap); + TogglePause(); + } + + public new void Stop() + { + base.Stop(); + + _Song = null; + + if (_Video != -1) + { + CBase.Video.Close(_Video); + CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture); + _Video = -1; + } + } + + public new void TogglePause() + { + if (IsPlaying && _Video != -1) + { + CBase.Video.Pause(_Video); + CBase.Video.Skip(_Video, CBase.Sound.GetPosition(_StreamID) + _FadeTime, _Song.VideoGap); + } + else if(_Video != -1) + { + CBase.Video.Resume(_Video); + } + base.TogglePause(); + } + + + private void _LoadVideo() + { + if (_Song == null) + return; + + string videoFilePath = Path.Combine(_Song.Folder, _Song.VideoFileName); + if (_Video != -1 || String.IsNullOrEmpty(videoFilePath)) + return; + _Video = CBase.Video.Load(videoFilePath); + CBase.Video.Skip(_Video, 0f, _Song.VideoGap); //Use gap, otherwhise we will overwrite position in GetVideoTexture + _VideoFading = new CFading(0f, 1f, 3f); + + if (IsPlaying) + { + CBase.Video.Skip(_Video, Position, _Song.VideoGap); + CBase.Video.Resume(_Video); + } + } + } +} diff --git a/VocaluxeLib/Utils/Player/CSoundPlayer.cs b/VocaluxeLib/Utils/Player/CSoundPlayer.cs new file mode 100644 index 00000000..4bbbd602 --- /dev/null +++ b/VocaluxeLib/Utils/Player/CSoundPlayer.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace VocaluxeLib.Utils.Player +{ + public class CSoundPlayer + { + protected int _StreamID = -1; + protected float _Volume; + protected float _StartPosition; + protected float _FadeTime = CBase.Settings.GetSoundPlayerFadeTime(); + + public float Volume + { + set + { + _Volume = value; + _ApplyVolume(); + } + get { return _Volume; } + } + public bool Loop; + + public float Position + { + set { + if(_StreamID == -1) + return; + _StartPosition = value; + } + get { + if(_StreamID == -1) + return -1; + return CBase.Sound.GetPosition(_StreamID); + } + } + + public float Length + { + get + { + if (_StreamID == -1) + return 0; + return CBase.Sound.GetLength(_StreamID); + } + } + + public bool RepeatSong; + public bool IsPlaying { get; protected set; } + + public bool IsFinished { get { return RepeatSong ? false : CBase.Sound.IsFinished(_StreamID); } } + + public CSoundPlayer(bool loop = false) + { + Loop = loop; + } + + public CSoundPlayer(string file, bool loop = false, float position = 0f, bool autoplay = false) + { + _StreamID = CBase.Sound.Load(file, false, true); + if(position > 0f) + Position = position; + Loop = loop; + if (autoplay) + Play(); + } + + public void Load(string file, float position = 0f, bool autoplay = false) + { + if (IsPlaying) + Stop(); + + _StreamID = CBase.Sound.Load(file, false, true); + if (position > 0f) + Position = position; + if (autoplay) + Play(); + } + + public void Play() + { + if (_StreamID == -1 || IsPlaying) + return; + + CBase.Sound.SetPosition(_StreamID, _StartPosition); + CBase.Sound.SetStreamVolume(_StreamID, 0f); + CBase.Sound.Fade(_StreamID, Volume, _FadeTime); + CBase.Sound.Play(_StreamID); + IsPlaying = true; + } + + public void TogglePause() + { + if (_StreamID == -1) + return; + + if(IsPlaying) + CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Pause); + else + { + CBase.Sound.Fade(_StreamID, Volume, _FadeTime); + CBase.Sound.Play(_StreamID); + } + + IsPlaying = !IsPlaying; + } + + public void Stop() + { + if (_StreamID == -1 || !IsPlaying) + return; + + CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Close); + _StreamID = -1; + + IsPlaying = false; + } + + public void Update() + { + if (_StreamID == -1 || !IsPlaying) + return; + + float timeToPlay; + float len = CBase.Sound.GetLength(_StreamID); + timeToPlay = (len > 0f) ? len - CBase.Sound.GetPosition(_StreamID) : _FadeTime + 1f; + + bool finished = CBase.Sound.IsFinished(_StreamID); + if (timeToPlay <= _FadeTime || finished) + { + if (RepeatSong) + { + //Set to false for restarting + IsPlaying = false; + Play(); + } + else + Stop(); + } + + } + + private void _ApplyVolume() + { + if (_StreamID == -1) + return; + + CBase.Sound.SetStreamVolume(_StreamID, Volume); + } + } +} diff --git a/VocaluxeLib/VocaluxeLib.csproj b/VocaluxeLib/VocaluxeLib.csproj index 3e17ea26..a367e8e1 100644 --- a/VocaluxeLib/VocaluxeLib.csproj +++ b/VocaluxeLib/VocaluxeLib.csproj @@ -135,6 +135,8 @@ + + diff --git a/WebserverInitalConfig/CConfigHttpApi.cs b/WebserverInitalConfig/CConfigHttpApi.cs index e13a9cda..90bdfc2b 100644 --- a/WebserverInitalConfig/CConfigHttpApi.cs +++ b/WebserverInitalConfig/CConfigHttpApi.cs @@ -60,9 +60,10 @@ namespace WebserverInitalConfig HttpApi.ReserveURL(networkString, "D:(A;;GX;;;S-1-1-0)"); } - public void ReserveUrl() + public void ReserveUrl(bool secure) { - _ReserveUrl("https://+:" + _Port + "/"); + string http = secure ? "https" : "http"; + _ReserveUrl(http + "://+:" + _Port + "/"); } private void _BindCert(X509Certificate cert) diff --git a/WebserverInitalConfig/HttpApi.cs b/WebserverInitalConfig/HttpApi.cs index 39f587ff..6473afea 100644 --- a/WebserverInitalConfig/HttpApi.cs +++ b/WebserverInitalConfig/HttpApi.cs @@ -25,6 +25,7 @@ using System.Security.Cryptography.X509Certificates; namespace WebserverInitalConfig { + // ReSharper disable InconsistentNaming static class HttpApi { private static readonly HTTPAPI_VERSION HttpApiVersion = new HTTPAPI_VERSION(1, 0); @@ -144,6 +145,14 @@ namespace WebserverInitalConfig public HTTP_SERVICE_CONFIG_URLACL_PARAM ParamDesc; } + [StructLayout(LayoutKind.Sequential)] + private struct HTTP_SERVICE_CONFIG_URLACL_QUERY + { + public HTTP_SERVICE_CONFIG_QUERY_TYPE QueryDesc; + public HTTP_SERVICE_CONFIG_URLACL_KEY KeyDesc; + public uint dwToken; + } + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct HTTP_SERVICE_CONFIG_URLACL_KEY { @@ -227,7 +236,7 @@ namespace WebserverInitalConfig if (retVal == ERROR_FILE_NOT_FOUND) return; - if (ERROR_INSUFFICIENT_BUFFER == retVal) // ERROR_INSUFFICIENT_BUFFER = 122 + if (ERROR_INSUFFICIENT_BUFFER == retVal) { pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength); @@ -431,7 +440,7 @@ namespace WebserverInitalConfig IntPtr.Zero); if (ERROR_NO_MORE_ITEMS == retVal) break; - if (ERROR_INSUFFICIENT_BUFFER == retVal) // ERROR_INSUFFICIENT_BUFFER = 122 + if (ERROR_INSUFFICIENT_BUFFER == retVal) { pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength); @@ -485,6 +494,101 @@ namespace WebserverInitalConfig return result.ToArray(); } + private static HTTP_SERVICE_CONFIG_URLACL_SET QueryReservation(string networkURL) + { + if (String.IsNullOrEmpty(networkURL)) + throw new ArgumentNullException("networkURL"); + HTTP_SERVICE_CONFIG_URLACL_SET res = new HTTP_SERVICE_CONFIG_URLACL_SET(); + res.KeyDesc = new HTTP_SERVICE_CONFIG_URLACL_KEY(""); + CallHttpApi( + delegate + { + HTTP_SERVICE_CONFIG_URLACL_QUERY inputquery = new HTTP_SERVICE_CONFIG_URLACL_QUERY + { + QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryExact, + KeyDesc = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURL) + }; + + IntPtr pInputQuery = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_QUERY))); + Marshal.StructureToPtr(inputquery, pInputQuery, false); + IntPtr pOutputConfigInfo = IntPtr.Zero; + int returnLength = 0; + try + { + uint retVal = HttpQueryServiceConfiguration(IntPtr.Zero, + HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, + pInputQuery, + Marshal.SizeOf(inputquery), + pOutputConfigInfo, + returnLength, + out returnLength, + IntPtr.Zero); + if (ERROR_INSUFFICIENT_BUFFER == retVal) + { + pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength); + retVal = HttpQueryServiceConfiguration(IntPtr.Zero, + HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, + pInputQuery, + Marshal.SizeOf(inputquery), + pOutputConfigInfo, + returnLength, + out returnLength, + IntPtr.Zero); + if (ERROR_FILE_NOT_FOUND == retVal) + return; + ThrowWin32ExceptionIfError(retVal); + res = (HTTP_SERVICE_CONFIG_URLACL_SET)Marshal.PtrToStructure(pOutputConfigInfo, typeof(HTTP_SERVICE_CONFIG_URLACL_SET)); + } + else if (ERROR_FILE_NOT_FOUND == retVal) + return; + else + ThrowWin32ExceptionIfError(retVal); + } + finally + { + Marshal.FreeCoTaskMem(pInputQuery); + if (pOutputConfigInfo != IntPtr.Zero) + Marshal.FreeCoTaskMem(pOutputConfigInfo); + } + } + ); + return res; + } + + public static uint DeleteReservation(string networkURL) + { + uint retVal = NOERROR; + if (String.IsNullOrEmpty(networkURL)) + throw new ArgumentNullException("networkURL"); + HTTP_SERVICE_CONFIG_URLACL_SET oldReservation = QueryReservation(networkURL); + if (oldReservation.KeyDesc.pUrlPrefix == "" && networkURL.Contains("+")) + { + networkURL = networkURL.Replace('+', '*'); + oldReservation = QueryReservation(networkURL); + } + if (oldReservation.KeyDesc.pUrlPrefix == "") + return ERROR_FILE_NOT_FOUND; + CallHttpApi( + delegate + { + IntPtr pInputConfigInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_SET))); + Marshal.StructureToPtr(oldReservation, pInputConfigInfo, false); + try + { + retVal = HttpDeleteServiceConfiguration(IntPtr.Zero, + HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, + pInputConfigInfo, + Marshal.SizeOf(oldReservation), + IntPtr.Zero); + } + finally + { + Marshal.FreeCoTaskMem(pInputConfigInfo); + } + }); + return retVal; + } + public static void ReserveURL(string networkURL, string securityDescriptor) { if (String.IsNullOrEmpty(networkURL)) @@ -495,7 +599,7 @@ namespace WebserverInitalConfig CallHttpApi( delegate { - uint retVal = (uint)NOERROR; // NOERROR = 0 + uint retVal; HTTP_SERVICE_CONFIG_URLACL_KEY keyDesc = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURL); HTTP_SERVICE_CONFIG_URLACL_PARAM paramDesc = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor); @@ -514,13 +618,15 @@ namespace WebserverInitalConfig Marshal.SizeOf(inputConfigInfoSet), IntPtr.Zero); - if (ERROR_ALREADY_EXISTS == retVal) // ERROR_ALREADY_EXISTS = 183 + if (ERROR_ALREADY_EXISTS == retVal) { - retVal = HttpDeleteServiceConfiguration(IntPtr.Zero, - HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, - pInputConfigInfo, - Marshal.SizeOf(inputConfigInfoSet), - IntPtr.Zero); + retVal = DeleteReservation(networkURL); + if (ERROR_FILE_NOT_FOUND == retVal) + { + string networkURLOld = networkURL.Contains("https") ? networkURL.Replace("https", "http") : + networkURL.Replace("http", "https"); + retVal = DeleteReservation(networkURLOld); + } if (NOERROR == retVal) { @@ -530,41 +636,11 @@ namespace WebserverInitalConfig Marshal.SizeOf(inputConfigInfoSet), IntPtr.Zero); } - else if (ERROR_FILE_NOT_FOUND == retVal) // ERROR_FILE_NOT_FOUND = 2 - { - string networkURLOld = networkURL.Contains("https") ? networkURL.Replace("https", "http") : - networkURL.Replace("http", "https"); - HTTP_SERVICE_CONFIG_URLACL_KEY keyDescOld = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURLOld); - HTTP_SERVICE_CONFIG_URLACL_PARAM paramDescOld = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor); - - HTTP_SERVICE_CONFIG_URLACL_SET inputConfigInfoSetOld = new HTTP_SERVICE_CONFIG_URLACL_SET(); - inputConfigInfoSetOld.KeyDesc = keyDescOld; - inputConfigInfoSetOld.ParamDesc = paramDescOld; - - IntPtr pInputConfigInfoOld = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_SET))); - Marshal.StructureToPtr(inputConfigInfoSetOld, pInputConfigInfoOld, false); - - retVal = HttpDeleteServiceConfiguration(IntPtr.Zero, - HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, - pInputConfigInfoOld, - Marshal.SizeOf(inputConfigInfoSetOld), - IntPtr.Zero); - - if (NOERROR == retVal) - { - retVal = HttpSetServiceConfiguration(IntPtr.Zero, - HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, - pInputConfigInfo, - Marshal.SizeOf(inputConfigInfoSet), - IntPtr.Zero); - } - } } } finally { Marshal.FreeCoTaskMem(pInputConfigInfo); - HttpTerminate(HTTP_INITIALIZE_CONFIG, IntPtr.Zero); } if (NOERROR != retVal) ThrowWin32ExceptionIfError(retVal); diff --git a/WebserverInitalConfig/Program.cs b/WebserverInitalConfig/Program.cs index 60e3ce4a..2223c5e8 100644 --- a/WebserverInitalConfig/Program.cs +++ b/WebserverInitalConfig/Program.cs @@ -30,34 +30,38 @@ namespace WebserverInitalConfig private static void Main(string[] args) // ReSharper restore InconsistentNaming { + int result = 0; try { int port; - if (args.Length < 2 || !int.TryParse(args[0], out port)) + if (args.Length < 3 || !int.TryParse(args[1], out port)) { - Console.WriteLine("Usage: VocaluxeServerConfig port isHttps"); - Environment.Exit(-1); + Console.WriteLine("Usage: VocaluxeServerConfig exeName port isHttps [reserve]"); + result = -1; } else { - CConfigHttpApi config = new CConfigHttpApi("Vocaluxe", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Vocaluxe.exe"), "0.0.0.0", port, true); + String exeName = args[0]; + bool isSecure = (args[2].ToLower() == "true"); + bool doReserve = (args.Length >= 4 && args[3].ToLower() == "true"); + CConfigHttpApi config = new CConfigHttpApi(exeName, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, exeName), "0.0.0.0", port, true); try { config.AddFirewallRule(); - if (args[1].ToLower() == "true") + if (isSecure) config.CreateAndAddCert(Dns.GetHostName()); - if ((args.Length >= 3 && args[2] == "reserve") || CConfigHttpApi.IsAdministrator()) - config.ReserveUrl(); + if (doReserve || CConfigHttpApi.IsAdministrator()) + config.ReserveUrl(isSecure); } catch (AuthenticationException) { ProcessStartInfo proc = new ProcessStartInfo { UseShellExecute = true, - WorkingDirectory = Environment.CurrentDirectory, - FileName = Process.GetCurrentProcess().MainModule.FileName, - Arguments = args[0] + " " + args[1], + WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory, + FileName = AppDomain.CurrentDomain.FriendlyName, + Arguments = String.Join(" ", args), Verb = "runas", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, @@ -65,21 +69,28 @@ namespace WebserverInitalConfig try { - Process.Start(proc); + using (Process p = Process.Start(proc)) + { + p.WaitForExit(); + result = p.ExitCode; + p.Close(); + } } catch { // The user refused the elevation. // Do nothing and return directly ... - Environment.Exit(-1); + result = -3; } } } } catch (Exception e) { - MessageBox.Show("Error while installing server: " + e.Message); + MessageBox.Show("Error while installing server: " + e.Message + "\r\n\r\nIn " + e.TargetSite + "\r\nBacktrace: " + e.StackTrace); + result = -4; } + Environment.Exit(result); } } } \ No newline at end of file