1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
15 private Color overlayColor, textColor;
22 public bool Finished => state > slideshowPrefab.Slides.Length;
26 slideshowPrefab = prefab;
27 overlayColor = Color.Black;
28 textColor = Color.Transparent;
29 pressAnyKeyText = TextManager.Get(
"pressanykey");
40 state = slideshowPrefab.Slides.Length + 1;
43 protected override void Update(
float deltaTime)
45 var slide = slideshowPrefab.Slides[Math.Min(state, slideshowPrefab.Slides.Length - 1)];
46 if (!
Visible || (
Finished && timer > slide.FadeOutDuration)) {
return; }
52 overlayColor = Color.Lerp(Color.Black, Color.White, Math.Min((timer - slide.FadeInDelay) / slide.FadeInDuration, 1.0f));
56 overlayColor = Color.Lerp(Color.Transparent, Color.White, Math.Min((timer - slide.FadeInDelay) / slide.FadeInDuration, 1.0f));
59 if (timer > slide.TextFadeInDelay)
61 textColor = Color.Lerp(Color.Transparent, Color.White, Math.Min((timer - slide.TextFadeInDelay) / slide.TextFadeInDuration, 1.0f));
64 if (timer > slide.TextFadeInDelay + slide.FadeInDuration)
66 overlayColor = textColor = Color.Transparent;
73 timer = slide.TextFadeInDelay + slide.TextFadeInDuration;
79 textColor = Color.Transparent;
82 timer = slide.TextFadeInDelay + slide.TextFadeInDuration;
86 if (state >= slideshowPrefab.Slides.Length)
88 overlayColor = Color.Lerp(Color.White, Color.Transparent, Math.Min(timer / slide.FadeOutDuration, 1.0f));
89 textColor = Color.Lerp(Color.White, Color.Transparent, Math.Min(timer / slide.FadeOutDuration, 1.0f));
90 if (timer >= slide.FadeOutDuration)
97 static bool AnyKeyHit()
105 private void RefreshText()
107 var slide = slideshowPrefab.Slides[Math.Min(state, slideshowPrefab.Slides.Length - 1)];
108 currentText = slide.Text
113 protected override void Draw(SpriteBatch spriteBatch)
115 if (slideshowPrefab.Slides.IsEmpty) {
return; }
117 var slide = slideshowPrefab.Slides[Math.Min(state, slideshowPrefab.Slides.Length - 1)];
118 if ((
Finished && timer > slide.FadeOutDuration)) {
return; }
120 var overlaySprite = slide.Portrait;
122 if (overlaySprite !=
null)
124 Sprite prevPortrait =
null;
125 if (state > 0 && state < slideshowPrefab.Slides.Length)
127 prevPortrait = slideshowPrefab.Slides[state - 1].Portrait;
128 DrawOverlay(prevPortrait, Color.White);
130 if (prevPortrait?.Texture != overlaySprite.
Texture)
132 DrawOverlay(overlaySprite, overlayColor);
140 if (!currentText.IsNullOrEmpty() && textColor.A > 0)
142 var backgroundSprite = GUIStyle.GetComponentStyle(
"CommandBackground").GetDefaultSprite();
145 Vector2 textSize = GUIStyle.Font.MeasureString(wrappedText);
146 Vector2 textPos = centerPos - textSize / 2;
147 backgroundSprite.Draw(spriteBatch,
149 Color.White * (textColor.A / 255.0f),
150 origin: backgroundSprite.size / 2,
152 scale:
new Vector2(
GameMain.
GraphicsWidth / 2 / backgroundSprite.size.X, textSize.Y / backgroundSprite.size.Y * 2.0f));
154 GUI.DrawString(spriteBatch, textPos + Vector2.One, wrappedText, Color.Black * (textColor.A / 255.0f));
155 GUI.DrawString(spriteBatch, textPos, wrappedText, textColor);
157 if (timer > slide.TextFadeInDelay * 2)
159 float alpha = Math.Min(timer - slide.TextFadeInDelay * 2, 1.0f);
160 Vector2 bottomTextPos = centerPos +
new Vector2(0.0f, textSize.Y / 2 + 40 * GUI.Scale) - GUIStyle.Font.MeasureString(pressAnyKeyText) / 2;
161 GUI.DrawString(spriteBatch, bottomTextPos + Vector2.One, pressAnyKeyText, Color.Black * (textColor.A / 255.0f) * alpha);
162 GUI.DrawString(spriteBatch, bottomTextPos, pressAnyKeyText, textColor * alpha);
168 if (sprite.
Texture ==
null) {
return; }
169 GUI.DrawBackgroundSprite(spriteBatch, sprite,
color);
static GameSession?? GameSession
static int GraphicsHeight
SubmarineInfo SubmarineInfo
LocalizedString Replace(Identifier find, LocalizedString replace, StringComparison stringComparison=StringComparison.Ordinal)
override void Update(float deltaTime)
SlideshowPlayer(RectTransform rectT, SlideshowPrefab prefab)
override void Draw(SpriteBatch spriteBatch)
static Submarine MainSub
Note that this can be null in some situations, e.g. editors and missions that don't load a submarine.