BackgroundMusic is now disabled properly

Moved video handling to CPopupScreenPlayerControl.cs
Some cleanup
This commit is contained in:
Stephan Sundermann committed 2012-03-10 12:00:48 +01:00
1 parent 4a37ca024e
commit 2c9cdd7f23
6 files changed
+89 -60

No files matched your search

+24 -37
View File
@@ -28,7 +28,7 @@ namespace Vocaluxe.Base
private static bool _BackgroundMusicAdded; private static bool _BackgroundMusicAdded;
private static bool _Playing; private static bool _Playing;
private static bool _VideoEnabled; private static bool _VideoEnabled;
private static bool _SmallVideoIsEnabled; private static bool _Disabled;
private static int _Video = -1; private static int _Video = -1;
private static STexture _CurrentVideoTexture = new STexture(-1); private static STexture _CurrentVideoTexture = new STexture(-1);
@@ -50,8 +50,8 @@ namespace Vocaluxe.Base
if(CConfig.BackgroundMusicSource != EBackgroundMusicSource.TR_CONFIG_ONLY_OWN_MUSIC) if(CConfig.BackgroundMusicSource != EBackgroundMusicSource.TR_CONFIG_ONLY_OWN_MUSIC)
AddBackgroundMusic(); AddBackgroundMusic();
if (VideoToBackgroundIsEnabled()) if (CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON)
ApplyBackgroundVideo(); EnableVideo();
_Playing = false; _Playing = false;
} }
@@ -72,8 +72,6 @@ namespace Vocaluxe.Base
} }
else else
Next(); Next();
if ((_VideoEnabled && _SmallVideoIsEnabled) || (_VideoEnabled && VideoToBackgroundIsEnabled()))
LoadVideo();
} }
} }
} }
@@ -94,7 +92,7 @@ namespace Vocaluxe.Base
public static void Pause() public static void Pause()
{ {
if (_VideoEnabled && _Video != 0) if (_VideoEnabled && _Video != -1)
CVideo.VdPause(_Video); CVideo.VdPause(_Video);
CSound.FadeAndPause(_CurrentMusicStream, 0f, CSettings.BackgroundMusicFadeTime); CSound.FadeAndPause(_CurrentMusicStream, 0f, CSettings.BackgroundMusicFadeTime);
_Playing = false; _Playing = false;
@@ -135,6 +133,8 @@ namespace Vocaluxe.Base
_CurrentPlaylistElement = _PreviousFileNames[_PreviousMusicIndex]; _CurrentPlaylistElement = _PreviousFileNames[_PreviousMusicIndex];
} }
_CurrentMusicStream = CSound.Load(_CurrentPlaylistElement.GetMusicFilePath()); _CurrentMusicStream = CSound.Load(_CurrentPlaylistElement.GetMusicFilePath());
if (_VideoEnabled)
LoadVideo();
CSound.SetStreamVolume(_CurrentMusicStream, 0f); CSound.SetStreamVolume(_CurrentMusicStream, 0f);
Play(); Play();
} }
@@ -155,6 +155,8 @@ namespace Vocaluxe.Base
_CurrentPlaylistElement = _PreviousFileNames[_PreviousMusicIndex]; _CurrentPlaylistElement = _PreviousFileNames[_PreviousMusicIndex];
_CurrentMusicStream = CSound.Load(_CurrentPlaylistElement.GetMusicFilePath()); _CurrentMusicStream = CSound.Load(_CurrentPlaylistElement.GetMusicFilePath());
if (_VideoEnabled)
LoadVideo();
CSound.SetStreamVolume(_CurrentMusicStream, 0f); CSound.SetStreamVolume(_CurrentMusicStream, 0f);
Play(); Play();
} }
@@ -352,22 +354,6 @@ namespace Vocaluxe.Base
return _VideoEnabled; return _VideoEnabled;
} }
public static bool VideoToBackgroundIsEnabled()
{
return CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON;
}
public static bool SmallVideoIsEnabled()
{
return _SmallVideoIsEnabled;
}
public static void ToggleSmallVideo()
{
_SmallVideoIsEnabled = !_SmallVideoIsEnabled;
ApplyBackgroundVideo();
}
public static bool HasVideo() public static bool HasVideo()
{ {
return File.Exists(_CurrentPlaylistElement.GetVideoFilePath()); return File.Exists(_CurrentPlaylistElement.GetVideoFilePath());
@@ -395,26 +381,27 @@ namespace Vocaluxe.Base
} }
} }
public static void ToggleVideoToBackground() public static void EnableVideo()
{ {
if (VideoToBackgroundIsEnabled()) if (!_VideoEnabled)
{
CConfig.VideosToBackground = EOffOn.TR_CONFIG_OFF;
if (!_SmallVideoIsEnabled) //No videos are enabled so we should call ToggleVideo() to close
ToggleVideo(); ToggleVideo();
} }
else
{
CConfig.VideosToBackground = EOffOn.TR_CONFIG_ON;
ApplyBackgroundVideo();
}
CConfig.SaveConfig();
}
public static void ApplyBackgroundVideo() public static void Disable()
{ {
if (!_VideoEnabled && (!_SmallVideoIsEnabled || !VideoToBackgroundIsEnabled()) || (!_SmallVideoIsEnabled && !VideoToBackgroundIsEnabled())) //No videos are enabled so we should call ToggleVideo() to close Pause();
ToggleVideo(); _Disabled = true;
}
public static void Enable()
{
Play();
_Disabled = false;
}
public static bool IsEnabled()
{
return !_Disabled;
} }
} }
} }
+1 -1
View File
@@ -137,7 +137,7 @@ namespace Vocaluxe.Menu
public bool Draw() public bool Draw()
{ {
bool ok = false; bool ok = false;
if (_Theme.Type == EBackgroundTypes.Video && CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON && CBackgroundMusic.VideoToBackgroundIsEnabled() && CBackgroundMusic.IsPlaying() && CBackgroundMusic.HasVideo() && CBackgroundMusic.IsVideoEnabled()) if (_Theme.Type == EBackgroundTypes.Video && CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON && CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON && CBackgroundMusic.IsPlaying() && CBackgroundMusic.HasVideo() && CBackgroundMusic.IsVideoEnabled() && CBackgroundMusic.IsEnabled())
{ {
Pause(); Pause();
ok = DrawBackgroundMusicVideo(); ok = DrawBackgroundMusicVideo();
+57 -17
View File
@@ -30,6 +30,30 @@ namespace Vocaluxe.Screens
private const string TextCurrentSong = "TextCurrentSong"; private const string TextCurrentSong = "TextCurrentSong";
private bool _VideoPreview = false;
private bool _VideoBackground
{
get
{
return CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON;
}
set
{
if (CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON)
{
CConfig.VideosToBackground = EOffOn.TR_CONFIG_OFF;
if (!_VideoPreview) //No videos are enabled so we should call ToggleVideo() to close
CBackgroundMusic.ToggleVideo();
}
else
{
CConfig.VideosToBackground = EOffOn.TR_CONFIG_ON;
CBackgroundMusic.EnableVideo();
}
CConfig.SaveConfig();
}
}
public CPopupScreenPlayerControl() public CPopupScreenPlayerControl()
{ {
Init(); Init();
@@ -92,11 +116,11 @@ namespace Vocaluxe.Screens
if (Buttons[htButtons(ButtonRepeat)].Selected) if (Buttons[htButtons(ButtonRepeat)].Selected)
CBackgroundMusic.Repeat(); CBackgroundMusic.Repeat();
if (Buttons[htButtons(ButtonShowVideo)].Selected) if (Buttons[htButtons(ButtonShowVideo)].Selected)
CBackgroundMusic.ToggleSmallVideo(); TogglePreviewVideo();
if (Buttons[htButtons(ButtonSing)].Selected) if (Buttons[htButtons(ButtonSing)].Selected)
StartSong(CBackgroundMusic.GetSongNr(), CBackgroundMusic.IsDuet()); StartSong(CBackgroundMusic.GetSongNr(), CBackgroundMusic.IsDuet());
if (Buttons[htButtons(ButtonToBackgroundVideo)].Selected) if (Buttons[htButtons(ButtonToBackgroundVideo)].Selected)
CBackgroundMusic.ToggleVideoToBackground(); ToggleBackgroundVideo();
break; break;
} }
} }
@@ -120,11 +144,11 @@ namespace Vocaluxe.Screens
if (Buttons[htButtons(ButtonRepeat)].Selected) if (Buttons[htButtons(ButtonRepeat)].Selected)
CBackgroundMusic.Repeat(); CBackgroundMusic.Repeat();
if (Buttons[htButtons(ButtonShowVideo)].Selected) if (Buttons[htButtons(ButtonShowVideo)].Selected)
CBackgroundMusic.ToggleSmallVideo(); TogglePreviewVideo();
if (Buttons[htButtons(ButtonSing)].Selected) if (Buttons[htButtons(ButtonSing)].Selected)
StartSong(CBackgroundMusic.GetSongNr(), CBackgroundMusic.IsDuet()); StartSong(CBackgroundMusic.GetSongNr(), CBackgroundMusic.IsDuet());
if (Buttons[htButtons(ButtonToBackgroundVideo)].Selected) if (Buttons[htButtons(ButtonToBackgroundVideo)].Selected)
CBackgroundMusic.ToggleVideoToBackground(); ToggleBackgroundVideo();
} else if (MouseEvent.LB) } else if (MouseEvent.LB)
{ {
CGraphics.HidePopup(EPopupScreens.PopupPlayerControl); CGraphics.HidePopup(EPopupScreens.PopupPlayerControl);
@@ -139,33 +163,24 @@ namespace Vocaluxe.Screens
public override bool UpdateGame() public override bool UpdateGame()
{ {
Statics[htStatics(StaticCover)].Visible = !CBackgroundMusic.SmallVideoIsEnabled(); Statics[htStatics(StaticCover)].Visible = !_VideoPreview;
Buttons[htButtons(ButtonToBackgroundVideo)].Pressed = CBackgroundMusic.VideoToBackgroundIsEnabled(); Buttons[htButtons(ButtonToBackgroundVideo)].Pressed = _VideoBackground;
Buttons[htButtons(ButtonShowVideo)].Pressed = CBackgroundMusic.SmallVideoIsEnabled(); Buttons[htButtons(ButtonShowVideo)].Pressed = _VideoPreview;
return true; return true;
} }
public override void OnShow() public override void OnShow()
{ {
base.OnShow(); base.OnShow();
} }
public override bool Draw() public override bool Draw()
{ {
if (!_Active) if (!_Active)
return false; return false;
Statics[htStatics(StaticCover)].Texture = CBackgroundMusic.GetCover();
if (CBackgroundMusic.IsVideoEnabled() && CBackgroundMusic.HasVideo()) if (CBackgroundMusic.IsVideoEnabled() && CBackgroundMusic.HasVideo())
{
Statics[htStatics(StaticCover)].Texture = CBackgroundMusic.GetCover();
//Statics[htStatics(StaticCover)].Visible = false;
CDraw.DrawTexture(Statics[htStatics(StaticCover)], CBackgroundMusic.GetVideoTexture(), EAspect.Crop); CDraw.DrawTexture(Statics[htStatics(StaticCover)], CBackgroundMusic.GetVideoTexture(), EAspect.Crop);
}
else
{
//Statics[htStatics(StaticCover)].Visible = true;
Statics[htStatics(StaticCover)].Texture = CBackgroundMusic.GetCover();
}
Buttons[htButtons(ButtonPause)].Visible = CBackgroundMusic.IsPlaying(); Buttons[htButtons(ButtonPause)].Visible = CBackgroundMusic.IsPlaying();
Buttons[htButtons(ButtonPlay)].Visible = !CBackgroundMusic.IsPlaying(); Buttons[htButtons(ButtonPlay)].Visible = !CBackgroundMusic.IsPlaying();
Texts[htTexts(TextCurrentSong)].Text = CBackgroundMusic.GetSongArtistAndTitle(); Texts[htTexts(TextCurrentSong)].Text = CBackgroundMusic.GetSongArtistAndTitle();
@@ -191,5 +206,30 @@ namespace Vocaluxe.Screens
CGraphics.FadeTo(EScreens.ScreenNames); CGraphics.FadeTo(EScreens.ScreenNames);
} }
} }
private void ToggleBackgroundVideo()
{
if (_VideoBackground)
{
CConfig.VideosToBackground = EOffOn.TR_CONFIG_OFF;
if (!_VideoPreview) //No videos are enabled so we should call ToggleVideo() to close
CBackgroundMusic.ToggleVideo();
}
else
{
CConfig.VideosToBackground = EOffOn.TR_CONFIG_ON;
CBackgroundMusic.EnableVideo();
}
CConfig.SaveConfig();
}
private void TogglePreviewVideo()
{
_VideoPreview = !_VideoPreview;
if (!_VideoPreview && !_VideoBackground)
CBackgroundMusic.ToggleVideo();
else
CBackgroundMusic.EnableVideo();
}
} }
} }
+1 -1
View File
@@ -128,7 +128,7 @@ namespace Vocaluxe.Screens
CConfig.VideoPreview = (EOffOn)SelectSlides[htSelectSlides(SelectSlideVideoPreview)].Selection; CConfig.VideoPreview = (EOffOn)SelectSlides[htSelectSlides(SelectSlideVideoPreview)].Selection;
CConfig.VideosInSongs = (EOffOn)SelectSlides[htSelectSlides(SelectSlideVideosInSongs)].Selection; CConfig.VideosInSongs = (EOffOn)SelectSlides[htSelectSlides(SelectSlideVideosInSongs)].Selection;
CConfig.VideosToBackground = (EOffOn)SelectSlides[htSelectSlides(SelectSlideVideosToBackground)].Selection; CConfig.VideosToBackground = (EOffOn)SelectSlides[htSelectSlides(SelectSlideVideosToBackground)].Selection;
CBackgroundMusic.ApplyBackgroundVideo(); CBackgroundMusic.EnableVideo();
CConfig.SaveConfig(); CConfig.SaveConfig();
} }
+3 -2
View File
@@ -326,7 +326,7 @@ namespace Vocaluxe.Screens
} }
SetVisuability(); SetVisuability();
CBackgroundMusic.Pause(); CBackgroundMusic.Disable();
} }
public override void OnShowFinish() public override void OnShowFinish()
@@ -335,7 +335,7 @@ namespace Vocaluxe.Screens
CGame.Start(); CGame.Start();
LoadNextSong(); LoadNextSong();
CBackgroundMusic.Pause(); CBackgroundMusic.Disable();
} }
public override bool Draw() public override bool Draw()
@@ -418,6 +418,7 @@ namespace Vocaluxe.Screens
public override void OnClose() public override void OnClose()
{ {
base.OnClose(); base.OnClose();
CBackgroundMusic.Enable();
CloseSong(); CloseSong();
} }
+3 -2
View File
@@ -173,12 +173,12 @@ namespace Vocaluxe.Screens
if ((CSongs.Category >= 0) && (song >= 0) && song < CSongs.VisibleSongs.Length) if ((CSongs.Category >= 0) && (song >= 0) && song < CSongs.VisibleSongs.Length)
{ {
Texts[htTexts(TextSelection)].Text = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title; Texts[htTexts(TextSelection)].Text = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title;
CBackgroundMusic.Pause(); CBackgroundMusic.Disable();
} }
else if ((CSongs.Category == -1) && (song >= 0) && song < CSongs.Categories.Length) else if ((CSongs.Category == -1) && (song >= 0) && song < CSongs.Categories.Length)
{ {
Texts[htTexts(TextSelection)].Text = CSongs.Categories[song].Name; Texts[htTexts(TextSelection)].Text = CSongs.Categories[song].Name;
CBackgroundMusic.Play(); CBackgroundMusic.Enable();
} }
else else
Texts[htTexts(TextSelection)].Text = String.Empty; Texts[htTexts(TextSelection)].Text = String.Empty;
@@ -213,6 +213,7 @@ namespace Vocaluxe.Screens
public override void OnClose() public override void OnClose()
{ {
base.OnClose(); base.OnClose();
CBackgroundMusic.Enable();
SongMenus[htSongMenus(SongMenu)].OnHide(); SongMenus[htSongMenus(SongMenu)].OnHide();
} }