Merge INotifyRearm/Repair into INotifyResupply
And streamline its notify methods. Also cache INotifyResupply traits at beginning of Resupply activity.
This commit is contained in:
@@ -14,6 +14,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits.Render
|
||||
{
|
||||
// TODO: Refactor this trait into WithResupplyOverlay
|
||||
[Desc("Displays an overlay when the building is being repaired by the player.")]
|
||||
public class WithRepairOverlayInfo : PausableConditionalTraitInfo, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo>
|
||||
{
|
||||
@@ -38,10 +39,11 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
public override object Create(ActorInitializer init) { return new WithRepairOverlay(init.Self, this); }
|
||||
}
|
||||
|
||||
public class WithRepairOverlay : PausableConditionalTrait<WithRepairOverlayInfo>, INotifyDamageStateChanged, INotifyRepair
|
||||
public class WithRepairOverlay : PausableConditionalTrait<WithRepairOverlayInfo>, INotifyDamageStateChanged, INotifyResupply
|
||||
{
|
||||
readonly Animation overlay;
|
||||
bool visible;
|
||||
bool repairing;
|
||||
|
||||
public WithRepairOverlay(Actor self, WithRepairOverlayInfo info)
|
||||
: base(info)
|
||||
@@ -65,8 +67,12 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, overlay.CurrentSequence.Name));
|
||||
}
|
||||
|
||||
void INotifyRepair.BeforeRepair(Actor self, Actor host)
|
||||
void INotifyResupply.BeforeResupply(Actor self, Actor target, ResupplyType types)
|
||||
{
|
||||
repairing = types.HasFlag(ResupplyType.Repair);
|
||||
if (!repairing)
|
||||
return;
|
||||
|
||||
if (Info.StartSequence != null)
|
||||
{
|
||||
visible = true;
|
||||
@@ -75,18 +81,18 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
}
|
||||
}
|
||||
|
||||
void INotifyRepair.RepairTick(Actor self, Actor host)
|
||||
void INotifyResupply.ResupplyTick(Actor self, Actor target, ResupplyType types)
|
||||
{
|
||||
if (Info.StartSequence == null)
|
||||
var wasRepairing = repairing;
|
||||
repairing = types.HasFlag(ResupplyType.Repair);
|
||||
|
||||
if (repairing && Info.StartSequence == null && !visible)
|
||||
{
|
||||
visible = true;
|
||||
overlay.PlayThen(overlay.CurrentSequence.Name, () => visible = false);
|
||||
}
|
||||
}
|
||||
|
||||
void INotifyRepair.AfterRepair(Actor self, Actor target)
|
||||
{
|
||||
if (Info.EndSequence != null)
|
||||
if (!repairing && wasRepairing && Info.EndSequence != null)
|
||||
{
|
||||
visible = true;
|
||||
overlay.PlayThen(Info.EndSequence, () => visible = false);
|
||||
|
||||
@@ -15,13 +15,6 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits.Render
|
||||
{
|
||||
[Flags]
|
||||
public enum ResupplyType
|
||||
{
|
||||
Rearm = 1,
|
||||
Repair = 2
|
||||
}
|
||||
|
||||
[Desc("Replaces the default animation when actor resupplies a unit.")]
|
||||
public class WithResupplyAnimationInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>
|
||||
{
|
||||
@@ -37,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
public override object Create(ActorInitializer init) { return new WithResupplyAnimation(init.Self, this); }
|
||||
}
|
||||
|
||||
public class WithResupplyAnimation : ConditionalTrait<WithResupplyAnimationInfo>, INotifyRepair, INotifyRearm, ITick
|
||||
public class WithResupplyAnimation : ConditionalTrait<WithResupplyAnimationInfo>, INotifyResupply, ITick
|
||||
{
|
||||
readonly WithSpriteBody wsb;
|
||||
bool animPlaying;
|
||||
@@ -71,28 +64,16 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
}
|
||||
}
|
||||
|
||||
void INotifyRepair.BeforeRepair(Actor self, Actor target)
|
||||
void INotifyResupply.BeforeResupply(Actor self, Actor target, ResupplyType types)
|
||||
{
|
||||
repairing = true;
|
||||
repairing = types.HasFlag(ResupplyType.Repair);
|
||||
rearming = types.HasFlag(ResupplyType.Rearm);
|
||||
}
|
||||
|
||||
void INotifyRepair.RepairTick(Actor self, Actor target) { }
|
||||
|
||||
void INotifyRepair.AfterRepair(Actor self, Actor target)
|
||||
void INotifyResupply.ResupplyTick(Actor self, Actor target, ResupplyType types)
|
||||
{
|
||||
repairing = false;
|
||||
}
|
||||
|
||||
void INotifyRearm.RearmingStarted(Actor self, Actor target)
|
||||
{
|
||||
rearming = true;
|
||||
}
|
||||
|
||||
void INotifyRearm.Rearming(Actor self, Actor target) { }
|
||||
|
||||
void INotifyRearm.RearmingFinished(Actor self, Actor target)
|
||||
{
|
||||
rearming = false;
|
||||
repairing = types.HasFlag(ResupplyType.Repair);
|
||||
rearming = types.HasFlag(ResupplyType.Rearm);
|
||||
}
|
||||
|
||||
protected override void TraitDisabled(Actor self)
|
||||
|
||||
Reference in New Issue
Block a user