コード例 #1
0
        public WithMuzzleOverlay(Actor self, WithMuzzleOverlayInfo info)
            : base(info)
        {
            var render = self.Trait <RenderSprites>();
            var facing = self.TraitOrDefault <IFacing>();

            armaments = self.TraitsImplementing <Armament>().ToArray();

            foreach (var arm in armaments)
            {
                var armClosure = arm;                   // closure hazard in AnimationWithOffset

                // Skip armaments that don't define muzzles
                if (arm.Info.MuzzleSequence == null)
                {
                    continue;
                }

                foreach (var b in arm.Barrels)
                {
                    var barrel   = b;
                    var turreted = self.TraitsImplementing <Turreted>()
                                   .FirstOrDefault(t => t.Name == arm.Info.Turret);

                    // Workaround for broken ternary operators in certain versions of mono (3.10 and
                    // certain versions of the 3.8 series): https://bugzilla.xamarin.com/show_bug.cgi?id=23319
                    if (turreted != null)
                    {
                        getFacing = () => turreted.TurretFacing;
                    }
                    else if (facing != null)
                    {
                        getFacing = () => facing.Facing;
                    }
                    else
                    {
                        getFacing = () => 0;
                    }

                    var muzzleFlash = new Animation(self.World, render.GetImage(self), getFacing);
                    visible.Add(barrel, false);
                    anims.Add(barrel,
                              new AnimationWithOffset(muzzleFlash,
                                                      () => info.IgnoreOffset ? WVec.Zero : armClosure.MuzzleOffset(self, barrel),
                                                      () => IsTraitDisabled || !visible[barrel],
                                                      p => RenderUtils.ZOffsetFromCenter(self, p, 2)));
                }
            }
        }
コード例 #2
0
        public WithSupportPowerActivationOverlay(Actor self, WithSupportPowerActivationOverlayInfo info)
            : base(info)
        {
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <BodyOrientation>();

            overlay = new Animation(self.World, rs.GetImage(self));
            overlay.PlayThen(info.Sequence, () => visible = false);

            var anim = new AnimationWithOffset(overlay,
                                               () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
                                               () => IsTraitDisabled || !visible,
                                               p => RenderUtils.ZOffsetFromCenter(self, p, 1));

            rs.Add(anim, info.Palette, info.IsPlayerPalette);
        }
コード例 #3
0
        public WithRepairOverlay(Actor self, WithRepairOverlayInfo info)
            : base(info)
        {
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <BodyOrientation>();

            buildComplete = !self.Info.HasTraitInfo <BuildingInfo>();            // always render instantly for units
            overlay       = new Animation(self.World, rs.GetImage(self), () => IsTraitPaused);
            overlay.PlayThen(info.Sequence, () => visible = false);

            var anim = new AnimationWithOffset(overlay,
                                               () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
                                               () => IsTraitDisabled || !visible || !buildComplete,
                                               p => RenderUtils.ZOffsetFromCenter(self, p, 1));

            rs.Add(anim, info.Palette, info.IsPlayerPalette);
        }
コード例 #4
0
        public WithIdleRepairOverlay(Actor self, WithIdleRepairOverlayInfo info)
            : base(info)
        {
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <BodyOrientation>();

            overlay = new Animation(self.World, rs.GetImage(self), () => IsTraitPaused);
            overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), Info.IdleSequence));
            idling = true;

            var anim = new AnimationWithOffset(overlay,
                                               () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
                                               () => IsTraitDisabled,
                                               p => RenderUtils.ZOffsetFromCenter(self, p, 1));

            rs.Add(anim, info.Palette, info.IsPlayerPalette);
        }
コード例 #5
0
        public WithSpriteTurret(Actor self, WithSpriteTurretInfo info)
            : base(info)
        {
            rs   = self.Trait <RenderSprites>();
            body = self.Trait <BodyOrientation>();
            t    = self.TraitsImplementing <Turreted>()
                   .First(tt => tt.Name == info.Turret);
            arms = self.TraitsImplementing <Armament>()
                   .Where(w => w.Info.Turret == info.Turret).ToArray();

            DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => t.WorldOrientation.Yaw);
            DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
            rs.Add(new AnimationWithOffset(DefaultAnimation,
                                           () => TurretOffset(self),
                                           () => IsTraitDisabled,
                                           p => RenderUtils.ZOffsetFromCenter(self, p, 1)), info.Palette, info.IsPlayerPalette);

            // Restrict turret facings to match the sprite
            t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
        }
コード例 #6
0
        public WithMuzzleOverlay(Actor self, WithMuzzleOverlayInfo info)
            : base(info)
        {
            var render = self.Trait <RenderSprites>();
            var facing = self.TraitOrDefault <IFacing>();

            armaments = self.TraitsImplementing <Armament>()
                        .Where(arm => arm.Info.MuzzleSequence != null)
                        .ToArray();

            foreach (var arm in armaments)
            {
                foreach (var b in arm.Barrels)
                {
                    var barrel   = b;
                    var turreted = self.TraitsImplementing <Turreted>()
                                   .FirstOrDefault(t => t.Name == arm.Info.Turret);

                    if (turreted != null)
                    {
                        getFacing = () => turreted.WorldOrientation.Yaw;
                    }
                    else if (facing != null)
                    {
                        getFacing = () => facing.Facing;
                    }
                    else
                    {
                        getFacing = () => WAngle.Zero;
                    }

                    var muzzleFlash = new Animation(self.World, render.GetImage(self), getFacing);
                    visible.Add(barrel, false);
                    anims.Add(barrel,
                              new AnimationWithOffset(muzzleFlash,
                                                      () => info.IgnoreOffset ? WVec.Zero : arm.MuzzleOffset(self, barrel),
                                                      () => IsTraitDisabled || !visible[barrel],
                                                      p => RenderUtils.ZOffsetFromCenter(self, p, 2)));
                }
            }
        }
コード例 #7
0
        public WithSpriteTurret(Actor self, WithSpriteTurretInfo info)
            : base(info)
        {
            rs     = self.Trait <RenderSprites>();
            body   = self.Trait <BodyOrientation>();
            Attack = self.TraitOrDefault <AttackBase>();
            t      = self.TraitsImplementing <Turreted>()
                     .First(tt => tt.Name == info.Turret);
            arms = self.TraitsImplementing <Armament>()
                   .Where(w => w.Info.Turret == info.Turret).ToArray();
            buildComplete = !self.Info.HasTraitInfo <BuildingInfo>();            // always render instantly for units

            DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => t.TurretFacing);
            DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
            rs.Add(new AnimationWithOffset(DefaultAnimation,
                                           () => TurretOffset(self),
                                           () => IsTraitDisabled || !buildComplete,
                                           p => RenderUtils.ZOffsetFromCenter(self, p, 1)));

            // Restrict turret facings to match the sprite
            t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
        }
コード例 #8
0
        public WithSpriteBarrel(Actor self, WithSpriteBarrelInfo info)
            : base(info)
        {
            this.self = self;
            body      = self.Trait <BodyOrientation>();
            armament  = self.TraitsImplementing <Armament>()
                        .First(a => a.Info.Name == Info.Armament);
            turreted = self.TraitsImplementing <Turreted>()
                       .First(tt => tt.Name == armament.Info.Turret);

            rs = self.Trait <RenderSprites>();
            DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => WAngle.FromFacing(turreted.TurretFacing));
            DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence));
            rs.Add(new AnimationWithOffset(
                       DefaultAnimation, () => BarrelOffset(), () => IsTraitDisabled, p => RenderUtils.ZOffsetFromCenter(self, p, 0)));

            // Restrict turret facings to match the sprite
            turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
        }