Add an Offset field to WithDamageOverlayInfo
This commit is contained in:
@@ -16,7 +16,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits.Render
|
namespace OpenRA.Mods.Common.Traits.Render
|
||||||
{
|
{
|
||||||
[Desc("Renders an overlay when the actor is taking heavy damage.")]
|
[Desc("Renders an overlay when the actor is taking heavy damage.")]
|
||||||
public class WithDamageOverlayInfo : TraitInfo, Requires<RenderSpritesInfo>
|
public class WithDamageOverlayInfo : TraitInfo, Requires<RenderSpritesInfo>, IRulesetLoaded
|
||||||
{
|
{
|
||||||
public readonly string Image = "smoke_m";
|
public readonly string Image = "smoke_m";
|
||||||
|
|
||||||
@@ -29,6 +29,9 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
[SequenceReference(nameof(Image))]
|
[SequenceReference(nameof(Image))]
|
||||||
public readonly string EndSequence = "end";
|
public readonly string EndSequence = "end";
|
||||||
|
|
||||||
|
[Desc("Position relative to the body orientation.")]
|
||||||
|
public readonly WVec Offset = WVec.Zero;
|
||||||
|
|
||||||
[PaletteReference(nameof(IsPlayerPalette))]
|
[PaletteReference(nameof(IsPlayerPalette))]
|
||||||
[Desc("Custom palette name.")]
|
[Desc("Custom palette name.")]
|
||||||
public readonly string Palette = null;
|
public readonly string Palette = null;
|
||||||
@@ -45,9 +48,15 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
public readonly DamageState MaximumDamageState = DamageState.Dead;
|
public readonly DamageState MaximumDamageState = DamageState.Dead;
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new WithDamageOverlay(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new WithDamageOverlay(init.Self, this); }
|
||||||
|
|
||||||
|
public void RulesetLoaded(Ruleset rules, ActorInfo info)
|
||||||
|
{
|
||||||
|
if (Offset != WVec.Zero && !info.HasTraitInfo<BodyOrientationInfo>())
|
||||||
|
throw new YamlException("Specifying WithDamageOverlay.Offset requires the BodyOrientation trait on the actor.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WithDamageOverlay : INotifyDamage
|
public class WithDamageOverlay : INotifyDamage, INotifyCreated
|
||||||
{
|
{
|
||||||
readonly WithDamageOverlayInfo info;
|
readonly WithDamageOverlayInfo info;
|
||||||
readonly Animation anim;
|
readonly Animation anim;
|
||||||
@@ -57,11 +66,16 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
public WithDamageOverlay(Actor self, WithDamageOverlayInfo info)
|
public WithDamageOverlay(Actor self, WithDamageOverlayInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
|
||||||
var rs = self.Trait<RenderSprites>();
|
|
||||||
|
|
||||||
anim = new Animation(self.World, info.Image);
|
anim = new Animation(self.World, info.Image);
|
||||||
rs.Add(new AnimationWithOffset(anim, null, () => !isSmoking),
|
}
|
||||||
|
|
||||||
|
void INotifyCreated.Created(Actor self)
|
||||||
|
{
|
||||||
|
var rs = self.Trait<RenderSprites>();
|
||||||
|
var body = self.TraitOrDefault<BodyOrientation>();
|
||||||
|
|
||||||
|
WVec AnimationOffset() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self.Orientation)));
|
||||||
|
rs.Add(new AnimationWithOffset(anim, info.Offset == WVec.Zero || body == null ? null : AnimationOffset, () => !isSmoking),
|
||||||
info.Palette, info.IsPlayerPalette);
|
info.Palette, info.IsPlayerPalette);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user