diff --git a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs index 1ae633bb4c..8916170d83 100644 --- a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs @@ -169,7 +169,8 @@ namespace OpenRA.Mods.Common.Orders { var td = new TypeDictionary() { - new RaceInit(race) + new RaceInit(race), + new HideBibPreviewInit() }; var init = new ActorPreviewInitializer(rules.Actors[building], producer.Owner, wr, td); diff --git a/OpenRA.Mods.Common/Traits/Buildings/Bib.cs b/OpenRA.Mods.Common/Traits/Buildings/Bib.cs index f4feaf7050..f5e89d797b 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Bib.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Bib.cs @@ -8,18 +8,57 @@ */ #endregion +using System.Collections.Generic; using OpenRA.Graphics; +using OpenRA.Mods.Common.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public class BibInfo : ITraitInfo, Requires, Requires + public class BibInfo : ITraitInfo, Requires, IRenderActorPreviewSpritesInfo, Requires { public readonly string Sequence = "bib"; public readonly string Palette = "terrain"; public readonly bool HasMinibib = false; public object Create(ActorInitializer init) { return new Bib(init.Self, this); } + + public IEnumerable RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) + { + if (init.Contains() && init.Get()) + yield break; + + var bi = init.Actor.Traits.Get(); + + var width = bi.Dimensions.X; + var bibOffset = bi.Dimensions.Y - 1; + var centerOffset = FootprintUtils.CenterOffset(init.World, bi); + var rows = HasMinibib ? 1 : 2; + var map = init.World.Map; + var location = CPos.Zero; + + if (init.Contains()) + location = init.Get(); + + for (var i = 0; i < rows * width; i++) + { + var index = i; + var anim = new Animation(init.World, image); + var cellOffset = new CVec(i % width, i / width + bibOffset); + var cell = location + cellOffset; + + // Some mods may define terrain-specific bibs + var terrain = map.GetTerrainInfo(cell).Type; + var testSequence = Sequence + "-" + terrain; + var sequence = anim.HasSequence(testSequence) ? testSequence : Sequence; + anim.PlayFetchIndex(sequence, () => index); + anim.IsDecoration = true; + + // Z-order is one set to the top of the footprint + var offset = map.CenterOfCell(cell) - map.CenterOfCell(location) - centerOffset; + yield return new SpriteActorPreview(anim, offset, -(offset.Y + centerOffset.Y + 512), p, rs.Scale); + } + } } public class Bib : INotifyAddedToWorld, INotifyRemovedFromWorld @@ -74,4 +113,12 @@ namespace OpenRA.Mods.Common.Traits rs.Remove("bib_{0}".F(i)); } } + + public class HideBibPreviewInit : IActorInit + { + [FieldFromYamlKey] readonly bool value = true; + public HideBibPreviewInit() { } + public HideBibPreviewInit(bool init) { value = init; } + public bool Value(World world) { return value; } + } }