@@ -30,40 +30,34 @@ namespace OpenRA.Traits
|
||||
|
||||
public class RenderSimple : RenderSprites, IAutoSelectionSize
|
||||
{
|
||||
RenderSimpleInfo Info;
|
||||
public readonly Animation DefaultAnimation;
|
||||
|
||||
public RenderSimple(Actor self, Func<int> baseFacing)
|
||||
: base(self)
|
||||
{
|
||||
Add("", new Animation(self.World, GetImage(self), baseFacing));
|
||||
Info = self.Info.Traits.Get<RenderSimpleInfo>();
|
||||
DefaultAnimation = new Animation(self.World, GetImage(self), baseFacing);
|
||||
Add("", DefaultAnimation);
|
||||
}
|
||||
|
||||
public RenderSimple(Actor self)
|
||||
: this(self, MakeFacingFunc(self))
|
||||
{
|
||||
anim.PlayRepeating("idle");
|
||||
self.Trait<IBodyOrientation>().SetAutodetectedFacings(anim.CurrentSequence.Facings);
|
||||
DefaultAnimation.PlayRepeating("idle");
|
||||
self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings);
|
||||
}
|
||||
|
||||
public int2 SelectionSize(Actor self)
|
||||
{
|
||||
return anims.Values.Where(b => (b.DisableFunc == null || !b.DisableFunc())
|
||||
&& b.Animation.CurrentSequence != null)
|
||||
.Select(a => (a.Animation.Image.size*Info.Scale).ToInt2())
|
||||
.FirstOrDefault();
|
||||
}
|
||||
public int2 SelectionSize(Actor self) { return AutoSelectionSize(self); }
|
||||
|
||||
public string NormalizeSequence(Actor self, string baseSequence)
|
||||
{
|
||||
return NormalizeSequence(anim, self.GetDamageState(), baseSequence);
|
||||
return NormalizeSequence(DefaultAnimation, self.GetDamageState(), baseSequence);
|
||||
}
|
||||
|
||||
public void PlayCustomAnim(Actor self, string name)
|
||||
{
|
||||
if (anim.HasSequence(name))
|
||||
anim.PlayThen(NormalizeSequence(self, name),
|
||||
() => anim.PlayRepeating(NormalizeSequence(self, "idle")));
|
||||
if (DefaultAnimation.HasSequence(name))
|
||||
DefaultAnimation.PlayThen(NormalizeSequence(self, name),
|
||||
() => DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Primitives;
|
||||
@@ -33,7 +34,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public class RenderSprites : IRender, ITick, INotifyOwnerChanged
|
||||
{
|
||||
public Dictionary<string, AnimationWithOffset> anims = new Dictionary<string, AnimationWithOffset>();
|
||||
Dictionary<string, AnimationWithOffset> anims = new Dictionary<string, AnimationWithOffset>();
|
||||
|
||||
public static Func<int> MakeFacingFunc(Actor self)
|
||||
{
|
||||
@@ -42,13 +43,6 @@ namespace OpenRA.Traits
|
||||
return () => facing.Facing;
|
||||
}
|
||||
|
||||
public Animation anim
|
||||
{
|
||||
get { return anims[""].Animation; }
|
||||
protected set { anims[""] = new AnimationWithOffset(value,
|
||||
anims[""].OffsetFunc, anims[""].DisableFunc, anims[""].Paused, anims[""].ZOffset); }
|
||||
}
|
||||
|
||||
RenderSpritesInfo Info;
|
||||
string cachedImage = null;
|
||||
bool initializePalette = true;
|
||||
@@ -131,5 +125,14 @@ namespace OpenRA.Traits
|
||||
|
||||
return baseSequence;
|
||||
}
|
||||
|
||||
// Required by RenderSimple
|
||||
protected int2 AutoSelectionSize(Actor self)
|
||||
{
|
||||
return anims.Values.Where(b => (b.DisableFunc == null || !b.DisableFunc())
|
||||
&& b.Animation.CurrentSequence != null)
|
||||
.Select(a => (a.Animation.Image.size*Info.Scale).ToInt2())
|
||||
.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (started)
|
||||
{
|
||||
// Don't break the actor if someone has overriden the animation prematurely
|
||||
if (rb.anim.CurrentSequence.Name != "make")
|
||||
if (rb.DefaultAnimation.CurrentSequence.Name != "make")
|
||||
{
|
||||
complete = true;
|
||||
OnComplete();
|
||||
|
||||
@@ -13,7 +13,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc
|
||||
{
|
||||
class DeadBuildingStateInfo : ITraitInfo, Requires<HealthInfo>, Requires<RenderSpritesInfo>
|
||||
class DeadBuildingStateInfo : ITraitInfo, Requires<HealthInfo>, Requires<RenderSimpleInfo>
|
||||
{
|
||||
public readonly int LingerTime = 20;
|
||||
|
||||
@@ -23,23 +23,23 @@ namespace OpenRA.Mods.Cnc
|
||||
class DeadBuildingState : INotifyKilled
|
||||
{
|
||||
DeadBuildingStateInfo info;
|
||||
RenderSprites rs;
|
||||
RenderSimple rs;
|
||||
|
||||
public DeadBuildingState(Actor self, DeadBuildingStateInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
rs = self.Trait<RenderSprites>();
|
||||
self.Trait<Health>().RemoveOnDeath = !rs.anim.HasSequence("dead");
|
||||
rs = self.Trait<RenderSimple>();
|
||||
self.Trait<Health>().RemoveOnDeath = !rs.DefaultAnimation.HasSequence("dead");
|
||||
}
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
if (!rs.anim.HasSequence("dead")) return;
|
||||
if (!rs.DefaultAnimation.HasSequence("dead")) return;
|
||||
|
||||
if (rs.anim.GetSequence("dead").Length > 1)
|
||||
rs.anim.Play("dead");
|
||||
if (rs.DefaultAnimation.GetSequence("dead").Length > 1)
|
||||
rs.DefaultAnimation.Play("dead");
|
||||
else
|
||||
rs.anim.PlayRepeating("dead");
|
||||
rs.DefaultAnimation.PlayRepeating("dead");
|
||||
|
||||
self.World.AddFrameEndTask(
|
||||
w => w.Add(
|
||||
|
||||
@@ -49,8 +49,8 @@ namespace OpenRA.Mods.RA.Render
|
||||
this.info = info;
|
||||
|
||||
// Work around a bogus crash
|
||||
anim.PlayRepeating(NormalizeSequence(self, "idle"));
|
||||
self.Trait<IBodyOrientation>().SetAutodetectedFacings(anim.CurrentSequence.Facings);
|
||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
|
||||
self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings);
|
||||
|
||||
// Can't call Complete() directly from ctor because other traits haven't been inited yet
|
||||
if (self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation && !init.Contains<SkipMakeAnimsInit>())
|
||||
@@ -61,45 +61,45 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
void Complete(Actor self)
|
||||
{
|
||||
anim.PlayRepeating(NormalizeSequence(self, "idle"));
|
||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
|
||||
foreach (var x in self.TraitsImplementing<INotifyBuildComplete>())
|
||||
x.BuildingComplete(self);
|
||||
|
||||
if (info.PauseOnLowPower)
|
||||
{
|
||||
var disabled = self.TraitsImplementing<IDisable>();
|
||||
anim.Paused = () => disabled.Any(d => d.Disabled)
|
||||
&& anim.CurrentSequence.Name == NormalizeSequence(self, "idle");
|
||||
DefaultAnimation.Paused = () => disabled.Any(d => d.Disabled)
|
||||
&& DefaultAnimation.CurrentSequence.Name == NormalizeSequence(self, "idle");
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayCustomAnimThen(Actor self, string name, Action a)
|
||||
{
|
||||
anim.PlayThen(NormalizeSequence(self, name),
|
||||
() => { anim.PlayRepeating(NormalizeSequence(self, "idle")); a(); });
|
||||
DefaultAnimation.PlayThen(NormalizeSequence(self, name),
|
||||
() => { DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); a(); });
|
||||
}
|
||||
|
||||
public void PlayCustomAnimRepeating(Actor self, string name)
|
||||
{
|
||||
anim.PlayThen(NormalizeSequence(self, name),
|
||||
DefaultAnimation.PlayThen(NormalizeSequence(self, name),
|
||||
() => PlayCustomAnimRepeating(self, name));
|
||||
}
|
||||
|
||||
public void PlayCustomAnimBackwards(Actor self, string name, Action a)
|
||||
{
|
||||
anim.PlayBackwardsThen(NormalizeSequence(self, name),
|
||||
() => { anim.PlayRepeating(NormalizeSequence(self, "idle")); a(); });
|
||||
DefaultAnimation.PlayBackwardsThen(NormalizeSequence(self, name),
|
||||
() => { DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); a(); });
|
||||
}
|
||||
|
||||
public void CancelCustomAnim(Actor self)
|
||||
{
|
||||
anim.PlayRepeating(NormalizeSequence(self, "idle"));
|
||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
|
||||
}
|
||||
|
||||
public virtual void DamageStateChanged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (anim.CurrentSequence != null)
|
||||
anim.ReplaceAnim(NormalizeSequence(self, "idle"));
|
||||
if (DefaultAnimation.CurrentSequence != null)
|
||||
DefaultAnimation.ReplaceAnim(NormalizeSequence(self, "idle"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ namespace OpenRA.Mods.RA.Render
|
||||
public void PlayCharge(Actor self)
|
||||
{
|
||||
Sound.Play(info.ChargeAudio, self.CenterPosition);
|
||||
anim.PlayThen(NormalizeSequence(self, info.ChargeSequence),
|
||||
() => anim.PlayRepeating(NormalizeSequence(self, "idle")));
|
||||
DefaultAnimation.PlayThen(NormalizeSequence(self, info.ChargeSequence),
|
||||
() => DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ namespace OpenRA.Mods.RA.Render
|
||||
public void BuildingComplete(Actor self)
|
||||
{
|
||||
var animation = (self.GetDamageState() >= DamageState.Heavy) ? "damaged-idle" : "idle";
|
||||
anim.PlayFetchIndex(animation,
|
||||
DefaultAnimation.PlayFetchIndex(animation,
|
||||
() => playerResources.OreCapacity != 0
|
||||
? ((10 * anim.CurrentSequence.Length - 1) * playerResources.Ore) / (10 * playerResources.OreCapacity)
|
||||
? ((10 * DefaultAnimation.CurrentSequence.Length - 1) * playerResources.Ore) / (10 * playerResources.OreCapacity)
|
||||
: 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,13 +34,13 @@ namespace OpenRA.Mods.RA.Render
|
||||
: base(init, info, MakeTurretFacingFunc(init.self))
|
||||
{
|
||||
t = init.self.TraitsImplementing<Turreted>().FirstOrDefault();
|
||||
t.QuantizedFacings = anim.CurrentSequence.Facings;
|
||||
t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
|
||||
}
|
||||
|
||||
public override void DamageStateChanged(Actor self, AttackInfo e)
|
||||
{
|
||||
base.DamageStateChanged(self, e);
|
||||
t.QuantizedFacings = anim.CurrentSequence.Facings;
|
||||
t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
public void BuildingComplete(Actor self)
|
||||
{
|
||||
anim.PlayFetchIndex(info.Sequence, () => adjacent);
|
||||
DefaultAnimation.PlayFetchIndex(info.Sequence, () => adjacent);
|
||||
}
|
||||
|
||||
public override void DamageStateChanged(Actor self, AttackInfo e)
|
||||
{
|
||||
anim.PlayFetchIndex(NormalizeSequence(anim, e.DamageState, info.Sequence), () => adjacent);
|
||||
DefaultAnimation.PlayFetchIndex(NormalizeSequence(DefaultAnimation, e.DamageState, info.Sequence), () => adjacent);
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
if (disguise.AsSprite != intendedSprite)
|
||||
{
|
||||
intendedSprite = disguise.AsSprite;
|
||||
anim.ChangeImage(intendedSprite ?? GetImage(self), info.StandAnimations.Random(Game.CosmeticRandom));
|
||||
DefaultAnimation.ChangeImage(intendedSprite ?? GetImage(self), info.StandAnimations.Random(Game.CosmeticRandom));
|
||||
UpdatePalette();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
public RenderFlare(Actor self)
|
||||
: base(self, () => 0)
|
||||
{
|
||||
anim.PlayThen("open", () => anim.PlayRepeating("idle"));
|
||||
DefaultAnimation.PlayThen("open", () => DefaultAnimation.PlayRepeating("idle"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,15 +40,15 @@ namespace OpenRA.Mods.RA.Render
|
||||
var desiredState = harv.Fullness * (info.ImagesByFullness.Length - 1) / 100;
|
||||
var desiredImage = info.ImagesByFullness[desiredState];
|
||||
|
||||
if (anim.Name != desiredImage)
|
||||
anim.ChangeImage(desiredImage, "idle");
|
||||
if (DefaultAnimation.Name != desiredImage)
|
||||
DefaultAnimation.ChangeImage(desiredImage, "idle");
|
||||
|
||||
base.Tick(self);
|
||||
}
|
||||
|
||||
public void Harvested(Actor self, ResourceType resource)
|
||||
{
|
||||
if (anim.CurrentSequence.Name != "harvest")
|
||||
if (DefaultAnimation.CurrentSequence.Name != "harvest")
|
||||
PlayCustomAnim(self, "harvest");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,20 +59,20 @@ namespace OpenRA.Mods.RA.Render
|
||||
: base(self, MakeFacingFunc(self))
|
||||
{
|
||||
this.info = info;
|
||||
anim.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0);
|
||||
DefaultAnimation.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0);
|
||||
State = AnimationState.Waiting;
|
||||
move = self.Trait<IMove>();
|
||||
|
||||
self.Trait<IBodyOrientation>().SetAutodetectedFacings(anim.CurrentSequence.Facings);
|
||||
self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings);
|
||||
}
|
||||
|
||||
public void Attacking(Actor self, Target target)
|
||||
{
|
||||
State = AnimationState.Attacking;
|
||||
if (anim.HasSequence(NormalizeInfantrySequence(self, "shoot")))
|
||||
anim.PlayThen(NormalizeInfantrySequence(self, "shoot"), () => State = AnimationState.Idle);
|
||||
else if (anim.HasSequence(NormalizeInfantrySequence(self, "heal")))
|
||||
anim.PlayThen(NormalizeInfantrySequence(self, "heal"), () => State = AnimationState.Idle);
|
||||
if (DefaultAnimation.HasSequence(NormalizeInfantrySequence(self, "shoot")))
|
||||
DefaultAnimation.PlayThen(NormalizeInfantrySequence(self, "shoot"), () => State = AnimationState.Idle);
|
||||
else if (DefaultAnimation.HasSequence(NormalizeInfantrySequence(self, "heal")))
|
||||
DefaultAnimation.PlayThen(NormalizeInfantrySequence(self, "heal"), () => State = AnimationState.Idle);
|
||||
}
|
||||
|
||||
public void Attacking(Actor self, Target target, Armament a, Barrel barrel)
|
||||
@@ -87,12 +87,12 @@ namespace OpenRA.Mods.RA.Render
|
||||
if ((State == AnimationState.Moving || dirty) && !move.IsMoving)
|
||||
{
|
||||
State = AnimationState.Waiting;
|
||||
anim.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0);
|
||||
DefaultAnimation.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0);
|
||||
}
|
||||
else if ((State != AnimationState.Moving || dirty) && move.IsMoving)
|
||||
{
|
||||
State = AnimationState.Moving;
|
||||
anim.PlayRepeating(NormalizeInfantrySequence(self, "run"));
|
||||
DefaultAnimation.PlayRepeating(NormalizeInfantrySequence(self, "run"));
|
||||
}
|
||||
|
||||
dirty = false;
|
||||
@@ -102,7 +102,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
if (State != AnimationState.Idle && State != AnimationState.IdleAnimating)
|
||||
{
|
||||
anim.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0);
|
||||
DefaultAnimation.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0);
|
||||
State = AnimationState.Idle;
|
||||
|
||||
if (info.IdleAnimations.Length > 0)
|
||||
@@ -113,12 +113,12 @@ namespace OpenRA.Mods.RA.Render
|
||||
}
|
||||
else if (AllowIdleAnimation(self) && idleDelay > 0 && --idleDelay == 0)
|
||||
{
|
||||
if (anim.HasSequence(idleSequence))
|
||||
if (DefaultAnimation.HasSequence(idleSequence))
|
||||
{
|
||||
State = AnimationState.IdleAnimating;
|
||||
anim.PlayThen(idleSequence, () =>
|
||||
DefaultAnimation.PlayThen(idleSequence, () =>
|
||||
{
|
||||
anim.PlayRepeating(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)));
|
||||
DefaultAnimation.PlayRepeating(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)));
|
||||
State = AnimationState.Waiting;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
var prefix = sc != null && sc.Panicking ? "panic-" : "";
|
||||
|
||||
if (anim.HasSequence(prefix + baseSequence))
|
||||
if (DefaultAnimation.HasSequence(prefix + baseSequence))
|
||||
return prefix + baseSequence;
|
||||
else
|
||||
return baseSequence;
|
||||
|
||||
@@ -51,20 +51,20 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
void Open()
|
||||
{
|
||||
if (open || !anim.HasSequence(info.OpenAnim))
|
||||
if (open || !DefaultAnimation.HasSequence(info.OpenAnim))
|
||||
return;
|
||||
|
||||
open = true;
|
||||
PlayCustomAnimation(self, info.OpenAnim, () =>
|
||||
{
|
||||
if (anim.HasSequence(info.UnloadAnim))
|
||||
if (DefaultAnimation.HasSequence(info.UnloadAnim))
|
||||
PlayCustomAnimRepeating(self, info.UnloadAnim);
|
||||
});
|
||||
}
|
||||
|
||||
void Close()
|
||||
{
|
||||
if (!open || !anim.HasSequence(info.OpenAnim))
|
||||
if (!open || !DefaultAnimation.HasSequence(info.OpenAnim))
|
||||
return;
|
||||
|
||||
open = false;
|
||||
|
||||
@@ -25,19 +25,19 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
public void PlayCustomAnimation(Actor self, string newAnim, Action after)
|
||||
{
|
||||
anim.PlayThen(newAnim, () => { anim.Play("idle"); if (after != null) after(); });
|
||||
DefaultAnimation.PlayThen(newAnim, () => { DefaultAnimation.Play("idle"); if (after != null) after(); });
|
||||
}
|
||||
|
||||
public void PlayCustomAnimRepeating(Actor self, string name)
|
||||
{
|
||||
anim.PlayThen(name,
|
||||
DefaultAnimation.PlayThen(name,
|
||||
() => { PlayCustomAnimRepeating(self, name); });
|
||||
}
|
||||
|
||||
public void PlayCustomAnimBackwards(Actor self, string name, Action after)
|
||||
{
|
||||
anim.PlayBackwardsThen(name,
|
||||
() => { anim.PlayRepeating("idle"); if (after != null) after(); });
|
||||
DefaultAnimation.PlayBackwardsThen(name,
|
||||
() => { DefaultAnimation.PlayRepeating("idle"); if (after != null) after(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ namespace OpenRA.Mods.RA.Render
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
var sequence = (armament.IsReloading ? "empty-" : "") + (attack.IsAttacking ? "aim" : "idle");
|
||||
if (sequence != anim.CurrentSequence.Name)
|
||||
anim.ReplaceAnim(sequence);
|
||||
if (sequence != DefaultAnimation.CurrentSequence.Name)
|
||||
DefaultAnimation.ReplaceAnim(sequence);
|
||||
|
||||
base.Tick(self);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
var prefix = tc != null && tc.IsProne ? "prone-" : "";
|
||||
|
||||
if (anim.HasSequence(prefix + baseSequence))
|
||||
if (DefaultAnimation.HasSequence(prefix + baseSequence))
|
||||
return prefix + baseSequence;
|
||||
else
|
||||
return baseSequence;
|
||||
|
||||
Reference in New Issue
Block a user