Fade in when shift starts, fixed fadeout canceling before screen is switched to lobby

This commit is contained in:
Regalis
2016-01-20 23:22:55 +02:00
parent 6f537ebc7c
commit 2761c4a610
5 changed files with 47 additions and 13 deletions
+33 -2
View File
@@ -1,5 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
namespace Barotrauma
{
@@ -20,8 +22,6 @@ namespace Barotrauma
{
if (selected != null && selected!=this) selected.Deselect();
selected = this;
GUI.ScreenOverlayColor = Color.Transparent;
}
public virtual void Update(double deltaTime)
@@ -32,5 +32,36 @@ namespace Barotrauma
{
}
public void ColorFade(Color from, Color to, float duration)
{
if (duration <= 0.0f) return;
CoroutineManager.StartCoroutine(UpdateColorFade(from, to, duration));
}
private IEnumerable<object> UpdateColorFade(Color from, Color to, float duration)
{
while (Screen.Selected != this)
{
yield return CoroutineStatus.Running;
}
float timer = 0.0f;
while (timer < duration)
{
GUI.ScreenOverlayColor = Color.Lerp(from, to, Math.Min(timer / duration, 1.0f));
timer += CoroutineManager.DeltaTime;
yield return CoroutineStatus.Running;
}
GUI.ScreenOverlayColor = to;
yield return CoroutineStatus.Success;
}
}
}