From 7937383bf4486cd63cb5f84e6a694b4b7c28b82c Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 15 Sep 2019 11:37:53 +0100 Subject: [PATCH] Replace scaleSizeWithZoom with SpriteAnnotation. --- .../Effects/SpriteAnnotation.cs | 48 +++++++++++++++++++ OpenRA.Mods.Common/Effects/SpriteEffect.cs | 15 +++--- OpenRA.Mods.Common/Projectiles/Bullet.cs | 2 +- OpenRA.Mods.Common/Projectiles/Missile.cs | 2 +- OpenRA.Mods.Common/Projectiles/NukeLaunch.cs | 2 +- .../Traits/Render/LeavesTrails.cs | 2 +- .../Traits/SmokeTrailWhenDamaged.cs | 2 +- .../WorldInteractionControllerWidget.cs | 2 +- 8 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 OpenRA.Mods.Common/Effects/SpriteAnnotation.cs diff --git a/OpenRA.Mods.Common/Effects/SpriteAnnotation.cs b/OpenRA.Mods.Common/Effects/SpriteAnnotation.cs new file mode 100644 index 0000000000..f9af40cdcc --- /dev/null +++ b/OpenRA.Mods.Common/Effects/SpriteAnnotation.cs @@ -0,0 +1,48 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using OpenRA.Effects; +using OpenRA.Graphics; + +namespace OpenRA.Mods.Common.Effects +{ + public class SpriteAnnotation : IEffect, IEffectAnnotation + { + readonly string palette; + readonly Animation anim; + readonly WPos pos; + + public SpriteAnnotation(WPos pos, World world, string image, string sequence, string palette) + { + this.palette = palette; + this.pos = pos; + anim = new Animation(world, image); + anim.PlayThen(sequence, () => world.AddFrameEndTask(w => { w.Remove(this); w.ScreenMap.Remove(this); })); + world.ScreenMap.Add(this, pos, anim.Image); + } + + void IEffect.Tick(World world) + { + anim.Tick(); + world.ScreenMap.Update(this, pos, anim.Image); + } + + IEnumerable IEffect.Render(WorldRenderer wr) { yield break; } + + IEnumerable IEffectAnnotation.RenderAnnotation(WorldRenderer wr) + { + var screenPos = wr.Viewport.WorldToViewPx(wr.ScreenPxPosition(pos)); + return anim.RenderUI(screenPos, WVec.Zero, 0, wr.Palette(palette), 1f); + } + } +} diff --git a/OpenRA.Mods.Common/Effects/SpriteEffect.cs b/OpenRA.Mods.Common/Effects/SpriteEffect.cs index f38649e463..aa212b2a0c 100644 --- a/OpenRA.Mods.Common/Effects/SpriteEffect.cs +++ b/OpenRA.Mods.Common/Effects/SpriteEffect.cs @@ -23,24 +23,22 @@ namespace OpenRA.Mods.Common.Effects readonly Animation anim; readonly Func posFunc; readonly bool visibleThroughFog; - readonly bool scaleSizeWithZoom; WPos pos; // Facing is last on these overloads partially for backwards compatibility with previous main ctor revision // and partially because most effects don't need it. - public SpriteEffect(WPos pos, World world, string image, string sequence, string palette, bool visibleThroughFog = false, bool scaleSizeWithZoom = false, int facing = 0) - : this(() => pos, () => facing, world, image, sequence, palette, visibleThroughFog, scaleSizeWithZoom) { } + public SpriteEffect(WPos pos, World world, string image, string sequence, string palette, bool visibleThroughFog = false, int facing = 0) + : this(() => pos, () => facing, world, image, sequence, palette, visibleThroughFog) { } - public SpriteEffect(Actor actor, World world, string image, string sequence, string palette, bool visibleThroughFog = false, bool scaleSizeWithZoom = false, int facing = 0) - : this(() => actor.CenterPosition, () => facing, world, image, sequence, palette, visibleThroughFog, scaleSizeWithZoom) { } + public SpriteEffect(Actor actor, World world, string image, string sequence, string palette, bool visibleThroughFog = false, int facing = 0) + : this(() => actor.CenterPosition, () => facing, world, image, sequence, palette, visibleThroughFog) { } public SpriteEffect(Func posFunc, Func facingFunc, World world, string image, string sequence, string palette, - bool visibleThroughFog = false, bool scaleSizeWithZoom = false) + bool visibleThroughFog = false) { this.world = world; this.posFunc = posFunc; this.palette = palette; - this.scaleSizeWithZoom = scaleSizeWithZoom; this.visibleThroughFog = visibleThroughFog; pos = posFunc(); anim = new Animation(world, image, facingFunc); @@ -61,8 +59,7 @@ namespace OpenRA.Mods.Common.Effects if (!visibleThroughFog && world.FogObscures(pos)) return SpriteRenderable.None; - var zoom = scaleSizeWithZoom ? 1f / wr.Viewport.Zoom : 1f; - return anim.Render(pos, WVec.Zero, 0, wr.Palette(palette), zoom); + return anim.Render(pos, wr.Palette(palette)); } } } diff --git a/OpenRA.Mods.Common/Projectiles/Bullet.cs b/OpenRA.Mods.Common/Projectiles/Bullet.cs index 58965b6577..f43be9b1b7 100644 --- a/OpenRA.Mods.Common/Projectiles/Bullet.cs +++ b/OpenRA.Mods.Common/Projectiles/Bullet.cs @@ -211,7 +211,7 @@ namespace OpenRA.Mods.Common.Projectiles { var delayedPos = WPos.LerpQuadratic(source, target, angle, ticks - info.TrailDelay, length); world.AddFrameEndTask(w => w.Add(new SpriteEffect(delayedPos, w, info.TrailImage, info.TrailSequences.Random(world.SharedRandom), - trailPalette, false, false, GetEffectiveFacing()))); + trailPalette, facing: GetEffectiveFacing()))); smokeTicks = info.TrailInterval; } diff --git a/OpenRA.Mods.Common/Projectiles/Missile.cs b/OpenRA.Mods.Common/Projectiles/Missile.cs index 60fe43f386..b322ea25c4 100644 --- a/OpenRA.Mods.Common/Projectiles/Missile.cs +++ b/OpenRA.Mods.Common/Projectiles/Missile.cs @@ -858,7 +858,7 @@ namespace OpenRA.Mods.Common.Projectiles if (!string.IsNullOrEmpty(info.TrailImage) && --ticksToNextSmoke < 0 && (state != States.Freefall || info.TrailWhenDeactivated)) { world.AddFrameEndTask(w => w.Add(new SpriteEffect(pos - 3 * move / 2, w, info.TrailImage, info.TrailSequences.Random(world.SharedRandom), - trailPalette, false, false, renderFacing))); + trailPalette, facing: renderFacing))); ticksToNextSmoke = info.TrailInterval; } diff --git a/OpenRA.Mods.Common/Projectiles/NukeLaunch.cs b/OpenRA.Mods.Common/Projectiles/NukeLaunch.cs index 231ed3b9d7..ea73f05745 100644 --- a/OpenRA.Mods.Common/Projectiles/NukeLaunch.cs +++ b/OpenRA.Mods.Common/Projectiles/NukeLaunch.cs @@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Effects : WPos.LerpQuadratic(descendSource, descendTarget, WAngle.Zero, ticks - turn - trailDelay, impactDelay - turn); world.AddFrameEndTask(w => w.Add(new SpriteEffect(trailPos, w, trailImage, trailSequences.Random(world.SharedRandom), - trailPalette, false, false, 0))); + trailPalette))); trailTicks = trailInterval; } diff --git a/OpenRA.Mods.Common/Traits/Render/LeavesTrails.cs b/OpenRA.Mods.Common/Traits/Render/LeavesTrails.cs index c7f4f54b6d..46563086b2 100644 --- a/OpenRA.Mods.Common/Traits/Render/LeavesTrails.cs +++ b/OpenRA.Mods.Common/Traits/Render/LeavesTrails.cs @@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits.Render if ((Info.TerrainTypes.Count == 0 || Info.TerrainTypes.Contains(type)) && !string.IsNullOrEmpty(Info.Image)) self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, self.World, Info.Image, - Info.Sequences.Random(Game.CosmeticRandom), Info.Palette, Info.VisibleThroughFog, false, spawnFacing))); + Info.Sequences.Random(Game.CosmeticRandom), Info.Palette, Info.VisibleThroughFog, spawnFacing))); cachedPosition = self.CenterPosition; cachedFacing = facing != null ? facing.Facing : 0; diff --git a/OpenRA.Mods.Common/Traits/SmokeTrailWhenDamaged.cs b/OpenRA.Mods.Common/Traits/SmokeTrailWhenDamaged.cs index e4235be74e..bf031fb8e4 100644 --- a/OpenRA.Mods.Common/Traits/SmokeTrailWhenDamaged.cs +++ b/OpenRA.Mods.Common/Traits/SmokeTrailWhenDamaged.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits { var offset = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation)); var pos = position + body.LocalToWorld(offset); - self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, w, info.Sprite, info.Sequence, info.Palette, false, false, getFacing))); + self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, w, info.Sprite, info.Sequence, info.Palette, facing: getFacing))); } ticks = info.Interval; diff --git a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs index daea81c865..b541807bd6 100644 --- a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs @@ -215,7 +215,7 @@ namespace OpenRA.Mods.Common.Widgets } else if (visualTarget.Type == TargetType.Terrain) { - world.AddFrameEndTask(w => w.Add(new SpriteEffect(visualTarget.CenterPosition, world, "moveflsh", "idle", "moveflash", true, true))); + world.AddFrameEndTask(w => w.Add(new SpriteAnnotation(visualTarget.CenterPosition, world, "moveflsh", "idle", "moveflash"))); flashed = true; } }