Move PlayMusicOnMapLoad to Mods.Common
This commit is contained in:
@@ -98,6 +98,7 @@
|
||||
<Compile Include="Widgets\MenuButtonWidget.cs" />
|
||||
<Compile Include="Widgets\RadarWidget.cs" />
|
||||
<Compile Include="Widgets\ResourceBarWidget.cs" />
|
||||
<Compile Include="World\PlayMusicOnMapLoad.cs" />
|
||||
<Compile Include="World\RadarPings.cs" />
|
||||
<Compile Include="World\SmudgeLayer.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
51
OpenRA.Mods.Common/World/PlayMusicOnMapLoad.cs
Normal file
51
OpenRA.Mods.Common/World/PlayMusicOnMapLoad.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common
|
||||
{
|
||||
class PlayMusicOnMapLoadInfo : ITraitInfo
|
||||
{
|
||||
public readonly string Music = null;
|
||||
public readonly bool Loop = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new PlayMusicOnMapLoad(init.world, this); }
|
||||
}
|
||||
|
||||
class PlayMusicOnMapLoad : IWorldLoaded
|
||||
{
|
||||
readonly PlayMusicOnMapLoadInfo info;
|
||||
readonly World world;
|
||||
|
||||
public PlayMusicOnMapLoad(World world, PlayMusicOnMapLoadInfo info)
|
||||
{
|
||||
this.world = world;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
PlayMusic();
|
||||
}
|
||||
|
||||
void PlayMusic()
|
||||
{
|
||||
var onComplete = info.Loop ? (Action)PlayMusic : () => {};
|
||||
|
||||
if (Game.Settings.Sound.MapMusic &&
|
||||
world.Map.Rules.Music.ContainsKey(info.Music))
|
||||
Sound.PlayMusicThen(world.Map.Rules.Music[info.Music], onComplete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user