split render building/overlay and play sound for charge
to add the Tiberian Sun Nod Obelisk tick slightly faster tweak the local offsets
This commit is contained in:
@@ -29,6 +29,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Delay between charge attacks (in ticks).")]
|
||||
public readonly int ChargeDelay = 3;
|
||||
|
||||
[Desc("Sound to play when actor charges.")]
|
||||
public readonly string ChargeAudio = null;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new AttackCharge(init.Self, this); }
|
||||
}
|
||||
|
||||
@@ -98,7 +101,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (attack.charges == 0)
|
||||
return this;
|
||||
|
||||
self.Trait<RenderBuildingCharge>().PlayCharge(self);
|
||||
foreach (var notify in self.TraitsImplementing<INotifyCharging>())
|
||||
notify.Charging(self, target);
|
||||
|
||||
if (!string.IsNullOrEmpty(attack.info.ChargeAudio))
|
||||
Sound.Play(attack.info.ChargeAudio, self.CenterPosition);
|
||||
|
||||
return Util.SequenceActivities(new Wait(attack.info.InitialChargeDelay), new ChargeFire(attack, target), this);
|
||||
}
|
||||
|
||||
@@ -8,21 +8,20 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Used for tesla coil and obelisk.")]
|
||||
public class RenderBuildingChargeInfo : RenderBuildingInfo
|
||||
{
|
||||
[Desc("Sound to play when building charges.")]
|
||||
public readonly string ChargeAudio = null;
|
||||
|
||||
[Desc("Sequence to use for building charge animation.")]
|
||||
public readonly string ChargeSequence = "active";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new RenderBuildingCharge(init, this); }
|
||||
}
|
||||
|
||||
public class RenderBuildingCharge : RenderBuilding
|
||||
public class RenderBuildingCharge : RenderBuilding, INotifyCharging
|
||||
{
|
||||
RenderBuildingChargeInfo info;
|
||||
|
||||
@@ -32,9 +31,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void PlayCharge(Actor self)
|
||||
public void Charging(Actor self, Target target)
|
||||
{
|
||||
Sound.Play(info.ChargeAudio, self.CenterPosition);
|
||||
PlayCustomAnim(self, info.ChargeSequence);
|
||||
}
|
||||
}
|
||||
|
||||
68
OpenRA.Mods.Common/Traits/Render/WithChargeOverlay.cs
Normal file
68
OpenRA.Mods.Common/Traits/Render/WithChargeOverlay.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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 OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Rendered together with AttackCharge.")]
|
||||
public class WithChargeOverlayInfo : ITraitInfo, Requires<RenderSpritesInfo>
|
||||
{
|
||||
[Desc("Sequence name to use")]
|
||||
public readonly string Sequence = "active";
|
||||
|
||||
[Desc("Custom palette name")]
|
||||
public readonly string Palette = null;
|
||||
|
||||
[Desc("Custom palette is a player palette BaseName")]
|
||||
public readonly bool IsPlayerPalette = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithChargeOverlay(init, this); }
|
||||
}
|
||||
|
||||
public class WithChargeOverlay : INotifyCharging, INotifyDamageStateChanged, INotifySold
|
||||
{
|
||||
readonly Animation overlay;
|
||||
readonly RenderSprites renderSprites;
|
||||
readonly WithChargeOverlayInfo info;
|
||||
|
||||
bool charging;
|
||||
|
||||
public WithChargeOverlay(ActorInitializer init, WithChargeOverlayInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
|
||||
renderSprites = init.Self.Trait<RenderSprites>();
|
||||
|
||||
overlay = new Animation(init.World, renderSprites.GetImage(init.Self));
|
||||
|
||||
renderSprites.Add(new AnimationWithOffset(overlay, null, () => !charging),
|
||||
info.Palette, info.IsPlayerPalette);
|
||||
}
|
||||
|
||||
public void Charging(Actor self, Target target)
|
||||
{
|
||||
charging = true;
|
||||
overlay.PlayThen(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.Sequence), () => charging = false);
|
||||
}
|
||||
|
||||
public void DamageStateChanged(Actor self, AttackInfo e)
|
||||
{
|
||||
overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, info.Sequence));
|
||||
}
|
||||
|
||||
public void Sold(Actor self) { }
|
||||
public void Selling(Actor self)
|
||||
{
|
||||
charging = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user