1 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
9 private static List<CameraTransition> activeTransitions =
new List<CameraTransition>();
18 private readonly Alignment? cameraStartPos;
19 private readonly Alignment? cameraEndPos;
20 private readonly
float? startZoom;
21 private readonly
float? endZoom;
38 public CameraTransition(
ISpatialEntity targetEntity,
Camera cam, Alignment? cameraStartPos, Alignment? cameraEndPos,
bool fadeOut =
true,
bool losFadeIn =
false,
float waitDuration = 0f,
float panDuration = 10.0f,
float? startZoom =
null,
float? endZoom =
null)
44 this.cameraStartPos = cameraStartPos;
45 this.cameraEndPos = cameraEndPos;
46 this.startZoom = startZoom;
47 this.endZoom = endZoom;
50 if (targetEntity ==
null) {
return; }
55 activeTransitions.
RemoveAll(a => !CoroutineManager.IsCoroutineRunning(a.updateCoroutine));
56 foreach (var activeTransition
in activeTransitions)
58 if (activeTransition.prevControlled !=
null)
60 prevControlled ??= activeTransition.prevControlled;
62 activeTransition.Stop();
64 updateCoroutine = CoroutineManager.StartCoroutine(Update(targetEntity, cam),
"CameraTransition");
65 activeTransitions.Add(
this);
70 CoroutineManager.StopCoroutines(updateCoroutine);
73 if (
FadeOut) { GUI.ScreenOverlayColor = Color.TransparentBlack; }
74 if (prevControlled !=
null && !prevControlled.
Removed)
81 private float DeltaTime => CoroutineManager.Paused && !
RunWhilePaused ? 0 : CoroutineManager.DeltaTime;
87 prevControlled ??= Character.Controlled;
91 GameMain.LightManager.LosEnabled =
false;
93 Character.Controlled =
null;
97 float startZoom = this.startZoom ?? cam.
Zoom;
98 float endZoom = this.endZoom ?? 0.5f;
99 Vector2 initialCameraPos = cam.
Position;
107 float clampedTimer = Math.Max(timer, 0f);
109 if (Screen.Selected != GameMain.GameScreen)
111 yield
return new WaitForSeconds(0.1f);
113 if (
FadeOut) { GUI.ScreenOverlayColor = Color.TransparentBlack; }
116 yield
return CoroutineStatus.Success;
126 GameMain.LightManager.LosEnabled =
false;
132 if (prevControlled !=
null && prevControlled.
Removed)
134 prevControlled =
null;
137 if (
AllowInterrupt && PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.Escape))
144 if (targetEntity is Submarine sub)
146 minPos =
new Vector2(sub.WorldPosition.X - sub.Borders.Width / 2, sub.WorldPosition.Y - sub.Borders.Height / 2);
147 maxPos =
new Vector2(sub.WorldPosition.X + sub.Borders.Width / 2, sub.WorldPosition.Y + sub.Borders.Height / 2);
150 Vector2 startPos = cameraStartPos.HasValue ?
152 MathHelper.Lerp(minPos.X, maxPos.X, (cameraStartPos.Value.ToVector2().X + 1.0f) / 2.0f),
153 MathHelper.Lerp(maxPos.Y, minPos.Y, (cameraStartPos.Value.ToVector2().Y + 1.0f) / 2.0f)) :
155 if (!cameraStartPos.HasValue && initialTargetPos.HasValue)
157 startPos += targetEntity.
WorldPosition - initialTargetPos.Value;
159 endPos = cameraEndPos.HasValue ?
161 MathHelper.Lerp(minPos.X, maxPos.X, (cameraEndPos.Value.ToVector2().X + 1.0f) / 2.0f),
162 MathHelper.Lerp(maxPos.Y, minPos.Y, (cameraEndPos.Value.ToVector2().Y + 1.0f) / 2.0f)) :
163 prevControlled?.WorldPosition ?? targetEntity.WorldPosition;
169 cam.
Zoom = MathHelper.SmoothStep(startZoom, endZoom, clampedTimer /
PanDuration);
172 if (
FadeOut) { GUI.ScreenOverlayColor = Color.Lerp(Color.TransparentBlack, Color.Black, ((clampedTimer /
PanDuration) - 0.9f) * 10.0f); }
176 if (!GameMain.DevMode)
178 GameMain.LightManager.LosEnabled =
true;
179 GameMain.LightManager.LosAlpha = ((clampedTimer /
PanDuration) - 0.8f) * 5.0f;
181 Lights.LightManager.ViewTarget = prevControlled ?? (targetEntity as Entity);
186 yield
return CoroutineStatus.Running;
189 float endTimer = 0.0f;
194 endTimer += DeltaTime;
195 yield
return CoroutineStatus.Running;
201 GUI.ScreenOverlayColor = Color.TransparentBlack;
202 if (!GameMain.DevMode)
204 GameMain.LightManager.LosEnabled =
true;
205 GameMain.LightManager.LosAlpha = 1f;
209 if (prevControlled !=
null && !prevControlled.
Removed)
214 yield
return CoroutineStatus.Success;
void Translate(Vector2 amount)
readonly float WaitDuration
CameraTransition(ISpatialEntity targetEntity, Camera cam, Alignment? cameraStartPos, Alignment? cameraEndPos, bool fadeOut=true, bool losFadeIn=false, float waitDuration=0f, float panDuration=10.0f, float? startZoom=null, float? endZoom=null)
readonly float PanDuration
bool RemoveControlFromCharacter
static Character? Controlled
static CoroutineStatus Success
@ Character
Characters only