(1beb64bd8) Removed: Duplicate code from VideoPlayer
This commit is contained in:
@@ -12,7 +12,6 @@ namespace Barotrauma
|
|||||||
class VideoPlayer
|
class VideoPlayer
|
||||||
{
|
{
|
||||||
private Video currentVideo;
|
private Video currentVideo;
|
||||||
private Point resolution;
|
|
||||||
private string filePath;
|
private string filePath;
|
||||||
|
|
||||||
private GUIFrame background, videoFrame, textFrame;
|
private GUIFrame background, videoFrame, textFrame;
|
||||||
@@ -29,7 +28,7 @@ namespace Barotrauma
|
|||||||
return isPlaying;
|
return isPlaying;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point defaultResolution = new Point(936, 540);
|
private Point scaledResolution;
|
||||||
private readonly int borderSize = 20;
|
private readonly int borderSize = 20;
|
||||||
private readonly Point buttonSize = new Point(160, 50);
|
private readonly Point buttonSize = new Point(160, 50);
|
||||||
private readonly int titleHeight = 30;
|
private readonly int titleHeight = 30;
|
||||||
@@ -51,24 +50,20 @@ namespace Barotrauma
|
|||||||
public struct VideoSettings
|
public struct VideoSettings
|
||||||
{
|
{
|
||||||
public string File;
|
public string File;
|
||||||
public int Width;
|
|
||||||
public int Height;
|
|
||||||
|
|
||||||
public VideoSettings(XElement element)
|
public VideoSettings(XElement element)
|
||||||
{
|
{
|
||||||
File = element.GetAttributeString("file", string.Empty);
|
File = element.GetAttributeString("file", string.Empty);
|
||||||
Width = 0;
|
|
||||||
Height = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public VideoPlayer()
|
public VideoPlayer()
|
||||||
{
|
{
|
||||||
int screenWidth = (int)(GameMain.GraphicsWidth * 0.55f);
|
int screenWidth = (int)(GameMain.GraphicsWidth * 0.55f);
|
||||||
defaultResolution = new Point(screenWidth, (int)(screenWidth / 16f * 9f));
|
scaledResolution = new Point(screenWidth, (int)(screenWidth / 16f * 9f));
|
||||||
|
|
||||||
int width = defaultResolution.X;
|
int width = scaledResolution.X;
|
||||||
int height = defaultResolution.Y;
|
int height = scaledResolution.Y;
|
||||||
|
|
||||||
background = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight), GUI.Canvas, Anchor.Center), "InnerFrame", backgroundColor);
|
background = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight), GUI.Canvas, Anchor.Center), "InnerFrame", backgroundColor);
|
||||||
videoFrame = new GUIFrame(new RectTransform(new Point(width + borderSize, height + borderSize), background.RectTransform, Anchor.Center, Pivot.Center) { AbsoluteOffset = new Point((int)(-100 / (GUI.Scale * 0.6f)), 0) }, "SonarFrame");
|
videoFrame = new GUIFrame(new RectTransform(new Point(width + borderSize, height + borderSize), background.RectTransform, Anchor.Center, Pivot.Center) { AbsoluteOffset = new Point((int)(-100 / (GUI.Scale * 0.6f)), 0) }, "SonarFrame");
|
||||||
@@ -124,7 +119,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
currentVideo.Dispose();
|
currentVideo.Dispose();
|
||||||
currentVideo = null;
|
currentVideo = null;
|
||||||
currentVideo = CreateVideo();
|
currentVideo = CreateVideo(scaledResolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddToGUIUpdateList(bool ignoreChildren = false, int order = 0)
|
public void AddToGUIUpdateList(bool ignoreChildren = false, int order = 0)
|
||||||
@@ -133,7 +128,7 @@ namespace Barotrauma
|
|||||||
background.AddToGUIUpdateList(ignoreChildren, order);
|
background.AddToGUIUpdateList(ignoreChildren, order);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadContentWithObjective(string contentPath, VideoSettings videoSettings, TextSettings textSettings, string contentId, bool startPlayback, string objective, Action callback = null)
|
public void LoadContent(string contentPath, VideoSettings videoSettings, TextSettings textSettings, string contentId, bool startPlayback, string objective = "", Action callback = null)
|
||||||
{
|
{
|
||||||
callbackOnStop = callback;
|
callbackOnStop = callback;
|
||||||
filePath = contentPath + videoSettings.File;
|
filePath = contentPath + videoSettings.File;
|
||||||
@@ -153,19 +148,10 @@ namespace Barotrauma
|
|||||||
currentVideo = null;
|
currentVideo = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolution = new Point(videoSettings.Width, videoSettings.Height);
|
currentVideo = CreateVideo(scaledResolution);
|
||||||
|
|
||||||
if (resolution.X == 0 || resolution.Y == 0)
|
videoFrame.RectTransform.NonScaledSize += scaledResolution + new Point(borderSize, borderSize);
|
||||||
{
|
videoView.RectTransform.NonScaledSize += scaledResolution;
|
||||||
resolution = defaultResolution;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentVideo = CreateVideo();
|
|
||||||
|
|
||||||
objectiveTitle.Visible = objectiveText.Visible = true;
|
|
||||||
|
|
||||||
videoFrame.RectTransform.NonScaledSize += resolution + new Point(borderSize, borderSize);
|
|
||||||
videoView.RectTransform.NonScaledSize += resolution;
|
|
||||||
|
|
||||||
title.Text = TextManager.Get(contentId);
|
title.Text = TextManager.Get(contentId);
|
||||||
title.RectTransform.NonScaledSize += new Point(textSettings.Width, titleHeight);
|
title.RectTransform.NonScaledSize += new Point(textSettings.Width, titleHeight);
|
||||||
@@ -180,74 +166,22 @@ namespace Barotrauma
|
|||||||
|
|
||||||
textContent.Text = textSettings.Text;
|
textContent.Text = textSettings.Text;
|
||||||
|
|
||||||
objectiveTitle.RectTransform.AbsoluteOffset = new Point(-10, textContent.RectTransform.Rect.Height + (int)(textHeight * 1.75f));
|
if (!string.IsNullOrEmpty(objective))
|
||||||
objectiveText.RectTransform.AbsoluteOffset = new Point(-10, textContent.RectTransform.Rect.Height + objectiveTitle.Rect.Height + (int)(textHeight * 2.25f));
|
|
||||||
|
|
||||||
textFrame.RectTransform.NonScaledSize += new Point(0, objectiveFrameHeight);
|
|
||||||
objectiveText.RectTransform.NonScaledSize += new Point(textFrame.Rect.Width, textHeight);
|
|
||||||
objectiveText.Text = objective;
|
|
||||||
|
|
||||||
var okButton = new GUIButton(new RectTransform(buttonSize, textFrame.RectTransform, Anchor.BottomRight, Pivot.BottomRight) { AbsoluteOffset = new Point(20, 20) },
|
|
||||||
TextManager.Get("OK"))
|
|
||||||
{
|
{
|
||||||
OnClicked = DisposeVideo
|
objectiveTitle.RectTransform.AbsoluteOffset = new Point(-10, textContent.RectTransform.Rect.Height + (int)(textHeight * 1.95f));
|
||||||
};
|
objectiveText.RectTransform.AbsoluteOffset = new Point(-10, textContent.RectTransform.Rect.Height + objectiveTitle.Rect.Height + (int)(textHeight * 2.25f));
|
||||||
|
|
||||||
if (startPlayback) Play();
|
textFrame.RectTransform.NonScaledSize += new Point(0, objectiveFrameHeight);
|
||||||
}
|
objectiveText.RectTransform.NonScaledSize += new Point(textFrame.Rect.Width, textHeight);
|
||||||
|
objectiveText.Text = objective;
|
||||||
public void LoadContent(string contentPath, VideoSettings videoSettings, TextSettings textSettings, string contentId, bool startPlayback, Action callback = null)
|
objectiveTitle.Visible = objectiveText.Visible = true;
|
||||||
{
|
|
||||||
callbackOnStop = callback;
|
|
||||||
filePath = contentPath + videoSettings.File;
|
|
||||||
|
|
||||||
if (!File.Exists(filePath))
|
|
||||||
{
|
|
||||||
DebugConsole.ThrowError("No video found at: " + filePath);
|
|
||||||
DisposeVideo(null, null);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
ResetFrameSizes();
|
|
||||||
|
|
||||||
if (currentVideo != null)
|
|
||||||
{
|
{
|
||||||
currentVideo.Dispose();
|
textFrame.RectTransform.NonScaledSize += new Point(0, borderSize);
|
||||||
currentVideo = null;
|
objectiveTitle.Visible = objectiveText.Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolution = new Point(0, 0);
|
|
||||||
|
|
||||||
if (currentVideo == null) // No preloaded video found
|
|
||||||
{
|
|
||||||
resolution = new Point(videoSettings.Width, videoSettings.Height);
|
|
||||||
|
|
||||||
if (resolution.X == 0 || resolution.Y == 0)
|
|
||||||
{
|
|
||||||
resolution = defaultResolution;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentVideo = CreateVideo();
|
|
||||||
}
|
|
||||||
|
|
||||||
objectiveTitle.Visible = objectiveText.Visible = false;
|
|
||||||
|
|
||||||
videoFrame.RectTransform.NonScaledSize += resolution + new Point(borderSize, borderSize);
|
|
||||||
videoView.RectTransform.NonScaledSize += resolution;
|
|
||||||
|
|
||||||
title.Text = TextManager.Get(contentId);
|
|
||||||
title.RectTransform.NonScaledSize += new Point(textSettings.Width, titleHeight);
|
|
||||||
|
|
||||||
if (textSettings.Text != string.Empty)
|
|
||||||
{
|
|
||||||
textSettings.Text = ToolBox.WrapText(textSettings.Text, textSettings.Width, GUI.Font);
|
|
||||||
int wrappedHeight = textSettings.Text.Split('\n').Length * textHeight;
|
|
||||||
textFrame.RectTransform.NonScaledSize += new Point(textSettings.Width + borderSize, wrappedHeight + borderSize + buttonSize.Y + titleHeight);
|
|
||||||
textContent.RectTransform.NonScaledSize = new Point(textSettings.Width, wrappedHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
textContent.Text = textSettings.Text;
|
|
||||||
|
|
||||||
var okButton = new GUIButton(new RectTransform(buttonSize, textFrame.RectTransform, Anchor.BottomRight, Pivot.BottomRight) { AbsoluteOffset = new Point(20, 20) },
|
var okButton = new GUIButton(new RectTransform(buttonSize, textFrame.RectTransform, Anchor.BottomRight, Pivot.BottomRight) { AbsoluteOffset = new Point(20, 20) },
|
||||||
TextManager.Get("OK"))
|
TextManager.Get("OK"))
|
||||||
{
|
{
|
||||||
@@ -269,7 +203,7 @@ namespace Barotrauma
|
|||||||
objectiveText.RectTransform.NonScaledSize = Point.Zero;
|
objectiveText.RectTransform.NonScaledSize = Point.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Video CreateVideo()
|
private Video CreateVideo(Point resolution)
|
||||||
{
|
{
|
||||||
Video video = null;
|
Video video = null;
|
||||||
|
|
||||||
|
|||||||
+2
-9
@@ -345,14 +345,7 @@ namespace Barotrauma.Tutorials
|
|||||||
|
|
||||||
private void ClosePreTextAndTriggerVideoCallback()
|
private void ClosePreTextAndTriggerVideoCallback()
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(activeSegment.Objective))
|
videoPlayer.LoadContent(playableContentPath, new VideoPlayer.VideoSettings(activeSegment.VideoContent), new VideoPlayer.TextSettings(activeSegment.VideoContent), activeSegment.Id, true, activeSegment.Objective, CurrentSegmentStopCallback);
|
||||||
{
|
|
||||||
videoPlayer.LoadContentWithObjective(playableContentPath, new VideoPlayer.VideoSettings(activeSegment.VideoContent), new VideoPlayer.TextSettings(activeSegment.VideoContent), activeSegment.Id, true, activeSegment.Objective, CurrentSegmentStopCallback);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
videoPlayer.LoadContent(playableContentPath, new VideoPlayer.VideoSettings(activeSegment.VideoContent), new VideoPlayer.TextSettings(activeSegment.VideoContent), activeSegment.Id, true, CurrentSegmentStopCallback);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CurrentSegmentStopCallback()
|
private void CurrentSegmentStopCallback()
|
||||||
@@ -804,7 +797,7 @@ namespace Barotrauma.Tutorials
|
|||||||
{
|
{
|
||||||
if (ContentRunning) return;
|
if (ContentRunning) return;
|
||||||
ContentRunning = true;
|
ContentRunning = true;
|
||||||
videoPlayer.LoadContent(playableContentPath, new VideoPlayer.VideoSettings(segment.VideoContent), new VideoPlayer.TextSettings(segment.VideoContent), segment.Id, true, () => ContentRunning = false);
|
videoPlayer.LoadContent(playableContentPath, new VideoPlayer.VideoSettings(segment.VideoContent), new VideoPlayer.TextSettings(segment.VideoContent), segment.Id, true, callback: () => ContentRunning = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<object> WaitToStop()
|
private IEnumerable<object> WaitToStop()
|
||||||
|
|||||||
@@ -752,6 +752,39 @@ namespace Barotrauma
|
|||||||
|
|
||||||
AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList();
|
AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList();
|
||||||
|
|
||||||
|
if (sprite == null)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!");
|
||||||
|
#if SERVER
|
||||||
|
sprite = new Sprite("", Vector2.Zero);
|
||||||
|
sprite.SourceRect = new Rectangle(0, 0, 32, 32);
|
||||||
|
#else
|
||||||
|
sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null)
|
||||||
|
{
|
||||||
|
Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
size = sprite.size;
|
||||||
|
sprite.EntityID = identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier))
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError(
|
||||||
|
"Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading.");
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(identifier))
|
||||||
|
{
|
||||||
|
MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier);
|
||||||
|
if (existingPrefab != null)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError(
|
||||||
|
"Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList();
|
||||||
|
|
||||||
List.Add(this);
|
List.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user