Replace INotifyBuildComplete in render traits with conditions.

This commit is contained in:
Paul Chote
2018-10-05 20:16:36 +00:00
committed by abcdefg30
parent 26b0a06a17
commit 14607f55c5
28 changed files with 152 additions and 407 deletions

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.D2k.Traits.Render
{
[Desc("Rendered together with the \"make\" animation.")]
public class WithCrumbleOverlayInfo : ITraitInfo, Requires<RenderSpritesInfo>
public class WithCrumbleOverlayInfo : ConditionalTraitInfo, Requires<RenderSpritesInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "crumble-overlay";
@@ -28,14 +28,13 @@ namespace OpenRA.Mods.D2k.Traits.Render
[Desc("Custom palette is a player palette BaseName")]
public readonly bool IsPlayerPalette = false;
public object Create(ActorInitializer init) { return new WithCrumbleOverlay(init, this); }
public override object Create(ActorInitializer init) { return new WithCrumbleOverlay(init, this); }
}
public class WithCrumbleOverlay : INotifyBuildComplete
public class WithCrumbleOverlay : ConditionalTrait<WithCrumbleOverlayInfo>
{
bool buildComplete = false;
public WithCrumbleOverlay(ActorInitializer init, WithCrumbleOverlayInfo info)
: base(info)
{
if (init.Contains<SkipMakeAnimsInit>())
return;
@@ -43,17 +42,12 @@ namespace OpenRA.Mods.D2k.Traits.Render
var rs = init.Self.Trait<RenderSprites>();
var overlay = new Animation(init.World, rs.GetImage(init.Self));
var anim = new AnimationWithOffset(overlay, null, () => !buildComplete);
var anim = new AnimationWithOffset(overlay, null, () => IsTraitDisabled);
// Remove the animation once it is complete
overlay.PlayThen(info.Sequence, () => init.World.AddFrameEndTask(w => rs.Remove(anim)));
rs.Add(anim, info.Palette, info.IsPlayerPalette);
}
void INotifyBuildComplete.BuildingComplete(Actor self)
{
buildComplete = true;
}
}
}