From 8a638d8e9a11e3703e7ae7796626978a9bccb126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sat, 26 Oct 2013 14:36:26 +0200 Subject: [PATCH 1/4] Added new background-option: SlideShow. --- Vocaluxe/Base/CMain.cs | 10 ++++ Vocaluxe/Base/CSettings.cs | 3 ++ VocaluxeLib/IBasic.cs | 3 ++ VocaluxeLib/Menu/CBackground.cs | 87 ++++++++++++++++++++++++++++++++- 4 files changed, 102 insertions(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index dbf75632..ff9f0f5d 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -233,6 +233,16 @@ namespace Vocaluxe.Base { return CSettings.DataPath; } + + public float GetSlideShowImageTime() + { + return CSettings.SlideShowImageTime; + } + + public float GetSlideShowFadeTime() + { + return CSettings.SlideShowFadeTime; + } } class CBtheme : ITheme diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index 9fe7b69f..74f2ed94 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -142,6 +142,9 @@ namespace Vocaluxe.Base public const float BackgroundMusicFadeTime = 0.5f; public const float PauseResetTime = 1f; + public const float SlideShowImageTime = 3500f; + public const float SlideShowFadeTime = 500f; + public static readonly List MusicFileTypes = new List { "*.mp3", diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index b64e5e60..ac8ed878 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -86,6 +86,9 @@ namespace VocaluxeLib string GetFolderProfiles(); string GetDataPath(); + + float GetSlideShowImageTime(); + float GetSlideShowFadeTime(); } public interface ITheme diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index 2e77ffc7..7d5a8e4f 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -18,6 +18,8 @@ using System; using System.Drawing; using System.Xml; +using System.Diagnostics; +using System.Collections.Generic; using VocaluxeLib.Draw; namespace VocaluxeLib.Menu @@ -27,6 +29,7 @@ namespace VocaluxeLib.Menu None, Color, Texture, + SlideShow, Video } @@ -36,6 +39,8 @@ namespace VocaluxeLib.Menu public EBackgroundTypes Type; + public List SlideShowTextures; + public string VideoName; public string TextureName; @@ -48,6 +53,10 @@ namespace VocaluxeLib.Menu private SThemeBackground _Theme; private bool _ThemeLoaded; + private int _SlideShowCurrent; + private Stopwatch _SlideShowTimer = new Stopwatch(); + private List _SlideShowTextures = new List(); + public SColorF Color; public string GetThemeName() @@ -92,6 +101,17 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= success; } + string slideShow = ""; + int i = 1; + _Theme.SlideShowTextures = new List(); + while (xmlReader.ItemExists(item + "/SlideShow" + i)) + { + xmlReader.GetValue(item + "/SlideShow" + i, out slideShow, String.Empty); + if (slideShow != "") + _Theme.SlideShowTextures.Add(slideShow); + i++; + } + if (_ThemeLoaded) { _Theme.Name = elementName; @@ -115,6 +135,12 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Background Texture name"); writer.WriteElementString("Skin", _Theme.TextureName); + writer.WriteComment(": Texture name for slide-show"); + for (int i = 0; i < _Theme.SlideShowTextures.Count; i++) + { + writer.WriteElementString("SlideShow" + (i + 1), _Theme.SlideShowTextures[i]); + } + writer.WriteComment(": Background color for type \"Color\" from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); if (!String.IsNullOrEmpty(_Theme.ColorName)) @@ -164,6 +190,11 @@ namespace VocaluxeLib.Menu ok = _DrawVideo(); } + if (_Theme.Type == EBackgroundTypes.SlideShow && _Theme.SlideShowTextures.Count > 0) + { + ok = _DrawSlideShow(); + } + if (!String.IsNullOrEmpty(_Theme.TextureName) && (_Theme.Type == EBackgroundTypes.Texture || (_Theme.Type == EBackgroundTypes.Video && (CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF || !ok)))) @@ -176,12 +207,15 @@ namespace VocaluxeLib.Menu return true; } - public void UnloadTextures() {} + public void UnloadTextures() { _SlideShowTextures.Clear(); } public void LoadTextures() { if (!String.IsNullOrEmpty(_Theme.ColorName)) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); + + foreach (string s in _Theme.SlideShowTextures) + _SlideShowTextures.Add(CBase.Theme.GetSkinTexture(s, _PartyModeID)); } public void ReloadTextures() @@ -214,6 +248,57 @@ namespace VocaluxeLib.Menu return false; } + private bool _DrawSlideShow() + { + if (_SlideShowTextures.Count > 0) + { + if (!_SlideShowTimer.IsRunning) + { + _SlideShowTimer.Start(); + _SlideShowCurrent = 0; + } + + CTexture texture = _SlideShowTextures[_SlideShowCurrent]; + + if (texture == null) + return false; + + var bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); + RectangleF rect; + CHelper.SetRect(bounds, out rect, texture.OrigAspect, EAspect.Crop); + + CBase.Drawing.DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); + + if (_SlideShowTimer.ElapsedMilliseconds >= (CBase.Settings.GetSlideShowFadeTime() + CBase.Settings.GetSlideShowImageTime())) + { + _SlideShowTimer.Restart(); + if (_SlideShowCurrent + 1 < _SlideShowTextures.Count) + _SlideShowCurrent++; + else if (_SlideShowCurrent != 0) + _SlideShowCurrent = 0; + } + else if (_SlideShowTimer.ElapsedMilliseconds >= CBase.Settings.GetSlideShowImageTime()) + { + if (_SlideShowCurrent + 1 < _SlideShowTextures.Count) + texture = _SlideShowTextures[_SlideShowCurrent + 1]; + else if (_SlideShowCurrent != 0) + texture = _SlideShowTextures[0]; + else + texture = null; + + if (texture != null) + { + float alpha = (_SlideShowTimer.ElapsedMilliseconds - CBase.Settings.GetSlideShowImageTime()) / CBase.Settings.GetSlideShowFadeTime(); + CHelper.SetRect(bounds, out rect, texture.OrigAspect, EAspect.Crop); + CBase.Drawing.DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, (CBase.Settings.GetZFar() / 4) - 1), new SColorF(1,1,1, alpha)); + } + } + + return true; + } + return false; + } + private bool _DrawVideo() { CTexture videoTexture = CBase.Theme.GetSkinVideoTexture(_Theme.VideoName, _PartyModeID); From 88344ec8b4b4cfaefde0f5a173b665ed9a6cab2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sat, 26 Oct 2013 15:17:14 +0200 Subject: [PATCH 2/4] #BACKGROUND-Tag could be multiple now, when there are more than one bgs, a slide-show will shown in ScreenSing. --- Vocaluxe/Screens/CScreenSing.cs | 21 +++++++++++++++++++-- VocaluxeLib/Menu/CBackground.cs | 26 ++++++++++++++++++++++++-- VocaluxeLib/Songs/CSong.cs | 8 ++++---- VocaluxeLib/Songs/CSongLoader.cs | 2 +- VocaluxeLib/Songs/CSongWriter.cs | 2 +- 5 files changed, 49 insertions(+), 10 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index e792ba4e..50ad4ed0 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -119,6 +119,8 @@ namespace Vocaluxe.Screens private bool _Pause; private bool _Webcam; + private CBackground _SlideShow; + public override void Init() { base.Init(); @@ -474,6 +476,8 @@ namespace Vocaluxe.Screens CDraw.DrawTexture(background, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, 0f), background.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f)); } + else if (_SlideShow != null) + _SlideShow.Draw(); } _DrawBG(); @@ -557,6 +561,9 @@ namespace Vocaluxe.Screens } CDraw.RemoveTexture(ref _Background); + if(_SlideShow != null) + _SlideShow.RemoveSlideShowTextures(); + _Lyrics[_LyricMain].Clear(); _Lyrics[_LyricSub].Clear(); _Lyrics[_LyricMainDuet].Clear(); @@ -622,8 +629,18 @@ namespace Vocaluxe.Screens } CDraw.RemoveTexture(ref _Background); - if (!String.IsNullOrEmpty(song.BackgroundFileName)) - _Background = CDraw.AddTexture(Path.Combine(song.Folder, song.BackgroundFileName)); + if (song.BackgroundFileNames.Count > 1) + { + _SlideShow = GetNewBackground(); + foreach(string s in song.BackgroundFileNames) + _SlideShow.AddSlideShowTexture(Path.Combine(song.Folder, s)); + _Background = null; + } + else if (song.BackgroundFileNames.Count == 1) + { + if (!String.IsNullOrEmpty(song.BackgroundFileNames[0])) + _Background = CDraw.AddTexture(Path.Combine(song.Folder, song.BackgroundFileNames[0])); + } _SingNotes[_SingBars].Reset(); diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index 7d5a8e4f..3fc5616b 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -70,6 +70,7 @@ namespace VocaluxeLib.Menu _PartyModeID = partyModeID; _ThemeLoaded = false; _Theme = new SThemeBackground(); + _Theme.SlideShowTextures = new List(); Color = new SColorF(0f, 0f, 0f, 1f); } @@ -103,7 +104,7 @@ namespace VocaluxeLib.Menu string slideShow = ""; int i = 1; - _Theme.SlideShowTextures = new List(); + while (xmlReader.ItemExists(item + "/SlideShow" + i)) { xmlReader.GetValue(item + "/SlideShow" + i, out slideShow, String.Empty); @@ -190,7 +191,7 @@ namespace VocaluxeLib.Menu ok = _DrawVideo(); } - if (_Theme.Type == EBackgroundTypes.SlideShow && _Theme.SlideShowTextures.Count > 0) + if (_Theme.Type == EBackgroundTypes.SlideShow ) { ok = _DrawSlideShow(); } @@ -218,6 +219,27 @@ namespace VocaluxeLib.Menu _SlideShowTextures.Add(CBase.Theme.GetSkinTexture(s, _PartyModeID)); } + public void AddSlideShowTexture(string image) + { + _Theme.Type = EBackgroundTypes.SlideShow; + if (!String.IsNullOrEmpty(image)) + { + CTexture texture = CBase.Drawing.AddTexture(image); + if(texture != null) + _SlideShowTextures.Add(texture); + } + } + + public void RemoveSlideShowTextures() + { + foreach (CTexture tex in _SlideShowTextures) + { + CTexture texture = tex; + CBase.Drawing.RemoveTexture(ref texture); + } + _SlideShowTextures.Clear(); + } + public void ReloadTextures() { UnloadTextures(); diff --git a/VocaluxeLib/Songs/CSong.cs b/VocaluxeLib/Songs/CSong.cs index aa0ced4b..9eb3e5a6 100644 --- a/VocaluxeLib/Songs/CSong.cs +++ b/VocaluxeLib/Songs/CSong.cs @@ -97,7 +97,7 @@ namespace VocaluxeLib.Songs public string MP3FileName = String.Empty; public string CoverFileName = String.Empty; - public string BackgroundFileName = String.Empty; + public List BackgroundFileNames = new List(); public string VideoFileName = String.Empty; public EAspect VideoAspect = EAspect.Crop; @@ -226,7 +226,7 @@ namespace VocaluxeLib.Songs MP3FileName = song.MP3FileName; CoverFileName = song.CoverFileName; - BackgroundFileName = song.BackgroundFileName; + BackgroundFileNames = song.BackgroundFileNames; VideoFileName = song.VideoFileName; VideoAspect = song.VideoAspect; @@ -328,7 +328,7 @@ namespace VocaluxeLib.Songs } } - if (BackgroundFileName == "") + if (BackgroundFileNames.Count == 0) { List files = CHelper.ListFiles(Folder, "*.jpg"); files.AddRange(CHelper.ListFiles(Folder, "*.jpeg")); @@ -338,7 +338,7 @@ namespace VocaluxeLib.Songs { if (file.ContainsIgnoreCase("[BG]") && (file.ContainsIgnoreCase(Title) || file.ContainsIgnoreCase(Artist))) - BackgroundFileName = file; + BackgroundFileNames.Add(file); } } } diff --git a/VocaluxeLib/Songs/CSongLoader.cs b/VocaluxeLib/Songs/CSongLoader.cs index 597398d4..4556b776 100644 --- a/VocaluxeLib/Songs/CSongLoader.cs +++ b/VocaluxeLib/Songs/CSongLoader.cs @@ -243,7 +243,7 @@ namespace VocaluxeLib.Songs break; case "BACKGROUND": if (File.Exists(Path.Combine(_Song.Folder, value))) - _Song.BackgroundFileName = value; + _Song.BackgroundFileNames.Add(value); else _LogWarning("Can't find background file: " + Path.Combine(_Song.Folder, value)); break; diff --git a/VocaluxeLib/Songs/CSongWriter.cs b/VocaluxeLib/Songs/CSongWriter.cs index 906c358f..9d7328b7 100644 --- a/VocaluxeLib/Songs/CSongWriter.cs +++ b/VocaluxeLib/Songs/CSongWriter.cs @@ -74,7 +74,7 @@ namespace VocaluxeLib.Songs _WriteHeaderEntry("YEAR", _Song.Year); _WriteHeaderEntry("MP3", _Song.MP3FileName); _WriteHeaderEntry("COVER", _Song.CoverFileName); - _WriteHeaderEntry("BACKGROUND", _Song.BackgroundFileName); + _WriteHeaderEntrys("BACKGROUND", _Song.BackgroundFileNames); _WriteHeaderEntry("VIDEO", _Song.VideoFileName); _WriteHeaderEntry("VIDEOGAP", _Song.VideoGap); if (_Song.VideoAspect != EAspect.Crop) From c5638a08d1728018fe4c74d2ddbc29500199f2ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Tue, 29 Oct 2013 10:13:17 +0100 Subject: [PATCH 3/4] Rename a variable. --- Vocaluxe/Screens/CScreenSing.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 50ad4ed0..e5c610d3 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -632,8 +632,8 @@ namespace Vocaluxe.Screens if (song.BackgroundFileNames.Count > 1) { _SlideShow = GetNewBackground(); - foreach(string s in song.BackgroundFileNames) - _SlideShow.AddSlideShowTexture(Path.Combine(song.Folder, s)); + foreach(string bgFile in song.BackgroundFileNames) + _SlideShow.AddSlideShowTexture(Path.Combine(song.Folder, bgFile)); _Background = null; } else if (song.BackgroundFileNames.Count == 1) From 124d7d0bf4708835e953122b933f26184334e562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 15 Dec 2013 12:27:09 +0100 Subject: [PATCH 4/4] Make random a bit less random, but already sung songs shouldn't be suggested frequently. --- .../CPartyModeChallengeMedley.cs | 8 +++++++- Vocaluxe/Base/CSongs.cs | 15 ++++++++++++++- Vocaluxe/Screens/CScreenScore.cs | 1 + VocaluxeLib/Songs/CSong.cs | 2 ++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index 234d1ca1..b0975714 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -513,12 +513,18 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley return false; } + //Calc avarage sing-count + int totalCounts = 0; + foreach (CSong song in visibleSongs) + totalCounts += song.NumPlayedSession; + int averageCount = totalCounts / visibleSongs.Count; + // ReSharper disable LoopCanBeConvertedToQuery foreach (CSong song in visibleSongs) { foreach (EGameMode mode in song.AvailableGameModes) { - if (mode == EGameMode.TR_GAMEMODE_MEDLEY) + if (mode == EGameMode.TR_GAMEMODE_MEDLEY && song.NumPlayedSession <= averageCount) ids.Add(song.ID); } } diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index c031209c..86a2f482 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -217,7 +217,20 @@ namespace Vocaluxe.Base public static void UpdateRandomSongList() { _SongsForRandom.Clear(); - _SongsForRandom.AddRange(VisibleSongs); + //Calc avarage sing-count + int totalCounts = 0; + foreach (CSong song in VisibleSongs) + totalCounts += song.NumPlayedSession; + int averageCount = totalCounts / NumSongsVisible; + + foreach(CSong song in VisibleSongs) + { + if (song.NumPlayedSession <= averageCount) + _SongsForRandom.Add(song); + } + + if(_SongsForRandom.Count == 0) + _SongsForRandom.AddRange(VisibleSongs); } public static int GetRandomCategory() diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index b1e06b1e..22cd465d 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -409,6 +409,7 @@ namespace Vocaluxe.Screens CSong song = CSongs.GetSong(players[p].SongID); CDataBase.IncreaseSongCounter(song.DataBaseSongID); song.NumPlayed++; + song.NumPlayedSession++; break; } } diff --git a/VocaluxeLib/Songs/CSong.cs b/VocaluxeLib/Songs/CSong.cs index 9eb3e5a6..d2c393e8 100644 --- a/VocaluxeLib/Songs/CSong.cs +++ b/VocaluxeLib/Songs/CSong.cs @@ -174,6 +174,7 @@ namespace VocaluxeLib.Songs public int DataBaseSongID = -1; public string DateAdded = ""; public int NumPlayed; + public int NumPlayedSession; // Notes public readonly CNotes Notes = new CNotes(); @@ -266,6 +267,7 @@ namespace VocaluxeLib.Songs DataBaseSongID = song.DataBaseSongID; DateAdded = song.DateAdded; NumPlayed = song.NumPlayed; + NumPlayedSession = song.NumPlayedSession; Notes = new CNotes(song.Notes); }