unhardcode and self-document render sequences
This commit is contained in:
@@ -46,25 +46,25 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var self = init.Self;
|
var self = init.Self;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
|
||||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
|
DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void BuildingComplete(Actor self)
|
public virtual void BuildingComplete(Actor self)
|
||||||
{
|
{
|
||||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
|
DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
|
||||||
|
|
||||||
if (info.PauseOnLowPower)
|
if (info.PauseOnLowPower)
|
||||||
{
|
{
|
||||||
var disabled = self.TraitsImplementing<IDisable>();
|
var disabled = self.TraitsImplementing<IDisable>();
|
||||||
DefaultAnimation.Paused = () => disabled.Any(d => d.Disabled)
|
DefaultAnimation.Paused = () => disabled.Any(d => d.Disabled)
|
||||||
&& DefaultAnimation.CurrentSequence.Name == NormalizeSequence(self, "idle");
|
&& DefaultAnimation.CurrentSequence.Name == NormalizeSequence(self, info.Sequence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayCustomAnimThen(Actor self, string name, Action a)
|
public void PlayCustomAnimThen(Actor self, string name, Action a)
|
||||||
{
|
{
|
||||||
DefaultAnimation.PlayThen(NormalizeSequence(self, name),
|
DefaultAnimation.PlayThen(NormalizeSequence(self, name),
|
||||||
() => { DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); a(); });
|
() => { DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence)); a(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayCustomAnimRepeating(Actor self, string name)
|
public void PlayCustomAnimRepeating(Actor self, string name)
|
||||||
@@ -76,12 +76,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public void PlayCustomAnimBackwards(Actor self, string name, Action a)
|
public void PlayCustomAnimBackwards(Actor self, string name, Action a)
|
||||||
{
|
{
|
||||||
DefaultAnimation.PlayBackwardsThen(NormalizeSequence(self, name),
|
DefaultAnimation.PlayBackwardsThen(NormalizeSequence(self, name),
|
||||||
() => { DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); a(); });
|
() => { DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence)); a(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CancelCustomAnim(Actor self)
|
public void CancelCustomAnim(Actor self)
|
||||||
{
|
{
|
||||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
|
DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void DamageStateChanged(Actor self, AttackInfo e)
|
public virtual void DamageStateChanged(Actor self, AttackInfo e)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
// Show a static frame instead of animating all of the fullness states
|
// Show a static frame instead of animating all of the fullness states
|
||||||
var anim = new Animation(init.World, image, () => 0);
|
var anim = new Animation(init.World, image, () => 0);
|
||||||
anim.PlayFetchIndex("idle", () => 0);
|
anim.PlayFetchIndex(Sequence, () => 0);
|
||||||
|
|
||||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||||
}
|
}
|
||||||
@@ -31,17 +31,19 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
class RenderBuildingSilo : RenderBuilding, INotifyBuildComplete, INotifyOwnerChanged
|
class RenderBuildingSilo : RenderBuilding, INotifyBuildComplete, INotifyOwnerChanged
|
||||||
{
|
{
|
||||||
|
readonly RenderBuildingSiloInfo info;
|
||||||
PlayerResources playerResources;
|
PlayerResources playerResources;
|
||||||
|
|
||||||
public RenderBuildingSilo(ActorInitializer init, RenderBuildingSiloInfo info)
|
public RenderBuildingSilo(ActorInitializer init, RenderBuildingSiloInfo info)
|
||||||
: base(init, info)
|
: base(init, info)
|
||||||
{
|
{
|
||||||
|
this.info = info;
|
||||||
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();
|
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void BuildingComplete(Actor self)
|
public override void BuildingComplete(Actor self)
|
||||||
{
|
{
|
||||||
var animation = (self.GetDamageState() >= DamageState.Heavy) ? "damaged-idle" : "idle";
|
var animation = RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), info.Sequence);
|
||||||
|
|
||||||
DefaultAnimation.PlayFetchIndex(animation,
|
DefaultAnimation.PlayFetchIndex(animation,
|
||||||
() => playerResources.ResourceCapacity != 0
|
() => playerResources.ResourceCapacity != 0
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
// Show the correct turret facing
|
// Show the correct turret facing
|
||||||
var anim = new Animation(init.World, image, () => t.InitialFacing);
|
var anim = new Animation(init.World, image, () => t.InitialFacing);
|
||||||
anim.PlayRepeating("idle");
|
anim.PlayRepeating(Sequence);
|
||||||
|
|
||||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
class RenderBuildingWallInfo : RenderBuildingInfo
|
class RenderBuildingWallInfo : RenderBuildingInfo
|
||||||
{
|
{
|
||||||
public readonly string Type = "wall";
|
public readonly string Type = "wall";
|
||||||
public readonly string Sequence = "idle";
|
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new RenderBuildingWall(init, this); }
|
public override object Create(ActorInitializer init) { return new RenderBuildingWall(init, this); }
|
||||||
|
|
||||||
@@ -27,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
// Show a static frame instead of animating all of the wall states
|
// Show a static frame instead of animating all of the wall states
|
||||||
var anim = new Animation(init.World, image, () => 0);
|
var anim = new Animation(init.World, image, () => 0);
|
||||||
anim.PlayFetchIndex("idle", () => 0);
|
anim.PlayFetchIndex(Sequence, () => 0);
|
||||||
|
|
||||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
class RenderFlareInfo : RenderSimpleInfo
|
class RenderFlareInfo : RenderSimpleInfo
|
||||||
{
|
{
|
||||||
|
public readonly string OpenSequence = "open";
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new RenderFlare(init, this); }
|
public override object Create(ActorInitializer init) { return new RenderFlare(init, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public RenderFlare(ActorInitializer init, RenderFlareInfo info)
|
public RenderFlare(ActorInitializer init, RenderFlareInfo info)
|
||||||
: base(init, info, () => 0)
|
: base(init, info, () => 0)
|
||||||
{
|
{
|
||||||
DefaultAnimation.PlayThen("open", () => DefaultAnimation.PlayRepeating("idle"));
|
DefaultAnimation.PlayThen(info.OpenSequence, () => DefaultAnimation.PlayRepeating(info.Sequence));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
class RenderHarvesterInfo : RenderUnitInfo, Requires<HarvesterInfo>
|
class RenderHarvesterInfo : RenderUnitInfo, Requires<HarvesterInfo>
|
||||||
{
|
{
|
||||||
public readonly string[] ImagesByFullness = { "harv" };
|
public readonly string[] ImagesByFullness = { "harv" };
|
||||||
|
|
||||||
|
public readonly string HarvestSequence = "harvest";
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new RenderHarvester(init, this); }
|
public override object Create(ActorInitializer init) { return new RenderHarvester(init, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,15 +45,15 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var desiredImage = info.ImagesByFullness[desiredState];
|
var desiredImage = info.ImagesByFullness[desiredState];
|
||||||
|
|
||||||
if (DefaultAnimation.Name != desiredImage)
|
if (DefaultAnimation.Name != desiredImage)
|
||||||
DefaultAnimation.ChangeImage(desiredImage, "idle");
|
DefaultAnimation.ChangeImage(desiredImage, info.Sequence);
|
||||||
|
|
||||||
base.Tick(self);
|
base.Tick(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Harvested(Actor self, ResourceType resource)
|
public void Harvested(Actor self, ResourceType resource)
|
||||||
{
|
{
|
||||||
if (DefaultAnimation.CurrentSequence.Name != "harvest")
|
if (DefaultAnimation.CurrentSequence.Name != info.HarvestSequence)
|
||||||
PlayCustomAnim(self, "harvest");
|
PlayCustomAnim(self, info.HarvestSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MovingToResources(Actor self, CPos targetCell, Activity next) { }
|
public void MovingToResources(Actor self, CPos targetCell, Activity next) { }
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
public class RenderSimpleInfo : RenderSpritesInfo, IRenderActorPreviewSpritesInfo, IQuantizeBodyOrientationInfo, ILegacyEditorRenderInfo, Requires<IBodyOrientationInfo>
|
public class RenderSimpleInfo : RenderSpritesInfo, IRenderActorPreviewSpritesInfo, IQuantizeBodyOrientationInfo, ILegacyEditorRenderInfo, Requires<IBodyOrientationInfo>
|
||||||
{
|
{
|
||||||
|
public readonly string Sequence = "idle";
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new RenderSimple(init, this); }
|
public override object Create(ActorInitializer init) { return new RenderSimple(init, this); }
|
||||||
|
|
||||||
public virtual IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
public virtual IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
@@ -26,13 +28,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var facing = ifacing != null ? init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing() : 0;
|
var facing = ifacing != null ? init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing() : 0;
|
||||||
|
|
||||||
var anim = new Animation(init.World, image, () => facing);
|
var anim = new Animation(init.World, image, () => facing);
|
||||||
anim.PlayRepeating("idle");
|
anim.PlayRepeating(Sequence);
|
||||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race)
|
public virtual int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race)
|
||||||
{
|
{
|
||||||
return sequenceProvider.GetSequence(GetImage(ai, sequenceProvider, race), "idle").Facings;
|
return sequenceProvider.GetSequence(GetImage(ai, sequenceProvider, race), Sequence).Facings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string EditorPalette { get { return Palette; } }
|
public string EditorPalette { get { return Palette; } }
|
||||||
@@ -43,9 +45,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
public readonly Animation DefaultAnimation;
|
public readonly Animation DefaultAnimation;
|
||||||
|
|
||||||
|
readonly RenderSimpleInfo info;
|
||||||
|
|
||||||
public RenderSimple(ActorInitializer init, RenderSimpleInfo info, Func<int> baseFacing)
|
public RenderSimple(ActorInitializer init, RenderSimpleInfo info, Func<int> baseFacing)
|
||||||
: base(init, info)
|
: base(init, info)
|
||||||
{
|
{
|
||||||
|
this.info = info;
|
||||||
|
|
||||||
DefaultAnimation = new Animation(init.World, GetImage(init.Self), baseFacing);
|
DefaultAnimation = new Animation(init.World, GetImage(init.Self), baseFacing);
|
||||||
Add("", DefaultAnimation);
|
Add("", DefaultAnimation);
|
||||||
}
|
}
|
||||||
@@ -53,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public RenderSimple(ActorInitializer init, RenderSimpleInfo info)
|
public RenderSimple(ActorInitializer init, RenderSimpleInfo info)
|
||||||
: this(init, info, MakeFacingFunc(init.Self))
|
: this(init, info, MakeFacingFunc(init.Self))
|
||||||
{
|
{
|
||||||
DefaultAnimation.PlayRepeating(NormalizeSequence(init.Self, "idle"));
|
DefaultAnimation.PlayRepeating(NormalizeSequence(init.Self, info.Sequence));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int2 SelectionSize(Actor self) { return AutoSelectionSize(self); }
|
public int2 SelectionSize(Actor self) { return AutoSelectionSize(self); }
|
||||||
@@ -67,7 +73,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
if (DefaultAnimation.HasSequence(name))
|
if (DefaultAnimation.HasSequence(name))
|
||||||
DefaultAnimation.PlayThen(NormalizeSequence(self, name),
|
DefaultAnimation.PlayThen(NormalizeSequence(self, name),
|
||||||
() => DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")));
|
() => DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public class RenderUnit : RenderSimple
|
public class RenderUnit : RenderSimple
|
||||||
{
|
{
|
||||||
|
readonly RenderUnitInfo info;
|
||||||
|
|
||||||
public RenderUnit(ActorInitializer init, RenderUnitInfo info)
|
public RenderUnit(ActorInitializer init, RenderUnitInfo info)
|
||||||
: base(init, info) { }
|
: base(init, info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
public void PlayCustomAnimation(Actor self, string newAnim, Action after)
|
public void PlayCustomAnimation(Actor self, string newAnim, Action after)
|
||||||
{
|
{
|
||||||
DefaultAnimation.PlayThen(newAnim, () => { DefaultAnimation.Play("idle"); if (after != null) after(); });
|
DefaultAnimation.PlayThen(newAnim, () => { DefaultAnimation.Play(info.Sequence); if (after != null) after(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayCustomAnimRepeating(Actor self, string name)
|
public void PlayCustomAnimRepeating(Actor self, string name)
|
||||||
@@ -37,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public void PlayCustomAnimBackwards(Actor self, string name, Action after)
|
public void PlayCustomAnimBackwards(Actor self, string name, Action after)
|
||||||
{
|
{
|
||||||
DefaultAnimation.PlayBackwardsThen(name,
|
DefaultAnimation.PlayBackwardsThen(name,
|
||||||
() => { DefaultAnimation.PlayRepeating("idle"); if (after != null) after(); });
|
() => { DefaultAnimation.PlayRepeating(info.Sequence); if (after != null) after(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,12 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
[Desc("Armament name")]
|
[Desc("Armament name")]
|
||||||
public readonly string Armament = "primary";
|
public readonly string Armament = "primary";
|
||||||
|
|
||||||
|
[Desc("Displayed while targeting.")]
|
||||||
|
public readonly string AimSequence = "aim";
|
||||||
|
|
||||||
|
[Desc("Shown while reloading.")]
|
||||||
|
public readonly string EmptyPrefix = "empty-";
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new RenderUnitReload(init, this); }
|
public override object Create(ActorInitializer init) { return new RenderUnitReload(init, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,10 +32,12 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
{
|
{
|
||||||
readonly AttackBase attack;
|
readonly AttackBase attack;
|
||||||
readonly Armament armament;
|
readonly Armament armament;
|
||||||
|
readonly RenderUnitReloadInfo info;
|
||||||
|
|
||||||
public RenderUnitReload(ActorInitializer init, RenderUnitReloadInfo info)
|
public RenderUnitReload(ActorInitializer init, RenderUnitReloadInfo info)
|
||||||
: base(init, info)
|
: base(init, info)
|
||||||
{
|
{
|
||||||
|
this.info = info;
|
||||||
attack = init.Self.Trait<AttackBase>();
|
attack = init.Self.Trait<AttackBase>();
|
||||||
armament = init.Self.TraitsImplementing<Armament>()
|
armament = init.Self.TraitsImplementing<Armament>()
|
||||||
.Single(a => a.Info.Name == info.Armament);
|
.Single(a => a.Info.Name == info.Armament);
|
||||||
@@ -37,7 +45,7 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
|
|
||||||
public override void Tick(Actor self)
|
public override void Tick(Actor self)
|
||||||
{
|
{
|
||||||
var sequence = (armament.IsReloading ? "empty-" : "") + (attack.IsAttacking ? "aim" : "idle");
|
var sequence = (armament.IsReloading ? info.EmptyPrefix : "") + (attack.IsAttacking ? info.AimSequence : info.Sequence);
|
||||||
if (sequence != DefaultAnimation.CurrentSequence.Name)
|
if (sequence != DefaultAnimation.CurrentSequence.Name)
|
||||||
DefaultAnimation.ReplaceAnim(sequence);
|
DefaultAnimation.ReplaceAnim(sequence);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user