diff --git a/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs b/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs index 261706c855..a32dbc64fe 100755 --- a/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs +++ b/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs @@ -17,23 +17,13 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { - class CncShellmapScriptInfo : ITraitInfo - { - public string Music = "map1"; - public object Create(ActorInitializer init) { return new CncShellmapScript(this); } - } + class CncShellmapScriptInfo : TraitInfo { } class CncShellmapScript: IWorldLoaded, ITick { - CncShellmapScriptInfo Info; Dictionary Actors; static int2 ViewportOrigin; - public CncShellmapScript(CncShellmapScriptInfo info) - { - Info = info; - } - public void WorldLoaded(World w) { var b = w.Map.Bounds; @@ -42,30 +32,19 @@ namespace OpenRA.Mods.RA Actors = w.WorldActor.Trait().Actors; - LoopMusic(); - SetViewport(); } - void LoopMusic() - { - if (!Game.Settings.Game.ShellmapMusic || - Info.Music == null || - !Rules.Music.ContainsKey(Info.Music)) - return; - - Sound.PlayMusicThen(Rules.Music[Info.Music], () => LoopMusic()); - } - void SetViewport() { var t = (ticks + 45) % (360f * speed) * (Math.PI / 180) * 1f / speed; var loc = ViewportOrigin + new float2(-15,4) * float2.FromAngle( (float)t ); Game.viewport.Center(loc); } - + int ticks = 0; float speed = 4f; + public void Tick(Actor self) { SetViewport(); diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index f68c5cb63f..c5bd81c676 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -358,6 +358,7 @@ + diff --git a/OpenRA.Mods.RA/World/PlayMusicOnMapLoad.cs b/OpenRA.Mods.RA/World/PlayMusicOnMapLoad.cs new file mode 100644 index 0000000000..314d6cec9e --- /dev/null +++ b/OpenRA.Mods.RA/World/PlayMusicOnMapLoad.cs @@ -0,0 +1,45 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using OpenRA.FileFormats; +using OpenRA.Traits; +using OpenRA.Widgets; + +namespace OpenRA.Mods.RA +{ + class PlayMusicOnMapLoadInfo : ITraitInfo + { + public readonly string Music = null; + public readonly bool Loop = false; + + public object Create(ActorInitializer init) { return new PlayMusicOnMapLoad(this); } + } + + class PlayMusicOnMapLoad : IWorldLoaded + { + PlayMusicOnMapLoadInfo Info; + + public PlayMusicOnMapLoad(PlayMusicOnMapLoadInfo info) { Info = info; } + + public void WorldLoaded(World w) { PlayMusic(); } + + void PlayMusic() + { + var onComplete = Info.Loop ? (Action)PlayMusic : () => {}; + + if (Game.Settings.Game.ShellmapMusic && + Rules.Music.ContainsKey(Info.Music)) + Sound.PlayMusicThen(Rules.Music[Info.Music], onComplete); + } + } +} + diff --git a/mods/cnc/maps/shellmap/map.yaml b/mods/cnc/maps/shellmap/map.yaml index a768825e40..5ebcbdbeac 100755 --- a/mods/cnc/maps/shellmap/map.yaml +++ b/mods/cnc/maps/shellmap/map.yaml @@ -1012,6 +1012,9 @@ Rules: -SpawnMPUnits: -MPStartLocations: -CrateSpawner: + PlayMusicOnMapLoad: + Music: map1 + Loop: true CncShellmapScript: LoadWidgetAtGameStart: Widget: MENU_BACKGROUND