Merge pull request #10759 from GraionDilach/spriteeffect-bleeding-fog

Do not render trails under fog by default.
This commit is contained in:
Oliver Brakmann
2016-02-14 20:51:43 +01:00
3 changed files with 14 additions and 4 deletions

View File

@@ -15,16 +15,20 @@ namespace OpenRA.Effects
{
public class SpriteEffect : IEffect
{
readonly World world;
readonly string palette;
readonly Animation anim;
readonly WPos pos;
readonly bool visibleThroughFog;
readonly bool scaleSizeWithZoom;
public SpriteEffect(WPos pos, World world, string image, string sequence, string palette, bool scaleSizeWithZoom = false)
public SpriteEffect(WPos pos, World world, string image, string sequence, string palette, bool visibleThroughFog = false, bool scaleSizeWithZoom = false)
{
this.world = world;
this.pos = pos;
this.palette = palette;
this.scaleSizeWithZoom = scaleSizeWithZoom;
this.visibleThroughFog = visibleThroughFog;
anim = new Animation(world, image);
anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this)));
}
@@ -36,8 +40,11 @@ namespace OpenRA.Effects
public IEnumerable<IRenderable> Render(WorldRenderer wr)
{
if (world.FogObscures(pos) && !visibleThroughFog)
return SpriteRenderable.None;
var zoom = scaleSizeWithZoom ? 1f / wr.Viewport.Zoom : 1f;
return anim.Render(pos, WVec.Zero, 0, wr.Palette(palette), zoom);
}
}
}
}

View File

@@ -196,7 +196,7 @@ namespace OpenRA.Widgets
else if (o.TargetLocation != CPos.Zero)
{
var pos = world.Map.CenterOfCell(cell);
world.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, world, "moveflsh", "idle", "moveflash", true)));
world.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, world, "moveflsh", "idle", "moveflash", true, true)));
flashed = true;
}
}

View File

@@ -33,6 +33,9 @@ namespace OpenRA.Mods.Common.Traits
"CenterPosition to draw the trail sprite at the current position.")]
public readonly TrailType Type = TrailType.Cell;
[Desc("Should the trail be visible through fog.")]
public readonly bool VisibleThroughFog = false;
[Desc("Display a trail while stationary.")]
public readonly bool TrailWhileStationary = false;
@@ -76,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
if (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.Sequences.Random(Game.CosmeticRandom), Info.Palette, Info.VisibleThroughFog)));
cachedPosition = self.CenterPosition;
ticks = 0;