Fix menu/exit fade effect for paused replays.
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -30,28 +31,45 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new MenuPaletteEffect(this); }
|
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 enum EffectType { None, Black, Desaturated }
|
||||||
public readonly MenuPaletteEffectInfo Info;
|
public readonly MenuPaletteEffectInfo Info;
|
||||||
|
|
||||||
int remainingFrames;
|
|
||||||
EffectType from = EffectType.Black;
|
EffectType from = EffectType.Black;
|
||||||
EffectType to = EffectType.Black;
|
EffectType to = EffectType.Black;
|
||||||
|
|
||||||
|
float frac = 0;
|
||||||
|
long startTime;
|
||||||
|
long endTime;
|
||||||
|
|
||||||
public MenuPaletteEffect(MenuPaletteEffectInfo info) { Info = info; }
|
public MenuPaletteEffect(MenuPaletteEffectInfo info) { Info = info; }
|
||||||
|
|
||||||
public void Fade(EffectType type)
|
public void Fade(EffectType type)
|
||||||
{
|
{
|
||||||
remainingFrames = Info.FadeLength;
|
startTime = Game.RunTime;
|
||||||
|
endTime = startTime + Game.Timestep * Info.FadeLength;
|
||||||
|
frac = 1;
|
||||||
|
|
||||||
from = to;
|
from = to;
|
||||||
to = type;
|
to = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ITickRender.TickRender(WorldRenderer wr, Actor self)
|
IEnumerable<IRenderable> IRender.Render(Actor self, WorldRenderer wr)
|
||||||
{
|
{
|
||||||
if (remainingFrames > 0)
|
if (endTime == 0)
|
||||||
remainingFrames--;
|
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)
|
static Color ColorForEffect(EffectType t, Color orig)
|
||||||
@@ -71,7 +89,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes)
|
public void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes)
|
||||||
{
|
{
|
||||||
if (to == EffectType.None && remainingFrames == 0)
|
if (to == EffectType.None && endTime == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var pal in palettes.Values)
|
foreach (var pal in palettes.Values)
|
||||||
@@ -81,12 +99,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var orig = pal.GetColor(x);
|
var orig = pal.GetColor(x);
|
||||||
var t = ColorForEffect(to, orig);
|
var t = ColorForEffect(to, orig);
|
||||||
|
|
||||||
if (remainingFrames == 0)
|
if (endTime == 0)
|
||||||
pal.SetColor(x, t);
|
pal.SetColor(x, t);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var f = ColorForEffect(from, orig);
|
var f = ColorForEffect(from, orig);
|
||||||
pal.SetColor(x, Exts.ColorLerp((float)remainingFrames / Info.FadeLength, t, f));
|
pal.SetColor(x, Exts.ColorLerp(frac, t, f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user