Merge pull request #12996 from atlimit8/RemoveIDisable-part2

Remove IDisable - part 2
This commit is contained in:
Paul Chote
2017-05-07 08:38:09 +01:00
committed by GitHub
23 changed files with 199 additions and 93 deletions

View File

@@ -21,9 +21,6 @@ namespace OpenRA.Mods.Common.Traits.Render
public readonly int Interval = 750;
[Desc("Pause when the actor is disabled. Deprecated. Use conditions instead.")]
public readonly bool PauseOnLowPower = false;
public override object Create(ActorInitializer init) { return new WithIdleAnimation(init.Self, this); }
}
@@ -48,8 +45,7 @@ namespace OpenRA.Mods.Common.Traits.Render
if (--ticks <= 0)
{
if (!(Info.PauseOnLowPower && self.IsDisabled()))
wsb.PlayCustomAnimation(self, Info.Sequences.Random(Game.CosmeticRandom), () => wsb.CancelCustomAnimation(self));
wsb.PlayCustomAnimation(self, Info.Sequences.Random(Game.CosmeticRandom), () => wsb.CancelCustomAnimation(self));
ticks = Info.Interval;
}
}

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Renders a decorative animation on units and buildings.")]
public class WithIdleOverlayInfo : ConditionalTraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo>
public class WithIdleOverlayInfo : PausableConditionalTraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo>
{
[Desc("Animation to play when the actor is created.")]
[SequenceReference] public readonly string StartSequence = null;
@@ -35,8 +35,6 @@ namespace OpenRA.Mods.Common.Traits.Render
[Desc("Custom palette is a player palette BaseName")]
public readonly bool IsPlayerPalette = false;
public readonly bool PauseOnLowPower = false;
public override object Create(ActorInitializer init) { return new WithIdleOverlay(init.Self, this); }
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
@@ -72,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits.Render
}
}
public class WithIdleOverlay : ConditionalTrait<WithIdleOverlayInfo>, INotifyDamageStateChanged, INotifyBuildComplete, INotifySold, INotifyTransform
public class WithIdleOverlay : PausableConditionalTrait<WithIdleOverlayInfo>, INotifyDamageStateChanged, INotifyBuildComplete, INotifySold, INotifyTransform
{
readonly Animation overlay;
bool buildComplete;
@@ -84,8 +82,7 @@ namespace OpenRA.Mods.Common.Traits.Render
var body = self.Trait<BodyOrientation>();
buildComplete = !self.Info.HasTraitInfo<BuildingInfo>(); // always render instantly for units
overlay = new Animation(self.World, rs.GetImage(self),
() => (info.PauseOnLowPower && self.IsDisabled()) || !buildComplete);
overlay = new Animation(self.World, rs.GetImage(self), () => IsTraitPaused || !buildComplete);
if (info.StartSequence != null)
overlay.PlayThen(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.StartSequence),
() => overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.Sequence)));

View File

@@ -14,32 +14,29 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Replaces the building animation when it rearms a unit.")]
public class WithRearmAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>
public class WithRearmAnimationInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "active";
public readonly bool PauseOnLowPower = false;
public object Create(ActorInitializer init) { return new WithRearmAnimation(init.Self, this); }
public override object Create(ActorInitializer init) { return new WithRearmAnimation(init.Self, this); }
}
public class WithRearmAnimation : INotifyRearm, INotifyBuildComplete, INotifySold
public class WithRearmAnimation : ConditionalTrait<WithRearmAnimationInfo>, INotifyRearm, INotifyBuildComplete, INotifySold
{
readonly WithRearmAnimationInfo info;
readonly WithSpriteBody spriteBody;
bool buildComplete;
public WithRearmAnimation(Actor self, WithRearmAnimationInfo info)
: base(info)
{
this.info = info;
spriteBody = self.TraitOrDefault<WithSpriteBody>();
}
void INotifyRearm.Rearming(Actor self, Actor target)
{
if (buildComplete && spriteBody != null && !(info.PauseOnLowPower && self.IsDisabled()))
spriteBody.PlayCustomAnimation(self, info.Sequence, () => spriteBody.CancelCustomAnimation(self));
if (buildComplete && spriteBody != null && !IsTraitDisabled)
spriteBody.PlayCustomAnimation(self, Info.Sequence, () => spriteBody.CancelCustomAnimation(self));
}
void INotifyBuildComplete.BuildingComplete(Actor self)

View File

@@ -14,32 +14,29 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Replaces the building animation when it repairs a unit.")]
public class WithRepairAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>
public class WithRepairAnimationInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "active";
public readonly bool PauseOnLowPower = false;
public object Create(ActorInitializer init) { return new WithRepairAnimation(init.Self, this); }
public override object Create(ActorInitializer init) { return new WithRepairAnimation(init.Self, this); }
}
public class WithRepairAnimation : INotifyRepair, INotifyBuildComplete, INotifySold
public class WithRepairAnimation : ConditionalTrait<WithRepairAnimationInfo>, INotifyRepair, INotifyBuildComplete, INotifySold
{
readonly WithRepairAnimationInfo info;
readonly WithSpriteBody spriteBody;
bool buildComplete;
public WithRepairAnimation(Actor self, WithRepairAnimationInfo info)
: base(info)
{
this.info = info;
spriteBody = self.TraitOrDefault<WithSpriteBody>();
}
void INotifyRepair.Repairing(Actor self, Actor target)
{
if (buildComplete && spriteBody != null && !(info.PauseOnLowPower && self.IsDisabled()))
spriteBody.PlayCustomAnimation(self, info.Sequence, () => spriteBody.CancelCustomAnimation(self));
if (buildComplete && spriteBody != null && !IsTraitDisabled)
spriteBody.PlayCustomAnimation(self, Info.Sequence, () => spriteBody.CancelCustomAnimation(self));
}
void INotifyBuildComplete.BuildingComplete(Actor self)

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Displays an overlay when the building is being repaired by the player.")]
public class WithRepairOverlayInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo>
public class WithRepairOverlayInfo : PausableConditionalTraitInfo, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "active";
@@ -30,30 +30,28 @@ namespace OpenRA.Mods.Common.Traits.Render
[Desc("Custom palette is a player palette BaseName")]
public readonly bool IsPlayerPalette = false;
public readonly bool PauseOnLowPower = false;
public object Create(ActorInitializer init) { return new WithRepairOverlay(init.Self, this); }
public override object Create(ActorInitializer init) { return new WithRepairOverlay(init.Self, this); }
}
public class WithRepairOverlay : INotifyDamageStateChanged, INotifyBuildComplete, INotifySold, INotifyRepair
public class WithRepairOverlay : PausableConditionalTrait<WithRepairOverlayInfo>, INotifyDamageStateChanged, INotifyBuildComplete, INotifySold, INotifyRepair
{
readonly Animation overlay;
bool buildComplete;
bool visible;
public WithRepairOverlay(Actor self, WithRepairOverlayInfo info)
: base(info)
{
var rs = self.Trait<RenderSprites>();
var body = self.Trait<BodyOrientation>();
buildComplete = !self.Info.HasTraitInfo<BuildingInfo>(); // always render instantly for units
overlay = new Animation(self.World, rs.GetImage(self),
() => info.PauseOnLowPower && self.IsDisabled());
overlay = new Animation(self.World, rs.GetImage(self), () => IsTraitPaused);
overlay.PlayThen(info.Sequence, () => visible = false);
var anim = new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !visible || !buildComplete,
() => IsTraitDisabled || !visible || !buildComplete,
p => RenderUtils.ZOffsetFromCenter(self, p, 1));
rs.Add(anim, info.Palette, info.IsPlayerPalette);