Introduce background music concept.

This commit is contained in:
Paul Chote
2015-08-01 19:28:33 +01:00
parent 583b4f92b6
commit fb0e2c5cc3
5 changed files with 75 additions and 59 deletions

View File

@@ -35,8 +35,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
BuildMusicTable();
Func<bool> noMusic = () => !musicPlaylist.IsMusicAvailable;
panel.Get("NO_MUSIC_LABEL").IsVisible = noMusic;
Func<bool> noMusic = () => !musicPlaylist.IsMusicAvailable || musicPlaylist.CurrentSongIsBackground || currentSong == null;
panel.Get("NO_MUSIC_LABEL").IsVisible = () => !musicPlaylist.IsMusicAvailable;
var playButton = panel.Get<ButtonWidget>("BUTTON_PLAY");
playButton.OnClick = Play;
@@ -63,14 +63,25 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var shuffleCheckbox = panel.Get<CheckboxWidget>("SHUFFLE");
shuffleCheckbox.IsChecked = () => Game.Settings.Sound.Shuffle;
shuffleCheckbox.OnClick = () => Game.Settings.Sound.Shuffle ^= true;
shuffleCheckbox.IsDisabled = () => musicPlaylist.CurrentSongIsBackground;
var repeatCheckbox = panel.Get<CheckboxWidget>("REPEAT");
repeatCheckbox.IsChecked = () => Game.Settings.Sound.Repeat;
repeatCheckbox.OnClick = () => Game.Settings.Sound.Repeat ^= true;
repeatCheckbox.IsDisabled = () => musicPlaylist.CurrentSongIsBackground;
panel.Get<LabelWidget>("TIME_LABEL").GetText = () => (currentSong == null) ? "" :
"{0:D2}:{1:D2} / {2:D2}:{3:D2}".F((int)Sound.MusicSeekPosition / 60, (int)Sound.MusicSeekPosition % 60,
currentSong.Length / 60, currentSong.Length % 60);
panel.Get<LabelWidget>("TIME_LABEL").GetText = () =>
{
if (currentSong == null || musicPlaylist.CurrentSongIsBackground)
return "";
var minutes = (int)Sound.MusicSeekPosition / 60;
var seconds = (int)Sound.MusicSeekPosition % 60;
var totalMinutes = currentSong.Length / 60;
var totalSeconds = currentSong.Length % 60;
return "{0:D2}:{1:D2} / {2:D2}:{3:D2}".F(minutes, seconds, totalMinutes, totalSeconds);
};
var musicSlider = panel.Get<SliderWidget>("MUSIC_SLIDER");
musicSlider.OnChange += x => Sound.MusicVolume = x;
@@ -94,7 +105,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
songWatcher.OnTick = () =>
{
if (Sound.CurrentMusic == null || currentSong == Sound.CurrentMusic)
if (musicPlaylist.CurrentSongIsBackground && currentSong != null)
currentSong = null;
if (Sound.CurrentMusic == null || currentSong == Sound.CurrentMusic || musicPlaylist.CurrentSongIsBackground)
return;
currentSong = Sound.CurrentMusic;
@@ -127,7 +141,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
musicList.AddChild(item);
}
if (currentSong != null)
if (currentSong != null && !musicPlaylist.CurrentSongIsBackground)
musicList.ScrollToItem(currentSong.Filename);
}