public MusicPlaylist(World world, MusicPlaylistInfo info) { this.info = info; IsMusicAvailable = world.Map.Rules.InstalledMusic.Any(); playlist = world.Map.Rules.InstalledMusic.Select(a => a.Value).ToArray(); if (!IsMusicAvailable) return; random = playlist.Shuffle(Game.CosmeticRandom).ToArray(); if (!string.IsNullOrEmpty(info.StartingMusic) && world.Map.Rules.Music.ContainsKey(info.StartingMusic) && world.Map.Rules.Music[info.StartingMusic].Exists) { currentSong = world.Map.Rules.Music[info.StartingMusic]; repeat = info.LoopStartingMusic; } else { currentSong = Game.Settings.Sound.Shuffle ? random.First() : playlist.First(); repeat = Game.Settings.Sound.Repeat; } Play(); }
public static void Initialize() { sounds = new Cache<string, ISoundSource>(LoadSound); music = null; currentMusic = null; video = null; }
public MusicPlaylist(World world, MusicPlaylistInfo info) { this.info = info; this.world = world; IsMusicInstalled = world.Map.Rules.InstalledMusic.Any(); if (!IsMusicInstalled) return; playlist = world.Map.Rules.InstalledMusic .Where(a => !a.Value.Hidden) .Select(a => a.Value) .ToArray(); random = playlist.Shuffle(Game.CosmeticRandom).ToArray(); IsMusicAvailable = playlist.Any(); if (SongExists(info.StartingMusic)) currentSong = world.Map.Rules.Music[info.StartingMusic]; else if (SongExists(info.BackgroundMusic)) { currentSong = currentBackgroundSong = world.Map.Rules.Music[info.BackgroundMusic]; CurrentSongIsBackground = true; } else { // Start playback with a random song, but only if the player has installed more music var installData = Game.ModData.Manifest.Get<ContentInstaller>(); if (playlist.Length > installData.ShippedSoundtracks) currentSong = random.FirstOrDefault(); } Play(); }
public MusicPlayerLogic(Widget widget, Ruleset modRules, Action onExit) { this.modRules = modRules; var panel = widget.Get("MUSIC_PANEL"); musicList = panel.Get<ScrollPanelWidget>("MUSIC_LIST"); itemTemplate = musicList.Get<ScrollItemWidget>("MUSIC_TEMPLATE"); BuildMusicTable(); Func<bool> noMusic = () => !installed; panel.Get("NO_MUSIC_LABEL").IsVisible = noMusic; var playButton = panel.Get<ButtonWidget>("BUTTON_PLAY"); playButton.OnClick = Play; playButton.IsDisabled = noMusic; playButton.IsVisible = () => !Sound.MusicPlaying; var pauseButton = panel.Get<ButtonWidget>("BUTTON_PAUSE"); pauseButton.OnClick = Sound.PauseMusic; pauseButton.IsDisabled = noMusic; pauseButton.IsVisible = () => Sound.MusicPlaying; var stopButton = panel.Get<ButtonWidget>("BUTTON_STOP"); stopButton.OnClick = Sound.StopMusic; stopButton.IsDisabled = noMusic; var nextButton = panel.Get<ButtonWidget>("BUTTON_NEXT"); nextButton.OnClick = () => { currentSong = GetNextSong(); Play(); }; nextButton.IsDisabled = noMusic; var prevButton = panel.Get<ButtonWidget>("BUTTON_PREV"); prevButton.OnClick = () => { currentSong = GetPrevSong(); Play(); }; prevButton.IsDisabled = noMusic; var shuffleCheckbox = panel.Get<CheckboxWidget>("SHUFFLE"); shuffleCheckbox.IsChecked = () => Game.Settings.Sound.Shuffle; shuffleCheckbox.OnClick = () => Game.Settings.Sound.Shuffle ^= true; var repeatCheckbox = panel.Get<CheckboxWidget>("REPEAT"); repeatCheckbox.IsChecked = () => Game.Settings.Sound.Repeat; repeatCheckbox.OnClick = () => Game.Settings.Sound.Repeat ^= true; 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); var musicSlider = panel.Get<SliderWidget>("MUSIC_SLIDER"); musicSlider.OnChange += x => Sound.MusicVolume = x; musicSlider.Value = Sound.MusicVolume; panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); }; }
public MusicPlaylist(World world, MusicPlaylistInfo info) { this.info = info; this.world = world; if (info.DisableWorldSounds) Game.Sound.DisableWorldSounds = true; IsMusicInstalled = world.Map.Rules.InstalledMusic.Any(); if (!IsMusicInstalled) return; playlist = world.Map.Rules.InstalledMusic .Where(a => !a.Value.Hidden) .Select(a => a.Value) .ToArray(); random = playlist.Shuffle(Game.CosmeticRandom).ToArray(); IsMusicAvailable = playlist.Any(); if (SongExists(info.BackgroundMusic)) { currentSong = currentBackgroundSong = world.Map.Rules.Music[info.BackgroundMusic]; CurrentSongIsBackground = true; } else { // Start playback with a random song currentSong = random.FirstOrDefault(); } if (SongExists(info.StartingMusic)) { currentSong = world.Map.Rules.Music[info.StartingMusic]; CurrentSongIsBackground = false; } Play(); }
public void GameOver(World world) { if (!IsMusicAvailable) return; var playedSong = currentSong; if (world.LocalPlayer.WinState == WinState.Won) { if (!string.IsNullOrEmpty(info.VictoryMusic) && world.Map.Rules.Music.ContainsKey(info.VictoryMusic) && world.Map.Rules.Music[info.VictoryMusic].Exists) { currentSong = world.Map.Rules.Music[info.VictoryMusic]; repeat = info.LoopVictoryMusic; } } else { // Most RTS treats observers losing the game, // no need for a special handling involving them here. if (!string.IsNullOrEmpty(info.DefeatMusic) && world.Map.Rules.Music.ContainsKey(info.DefeatMusic) && world.Map.Rules.Music[info.DefeatMusic].Exists) { currentSong = world.Map.Rules.Music[info.DefeatMusic]; repeat = info.LoopDefeatMusic; } } if (playedSong != currentSong) Play(); }
public MusicPlayerLogic(Widget widget, Ruleset modRules, World world, Action onExit) { var panel = widget; musicList = panel.Get<ScrollPanelWidget>("MUSIC_LIST"); itemTemplate = musicList.Get<ScrollItemWidget>("MUSIC_TEMPLATE"); musicPlaylist = world.WorldActor.Trait<MusicPlaylist>(); BuildMusicTable(); 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; playButton.IsDisabled = noMusic; playButton.IsVisible = () => !Game.Sound.MusicPlaying; var pauseButton = panel.Get<ButtonWidget>("BUTTON_PAUSE"); pauseButton.OnClick = Game.Sound.PauseMusic; pauseButton.IsDisabled = noMusic; pauseButton.IsVisible = () => Game.Sound.MusicPlaying; var stopButton = panel.Get<ButtonWidget>("BUTTON_STOP"); stopButton.OnClick = () => { musicPlaylist.Stop(); }; stopButton.IsDisabled = noMusic; var nextButton = panel.Get<ButtonWidget>("BUTTON_NEXT"); nextButton.OnClick = () => { currentSong = musicPlaylist.GetNextSong(); Play(); }; nextButton.IsDisabled = noMusic; var prevButton = panel.Get<ButtonWidget>("BUTTON_PREV"); prevButton.OnClick = () => { currentSong = musicPlaylist.GetPrevSong(); Play(); }; prevButton.IsDisabled = noMusic; 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 = () => { if (currentSong == null || musicPlaylist.CurrentSongIsBackground) return ""; var minutes = (int)Game.Sound.MusicSeekPosition / 60; var seconds = (int)Game.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 musicTitle = panel.GetOrNull<LabelWidget>("TITLE_LABEL"); if (musicTitle != null) musicTitle.GetText = () => currentSong != null ? currentSong.Title : "No song playing"; var musicSlider = panel.Get<SliderWidget>("MUSIC_SLIDER"); musicSlider.OnChange += x => Game.Sound.MusicVolume = x; musicSlider.Value = Game.Sound.MusicVolume; var installButton = widget.GetOrNull<ButtonWidget>("INSTALL_BUTTON"); if (installButton != null) { installButton.IsDisabled = () => world.Type != WorldType.Shellmap; var args = new[] { "installMusic={0}".F(Game.ModData.Manifest.Mod.Id) }; installButton.OnClick = () => Game.RunAfterTick(() => Game.InitializeMod("modchooser", new Arguments(args))); var installData = Game.ModData.Manifest.Get<ContentInstaller>(); installButton.IsVisible = () => modRules.InstalledMusic.ToArray().Length <= installData.ShippedSoundtracks; } var songWatcher = widget.GetOrNull<LogicTickerWidget>("SONG_WATCHER"); if (songWatcher != null) { songWatcher.OnTick = () => { if (musicPlaylist.CurrentSongIsBackground && currentSong != null) currentSong = null; if (Game.Sound.CurrentMusic == null || currentSong == Game.Sound.CurrentMusic || musicPlaylist.CurrentSongIsBackground) return; currentSong = Game.Sound.CurrentMusic; }; } var backButton = panel.GetOrNull<ButtonWidget>("BACK_BUTTON"); if (backButton != null) backButton.OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); }; }
void Play() { if (currentSong == null || !IsMusicAvailable) return; Sound.PlayMusicThen(currentSong, () => { if (!repeat) currentSong = GetNextSong(); Play(); }); }
public void BuildMusicTable() { music = modRules.InstalledMusic.Select(a => a.Value).ToArray(); random = music.Shuffle(Game.CosmeticRandom).ToArray(); currentSong = Sound.CurrentMusic; if (currentSong == null && music.Any()) currentSong = Game.Settings.Sound.Shuffle ? random.First() : music.First(); musicList.RemoveChildren(); foreach (var s in music) { var song = s; if (currentSong == null) currentSong = song; // TODO: We leak the currentSong MusicInfo across map load, so compare the Filename instead. var item = ScrollItemWidget.Setup(song.Filename, itemTemplate, () => currentSong.Filename == song.Filename, () => { currentSong = song; Play(); }, () => {}); item.Get<LabelWidget>("TITLE").GetText = () => song.Title; item.Get<LabelWidget>("LENGTH").GetText = () => SongLengthLabel(song); musicList.AddChild(item); } if (currentSong != null) musicList.ScrollToItem(currentSong.Filename); installed = modRules.InstalledMusic.Any(); }
public static void PlayMusicThen(MusicInfo m, Action then) { if (m == null || !m.Exists) return; OnMusicComplete = then; if (m == currentMusic && music != null) { soundEngine.PauseSound(music, false); MusicPlaying = true; return; } StopMusic(); var sound = sounds[m.Filename]; if (sound == null) return; music = soundEngine.Play2D(sound, false, true, WPos.Zero, MusicVolume, false); currentMusic = m; MusicPlaying = true; }
public void GameOver(World world) { if (world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Won) { if (SongExists(info.VictoryMusic)) { currentBackgroundSong = world.Map.Rules.Music[info.VictoryMusic]; Stop(); } } else { // Most RTS treats observers losing the game, // no need for a special handling involving them here. if (SongExists(info.DefeatMusic)) { currentBackgroundSong = world.Map.Rules.Music[info.DefeatMusic]; Stop(); } } }
public void BuildMusicTable() { if (!musicPlaylist.IsMusicAvailable) return; var music = musicPlaylist.AvailablePlaylist(); currentSong = musicPlaylist.CurrentSong(); if (currentSong == null && music.Any()) currentSong = musicPlaylist.GetNextSong(); musicList.RemoveChildren(); foreach (var s in music) { var song = s; if (currentSong == null) currentSong = song; var item = ScrollItemWidget.Setup(song.Filename, itemTemplate, () => currentSong == song, () => { currentSong = song; Play(); }, () => { }); item.Get<LabelWidget>("TITLE").GetText = () => song.Title; item.Get<LabelWidget>("LENGTH").GetText = () => SongLengthLabel(song); musicList.AddChild(item); } if (currentSong != null) musicList.ScrollToItem(currentSong.Filename); }
public MusicPlayerLogic(Widget widget, Ruleset modRules, World world, Action onExit) { var panel = widget.Get("MUSIC_PANEL"); musicList = panel.Get<ScrollPanelWidget>("MUSIC_LIST"); itemTemplate = musicList.Get<ScrollItemWidget>("MUSIC_TEMPLATE"); musicPlaylist = world.WorldActor.Trait<MusicPlaylist>(); BuildMusicTable(); Func<bool> noMusic = () => !musicPlaylist.IsMusicAvailable; panel.Get("NO_MUSIC_LABEL").IsVisible = noMusic; var playButton = panel.Get<ButtonWidget>("BUTTON_PLAY"); playButton.OnClick = Play; playButton.IsDisabled = noMusic; playButton.IsVisible = () => !Sound.MusicPlaying; var pauseButton = panel.Get<ButtonWidget>("BUTTON_PAUSE"); pauseButton.OnClick = Sound.PauseMusic; pauseButton.IsDisabled = noMusic; pauseButton.IsVisible = () => Sound.MusicPlaying; var stopButton = panel.Get<ButtonWidget>("BUTTON_STOP"); stopButton.OnClick = () => { musicPlaylist.Stop(); }; stopButton.IsDisabled = noMusic; var nextButton = panel.Get<ButtonWidget>("BUTTON_NEXT"); nextButton.OnClick = () => { currentSong = musicPlaylist.GetNextSong(); Play(); }; nextButton.IsDisabled = noMusic; var prevButton = panel.Get<ButtonWidget>("BUTTON_PREV"); prevButton.OnClick = () => { currentSong = musicPlaylist.GetPrevSong(); Play(); }; prevButton.IsDisabled = noMusic; var shuffleCheckbox = panel.Get<CheckboxWidget>("SHUFFLE"); shuffleCheckbox.IsChecked = () => Game.Settings.Sound.Shuffle; shuffleCheckbox.OnClick = () => Game.Settings.Sound.Shuffle ^= true; var repeatCheckbox = panel.Get<CheckboxWidget>("REPEAT"); repeatCheckbox.IsChecked = () => Game.Settings.Sound.Repeat; repeatCheckbox.OnClick = () => Game.Settings.Sound.Repeat ^= true; 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); var musicSlider = panel.Get<SliderWidget>("MUSIC_SLIDER"); musicSlider.OnChange += x => Sound.MusicVolume = x; musicSlider.Value = Sound.MusicVolume; var installButton = widget.GetOrNull<ButtonWidget>("INSTALL_BUTTON"); if (installButton != null) { installButton.IsDisabled = () => world == null || world.Type != WorldType.Shellmap; var args = new string[] { "Install.Music=true" }; installButton.OnClick = () => Game.RunAfterTick(() => Game.InitializeMod(Game.Settings.Game.Mod, new Arguments(args))); var installData = Game.ModData.Manifest.Get<ContentInstaller>(); installButton.IsVisible = () => modRules.InstalledMusic.ToArray().Length <= installData.ShippedSoundtracks; } var songWatcher = widget.GetOrNull<LogicTickerWidget>("SONG_WATCHER"); if (songWatcher != null) { songWatcher.OnTick = () => { if (Sound.CurrentMusic == null || currentSong == Sound.CurrentMusic) return; currentSong = Sound.CurrentMusic; }; } panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); }; }
void BuildMusicTable(Widget list) { music = Rules.Music.Where(a => a.Value.Exists).Select(a => a.Value).ToArray(); random = music.Shuffle(Game.CosmeticRandom).ToArray(); list.RemoveChildren(); foreach (var s in music) { var song = s; if (currentSong == null) currentSong = song; var item = ScrollItemWidget.Setup(itemTemplate, () => currentSong == song, () => { currentSong = song; Play(); }); item.Get<LabelWidget>("TITLE").GetText = () => song.Title; item.Get<LabelWidget>("LENGTH").GetText = () => SongLengthLabel(song); list.AddChild(item); } }
public CncMusicPlayerLogic(Widget widget, Action onExit) { panel = widget.Get("MUSIC_PANEL"); var ml = panel.Get<ScrollPanelWidget>("MUSIC_LIST"); itemTemplate = ml.Get<ScrollItemWidget>("MUSIC_TEMPLATE"); BuildMusicTable(ml); currentSong = Sound.CurrentMusic ?? GetNextSong(); installed = Rules.Music.Where(m => m.Value.Exists).Any(); Func<bool> noMusic = () => !installed; panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); }; Action afterInstall = () => { // Mount the new mixfile and rebuild the scores list try { var path = new string[] { Platform.SupportDir, "Content", "cnc" }.Aggregate(Path.Combine); FileSystem.Mount(Path.Combine(path, "scores.mix")); FileSystem.Mount(Path.Combine(path, "transit.mix")); Rules.Music.Do(m => m.Value.Reload()); } catch (Exception) { } installed = Rules.Music.Where(m => m.Value.Exists).Any(); BuildMusicTable(ml); }; var installButton = panel.Get<ButtonWidget>("INSTALL_BUTTON"); installButton.OnClick = () => Ui.OpenWindow("INSTALL_MUSIC_PANEL", new WidgetArgs() { { "afterInstall", afterInstall }, { "filesToCopy", new [] { "SCORES.MIX" } }, { "filesToExtract", new [] { "transit.mix" } }, }); installButton.IsVisible = () => music.Length < 3; // Hack around music being split between transit.mix and scores.mix panel.Get("NO_MUSIC_LABEL").IsVisible = noMusic; var playButton = panel.Get<ButtonWidget>("BUTTON_PLAY"); playButton.OnClick = Play; playButton.IsDisabled = noMusic; var pauseButton = panel.Get<ButtonWidget>("BUTTON_PAUSE"); pauseButton.OnClick = Pause; pauseButton.IsDisabled = noMusic; var stopButton = panel.Get<ButtonWidget>("BUTTON_STOP"); stopButton.OnClick = Stop; stopButton.IsDisabled = noMusic; var nextButton = panel.Get<ButtonWidget>("BUTTON_NEXT"); nextButton.OnClick = () => { currentSong = GetNextSong(); Play(); }; nextButton.IsDisabled = noMusic; var prevButton = panel.Get<ButtonWidget>("BUTTON_PREV"); prevButton.OnClick = () => { currentSong = GetPrevSong(); Play(); }; prevButton.IsDisabled = noMusic; var shuffleCheckbox = panel.Get<CheckboxWidget>("SHUFFLE"); shuffleCheckbox.IsChecked = () => Game.Settings.Sound.Shuffle; shuffleCheckbox.OnClick = () => Game.Settings.Sound.Shuffle ^= true; var repeatCheckbox = panel.Get<CheckboxWidget>("REPEAT"); repeatCheckbox.IsChecked = () => Game.Settings.Sound.Repeat; repeatCheckbox.OnClick = () => Game.Settings.Sound.Repeat ^= true; 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>("TITLE_LABEL").GetText = () => (currentSong == null) ? "" : currentSong.Title; var musicSlider = panel.Get<SliderWidget>("MUSIC_SLIDER"); musicSlider.OnChange += x => Sound.MusicVolume = x; musicSlider.Value = Sound.MusicVolume; }
bool SongExists(MusicInfo song) { return song != null && song.Exists; }
void Play() { if (!SongExists(currentSong)) return; Sound.PlayMusicThen(currentSong, () => { if (!CurrentSongIsBackground && !Game.Settings.Sound.Repeat) currentSong = GetNextSong(); Play(); }); }
public void Stop() { currentSong = null; Sound.StopMusic(); if (currentBackgroundSong != null) { currentSong = currentBackgroundSong; CurrentSongIsBackground = true; Play(); } }
public void Play(MusicInfo music, Action onComplete) { if (music == null) return; currentSong = music; CurrentSongIsBackground = false; Sound.PlayMusicThen(music, onComplete); }
public void Play(MusicInfo music) { if (music == null) return; currentSong = music; CurrentSongIsBackground = false; Play(); }
void Play() { if (currentSong == null) return; Sound.PlayMusicThen(currentSong, () => { if (!Game.Settings.Sound.Repeat) currentSong = GetNextSong(); Play(); }); panel.Get("BUTTON_PLAY").Visible = false; panel.Get("BUTTON_PAUSE").Visible = true; }
public MusicPlayerLogic(Widget widget, ModData modData, World world, Action onExit) { var panel = widget; musicList = panel.Get<ScrollPanelWidget>("MUSIC_LIST"); itemTemplate = musicList.Get<ScrollItemWidget>("MUSIC_TEMPLATE"); musicPlaylist = world.WorldActor.Trait<MusicPlaylist>(); BuildMusicTable(); Func<bool> noMusic = () => !musicPlaylist.IsMusicAvailable || musicPlaylist.CurrentSongIsBackground || currentSong == null; panel.Get("NO_MUSIC_LABEL").IsVisible = () => !musicPlaylist.IsMusicAvailable; if (musicPlaylist.IsMusicAvailable) { panel.Get<LabelWidget>("MUTE_LABEL").GetText = () => { if (Game.Settings.Sound.Mute) return "Audio has been muted in settings."; return ""; }; } var playButton = panel.Get<ButtonWidget>("BUTTON_PLAY"); playButton.OnClick = Play; playButton.IsDisabled = noMusic; playButton.IsVisible = () => !Game.Sound.MusicPlaying; var pauseButton = panel.Get<ButtonWidget>("BUTTON_PAUSE"); pauseButton.OnClick = Game.Sound.PauseMusic; pauseButton.IsDisabled = noMusic; pauseButton.IsVisible = () => Game.Sound.MusicPlaying; var stopButton = panel.Get<ButtonWidget>("BUTTON_STOP"); stopButton.OnClick = () => { musicPlaylist.Stop(); }; stopButton.IsDisabled = noMusic; var nextButton = panel.Get<ButtonWidget>("BUTTON_NEXT"); nextButton.OnClick = () => { currentSong = musicPlaylist.GetNextSong(); Play(); }; nextButton.IsDisabled = noMusic; var prevButton = panel.Get<ButtonWidget>("BUTTON_PREV"); prevButton.OnClick = () => { currentSong = musicPlaylist.GetPrevSong(); Play(); }; prevButton.IsDisabled = noMusic; 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 = () => { if (currentSong == null || musicPlaylist.CurrentSongIsBackground) return ""; var minutes = (int)Game.Sound.MusicSeekPosition / 60; var seconds = (int)Game.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 musicTitle = panel.GetOrNull<LabelWidget>("TITLE_LABEL"); if (musicTitle != null) musicTitle.GetText = () => currentSong != null ? currentSong.Title : "No song playing"; var musicSlider = panel.Get<SliderWidget>("MUSIC_SLIDER"); musicSlider.OnChange += x => Game.Sound.MusicVolume = x; musicSlider.Value = Game.Sound.MusicVolume; var songWatcher = widget.GetOrNull<LogicTickerWidget>("SONG_WATCHER"); if (songWatcher != null) { songWatcher.OnTick = () => { if (musicPlaylist.CurrentSongIsBackground && currentSong != null) currentSong = null; if (Game.Sound.CurrentMusic == null || currentSong == Game.Sound.CurrentMusic || musicPlaylist.CurrentSongIsBackground) return; currentSong = Game.Sound.CurrentMusic; }; } var backButton = panel.GetOrNull<ButtonWidget>("BACK_BUTTON"); if (backButton != null) backButton.OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); }; }
public void Initialize(ISoundLoader[] loaders, IReadOnlyFileSystem fileSystem) { sounds = new Cache<string, ISoundSource>(s => LoadSound(loaders, fileSystem, s)); currentSounds = new Dictionary<uint, ISound>(); music = null; currentMusic = null; video = null; }
public void PlayMusic(string track = null, LuaFunction func = null) { if (!Game.Settings.Sound.MapMusic) return; var music = world.Map.Rules.InstalledMusic.Select(a => a.Value).ToArray(); if (!music.Any()) return; var musicInfo = !string.IsNullOrEmpty(track) ? world.Map.Rules.Music[track] : Game.Settings.Sound.Repeat && previousMusic != null ? previousMusic : Game.Settings.Sound.Shuffle ? music.Random(Game.CosmeticRandom) : previousMusic == null ? music.First() : music.SkipWhile(s => s != previousMusic).Skip(1).First(); if (func != null) { var f = func.CopyReference() as LuaFunction; onComplete = () => { try { using (f) f.Call().Dispose(); } catch (LuaException e) { Context.FatalError(e.Message); } }; } else onComplete = () => { }; Sound.PlayMusicThen(musicInfo, onComplete); previousMusic = Sound.CurrentMusic; }
static string SongLengthLabel(MusicInfo song) { return "{0:D1}:{1:D2}".F(song.Length / 60, song.Length % 60); }
public void Play(MusicInfo music) { if (music == null || !IsMusicAvailable) return; currentSong = music; repeat = Game.Settings.Sound.Repeat; Sound.PlayMusicThen(music, () => { if (!repeat) currentSong = GetNextSong(); Play(); }); }
public static void PlayMusic(MusicInfo m) { PlayMusicThen(m, () => { }); }
public void Play(MusicInfo music, Action onComplete) { if (music == null || !IsMusicAvailable) return; currentSong = music; Sound.PlayMusicThen(music, onComplete); }
public static void StopMusic() { if (music != null) soundEngine.StopSound(music); MusicPlaying = false; currentMusic = null; }
public void Stop() { currentSong = null; Sound.StopMusic(); }