diff --git a/OpenRA.Mods.Common/Effects/MapNotificationEffect.cs b/OpenRA.Mods.Common/Effects/MapNotificationEffect.cs new file mode 100644 index 0000000000..78f142b9df --- /dev/null +++ b/OpenRA.Mods.Common/Effects/MapNotificationEffect.cs @@ -0,0 +1,65 @@ +#region Copyright & License Information +/* + * Copyright 2007-2016 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, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using System.Drawing; +using OpenRA.Effects; +using OpenRA.Graphics; +using OpenRA.Mods.Common.Traits; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Effects +{ + public class MapNotificationEffect : IEffect + { + readonly RadarPings radarPings; + + readonly WPos pos; + readonly Player player; + readonly int duration; + readonly string category; + readonly string notification; + readonly bool visible; + readonly Color color; + + int remainingDelay; + + public MapNotificationEffect(Player player, string category, string notification, int delay, + bool pingVisible, WPos pos, Color pingColor, int pingDuration = 50) + { + this.player = player; + remainingDelay = delay; + this.category = category; + this.notification = notification; + this.pos = pos; + duration = pingDuration; + visible = pingVisible; + color = pingColor; + + radarPings = player.World.WorldActor.TraitOrDefault(); + } + + public void Tick(World world) + { + if (remainingDelay-- > 0) + return; + + Game.Sound.PlayNotification(player.World.Map.Rules, player, category, notification, player.Faction.InternalName); + + if (visible && radarPings != null && player == player.World.RenderPlayer) + radarPings.Add(() => true, pos, color, duration); + + world.AddFrameEndTask(w => w.Remove(this)); + } + + public IEnumerable Render(WorldRenderer wr) { return SpriteRenderable.None; } + } +} diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index f29d2ca8ce..770fd27890 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -141,6 +141,7 @@ +