Replace scaleSizeWithZoom with SpriteAnnotation.

This commit is contained in:
Paul Chote
2019-09-15 11:37:53 +01:00
committed by abcdefg30
parent e772adb0a9
commit 7937383bf4
8 changed files with 60 additions and 15 deletions

View File

@@ -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<IRenderable> IEffect.Render(WorldRenderer wr) { yield break; }
IEnumerable<IRenderable> IEffectAnnotation.RenderAnnotation(WorldRenderer wr)
{
var screenPos = wr.Viewport.WorldToViewPx(wr.ScreenPxPosition(pos));
return anim.RenderUI(screenPos, WVec.Zero, 0, wr.Palette(palette), 1f);
}
}
}

View File

@@ -23,24 +23,22 @@ namespace OpenRA.Mods.Common.Effects
readonly Animation anim; readonly Animation anim;
readonly Func<WPos> posFunc; readonly Func<WPos> posFunc;
readonly bool visibleThroughFog; readonly bool visibleThroughFog;
readonly bool scaleSizeWithZoom;
WPos pos; WPos pos;
// Facing is last on these overloads partially for backwards compatibility with previous main ctor revision // Facing is last on these overloads partially for backwards compatibility with previous main ctor revision
// and partially because most effects don't need it. // 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) 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, scaleSizeWithZoom) { } : 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) 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, scaleSizeWithZoom) { } : this(() => actor.CenterPosition, () => facing, world, image, sequence, palette, visibleThroughFog) { }
public SpriteEffect(Func<WPos> posFunc, Func<int> facingFunc, World world, string image, string sequence, string palette, public SpriteEffect(Func<WPos> posFunc, Func<int> facingFunc, World world, string image, string sequence, string palette,
bool visibleThroughFog = false, bool scaleSizeWithZoom = false) bool visibleThroughFog = false)
{ {
this.world = world; this.world = world;
this.posFunc = posFunc; this.posFunc = posFunc;
this.palette = palette; this.palette = palette;
this.scaleSizeWithZoom = scaleSizeWithZoom;
this.visibleThroughFog = visibleThroughFog; this.visibleThroughFog = visibleThroughFog;
pos = posFunc(); pos = posFunc();
anim = new Animation(world, image, facingFunc); anim = new Animation(world, image, facingFunc);
@@ -61,8 +59,7 @@ namespace OpenRA.Mods.Common.Effects
if (!visibleThroughFog && world.FogObscures(pos)) if (!visibleThroughFog && world.FogObscures(pos))
return SpriteRenderable.None; return SpriteRenderable.None;
var zoom = scaleSizeWithZoom ? 1f / wr.Viewport.Zoom : 1f; return anim.Render(pos, wr.Palette(palette));
return anim.Render(pos, WVec.Zero, 0, wr.Palette(palette), zoom);
} }
} }
} }

View File

@@ -211,7 +211,7 @@ namespace OpenRA.Mods.Common.Projectiles
{ {
var delayedPos = WPos.LerpQuadratic(source, target, angle, ticks - info.TrailDelay, length); 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), 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; smokeTicks = info.TrailInterval;
} }

View File

@@ -858,7 +858,7 @@ namespace OpenRA.Mods.Common.Projectiles
if (!string.IsNullOrEmpty(info.TrailImage) && --ticksToNextSmoke < 0 && (state != States.Freefall || info.TrailWhenDeactivated)) 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), 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; ticksToNextSmoke = info.TrailInterval;
} }

View File

@@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Effects
: WPos.LerpQuadratic(descendSource, descendTarget, WAngle.Zero, ticks - turn - trailDelay, impactDelay - turn); : 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), world.AddFrameEndTask(w => w.Add(new SpriteEffect(trailPos, w, trailImage, trailSequences.Random(world.SharedRandom),
trailPalette, false, false, 0))); trailPalette)));
trailTicks = trailInterval; trailTicks = trailInterval;
} }

View File

@@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits.Render
if ((Info.TerrainTypes.Count == 0 || Info.TerrainTypes.Contains(type)) && !string.IsNullOrEmpty(Info.Image)) 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, 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; cachedPosition = self.CenterPosition;
cachedFacing = facing != null ? facing.Facing : 0; cachedFacing = facing != null ? facing.Facing : 0;

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
var offset = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation)); var offset = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation));
var pos = position + body.LocalToWorld(offset); 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; ticks = info.Interval;

View File

@@ -215,7 +215,7 @@ namespace OpenRA.Mods.Common.Widgets
} }
else if (visualTarget.Type == TargetType.Terrain) 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; flashed = true;
} }
} }