Adjust GetImage plumbing in preparation for race-specific sequences.
This commit is contained in:
@@ -238,7 +238,9 @@ namespace OpenRA.Editor
|
||||
if (rsi != null && rsi.EditorPalette != null && rsi.EditorPalette.Contains("terrain"))
|
||||
templatePalette = palette;
|
||||
|
||||
var template = RenderUtils.RenderActor(info, tileset, templatePalette);
|
||||
var race = Program.Rules.Actors["world"].Traits.WithInterface<CountryInfo>().First().Race;
|
||||
var sequenceProvider = Program.Rules.Sequences[tileset.Id];
|
||||
var template = RenderUtils.RenderActor(info, sequenceProvider, tileset, templatePalette, race);
|
||||
var ibox = new PictureBox
|
||||
{
|
||||
Image = template.Bitmap,
|
||||
|
||||
@@ -46,9 +46,9 @@ namespace OpenRA.Editor
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static ActorTemplate RenderActor(ActorInfo info, TileSet tileset, IPalette p)
|
||||
public static ActorTemplate RenderActor(ActorInfo info, SequenceProvider sequenceProvider, TileSet tileset, IPalette p, string race)
|
||||
{
|
||||
var image = info.Traits.Get<ILegacyEditorRenderInfo>().EditorImage(info);
|
||||
var image = info.Traits.Get<ILegacyEditorRenderInfo>().EditorImage(info, sequenceProvider, race);
|
||||
using (var s = GlobalFileSystem.OpenWithExts(image, tileset.Extensions))
|
||||
{
|
||||
var shp = new ShpTDSprite(s);
|
||||
|
||||
@@ -102,4 +102,14 @@ namespace OpenRA
|
||||
return world.Players.First(x => x.InternalName == PlayerName);
|
||||
}
|
||||
}
|
||||
|
||||
// Allows maps / transformations to specify the race variant of an actor.
|
||||
public class RaceInit : IActorInit<string>
|
||||
{
|
||||
[FieldFromYamlKey] public readonly string Race;
|
||||
|
||||
public RaceInit() { }
|
||||
public RaceInit(string race) { Race = race; }
|
||||
public string Value(World world) { return Race; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRA.Traits
|
||||
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new BodyOrientation(init.Self, this); }
|
||||
public object Create(ActorInitializer init) { return new BodyOrientation(init, this); }
|
||||
}
|
||||
|
||||
public class BodyOrientation : IBodyOrientation
|
||||
@@ -50,9 +50,11 @@ namespace OpenRA.Traits
|
||||
|
||||
[Sync] public int QuantizedFacings { get { return quantizedFacings.Value; } }
|
||||
|
||||
public BodyOrientation(Actor self, BodyOrientationInfo info)
|
||||
public BodyOrientation(ActorInitializer init, BodyOrientationInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
var self = init.Self;
|
||||
var race = init.Contains<RaceInit>() ? init.Get<RaceInit, string>() : self.Owner.Country.Race;
|
||||
|
||||
quantizedFacings = Exts.Lazy(() =>
|
||||
{
|
||||
@@ -64,7 +66,7 @@ namespace OpenRA.Traits
|
||||
if (qboi == null)
|
||||
throw new InvalidOperationException("Actor type '" + self.Info.Name + "' does not define a quantized body orientation.");
|
||||
|
||||
return qboi.QuantizedBodyFacings(self.World.Map.SequenceProvider, self.Info);
|
||||
return qboi.QuantizedBodyFacings(self.Info, self.World.Map.SequenceProvider, race);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -289,7 +289,7 @@ namespace OpenRA.Traits
|
||||
WRot QuantizeOrientation(WRot orientation, int facings);
|
||||
}
|
||||
|
||||
public interface IQuantizeBodyOrientationInfo { int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai); }
|
||||
public interface IQuantizeBodyOrientationInfo { int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race); }
|
||||
|
||||
public interface ITargetableInfo
|
||||
{
|
||||
@@ -334,6 +334,6 @@ namespace OpenRA.Traits
|
||||
public interface ILegacyEditorRenderInfo
|
||||
{
|
||||
string EditorPalette { get; }
|
||||
string EditorImage(ActorInfo actor);
|
||||
string EditorImage(ActorInfo actor, SequenceProvider sequenceProvider, string race);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
|
||||
public override object Create(ActorInitializer init) { return new RenderGunboat(init, this); }
|
||||
|
||||
public int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai)
|
||||
public int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -74,14 +74,4 @@ namespace OpenRA.Mods.Common.Traits
|
||||
enabled = owner.PlayerActor.Trait<TechTree>().HasPrerequisites(info.RequiresPrerequisites);
|
||||
}
|
||||
}
|
||||
|
||||
// Allows maps / transformations to specify the race variant of an actor.
|
||||
public class RaceInit : IActorInit<string>
|
||||
{
|
||||
[FieldFromYamlKey] public readonly string Race;
|
||||
|
||||
public RaceInit() { }
|
||||
public RaceInit(string race) { Race = race; }
|
||||
public string Value(World world) { return Race; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,9 +39,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
|
||||
public override int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai)
|
||||
public override int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race)
|
||||
{
|
||||
return sequenceProvider.GetSequence(RenderSprites.GetImage(ai), StandAnimations.First()).Facings;
|
||||
return sequenceProvider.GetSequence(GetImage(ai, sequenceProvider, race), StandAnimations.First()).Facings;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
|
||||
public virtual int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai)
|
||||
public virtual int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race)
|
||||
{
|
||||
return sequenceProvider.GetSequence(RenderSprites.GetImage(ai), "idle").Facings;
|
||||
return sequenceProvider.GetSequence(GetImage(ai, sequenceProvider, race), "idle").Facings;
|
||||
}
|
||||
|
||||
public string EditorPalette { get { return Palette; } }
|
||||
public string EditorImage(ActorInfo actor) { return RenderSimple.GetImage(actor); }
|
||||
public string EditorImage(ActorInfo actor, SequenceProvider sequenceProvider, string race) { return GetImage(actor, sequenceProvider, race); }
|
||||
}
|
||||
|
||||
public class RenderSimple : RenderSprites, IAutoSelectionSize
|
||||
|
||||
@@ -37,18 +37,24 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init)
|
||||
{
|
||||
var sequenceProvider = init.World.Map.SequenceProvider;
|
||||
var image = RenderSprites.GetImage(init.Actor);
|
||||
var palette = init.WorldRenderer.Palette(Palette ?? (init.Owner != null ? PlayerPalette + init.Owner.InternalName : null));
|
||||
var race = init.Contains<RaceInit>() ? init.Get<RaceInit, string>() : init.Owner.Country.Race;
|
||||
var image = GetImage(init.Actor, sequenceProvider, race);
|
||||
var palette = init.WorldRenderer.Palette(Palette ?? PlayerPalette + init.Owner.InternalName);
|
||||
|
||||
var facings = 0;
|
||||
var body = init.Actor.Traits.GetOrDefault<BodyOrientationInfo>();
|
||||
if (body != null)
|
||||
facings = body.QuantizedFacings == -1 ? init.Actor.Traits.Get<IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(sequenceProvider, init.Actor) : body.QuantizedFacings;
|
||||
facings = body.QuantizedFacings == -1 ? init.Actor.Traits.Get<IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(init.Actor, sequenceProvider, init.Owner.Country.Race) : body.QuantizedFacings;
|
||||
|
||||
foreach (var spi in init.Actor.Traits.WithInterface<IRenderActorPreviewSpritesInfo>())
|
||||
foreach (var preview in spi.RenderPreviewSprites(init, this, image, facings, palette))
|
||||
yield return preview;
|
||||
}
|
||||
|
||||
public string GetImage(ActorInfo actor, SequenceProvider sequenceProvider, string race)
|
||||
{
|
||||
return (Image ?? actor.Name).ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
|
||||
public class RenderSprites : IRender, ITick, INotifyOwnerChanged, INotifyEffectiveOwnerChanged
|
||||
@@ -88,9 +94,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
readonly string race;
|
||||
readonly RenderSpritesInfo info;
|
||||
string cachedImage = null;
|
||||
Dictionary<string, AnimationWrapper> anims = new Dictionary<string, AnimationWrapper>();
|
||||
readonly Dictionary<string, AnimationWrapper> anims = new Dictionary<string, AnimationWrapper>();
|
||||
string cachedImage;
|
||||
|
||||
public static Func<int> MakeFacingFunc(Actor self)
|
||||
{
|
||||
@@ -102,12 +109,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public RenderSprites(ActorInitializer init, RenderSpritesInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public static string GetImage(ActorInfo actor)
|
||||
{
|
||||
var info = actor.Traits.Get<RenderSpritesInfo>();
|
||||
return (info.Image ?? actor.Name).ToLowerInvariant();
|
||||
race = init.Contains<RaceInit>() ? init.Get<RaceInit, string>() : init.Self.Owner.Country.Race;
|
||||
}
|
||||
|
||||
public string GetImage(Actor self)
|
||||
@@ -115,7 +117,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (cachedImage != null)
|
||||
return cachedImage;
|
||||
|
||||
return cachedImage = GetImage(self.Info);
|
||||
return cachedImage = info.GetImage(self.Info, self.World.Map.SequenceProvider, race);
|
||||
}
|
||||
|
||||
protected void UpdatePalette()
|
||||
|
||||
@@ -67,11 +67,13 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (current == null)
|
||||
continue;
|
||||
|
||||
var race = queue.Trait.Actor.Owner.Country.Race;
|
||||
var actor = queue.Trait.AllItems().FirstOrDefault(a => a.Name == current.Item);
|
||||
if (actor == null)
|
||||
continue;
|
||||
|
||||
var icon = new Animation(world, RenderSimple.GetImage(actor));
|
||||
var rsi = actor.Traits.Get<RenderSpritesInfo>();
|
||||
var icon = new Animation(world, rsi.GetImage(actor, world.Map.SequenceProvider, race));
|
||||
icon.Play(actor.Traits.Get<TooltipInfo>().Icon);
|
||||
var location = new float2(RenderBounds.Location) + new float2(queue.i * (IconWidth + IconSpacing), 0);
|
||||
WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer, 0.5f);
|
||||
|
||||
@@ -268,13 +268,16 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
var ks = Game.Settings.Keys;
|
||||
var rb = RenderBounds;
|
||||
var race = CurrentQueue.Actor.Owner.Country.Race;
|
||||
|
||||
foreach (var item in AllBuildables.Skip(IconRowOffset * Columns).Take(MaxIconRowOffset * Columns))
|
||||
{
|
||||
var x = DisplayedIconCount % Columns;
|
||||
var y = DisplayedIconCount / Columns;
|
||||
var rect = new Rectangle(rb.X + x * (IconSize.X + IconMargin.X), rb.Y + y * (IconSize.Y + IconMargin.Y), IconSize.X, IconSize.Y);
|
||||
var icon = new Animation(World, RenderSimple.GetImage(item));
|
||||
|
||||
var rsi = item.Traits.Get<RenderSpritesInfo>();
|
||||
var icon = new Animation(World, rsi.GetImage(item, World.Map.SequenceProvider, race));
|
||||
icon.Play(item.Traits.Get<TooltipInfo>().Icon);
|
||||
|
||||
var pi = new ProductionIcon()
|
||||
|
||||
@@ -152,7 +152,8 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
isCarrying = true;
|
||||
|
||||
// Create a new animation for our carryable unit
|
||||
anim = new Animation(self.World, RenderSprites.GetImage(carryable.Info), RenderSprites.MakeFacingFunc(self));
|
||||
var rs = carryable.Trait<RenderSprites>();
|
||||
anim = new Animation(self.World, rs.GetImage(carryable), RenderSprites.MakeFacingFunc(self));
|
||||
anim.PlayRepeating("idle");
|
||||
anim.IsDecoration = true;
|
||||
}
|
||||
|
||||
@@ -21,18 +21,20 @@ namespace OpenRA.Mods.RA.Traits
|
||||
[Desc("Uses the \"Cloneable\" trait to determine whether or not we should clone a produced unit.")]
|
||||
public readonly string[] CloneableTypes = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new ClonesProducedUnits(init.Self, this); }
|
||||
public object Create(ActorInitializer init) { return new ClonesProducedUnits(init, this); }
|
||||
}
|
||||
|
||||
public class ClonesProducedUnits : INotifyOtherProduction
|
||||
{
|
||||
readonly ClonesProducedUnitsInfo info;
|
||||
readonly Production production;
|
||||
readonly string race;
|
||||
|
||||
public ClonesProducedUnits(Actor self, ClonesProducedUnitsInfo info)
|
||||
public ClonesProducedUnits(ActorInitializer init, ClonesProducedUnitsInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
production = self.Trait<Production>();
|
||||
production = init.Self.Trait<Production>();
|
||||
race = init.Contains<RaceInit>() ? init.Get<RaceInit, string>() : init.Self.Owner.Country.Race;
|
||||
}
|
||||
|
||||
public void UnitProducedByOther(Actor self, Actor producer, Actor produced)
|
||||
@@ -45,7 +47,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
if (ci == null || !info.CloneableTypes.Intersect(ci.Types).Any())
|
||||
return;
|
||||
|
||||
production.Produce(self, produced.Info, self.Owner.Country.Race);
|
||||
production.Produce(self, produced.Info, race);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ namespace OpenRA.Mods.TS.Traits
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var sequenceProvider = init.World.Map.SequenceProvider;
|
||||
var image = Image ?? init.Actor.Name;
|
||||
var facings = body.QuantizedFacings == -1 ? init.Actor.Traits.Get<IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(sequenceProvider, init.Actor) : body.QuantizedFacings;
|
||||
var palette = init.WorldRenderer.Palette(Palette ?? (init.Owner != null ? PlayerPalette + init.Owner.InternalName : null));
|
||||
var facings = body.QuantizedFacings == -1 ? init.Actor.Traits.Get<IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(init.Actor, sequenceProvider, init.Owner.Country.Race) : body.QuantizedFacings;
|
||||
var palette = init.WorldRenderer.Palette(Palette ?? PlayerPalette + init.Owner.InternalName);
|
||||
|
||||
var ifacing = init.Actor.Traits.GetOrDefault<IFacingInfo>();
|
||||
var facing = ifacing != null ? init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing() : 0;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.TS.Traits
|
||||
() => false, () => 0);
|
||||
}
|
||||
|
||||
public int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai) { return 0; }
|
||||
public int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race) { return 0; }
|
||||
}
|
||||
|
||||
public class WithVoxelBody : IAutoSelectionSize
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.TS.Traits
|
||||
() => false, () => 0);
|
||||
}
|
||||
|
||||
public int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai) { return 0; }
|
||||
public int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race) { return 0; }
|
||||
}
|
||||
|
||||
public class WithVoxelUnloadBody : IAutoSelectionSize
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace OpenRA.Mods.TS.Traits
|
||||
public readonly int TickRate = 5;
|
||||
public object Create(ActorInitializer init) { return new WithVoxelWalkerBody(init.Self, this); }
|
||||
|
||||
public int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai) { return 0; }
|
||||
public int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race) { return 0; }
|
||||
}
|
||||
|
||||
public class WithVoxelWalkerBody : IAutoSelectionSize, ITick
|
||||
|
||||
Reference in New Issue
Block a user