1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
7 using Microsoft.Xna.Framework.Input;
15 private Video currentVideo;
16 private string filePath;
18 private GUIFrame background, videoFrame, textFrame;
19 private GUITextBlock title, textContent, objectiveTitle, objectiveText;
23 private Color backgroundColor =
new Color(0f, 0f, 0f, 0.8f);
24 private Action callbackOnStop;
26 private Point scaledVideoResolution;
27 private readonly
int borderSize = 20;
28 private readonly Point buttonSize =
new Point(120, 30);
29 private readonly
int titleHeight = 30;
30 private readonly
int objectiveFrameHeight = 60;
31 private readonly
int textHeight = 25;
33 private bool useTextOnRightSide =
false;
42 Text = TextManager.GetFormatted(textTag);
48 Text = TextManager.GetFormatted(element.GetAttributeIdentifier(
"text", Identifier.Empty));
49 Width = element.GetAttributeInt(
"width", 450);
55 public readonly
string File;
66 scaledVideoResolution =
new Point(screenWidth, (
int)(screenWidth / 16f * 9f));
68 int width = scaledVideoResolution.X;
69 int height = scaledVideoResolution.Y;
74 if (useTextOnRightSide)
89 objectiveTitle.
Text = TextManager.Get(
"Tutorial.NewObjective");
90 objectiveText =
new GUITextBlock(
new RectTransform(Point.Zero, textFrame.
RectTransform,
Anchor.TopCenter,
Pivot.TopCenter),
string.Empty, font: GUIStyle.SubHeadingFont, textColor:
new Color(4, 180, 108), textAlignment: Alignment.CenterRight);
103 if (currentVideo ==
null)
return;
108 private bool DisposeVideo(
GUIButton button,
object userData)
111 callbackOnStop?.Invoke();
117 if (currentVideo ==
null)
return;
136 callbackOnStop = onStop;
137 filePath = contentPath + videoSettings.
File;
139 if (!File.Exists(filePath))
141 DebugConsole.ThrowError(
"No video found at: " + filePath);
142 DisposeVideo(
null,
null);
146 if (currentVideo !=
null)
152 currentVideo = CreateVideo();
153 title.
Text = textSettings !=
null ? TextManager.Get(contentId) :
string.Empty;
154 textContent.
Text = textSettings !=
null ? textSettings.
Text :
string.Empty;
155 objectiveText.
Text = objective;
157 AdjustFrames(videoSettings, textSettings);
159 if (startPlayback)
Play();
162 private void AdjustFrames(VideoSettings videoSettings, TextSettings textSettings)
165 scaledVideoResolution =
new Point(screenWidth, (
int)(screenWidth / 16f * 9f));
179 int scaledBorderSize = (int)(borderSize * GUI.Scale);
180 int scaledTextWidth = 0;
181 if (textSettings !=
null) scaledTextWidth = useTextOnRightSide ? (int)(textSettings.Width * GUI.Scale) : scaledVideoResolution.X / 2;
182 int scaledTitleHeight = (int)(titleHeight * GUI.Scale);
183 int scaledTextHeight = (int)(textHeight * GUI.Scale);
184 int scaledObjectiveFrameHeight = (int)(objectiveFrameHeight * GUI.Scale);
186 Point scaledButtonSize =
new Point((
int)(buttonSize.X * GUI.Scale), (
int)(buttonSize.Y * GUI.Scale));
197 if (textSettings !=
null && !textSettings.Text.IsNullOrEmpty())
199 textSettings.Text = ToolBox.WrapText(textSettings.Text, scaledTextWidth, GUIStyle.Font);
200 int wrappedHeight = textSettings.Text.Value.Split(
'\n').Length * scaledTextHeight;
202 textFrame.
RectTransform.
NonScaledSize =
new Point(scaledTextWidth + scaledBorderSize, wrappedHeight + scaledBorderSize + scaledButtonSize.Y + scaledTitleHeight);
204 if (useTextOnRightSide)
217 if (!objectiveText.
Text.IsNullOrEmpty())
219 int scaledXOffset = (int)(-10 * GUI.Scale);
234 if (okButton !=
null)
240 if (textSettings !=
null)
242 if (useTextOnRightSide)
244 int totalFrameWidth = videoFrame.
Rect.Width + textFrame.
Rect.Width + scaledBorderSize * 2;
245 int xOffset = videoFrame.
Rect.Width / 2 + scaledBorderSize - (videoFrame.
Rect.Width / 2 - textFrame.
Rect.Width / 2);
250 int totalFrameHeight = videoFrame.
Rect.Height + textFrame.
Rect.Height + scaledBorderSize * 2;
251 int yOffset = videoFrame.
Rect.Height / 2 + scaledBorderSize - (videoFrame.
Rect.Height / 2 - textFrame.
Rect.Height / 2);
255 okButton =
new GUIButton(
new RectTransform(scaledButtonSize, textFrame.
RectTransform,
Anchor.BottomRight,
Pivot.BottomRight) { AbsoluteOffset = new Point(scaledBorderSize, scaledBorderSize) }, TextManager.Get(
"OK"))
257 OnClicked = DisposeVideo
264 okButton =
new GUIButton(
new RectTransform(scaledButtonSize, videoFrame.
RectTransform,
Anchor.TopLeft,
Pivot.TopLeft) { AbsoluteOffset = new Point(scaledBorderSize, scaledBorderSize) }, TextManager.Get(
"Back"))
266 OnClicked = DisposeVideo
271 private Video CreateVideo()
277 video =
Video.
Load(GameMain.Instance.GraphicsDevice, GameMain.SoundManager, filePath);
281 DebugConsole.ThrowError(
"Error loading video content " + filePath +
"!", e);
287 private void DrawVideo(SpriteBatch spriteBatch, Rectangle rect)
290 spriteBatch.Draw(currentVideo.
GetTexture(), rect, Color.White);
295 if (currentVideo !=
null)
virtual void RemoveChild(GUIComponent child)
virtual void AddToGUIUpdateList(bool ignoreChildren=false, int order=0)
RectTransform RectTransform
GUIComponent that can be used to render custom content on the UI
static int GraphicsHeight
static readonly RawLString EmptyString
TextSettings(Identifier textTag, int width)
TextSettings(XElement element)
VideoSettings(string file)
void AddToGUIUpdateList(bool ignoreChildren=false, int order=0)
void LoadContent(string contentPath, VideoSettings videoSettings, TextSettings textSettings, Identifier contentId, bool startPlayback)
void LoadContent(string contentPath, VideoSettings videoSettings, TextSettings textSettings, Identifier contentId, bool startPlayback, LocalizedString objective, Action onStop=null)