Exemplo n.º 1
0
        public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            // Show a static frame instead of animating all of the fullness states
            var anim = new Animation(init.World, image, () => 0);
            anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0);

            yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
        }
Exemplo n.º 2
0
 public RenderSprites(ActorInitializer init, RenderSpritesInfo info)
 {
     this.info = info;
     race = init.Contains<RaceInit>() ? init.Get<RaceInit, string>() : init.Self.Owner.Country.Race;
 }
Exemplo n.º 3
0
        public override IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (!EnabledByDefault)
            {
                yield break;
            }

            var t   = init.Actor.TraitInfos <TurretedInfo>().FirstOrDefault();
            var wsb = init.Actor.TraitInfos <WithSpriteBodyInfo>().FirstOrDefault();

            // Show the correct turret facing
            var facing = init.Contains <TurretFacingInit>() ? init.Get <TurretFacingInit>().Value(init.World) : t.InitialFacing;

            var anim = new Animation(init.World, image, () => facing);

            anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), wsb.Sequence));

            yield return(new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p, rs.Scale));
        }
Exemplo n.º 4
0
 public RenderSprites(ActorInitializer init, RenderSpritesInfo info)
 {
     this.info = info;
     race = init.Contains<RaceInit>() ? init.Get<RaceInit, string>() : init.Self.Owner.Faction.InternalName;
 }
Exemplo n.º 5
0
        public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            var anim = new Animation(init.World, image);
            anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequences.First()), () => 0);

            yield return new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p, rs.Scale);
        }
Exemplo n.º 6
0
        public new IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (!EnabledByDefault)
            {
                yield break;
            }

            var body = init.Actor.TraitInfo <BodyOrientationInfo>();
            var t    = init.Actor.TraitInfos <TurretedInfo>()
                       .First(tt => tt.Turret == Turret);

            var bodyAnim = new Animation(init.World, image, init.GetFacing());

            bodyAnim.PlayRepeating(RenderSprites.NormalizeSequence(bodyAnim, init.GetDamageState(), "idle"));
            var         bodySequence = bodyAnim.CurrentSequence as OffsetsSpriteSequence;
            Func <WVec> offset       = null;

            if (bodySequence != null && bodySequence.EmbeddedOffsets.ContainsKey(bodyAnim.Image) && bodySequence.EmbeddedOffsets[bodyAnim.Image] != null)
            {
                var point = bodySequence.EmbeddedOffsets[bodyAnim.Image].FirstOrDefault(p1 => p1.Id == 0);

                if (point != null)
                {
                    offset = () => new WVec(point.X * 32, point.Y * 32, 0);
                }
            }

            var turretFacing = Turreted.TurretFacingFromInit(init, t.InitialFacing, Turret);
            var anim         = new Animation(init.World, image, turretFacing);

            anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));

            if (offset == null)
            {
                Func <int>  facing      = init.GetFacing();
                Func <WRot> orientation = () => body.QuantizeOrientation(WRot.FromFacing(facing()), facings);
                offset = () => body.LocalToWorld(t.Offset.Rotate(orientation()));
            }

            Func <int> zOffset = () =>
            {
                var tmpOffset = offset();
                return(-(tmpOffset.Y + tmpOffset.Z) + 1);
            };

            yield return(new SpriteActorPreview(anim, offset, zOffset, p, rs.Scale));
        }
Exemplo n.º 7
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (init.Contains <HideBibPreviewInit>() && init.Get <HideBibPreviewInit, bool>())
            {
                yield break;
            }

            if (Palette != null)
            {
                p = init.WorldRenderer.Palette(Palette);
            }

            var bi = init.Actor.TraitInfo <BuildingInfo>();

            var rows         = HasMinibib ? 1 : 2;
            var width        = bi.Dimensions.X;
            var bibOffset    = bi.Dimensions.Y - rows;
            var centerOffset = bi.CenterOffset(init.World);
            var map          = init.World.Map;
            var location     = CPos.Zero;

            if (init.Contains <LocationInit>())
            {
                location = init.Get <LocationInit, CPos>();
            }

            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));
            }
        }
Exemplo n.º 8
0
 public RenderSprites(Actor self)
 {
     info = self.Info.Traits.Get<RenderSpritesInfo>();
 }
Exemplo n.º 9
0
        public new IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (!EnabledByDefault)
            {
                yield break;
            }

            if (Palette != null)
            {
                p = init.WorldRenderer.Palette(Palette);
            }

            Func <WAngle> facing;
            var           dynamicfacingInit = init.GetOrDefault <DynamicFacingInit>(this);

            if (dynamicfacingInit != null)
            {
                facing = dynamicfacingInit.Value;
            }
            else
            {
                var f = init.GetValue <FacingInit, WAngle>(this, WAngle.Zero);
                facing = () => f;
            }

            var anim = new Animation(init.World, image, facing);

            anim.IsDecoration = IsDecoration;
            anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));

            var         body        = init.Actor.TraitInfo <BodyOrientationInfo>();
            Func <WRot> orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
            Func <WVec> offset      = () => body.LocalToWorld(Offset.Rotate(orientation()));
            Func <int>  zOffset     = () =>
            {
                var tmpOffset = offset();
                return(tmpOffset.Y + tmpOffset.Z + 1);
            };

            yield return(new SpriteActorPreview(anim, offset, zOffset, p, rs.Scale));
        }
Exemplo n.º 10
0
 public WithMovePalette(ActorInitializer init, WithMovePaletteInfo info)
 {
     this.info         = info;
     move              = init.Self.Trait <IMove>();
     renderSpritesInfo = init.Self.Info.TraitInfo <RenderSpritesInfo>();
 }
Exemplo n.º 11
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (Palette != null)
            {
                p = init.WorldRenderer.Palette(Palette);
            }

            var bi = init.Actor.TraitInfo <BuildingInfo>();

            var cols = bi.Dimensions.X;
            var rows = bi.Dimensions.Y;

            for (var index = 0; index < (cols * rows); index++)
            {
                if (SkipFrames == null || !SkipFrames.Contains(index))
                {
                    var y = index / cols;
                    var x = index % cols;

                    var         anim    = new Animation(init.World, image);
                    Func <WVec> offset  = () => new WVec(x * 1024 - 512, y * 1024 - 512, 0);
                    Func <int>  zOffset = () => 0;

                    var frameIndex = index;
                    anim.PlayFetchIndex(Sequence, () => frameIndex);
                    anim.IsDecoration = true;

                    yield return(new SpriteActorPreview(anim, offset, zOffset, p, rs.Scale));
                }
            }
        }
Exemplo n.º 12
0
        public new IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (!EnabledByDefault)
            {
                yield break;
            }

            if (Palette != null)
            {
                p = init.WorldRenderer.Palette(Palette);
            }

            var        idleImage = Image != null ? Image : image;
            Func <int> facing;

            if (init.Contains <DynamicFacingInit>())
            {
                facing = init.Get <DynamicFacingInit, Func <int> >();
            }
            else
            {
                var f = init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : 0;
                facing = () => f;
            }

            var anim = new Animation(init.World, idleImage, facing);

            anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));

            var         body        = init.Actor.TraitInfo <BodyOrientationInfo>();
            Func <WRot> orientation = () => body.QuantizeOrientation(WRot.FromFacing(facing()), facings);
            Func <WVec> offset      = () => body.LocalToWorld(Offset.Rotate(orientation()));
            Func <int>  zOffset     = () =>
            {
                var tmpOffset = offset();
                return(tmpOffset.Y + tmpOffset.Z + 1);
            };

            yield return(new SpriteActorPreview(anim, offset, zOffset, p, rs.Scale));
        }
Exemplo n.º 13
0
 public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
 {
     var anim = new Animation(init.World, image);
     var sequence = init.World.Type == WorldType.Editor ? EditorSequence : Sequence;
     var palette = init.World.Type == WorldType.Editor ? init.WorldRenderer.Palette(EditorPalette) : p;
     anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), sequence), () => 0);
     yield return new SpriteActorPreview(anim, () => WVec.Zero, () => 0, palette, rs.Scale);
 }
Exemplo n.º 14
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            var anim = new Animation(init.World, image, init.GetFacing());

            anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), StandSequences.First()));
            yield return(new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p, rs.Scale));
        }
Exemplo n.º 15
0
        public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            foreach (var orig in base.RenderPreviewSprites(init, rs, image, facings, p))
                yield return orig;

            // Show additional roof overlay
            var anim = new Animation(init.World, image, () => 0);
            anim.PlayRepeating("idle-top");

            var bi = init.Actor.Traits.Get<BuildingInfo>();
            var offset = FootprintUtils.CenterOffset(init.World, bi).Y + 512;
            yield return new SpriteActorPreview(anim, WVec.Zero, offset, p, rs.Scale);
        }
Exemplo n.º 16
0
        public new IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (UpgradeMinEnabledLevel > 0)
            {
                yield break;
            }

            if (Palette != null)
            {
                p = init.WorldRenderer.Palette(Palette);
            }

            var idleImage = Image != null ? Image : image;

            var body   = init.Actor.TraitInfo <BodyOrientationInfo>();
            var facing = init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : 0;
            var anim   = new Animation(init.World, idleImage, () => facing);

            anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));

            var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)), facings);
            var offset      = body.LocalToWorld(Offset.Rotate(orientation));

            yield return(new SpriteActorPreview(anim, offset, offset.Y + offset.Z + 1, p, rs.Scale));
        }