From 2761c4a61054666523c01e7a0b60cc1e395b19da Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 20 Jan 2016 23:22:55 +0200 Subject: [PATCH] Fade in when shift starts, fixed fadeout canceling before screen is switched to lobby --- Subsurface/Source/GameMain.cs | 6 ---- Subsurface/Source/GameSession/GameSession.cs | 3 +- Subsurface/Source/Map/TransitionCinematic.cs | 14 ++++++-- Subsurface/Source/Screens/LobbyScreen.cs | 2 -- Subsurface/Source/Screens/Screen.cs | 35 ++++++++++++++++++-- 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/Subsurface/Source/GameMain.cs b/Subsurface/Source/GameMain.cs index 709d35ec8..aa071e44e 100644 --- a/Subsurface/Source/GameMain.cs +++ b/Subsurface/Source/GameMain.cs @@ -182,9 +182,6 @@ namespace Barotrauma { GUI.Init(Content); - sw = new Stopwatch(); - - GUIComponent.Init(Window); DebugConsole.Init(Window); yield return CoroutineStatus.Running; @@ -338,11 +335,8 @@ namespace Barotrauma //{ // System.Threading.Thread.Sleep((int)((Physics.step - elapsed) * 1000.0)); //} - sw.Restart(); } - Stopwatch sw; - static bool waitForKeyHit = true; public static void ShowLoading(IEnumerable loader, bool waitKeyHit = true) { diff --git a/Subsurface/Source/GameSession/GameSession.cs b/Subsurface/Source/GameSession/GameSession.cs index a7d0fbb1c..340aeff54 100644 --- a/Subsurface/Source/GameSession/GameSession.cs +++ b/Subsurface/Source/GameSession/GameSession.cs @@ -28,7 +28,6 @@ namespace Barotrauma get { return currentMission; - return null; } } @@ -137,6 +136,8 @@ namespace Barotrauma if (gameMode!=null) gameMode.Start(); TaskManager.StartShift(level); + + GameMain.GameScreen.ColorFade(Color.Black, Color.TransparentBlack, 5.0f); } public void EndShift(string endMessage) diff --git a/Subsurface/Source/Map/TransitionCinematic.cs b/Subsurface/Source/Map/TransitionCinematic.cs index d38c580ca..e0ba932c5 100644 --- a/Subsurface/Source/Map/TransitionCinematic.cs +++ b/Subsurface/Source/Map/TransitionCinematic.cs @@ -54,6 +54,14 @@ namespace Barotrauma while (timer < duration) { + if (Screen.Selected != GameMain.GameScreen) + { + yield return new WaitForSeconds(0.1f); + + GUI.ScreenOverlayColor = Color.TransparentBlack; + yield return CoroutineStatus.Success; + } + cam.Zoom = Math.Max(0.2f, cam.Zoom - CoroutineManager.DeltaTime * 0.1f); Vector2 cameraPos = sub.Position + Submarine.HiddenSubPosition; @@ -73,10 +81,12 @@ namespace Barotrauma yield return CoroutineStatus.Running; } - GUI.ScreenOverlayColor = Color.TransparentBlack; - Running = false; + yield return new WaitForSeconds(0.1f); + + GUI.ScreenOverlayColor = Color.TransparentBlack; + yield return CoroutineStatus.Success; } } diff --git a/Subsurface/Source/Screens/LobbyScreen.cs b/Subsurface/Source/Screens/LobbyScreen.cs index 05fd1b7e3..e67d8a119 100644 --- a/Subsurface/Source/Screens/LobbyScreen.cs +++ b/Subsurface/Source/Screens/LobbyScreen.cs @@ -168,8 +168,6 @@ namespace Barotrauma { base.Select(); - GUI.ScreenOverlayColor = Color.Transparent; - gameMode = GameMain.GameSession.gameMode as SinglePlayerMode; foreach (GUIComponent component in topPanel.children) diff --git a/Subsurface/Source/Screens/Screen.cs b/Subsurface/Source/Screens/Screen.cs index 57f959397..b45e81416 100644 --- a/Subsurface/Source/Screens/Screen.cs +++ b/Subsurface/Source/Screens/Screen.cs @@ -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 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; + } + } }