From dad5f5ec11e4ca61e96d83c7db52da269100974b Mon Sep 17 00:00:00 2001 From: Jiiniasu Date: Tue, 7 Nov 2017 20:19:43 +0100 Subject: [PATCH] Add a delay before playing preview --- VocaluxeLib/Menu/SongMenu/CSongMenuList.cs | 53 ++++++++++++++----- .../Menu/SongMenu/CSongMenuTileBoard.cs | 53 ++++++++++++++----- 2 files changed, 80 insertions(+), 26 deletions(-) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuList.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuList.cs index 58de1560..fc0befc5 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuList.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuList.cs @@ -64,6 +64,9 @@ namespace VocaluxeLib.Menu.SongMenu private readonly List _SubElements = new List(); + private int _AutoplayDelay = 500; + private System.Timers.Timer _AutoplayTimer = new System.Timers.Timer(); + public override float SelectedTileZoomFactor { get { return 1.2f; } @@ -204,7 +207,7 @@ namespace VocaluxeLib.Menu.SongMenu public override void Update(SScreenSongOptions songOptions) { if (songOptions.Selection.RandomOnly) - _PreviewNr = _SelectionNr; + _PreviewSelectedSong(); if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.BackgroundMusic.GetLength() > 0) _UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr)); @@ -300,7 +303,7 @@ namespace VocaluxeLib.Menu.SongMenu SetSelectedSong(_SelectionNr < 0 ? 0 : _SelectionNr); else SetSelectedCategory(_SelectionNr < 0 ? 0 : _SelectionNr); - _PreviewNr = _SelectionNr; + _PreviewSelectedSong(); _UpdateListIfRequired(); } @@ -323,7 +326,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (_SelectionNr >= 0 && _PreviewNr != _SelectionNr) { - _PreviewNr = _SelectionNr; + _PreviewSelectedSong(); keyEvent.Handled = true; } } @@ -413,7 +416,7 @@ namespace VocaluxeLib.Menu.SongMenu break; } if (!CBase.Songs.IsInCategory()) - _PreviewNr = _SelectionNr; + _PreviewSelectedSong(); return keyEvent.Handled; } @@ -473,7 +476,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (_PreviewNr == _SelectionNr) return false; - _PreviewNr = _SelectionNr; + _PreviewSelectedSong(); } else EnterSelectedCategory(); @@ -560,14 +563,6 @@ namespace VocaluxeLib.Menu.SongMenu _UpdateListIfRequired(); } - private void _AutoplayPreviewIfEnabled() - { - if(CBase.Config.GetAutoplayPreviews() == EOffOn.TR_CONFIG_ON) - { - _PreviewNr = _SelectionNr; - } - } - private void _NextCategory() { if (CBase.Songs.IsInCategory()) @@ -586,6 +581,38 @@ namespace VocaluxeLib.Menu.SongMenu } } + private void _PreviewSelectedSong() + { + _PreviewNr = _SelectionNr; + } + + private void _AutoplayPreviewIfEnabled() + { + if (CBase.Config.GetAutoplayPreviews() == EOffOn.TR_CONFIG_ON) + { + _PlayPreviewAfterDelay(_AutoplayDelay); + } + } + + private void _PlayPreviewAfterDelay(double delay) + { + if (!_AutoplayTimer.Enabled) + { + _AutoplayTimer = new System.Timers.Timer(delay); + _AutoplayTimer.AutoReset = false; + _AutoplayTimer.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => + { + _PreviewSelectedSong(); + }; + _AutoplayTimer.Start(); + } + else + { + _AutoplayTimer.Stop(); + _AutoplayTimer.Start(); + } + } + private void _UpdateListIfRequired() { int curElements = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories(); diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 56795c16..7d7bb0fe 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -60,6 +60,9 @@ namespace VocaluxeLib.Menu.SongMenu private readonly List _SubElements = new List(); + private int _AutoplayDelay = 500; + private System.Timers.Timer _AutoplayTimer = new System.Timers.Timer(); + public override float SelectedTileZoomFactor { get { return 1.2f; } @@ -195,7 +198,7 @@ namespace VocaluxeLib.Menu.SongMenu public override void Update(SScreenSongOptions songOptions) { if (songOptions.Selection.RandomOnly) - _PreviewNr = _SelectionNr; + _PreviewSelectedSong(); if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.BackgroundMusic.GetLength() > 0) _UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr)); @@ -291,7 +294,7 @@ namespace VocaluxeLib.Menu.SongMenu SetSelectedSong(_SelectionNr < 0 ? 0 : _SelectionNr); else SetSelectedCategory(_SelectionNr < 0 ? 0 : _SelectionNr); - _PreviewNr = _SelectionNr; + _PreviewSelectedSong(); _UpdateListIfRequired(); } @@ -314,7 +317,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (_SelectionNr >= 0 && _PreviewNr != _SelectionNr) { - _PreviewNr = _SelectionNr; + _PreviewSelectedSong(); keyEvent.Handled = true; } } @@ -404,7 +407,7 @@ namespace VocaluxeLib.Menu.SongMenu break; } if (!CBase.Songs.IsInCategory()) - _PreviewNr = _SelectionNr; + _PreviewSelectedSong(); return keyEvent.Handled; } @@ -460,7 +463,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (_PreviewNr == _SelectionNr) return false; - _PreviewNr = _SelectionNr; + _PreviewSelectedSong(); } else EnterSelectedCategory(); @@ -523,14 +526,6 @@ namespace VocaluxeLib.Menu.SongMenu _UpdateListIfRequired(); } - private void _AutoplayPreviewIfEnabled() - { - if (CBase.Config.GetAutoplayPreviews() == EOffOn.TR_CONFIG_ON) - { - _PreviewNr = _SelectionNr; - } - } - private void _NextCategory() { if (CBase.Songs.IsInCategory()) @@ -549,6 +544,38 @@ namespace VocaluxeLib.Menu.SongMenu } } + private void _PreviewSelectedSong() + { + _PreviewNr = _SelectionNr; + } + + private void _AutoplayPreviewIfEnabled() + { + if (CBase.Config.GetAutoplayPreviews() == EOffOn.TR_CONFIG_ON) + { + _PlayPreviewAfterDelay(_AutoplayDelay); + } + } + + private void _PlayPreviewAfterDelay(double delay) + { + if (!_AutoplayTimer.Enabled) + { + _AutoplayTimer = new System.Timers.Timer(delay); + _AutoplayTimer.AutoReset = false; + _AutoplayTimer.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => + { + _PreviewSelectedSong(); + }; + _AutoplayTimer.Start(); + } + else + { + _AutoplayTimer.Stop(); + _AutoplayTimer.Start(); + } + } + private void _UpdateListIfRequired() { int curElements = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();