Fix menu/exit fade effect for paused replays.

This commit is contained in:
Paul Chote
2018-09-09 05:49:20 +00:00
committed by abcdefg30
parent bbf6e38faa
commit 16ff9fbc8e

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Traits;
@@ -30,28 +31,45 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new MenuPaletteEffect(this); }
}
public class MenuPaletteEffect : IPaletteModifier, ITickRender, IWorldLoaded
public class MenuPaletteEffect : IPaletteModifier, IRender, IWorldLoaded
{
public enum EffectType { None, Black, Desaturated }
public readonly MenuPaletteEffectInfo Info;
int remainingFrames;
EffectType from = EffectType.Black;
EffectType to = EffectType.Black;
float frac = 0;
long startTime;
long endTime;
public MenuPaletteEffect(MenuPaletteEffectInfo info) { Info = info; }
public void Fade(EffectType type)
{
remainingFrames = Info.FadeLength;
startTime = Game.RunTime;
endTime = startTime + Game.Timestep * Info.FadeLength;
frac = 1;
from = to;
to = type;
}
void ITickRender.TickRender(WorldRenderer wr, Actor self)
IEnumerable<IRenderable> IRender.Render(Actor self, WorldRenderer wr)
{
if (remainingFrames > 0)
remainingFrames--;
if (endTime == 0)
yield break;
frac = (endTime - Game.RunTime) * 1f / (endTime - startTime);
if (frac < 0)
frac = startTime = endTime = 0;
yield break;
}
IEnumerable<Rectangle> IRender.ScreenBounds(Actor self, WorldRenderer wr)
{
yield break;
}
static Color ColorForEffect(EffectType t, Color orig)
@@ -71,7 +89,7 @@ namespace OpenRA.Mods.Common.Traits
public void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes)
{
if (to == EffectType.None && remainingFrames == 0)
if (to == EffectType.None && endTime == 0)
return;
foreach (var pal in palettes.Values)
@@ -81,12 +99,12 @@ namespace OpenRA.Mods.Common.Traits
var orig = pal.GetColor(x);
var t = ColorForEffect(to, orig);
if (remainingFrames == 0)
if (endTime == 0)
pal.SetColor(x, t);
else
{
var f = ColorForEffect(from, orig);
pal.SetColor(x, Exts.ColorLerp((float)remainingFrames / Info.FadeLength, t, f));
pal.SetColor(x, Exts.ColorLerp(frac, t, f));
}
}
}