protected WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info, Func <int> baseFacing) : base(info) { rs = init.Self.Trait <RenderSprites>(); Func <bool> paused = () => IsTraitPaused && DefaultAnimation.CurrentSequence.Name == NormalizeSequence(init.Self, Info.Sequence); DefaultAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused); rs.Add(new AnimationWithOffset(DefaultAnimation, null, () => IsTraitDisabled)); // Cache the bounds from the default sequence to avoid flickering when the animation changes boundsAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused); boundsAnimation.PlayRepeating(info.Sequence); if (info.StartSequence != null) { PlayCustomAnimation(init.Self, info.StartSequence, () => PlayCustomAnimationRepeating(init.Self, info.Sequence)); } else { DefaultAnimation.PlayRepeating(NormalizeSequence(init.Self, info.Sequence)); } }
public WithAttackOverlay(ActorInitializer init, WithAttackOverlayInfo info) { this.info = info; renderSprites = init.Self.Trait <RenderSprites>(); overlay = new Animation(init.World, renderSprites.GetImage(init.Self)); renderSprites.Add(new AnimationWithOffset(overlay, null, () => !attacking), info.Palette, info.IsPlayerPalette); }
public WithChargeOverlay(Actor self, WithChargeOverlayInfo info) { this.info = info; rs = self.Trait <RenderSprites>(); wsb = self.Trait <WithSpriteBody>(); var attackCharges = self.Trait <AttackCharges>(); var attackChargesInfo = (AttackChargesInfo)attackCharges.Info; overlay = new Animation(self.World, rs.GetImage(self)); overlay.PlayFetchIndex(wsb.NormalizeSequence(self, info.Sequence), () => int2.Lerp(0, overlay.CurrentSequence.Length, attackCharges.ChargeLevel, attackChargesInfo.ChargeLevel + 1)); rs.Add(new AnimationWithOffset(overlay, null, () => !buildComplete, 1024), info.Palette, info.IsPlayerPalette); }
public WithResources(Actor self, WithResourcesInfo info) { this.info = info; rs = self.Trait <RenderSprites>(); wsb = self.Trait <WithSpriteBody>(); playerResources = self.Owner.PlayerActor.Trait <PlayerResources>(); var a = new Animation(self.World, rs.GetImage(self)); a.PlayFetchIndex(info.Sequence, () => playerResources.ResourceCapacity != 0 ? ((10 * a.CurrentSequence.Length - 1) * playerResources.Resources) / (10 * playerResources.ResourceCapacity) : 0); anim = new AnimationWithOffset(a, null, () => !buildComplete, 1024); rs.Add(anim); }
public WithResourceLevelOverlay(Actor self, WithResourceLevelOverlayInfo info) : base(info) { rs = self.Trait <RenderSprites>(); wsb = self.Trait <WithSpriteBody>(); playerResources = self.Owner.PlayerActor.Trait <PlayerResources>(); var a = new Animation(self.World, rs.GetImage(self)); a.PlayFetchIndex(info.Sequence, () => playerResources.ResourceCapacity != 0 ? ((10 * a.CurrentSequence.Length - 1) * playerResources.Resources) / (10 * playerResources.ResourceCapacity) : 0); anim = new AnimationWithOffset(a, null, () => IsTraitDisabled, 1024); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
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; }
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; }
protected WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info, Func <WAngle> baseFacing) : base(info) { rs = init.Self.Trait <RenderSprites>(); Func <bool> paused = () => IsTraitPaused && DefaultAnimation.CurrentSequence.Name == NormalizeSequence(init.Self, Info.Sequence); Func <WVec> subtractDAT = null; if (info.ForceToGround) { subtractDAT = () => new WVec(0, 0, -init.Self.World.Map.DistanceAboveTerrain(init.Self.CenterPosition).Length); } DefaultAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused); rs.Add(new AnimationWithOffset(DefaultAnimation, subtractDAT, () => IsTraitDisabled)); // Cache the bounds from the default sequence to avoid flickering when the animation changes boundsAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused); boundsAnimation.PlayRepeating(info.Sequence); }
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; }