Add start and stop repair overlay animation support.

This commit is contained in:
Matthias Mailänder
2017-08-30 19:29:09 +02:00
committed by Paul Chote
parent 7160c8a1a9
commit 0018bf3063
6 changed files with 99 additions and 12 deletions

View File

@@ -35,6 +35,15 @@ namespace OpenRA.Mods.Common.Activities
health = self.TraitOrDefault<Health>();
}
protected override void OnFirstRun(Actor self)
{
if (host.Actor.IsDead)
return;
foreach (var depot in host.Actor.TraitsImplementing<INotifyRepair>())
depot.BeforeRepair(host.Actor, self);
}
public override Activity Tick(Actor self)
{
if (IsCanceled)
@@ -81,6 +90,7 @@ namespace OpenRA.Mods.Common.Activities
}
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", repairsUnits.Info.FinishRepairingNotification, self.Owner.Faction.InternalName);
return NextActivity;
}
@@ -105,7 +115,7 @@ namespace OpenRA.Mods.Common.Activities
self.InflictDamage(host.Actor, new Damage(-hpToRepair));
foreach (var depot in host.Actor.TraitsImplementing<INotifyRepair>())
depot.Repairing(host.Actor, self);
depot.RepairTick(host.Actor, self);
remainingTicks = repairsUnits.Info.Interval;
}
@@ -114,5 +124,14 @@ namespace OpenRA.Mods.Common.Activities
return this;
}
protected override void OnLastRun(Actor self)
{
if (host.Actor.IsDead)
return;
foreach (var depot in host.Actor.TraitsImplementing<INotifyRepair>())
depot.AfterRepair(host.Actor, self);
}
}
}

View File

@@ -33,12 +33,16 @@ namespace OpenRA.Mods.Common.Traits.Render
spriteBody = self.TraitOrDefault<WithSpriteBody>();
}
void INotifyRepair.Repairing(Actor self, Actor target)
void INotifyRepair.BeforeRepair(Actor self, Actor target) { }
void INotifyRepair.RepairTick(Actor self, Actor target)
{
if (buildComplete && spriteBody != null && !IsTraitDisabled)
spriteBody.PlayCustomAnimation(self, Info.Sequence);
}
void INotifyRepair.AfterRepair(Actor self, Actor target) { }
void INotifyBuildComplete.BuildingComplete(Actor self)
{
buildComplete = true;

View File

@@ -18,9 +18,15 @@ namespace OpenRA.Mods.Common.Traits.Render
[Desc("Displays an overlay when the building is being repaired by the player.")]
public class WithRepairOverlayInfo : PausableConditionalTraitInfo, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo>
{
[Desc("Sequence name to use")]
[Desc("Sequence to use upon repair beginning.")]
[SequenceReference("Image")] public readonly string StartSequence = null;
[Desc("Sequence name to play once during repair intervals or repeatedly if a start sequence is set.")]
[SequenceReference] public readonly string Sequence = "active";
[Desc("Sequence to use after repairing has finished.")]
[SequenceReference("Image")] public readonly string EndSequence = null;
[Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero;
@@ -73,10 +79,32 @@ namespace OpenRA.Mods.Common.Traits.Render
overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, overlay.CurrentSequence.Name));
}
void INotifyRepair.Repairing(Actor self, Actor host)
void INotifyRepair.BeforeRepair(Actor self, Actor host)
{
if (Info.StartSequence != null)
{
visible = true;
overlay.PlayThen(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), Info.StartSequence),
() => overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), Info.Sequence)));
}
}
void INotifyRepair.RepairTick(Actor self, Actor host)
{
if (Info.StartSequence == null)
{
visible = true;
overlay.PlayThen(overlay.CurrentSequence.Name, () => visible = false);
}
}
void INotifyRepair.AfterRepair(Actor self, Actor target)
{
if (Info.EndSequence != null)
{
visible = true;
overlay.PlayThen(Info.EndSequence, () => visible = false);
}
}
}
}

View File

@@ -86,8 +86,16 @@ namespace OpenRA.Mods.Common.Traits
public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
public interface INotifyKilled { void Killed(Actor self, AttackInfo e); }
public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); }
[RequireExplicitImplementation]
public interface INotifyRepair
{
void BeforeRepair(Actor self, Actor target);
void RepairTick(Actor self, Actor target);
void AfterRepair(Actor self, Actor target);
}
public interface INotifyBuildingPlaced { void BuildingPlaced(Actor self); }
public interface INotifyRepair { void Repairing(Actor self, Actor target); }
public interface INotifyNuke { void Launching(Actor self); }
public interface INotifyBurstComplete { void FiredBurst(Actor self, Target target, Armament a); }
public interface INotifyChat { bool OnChat(string from, string message); }

View File

@@ -280,7 +280,9 @@ GADEPT:
Sequence: circuits
WithRepairOverlay@CRANE:
PauseOnCondition: empdisable
Sequence: crane
StartSequence: crane-start
Sequence: crane-loop
EndSequence: crane-end
WithRepairOverlay@PLATFORM:
RequiresCondition: !empdisable
Sequence: platform

View File

@@ -1737,9 +1737,22 @@ gadept.gdi:
ZOffset: -1c511
Tick: 120
ZRamp: 1
crane: gtdept_c
Length: 16
crane-start: gtdept_c
Length: 6
Offset: 0, -36, 12
Tick: 60
DepthSprite: isodepth.shp
crane-loop: gtdept_c
Start: 6
Length: 5
Offset: 0, -36, 12
Tick: 60
DepthSprite: isodepth.shp
crane-end: gtdept_c
Start: 10
Length: 6
Offset: 0, -36, 12
Tick: 60
DepthSprite: isodepth.shp
platform: gtdept_d
Length: 7
@@ -1821,10 +1834,23 @@ gadept.nod:
ZOffset: -1c511
Tick: 120
ZRamp: 1
crane: gtdept_c
Length: 16
crane-start: gtdept_c
Length: 6
Offset: 0, -36, 12
DepthSprite: isodepth.shp
Tick: 60
crane-loop: gtdept_c
Start: 6
Length: 5
Offset: 0, -36, 12
DepthSprite: isodepth.shp
Tick: 60
crane-end: gtdept_c
Start: 10
Length: 6
Offset: 0, -36, 12
DepthSprite: isodepth.shp
Tick: 60
platform: gtdept_d
Length: 7
ZOffset: -1c511