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 Func<WPos> 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<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.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));
}
}
}