From fb0e2c5cc3a70d3cb6a1be04574671ec78b4ad8c Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 1 Aug 2015 19:28:33 +0100 Subject: [PATCH 1/8] Introduce background music concept. --- OpenRA.Game/Traits/World/MusicPlaylist.cs | 97 ++++++++++--------- .../Widgets/Logic/MusicPlayerLogic.cs | 28 ++++-- mods/cnc/maps/shellmap/map.yaml | 3 +- mods/d2k/maps/shellmap/map.yaml | 3 +- mods/ts/maps/blank-shellmap/map.yaml | 3 +- 5 files changed, 75 insertions(+), 59 deletions(-) diff --git a/OpenRA.Game/Traits/World/MusicPlaylist.cs b/OpenRA.Game/Traits/World/MusicPlaylist.cs index 7542d22e2b..e79777dba3 100644 --- a/OpenRA.Game/Traits/World/MusicPlaylist.cs +++ b/OpenRA.Game/Traits/World/MusicPlaylist.cs @@ -20,20 +20,15 @@ namespace OpenRA.Traits [Desc("Music to play when the map starts.", "Plays the first song on the playlist when undefined.")] public readonly string StartingMusic = null; - [Desc("Should the starting music loop?")] - public readonly bool LoopStartingMusic = false; - [Desc("Music to play when the game has been won.")] public readonly string VictoryMusic = null; - [Desc("Should the victory music loop?")] - public readonly bool LoopVictoryMusic = false; - [Desc("Music to play when the game has been lost.")] public readonly string DefeatMusic = null; - [Desc("Should the defeat music loop?")] - public readonly bool LoopDefeatMusic = false; + [Desc("This track is played when no other music is playing.", + "It cannot be paused, but can be overridden by selecting a new track.")] + public readonly string BackgroundMusic = null; public object Create(ActorInitializer init) { return new MusicPlaylist(init.World, this); } } @@ -41,18 +36,21 @@ namespace OpenRA.Traits public class MusicPlaylist : INotifyActorDisposing, IGameOver { readonly MusicPlaylistInfo info; + readonly World world; readonly MusicInfo[] random; readonly MusicInfo[] playlist; public readonly bool IsMusicAvailable; + public bool CurrentSongIsBackground { get; private set; } MusicInfo currentSong; - bool repeat; + MusicInfo currentBackgroundSong; public MusicPlaylist(World world, MusicPlaylistInfo info) { this.info = info; + this.world = world; IsMusicAvailable = world.Map.Rules.InstalledMusic.Any(); @@ -63,22 +61,31 @@ namespace OpenRA.Traits 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) + if (SongExists(info.StartingMusic)) { currentSong = world.Map.Rules.Music[info.StartingMusic]; - repeat = info.LoopStartingMusic; } - else + else if (SongExists(info.BackgroundMusic)) { - currentSong = Game.Settings.Sound.Shuffle ? random.First() : playlist.First(); - repeat = Game.Settings.Sound.Repeat; + currentSong = currentBackgroundSong = world.Map.Rules.Music[info.BackgroundMusic]; + CurrentSongIsBackground = true; } Play(); } + bool SongExists(string song) + { + return !string.IsNullOrEmpty(song) + && world.Map.Rules.Music.ContainsKey(song) + && world.Map.Rules.Music[song].Exists; + } + + bool SongExists(MusicInfo song) + { + return song != null && song.Exists; + } + public MusicInfo CurrentSong() { return currentSong; @@ -95,43 +102,34 @@ namespace OpenRA.Traits if (!IsMusicAvailable) return; - var playedSong = currentSong; - if (world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Won) { - if (!string.IsNullOrEmpty(info.VictoryMusic) - && world.Map.Rules.Music.ContainsKey(info.VictoryMusic) - && world.Map.Rules.Music[info.VictoryMusic].Exists) + if (SongExists(info.VictoryMusic)) { - currentSong = world.Map.Rules.Music[info.VictoryMusic]; - repeat = info.LoopVictoryMusic; + 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 (!string.IsNullOrEmpty(info.DefeatMusic) - && world.Map.Rules.Music.ContainsKey(info.DefeatMusic) - && world.Map.Rules.Music[info.DefeatMusic].Exists) + if (SongExists(info.DefeatMusic)) { - currentSong = world.Map.Rules.Music[info.DefeatMusic]; - repeat = info.LoopDefeatMusic; + currentBackgroundSong = world.Map.Rules.Music[info.DefeatMusic]; + Stop(); } } - - if (playedSong != currentSong) - Play(); } void Play() { - if (currentSong == null || !IsMusicAvailable) + if (!SongExists(currentSong) || !IsMusicAvailable) return; Sound.PlayMusicThen(currentSong, () => { - if (!repeat) + if (!CurrentSongIsBackground && !Game.Settings.Sound.Repeat) currentSong = GetNextSong(); Play(); @@ -144,15 +142,9 @@ namespace OpenRA.Traits return; currentSong = music; - repeat = Game.Settings.Sound.Repeat; + CurrentSongIsBackground = false; - Sound.PlayMusicThen(music, () => - { - if (!repeat) - currentSong = GetNextSong(); - - Play(); - }); + Play(); } public void Play(MusicInfo music, Action onComplete) @@ -161,6 +153,7 @@ namespace OpenRA.Traits return; currentSong = music; + CurrentSongIsBackground = false; Sound.PlayMusicThen(music, onComplete); } @@ -181,22 +174,34 @@ namespace OpenRA.Traits var songs = Game.Settings.Sound.Shuffle ? random : playlist; - return reverse ? songs.SkipWhile(m => m != currentSong) - .Skip(1).FirstOrDefault() ?? songs.FirstOrDefault() : - songs.Reverse().SkipWhile(m => m != currentSong) - .Skip(1).FirstOrDefault() ?? songs.Reverse().FirstOrDefault(); + var next = reverse ? songs.Reverse().SkipWhile(m => m != currentSong) + .Skip(1).FirstOrDefault() ?? songs.Reverse().FirstOrDefault() : + songs.SkipWhile(m => m != currentSong) + .Skip(1).FirstOrDefault() ?? songs.FirstOrDefault(); + + if (SongExists(next)) + return next; + + return null; } public void Stop() { currentSong = null; Sound.StopMusic(); + + if (currentBackgroundSong != null) + { + currentSong = currentBackgroundSong; + CurrentSongIsBackground = true; + Play(); + } } public void Disposing(Actor self) { if (currentSong != null) - Stop(); + Sound.StopMusic(); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs index 2830512b0e..c1ce802d19 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs @@ -35,8 +35,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic BuildMusicTable(); - Func noMusic = () => !musicPlaylist.IsMusicAvailable; - panel.Get("NO_MUSIC_LABEL").IsVisible = noMusic; + Func noMusic = () => !musicPlaylist.IsMusicAvailable || musicPlaylist.CurrentSongIsBackground || currentSong == null; + panel.Get("NO_MUSIC_LABEL").IsVisible = () => !musicPlaylist.IsMusicAvailable; var playButton = panel.Get("BUTTON_PLAY"); playButton.OnClick = Play; @@ -63,14 +63,25 @@ namespace OpenRA.Mods.Common.Widgets.Logic var shuffleCheckbox = panel.Get("SHUFFLE"); shuffleCheckbox.IsChecked = () => Game.Settings.Sound.Shuffle; shuffleCheckbox.OnClick = () => Game.Settings.Sound.Shuffle ^= true; + shuffleCheckbox.IsDisabled = () => musicPlaylist.CurrentSongIsBackground; var repeatCheckbox = panel.Get("REPEAT"); repeatCheckbox.IsChecked = () => Game.Settings.Sound.Repeat; repeatCheckbox.OnClick = () => Game.Settings.Sound.Repeat ^= true; + repeatCheckbox.IsDisabled = () => musicPlaylist.CurrentSongIsBackground; - panel.Get("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("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("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); } diff --git a/mods/cnc/maps/shellmap/map.yaml b/mods/cnc/maps/shellmap/map.yaml index 2c1f73a826..acf5eb080e 100644 --- a/mods/cnc/maps/shellmap/map.yaml +++ b/mods/cnc/maps/shellmap/map.yaml @@ -995,8 +995,7 @@ Rules: LuaScript: Scripts: shellmap.lua MusicPlaylist: - StartingMusic: map1 - LoopStartingMusic: True + BackgroundMusic: map1 LST: Mobile: Speed: 42 diff --git a/mods/d2k/maps/shellmap/map.yaml b/mods/d2k/maps/shellmap/map.yaml index 31b324a808..ab67831c2a 100644 --- a/mods/d2k/maps/shellmap/map.yaml +++ b/mods/d2k/maps/shellmap/map.yaml @@ -124,8 +124,7 @@ Rules: Minimum: 1 Maximum: 1 MusicPlaylist: - StartingMusic: options - LoopStartingMusic: True + BackgroundMusic: options rockettower: Power: Amount: 100 diff --git a/mods/ts/maps/blank-shellmap/map.yaml b/mods/ts/maps/blank-shellmap/map.yaml index a7bd4c73b0..c25582f018 100644 --- a/mods/ts/maps/blank-shellmap/map.yaml +++ b/mods/ts/maps/blank-shellmap/map.yaml @@ -41,8 +41,7 @@ Rules: -SpawnMPUnits: -MPStartLocations: MusicPlaylist: - StartingMusic: intro - LoopStartingMusic: True + BackgroundMusic: intro Sequences: From 5952d8c9792d46f5d1ca63d7af0c6c9ace534981 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 1 Aug 2015 19:14:58 +0100 Subject: [PATCH 2/8] Fix crash when opening music player from TD lobby. --- OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 824f5e23c9..0052a8a805 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -560,7 +560,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic musicButton.OnClick = () => Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs { { "onExit", DoNothing }, - { "world", orderManager.World } + { "world", worldRenderer.World } }); var settingsButton = lobby.GetOrNull("SETTINGS_BUTTON"); From a8ddc4e360e1f16e32fead1e5ab2b468d0e0279a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 1 Aug 2015 19:21:12 +0100 Subject: [PATCH 3/8] Always start the game with a random song. This fixes the issue where games will always start with shellmap theme. --- OpenRA.Game/Traits/World/MusicPlaylist.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Traits/World/MusicPlaylist.cs b/OpenRA.Game/Traits/World/MusicPlaylist.cs index e79777dba3..babef06050 100644 --- a/OpenRA.Game/Traits/World/MusicPlaylist.cs +++ b/OpenRA.Game/Traits/World/MusicPlaylist.cs @@ -61,10 +61,11 @@ namespace OpenRA.Traits random = playlist.Shuffle(Game.CosmeticRandom).ToArray(); + // Always start with a random song + currentSong = random.FirstOrDefault(); + if (SongExists(info.StartingMusic)) - { currentSong = world.Map.Rules.Music[info.StartingMusic]; - } else if (SongExists(info.BackgroundMusic)) { currentSong = currentBackgroundSong = world.Map.Rules.Music[info.BackgroundMusic]; From 21254db120be82b41a503d74e8bc0859ea19b32c Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 1 Aug 2015 22:24:40 +0100 Subject: [PATCH 4/8] Add background music to RA shellmap. --- mods/ra/maps/desert-shellmap/map.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mods/ra/maps/desert-shellmap/map.yaml b/mods/ra/maps/desert-shellmap/map.yaml index 664d90db32..799075da85 100644 --- a/mods/ra/maps/desert-shellmap/map.yaml +++ b/mods/ra/maps/desert-shellmap/map.yaml @@ -1255,6 +1255,8 @@ Rules: -CrateSpawner: -SpawnMPUnits: -MPStartLocations: + MusicPlaylist: + BackgroundMusic: intro ResourceType@ore: ValuePerUnit: 0 LuaScript: From 1d80c37fdad750f2a354ee11ea197cf52215fc26 Mon Sep 17 00:00:00 2001 From: Zimmermann Gyula Date: Mon, 20 Jul 2015 14:41:55 +0200 Subject: [PATCH 5/8] Add support for hiding music tracks. --- OpenRA.Game/GameRules/MusicInfo.cs | 14 +++++++++++-- OpenRA.Game/Traits/World/MusicPlaylist.cs | 24 ++++++++++++----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/OpenRA.Game/GameRules/MusicInfo.cs b/OpenRA.Game/GameRules/MusicInfo.cs index d8568ac898..68ee8c63f7 100644 --- a/OpenRA.Game/GameRules/MusicInfo.cs +++ b/OpenRA.Game/GameRules/MusicInfo.cs @@ -15,8 +15,10 @@ namespace OpenRA.GameRules { public class MusicInfo { - public readonly string Filename = null; - public readonly string Title = null; + public readonly string Filename; + public readonly string Title; + public readonly bool Hidden; + public int Length { get; private set; } // seconds public bool Exists { get; private set; } @@ -25,17 +27,23 @@ namespace OpenRA.GameRules Title = value.Value; var nd = value.ToDictionary(); + if (nd.ContainsKey("Hidden")) + bool.TryParse(nd["Hidden"].Value, out Hidden); + var ext = nd.ContainsKey("Extension") ? nd["Extension"].Value : "aud"; Filename = (nd.ContainsKey("Filename") ? nd["Filename"].Value : key) + "." + ext; + if (!GlobalFileSystem.Exists(Filename)) return; Exists = true; using (var s = GlobalFileSystem.Open(Filename)) + { if (Filename.ToLowerInvariant().EndsWith("wav")) Length = (int)WavLoader.WaveLength(s); else Length = (int)AudLoader.SoundLength(s); + } } public void Reload() @@ -45,10 +53,12 @@ namespace OpenRA.GameRules Exists = true; using (var s = GlobalFileSystem.Open(Filename)) + { if (Filename.ToLowerInvariant().EndsWith("wav")) Length = (int)WavLoader.WaveLength(s); else Length = (int)AudLoader.SoundLength(s); + } } } } diff --git a/OpenRA.Game/Traits/World/MusicPlaylist.cs b/OpenRA.Game/Traits/World/MusicPlaylist.cs index babef06050..eb7c3f353c 100644 --- a/OpenRA.Game/Traits/World/MusicPlaylist.cs +++ b/OpenRA.Game/Traits/World/MusicPlaylist.cs @@ -41,6 +41,7 @@ namespace OpenRA.Traits readonly MusicInfo[] random; readonly MusicInfo[] playlist; + public readonly bool IsMusicInstalled; public readonly bool IsMusicAvailable; public bool CurrentSongIsBackground { get; private set; } @@ -52,13 +53,17 @@ namespace OpenRA.Traits this.info = info; this.world = world; - IsMusicAvailable = world.Map.Rules.InstalledMusic.Any(); - - playlist = world.Map.Rules.InstalledMusic.Select(a => a.Value).ToArray(); - - if (!IsMusicAvailable) + IsMusicInstalled = world.Map.Rules.InstalledMusic.Any(); + if (!IsMusicInstalled) return; + playlist = world.Map.Rules.InstalledMusic + .Where(a => !a.Value.Hidden) + .Select(a => a.Value) + .ToArray(); + + IsMusicAvailable = playlist.Any(); + random = playlist.Shuffle(Game.CosmeticRandom).ToArray(); // Always start with a random song @@ -100,9 +105,6 @@ namespace OpenRA.Traits public void GameOver(World world) { - if (!IsMusicAvailable) - return; - if (world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Won) { if (SongExists(info.VictoryMusic)) @@ -125,7 +127,7 @@ namespace OpenRA.Traits void Play() { - if (!SongExists(currentSong) || !IsMusicAvailable) + if (!SongExists(currentSong)) return; Sound.PlayMusicThen(currentSong, () => @@ -139,7 +141,7 @@ namespace OpenRA.Traits public void Play(MusicInfo music) { - if (music == null || !IsMusicAvailable) + if (music == null) return; currentSong = music; @@ -150,7 +152,7 @@ namespace OpenRA.Traits public void Play(MusicInfo music, Action onComplete) { - if (music == null || !IsMusicAvailable) + if (music == null) return; currentSong = music; From c6e246102ea07c05748d8e017165d5bce58dcddd Mon Sep 17 00:00:00 2001 From: Zimmermann Gyula Date: Fri, 17 Jul 2015 19:18:25 +0200 Subject: [PATCH 6/8] Hide the songs which were hidden in the base games. --- mods/cnc/audio/music.yaml | 8 +++++++- mods/d2k/audio/music.yaml | 2 ++ mods/ra/audio/music.yaml | 5 ++++- mods/ts/audio/music.yaml | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mods/cnc/audio/music.yaml b/mods/cnc/audio/music.yaml index 555f2c9731..363ef9c569 100644 --- a/mods/cnc/audio/music.yaml +++ b/mods/cnc/audio/music.yaml @@ -24,6 +24,7 @@ fwp: Fight Win Prevail fist226m: Iron Fist warfare: Warfare (Full Stop) win1: Great Shot! + Hidden: true win2: Great Shot! (Voiced) Filename: win2 Extension: var @@ -41,6 +42,7 @@ justdoit2: Just Do it Up (Voiced) Filename: justdoit Extension: var map1: Map Theme + Hidden: true march: March to Doom nomercy: No Mercy nomercy2: No Mercy (Voiced) @@ -58,5 +60,9 @@ target: Target (Mechanical Man) j1: Untamed Land valkyrie: Ride of the Valkyries voic226m: Voice Rhythm +outtakes: Outtakes + Hidden: true nod_map1: Nod Map Theme -nod_win1: Nod Win Theme \ No newline at end of file + Hidden: true +nod_win1: Nod Win Theme + Hidden: true diff --git a/mods/d2k/audio/music.yaml b/mods/d2k/audio/music.yaml index ae048b4609..4e811574c1 100644 --- a/mods/d2k/audio/music.yaml +++ b/mods/d2k/audio/music.yaml @@ -17,6 +17,7 @@ LANDSAND: Land of Sand Extension: AUD OPTIONS: Options Extension: AUD + Hidden: true PLOTTING: Plotting Extension: AUD RISEHARK: Rise of Harkonnen @@ -25,6 +26,7 @@ ROBOTIX: Robotix Extension: AUD SCORE: Score Extension: AUD + Hidden: true SOLDAPPR: The Soldiers Approach Extension: AUD SPICESCT: Spice Scouting diff --git a/mods/ra/audio/music.yaml b/mods/ra/audio/music.yaml index 638ecf0cdc..adab542155 100644 --- a/mods/ra/audio/music.yaml +++ b/mods/ra/audio/music.yaml @@ -1,9 +1,12 @@ intro: Intro + Hidden: true map: Map + Hidden: true score: Militant Force + Hidden: true await_r: Await bigf226m: Bigfoot -credits: End Credits +credits: Reload Fire crus226m: Crush dense_r: Dense fac1226m: Face to the Enemy 1 diff --git a/mods/ts/audio/music.yaml b/mods/ts/audio/music.yaml index b40169be56..a255032ac2 100644 --- a/mods/ts/audio/music.yaml +++ b/mods/ts/audio/music.yaml @@ -1,5 +1,6 @@ #Tiberian Sun intro: Intro + Hidden: true approach: Approach defense: The Defense duskhour: Dusk Hour @@ -14,12 +15,14 @@ nodcrush: Nod Crush pharotek: Pharotek redsky: Red Sky score: Score + Hidden: true scout: Scouting storm: Storm timebomb: Timebomb valves1b: Valves whatlurk: What Lurks maps: Map Selection + Hidden: true #Firestorm dmachine: Deploy Machines elusive: Elusive From 9b3ef9e7f74c6c9cbbcb3bceff9f1a29da263458 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 1 Aug 2015 22:50:43 +0100 Subject: [PATCH 7/8] Move MusicPlaylist to Mods.Common. --- OpenRA.Game/OpenRA.Game.csproj | 1 - OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs | 1 + .../Traits/World/MusicPlaylist.cs | 3 ++- OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs | 2 +- 5 files changed, 5 insertions(+), 3 deletions(-) rename {OpenRA.Game => OpenRA.Mods.Common}/Traits/World/MusicPlaylist.cs (98%) diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index f0e91d291e..b31585cea1 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -181,7 +181,6 @@ - diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 564ab510c2..fbaf2927d0 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -702,6 +702,7 @@ + diff --git a/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs index 67121bc392..9672635c20 100644 --- a/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs @@ -17,6 +17,7 @@ using OpenRA.FileFormats; using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Mods.Common.Effects; +using OpenRA.Mods.Common.Traits; using OpenRA.Scripting; using OpenRA.Traits; diff --git a/OpenRA.Game/Traits/World/MusicPlaylist.cs b/OpenRA.Mods.Common/Traits/World/MusicPlaylist.cs similarity index 98% rename from OpenRA.Game/Traits/World/MusicPlaylist.cs rename to OpenRA.Mods.Common/Traits/World/MusicPlaylist.cs index eb7c3f353c..89a9132b68 100644 --- a/OpenRA.Game/Traits/World/MusicPlaylist.cs +++ b/OpenRA.Mods.Common/Traits/World/MusicPlaylist.cs @@ -11,8 +11,9 @@ using System; using System.Linq; using OpenRA.GameRules; +using OpenRA.Traits; -namespace OpenRA.Traits +namespace OpenRA.Mods.Common.Traits { [Desc("Trait for music handling. Attach this to the world actor.")] public class MusicPlaylistInfo : ITraitInfo diff --git a/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs index c1ce802d19..33a57ef3e7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs @@ -11,7 +11,7 @@ using System; using System.Linq; using OpenRA.GameRules; -using OpenRA.Traits; +using OpenRA.Mods.Common.Traits; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic From 1d307bfe0755eb75f49aad2a2c475d94b9dc2a3b Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 1 Aug 2015 23:05:09 +0100 Subject: [PATCH 8/8] Disable music auto-play unless tracks are installed. --- OpenRA.Mods.Common/Traits/World/MusicPlaylist.cs | 13 ++++++++----- .../Widgets/Logic/MusicPlayerLogic.cs | 5 ----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/World/MusicPlaylist.cs b/OpenRA.Mods.Common/Traits/World/MusicPlaylist.cs index 89a9132b68..af4af52c41 100644 --- a/OpenRA.Mods.Common/Traits/World/MusicPlaylist.cs +++ b/OpenRA.Mods.Common/Traits/World/MusicPlaylist.cs @@ -63,12 +63,8 @@ namespace OpenRA.Mods.Common.Traits .Select(a => a.Value) .ToArray(); - IsMusicAvailable = playlist.Any(); - random = playlist.Shuffle(Game.CosmeticRandom).ToArray(); - - // Always start with a random song - currentSong = random.FirstOrDefault(); + IsMusicAvailable = playlist.Any(); if (SongExists(info.StartingMusic)) currentSong = world.Map.Rules.Music[info.StartingMusic]; @@ -77,6 +73,13 @@ namespace OpenRA.Mods.Common.Traits 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(); + if (playlist.Length > installData.ShippedSoundtracks) + currentSong = random.FirstOrDefault(); + } Play(); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs index 33a57ef3e7..52e42b04de 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs @@ -125,16 +125,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic 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("TITLE").GetText = () => song.Title; item.Get("LENGTH").GetText = () => SongLengthLabel(song);