Submarine preview window with a preview image & some extra information of the subs
This commit is contained in:
@@ -60,6 +60,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private static SpriteBatch spriteBatch;
|
private static SpriteBatch spriteBatch;
|
||||||
|
|
||||||
|
private Viewport defaultViewport;
|
||||||
|
|
||||||
public static GameMain Instance
|
public static GameMain Instance
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@@ -169,6 +171,13 @@ namespace Barotrauma
|
|||||||
GraphicsDeviceManager.PreferredBackBufferHeight = GraphicsHeight;
|
GraphicsDeviceManager.PreferredBackBufferHeight = GraphicsHeight;
|
||||||
|
|
||||||
GraphicsDeviceManager.ApplyChanges();
|
GraphicsDeviceManager.ApplyChanges();
|
||||||
|
|
||||||
|
defaultViewport = GraphicsDevice.Viewport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetViewPort()
|
||||||
|
{
|
||||||
|
GraphicsDevice.Viewport = defaultViewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -20,19 +20,31 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private VertexBuffer wallVertices, bodyVertices;
|
private VertexBuffer wallVertices, bodyVertices;
|
||||||
|
|
||||||
//public VertexPositionTexture[] WallVertices;
|
public static Sprite Background
|
||||||
//public VertexPositionColor[] BodyVertices;
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (background == null) background = new Sprite("Content/Map/background2.png", Vector2.Zero);
|
||||||
|
return background;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Sprite BackgroundTop
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (backgroundTop == null) backgroundTop = new Sprite("Content/Map/background.png", Vector2.Zero);
|
||||||
|
return backgroundTop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public LevelRenderer(Level level)
|
public LevelRenderer(Level level)
|
||||||
{
|
{
|
||||||
if (shaftTexture == null) shaftTexture = TextureLoader.FromFile("Content/Map/iceWall.png");
|
if (shaftTexture == null) shaftTexture = TextureLoader.FromFile("Content/Map/iceWall.png");
|
||||||
|
|
||||||
if (background==null)
|
if (background == null) background = new Sprite("Content/Map/background2.png", Vector2.Zero);
|
||||||
{
|
if (backgroundTop == null) backgroundTop = new Sprite("Content/Map/background.png", Vector2.Zero);
|
||||||
background = new Sprite("Content/Map/background2.png", Vector2.Zero);
|
if (dustParticles == null) dustParticles = new Sprite("Content/Map/dustparticles.png", Vector2.Zero);
|
||||||
backgroundTop = new Sprite("Content/Map/background.png", Vector2.Zero);
|
|
||||||
dustParticles = new Sprite("Content/Map/dustparticles.png", Vector2.Zero);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wallEdgeEffect == null)
|
if (wallEdgeEffect == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,13 +4,15 @@ using Microsoft.Xna.Framework;
|
|||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Linq;
|
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
partial class Submarine : Entity, IServerSerializable
|
partial class Submarine : Entity, IServerSerializable
|
||||||
{
|
{
|
||||||
|
public Sprite PreviewImage;
|
||||||
|
|
||||||
public static void Draw(SpriteBatch spriteBatch, bool editing = false)
|
public static void Draw(SpriteBatch spriteBatch, bool editing = false)
|
||||||
{
|
{
|
||||||
var entitiesToRender = !editing && visibleEntities != null ? visibleEntities : MapEntity.mapEntityList;
|
var entitiesToRender = !editing && visibleEntities != null ? visibleEntities : MapEntity.mapEntityList;
|
||||||
@@ -104,7 +106,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool SaveCurrent(string filePath)
|
public static bool SaveCurrent(string filePath, MemoryStream previewImage = null)
|
||||||
{
|
{
|
||||||
if (MainSub == null)
|
if (MainSub == null)
|
||||||
{
|
{
|
||||||
@@ -112,7 +114,42 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
MainSub.filePath = filePath;
|
MainSub.filePath = filePath;
|
||||||
return MainSub.SaveAs(filePath);
|
return MainSub.SaveAs(filePath, previewImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreatePreviewWindow(GUIComponent frame)
|
||||||
|
{
|
||||||
|
new GUITextBlock(new Rectangle(0, 0, 0, 20), Name, "", Alignment.TopCenter, Alignment.TopCenter, frame, true, GUI.LargeFont);
|
||||||
|
|
||||||
|
if (PreviewImage == null)
|
||||||
|
{
|
||||||
|
var txtBlock = new GUITextBlock(new Rectangle(-10, 60, 256, 128), TextManager.Get("SubPreviewImageNotFound"), Color.Black * 0.5f, null, Alignment.Center, "", frame, true);
|
||||||
|
txtBlock.OutlineColor = txtBlock.TextColor;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new GUIImage(new Rectangle(-10, 60, 256, 128), PreviewImage, Alignment.TopLeft, frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 realWorldDimensions = Dimensions * Physics.DisplayToRealWorldRatio;
|
||||||
|
string dimensionsStr = realWorldDimensions == Vector2.Zero ?
|
||||||
|
TextManager.Get("Unknown") :
|
||||||
|
TextManager.Get("DimensionsFormat").Replace("[width]", ((int)(realWorldDimensions.X)).ToString()).Replace("[height]", ((int)(realWorldDimensions.Y)).ToString());
|
||||||
|
|
||||||
|
new GUITextBlock(new Rectangle(256, 60, 100, 20),
|
||||||
|
TextManager.Get("Dimensions") + ": " + dimensionsStr,
|
||||||
|
"", frame, GUI.SmallFont);
|
||||||
|
|
||||||
|
new GUITextBlock(new Rectangle(256, 80, 100, 20),
|
||||||
|
TextManager.Get("RecommendedCrewSize") + ": " + (RecommendedCrewSizeMax == 0 ? TextManager.Get("Unknown") : RecommendedCrewSizeMin + " - " + RecommendedCrewSizeMax),
|
||||||
|
"", frame, GUI.SmallFont);
|
||||||
|
|
||||||
|
new GUITextBlock(new Rectangle(256, 100, 100, 20),
|
||||||
|
TextManager.Get("RecommendedCrewExperience") + ": " + (string.IsNullOrEmpty(RecommendedCrewExperience) ? TextManager.Get("unknown") : RecommendedCrewExperience),
|
||||||
|
"", frame, GUI.SmallFont);
|
||||||
|
|
||||||
|
var descr = new GUITextBlock(new Rectangle(0, 200, 0, 100), Description, "", Alignment.TopLeft, Alignment.TopLeft, frame, true, GUI.SmallFont);
|
||||||
|
descr.CanBeFocused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CheckForErrors()
|
public void CheckForErrors()
|
||||||
|
|||||||
@@ -109,10 +109,19 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
textBlock.TextColor = textBlock.TextColor * 0.85f;
|
textBlock.TextColor = textBlock.TextColor * 0.85f;
|
||||||
|
|
||||||
var shuttleText = new GUITextBlock(new Rectangle(0, 0, 0, 25), TextManager.Get("Shuttle"), "", Alignment.Left, Alignment.CenterY | Alignment.Right, textBlock, false, GUI.SmallFont);
|
var shuttleText = new GUITextBlock(new Rectangle(-20, 0, 0, 25), TextManager.Get("Shuttle"), "", Alignment.CenterRight, Alignment.CenterRight, textBlock, false, GUI.SmallFont);
|
||||||
shuttleText.TextColor = textBlock.TextColor * 0.8f;
|
shuttleText.TextColor = textBlock.TextColor * 0.8f;
|
||||||
shuttleText.ToolTip = textBlock.ToolTip;
|
shuttleText.ToolTip = textBlock.ToolTip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GUIButton infoButton = new GUIButton(new Rectangle(0, 0, 20, 20), "?", Alignment.CenterRight, "", textBlock);
|
||||||
|
infoButton.UserData = sub;
|
||||||
|
infoButton.OnClicked += (component, userdata) =>
|
||||||
|
{
|
||||||
|
var msgBox = new GUIMessageBox("", "", 550, 350);
|
||||||
|
((Submarine)userdata).CreatePreviewWindow(msgBox.InnerFrame);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (Submarine.SavedSubmarines.Count > 0) subList.Select(Submarine.SavedSubmarines[0]);
|
if (Submarine.SavedSubmarines.Count > 0) subList.Select(Submarine.SavedSubmarines[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ using Microsoft.Xna.Framework;
|
|||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -756,7 +756,6 @@ namespace Barotrauma
|
|||||||
UserData = sub
|
UserData = sub
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == sub.Name && s.MD5Hash.Hash == sub.MD5Hash.Hash);
|
var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == sub.Name && s.MD5Hash.Hash == sub.MD5Hash.Hash);
|
||||||
if (matchingSub == null) matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == sub.Name);
|
if (matchingSub == null) matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == sub.Name);
|
||||||
|
|
||||||
@@ -776,11 +775,20 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
subTextBlock.TextColor = new Color(subTextBlock.TextColor, sub.HasTag(SubmarineTag.Shuttle) ? 1.0f : 0.6f);
|
subTextBlock.TextColor = new Color(subTextBlock.TextColor, sub.HasTag(SubmarineTag.Shuttle) ? 1.0f : 0.6f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GUIButton infoButton = new GUIButton(new Rectangle(0, 0, 20, 20), "?", Alignment.CenterRight, "", subTextBlock);
|
||||||
|
infoButton.UserData = sub;
|
||||||
|
infoButton.OnClicked += (component, userdata) =>
|
||||||
|
{
|
||||||
|
var msgBox = new GUIMessageBox("", "", 550, 350);
|
||||||
|
((Submarine)userdata).CreatePreviewWindow(msgBox.InnerFrame);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sub.HasTag(SubmarineTag.Shuttle))
|
if (sub.HasTag(SubmarineTag.Shuttle))
|
||||||
{
|
{
|
||||||
var shuttleText = new GUITextBlock(new Rectangle(0, 0, 0, 25), TextManager.Get("Shuttle"), "", Alignment.Left, Alignment.CenterY | Alignment.Right, subTextBlock, false, GUI.SmallFont);
|
var shuttleText = new GUITextBlock(new Rectangle(-20, 0, 0, 25), TextManager.Get("Shuttle"), "", Alignment.CenterRight, Alignment.CenterRight, subTextBlock, false, GUI.SmallFont);
|
||||||
shuttleText.TextColor = subTextBlock.TextColor * 0.8f;
|
shuttleText.TextColor = subTextBlock.TextColor * 0.8f;
|
||||||
shuttleText.ToolTip = subTextBlock.ToolTip;
|
shuttleText.ToolTip = subTextBlock.ToolTip;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,13 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
class SubEditorScreen : Screen
|
class SubEditorScreen : Screen
|
||||||
{
|
{
|
||||||
|
private static string[] crewExperienceLevels = new string[]
|
||||||
|
{
|
||||||
|
TextManager.Get("CrewExperienceLow"),
|
||||||
|
TextManager.Get("CrewExperienceMid"),
|
||||||
|
TextManager.Get("CrewExperienceHigh")
|
||||||
|
};
|
||||||
|
|
||||||
private Camera cam;
|
private Camera cam;
|
||||||
private BlurEffect lightBlur;
|
private BlurEffect lightBlur;
|
||||||
|
|
||||||
@@ -406,7 +413,6 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
string savePath = nameBox.Text + ".sub";
|
string savePath = nameBox.Text + ".sub";
|
||||||
|
|
||||||
if (Submarine.MainSub != null)
|
if (Submarine.MainSub != null)
|
||||||
{
|
{
|
||||||
savePath = Path.Combine(Path.GetDirectoryName(Submarine.MainSub.FilePath), savePath);
|
savePath = Path.Combine(Path.GetDirectoryName(Submarine.MainSub.FilePath), savePath);
|
||||||
@@ -416,7 +422,10 @@ namespace Barotrauma
|
|||||||
savePath = Path.Combine(Submarine.SavePath, savePath);
|
savePath = Path.Combine(Submarine.SavePath, savePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
Submarine.SaveCurrent(savePath);
|
MemoryStream imgStream = new MemoryStream();
|
||||||
|
CreateImage(256, 128, imgStream);
|
||||||
|
|
||||||
|
Submarine.SaveCurrent(savePath, imgStream);
|
||||||
Submarine.MainSub.CheckForErrors();
|
Submarine.MainSub.CheckForErrors();
|
||||||
|
|
||||||
GUI.AddMessage(TextManager.Get("SubSavedNotification").Replace("[filepath]", Submarine.MainSub.FilePath), Color.Green, 3.0f);
|
GUI.AddMessage(TextManager.Get("SubSavedNotification").Replace("[filepath]", Submarine.MainSub.FilePath), Color.Green, 3.0f);
|
||||||
@@ -467,7 +476,7 @@ namespace Barotrauma
|
|||||||
descriptionBox.Text = Submarine.MainSub == null ? "" : Submarine.MainSub.Description;
|
descriptionBox.Text = Submarine.MainSub == null ? "" : Submarine.MainSub.Description;
|
||||||
descriptionBox.OnTextChanged = ChangeSubDescription;
|
descriptionBox.OnTextChanged = ChangeSubDescription;
|
||||||
|
|
||||||
y += descriptionBox.Rect.Height + 15;
|
y += descriptionBox.Rect.Height;
|
||||||
new GUITextBlock(new Rectangle(0, y, 150, 20), TextManager.Get("SaveSubDialogSettings"), "", saveFrame);
|
new GUITextBlock(new Rectangle(0, y, 150, 20), TextManager.Get("SaveSubDialogSettings"), "", saveFrame);
|
||||||
|
|
||||||
y += 20;
|
y += 20;
|
||||||
@@ -480,7 +489,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
string tagStr = attributes.Length > 0 ? attributes[0].Description : "";
|
string tagStr = attributes.Length > 0 ? attributes[0].Description : "";
|
||||||
|
|
||||||
var tagTickBox = new GUITickBox(new Rectangle(tagX, y+ tagY, 20, 20), tagStr, Alignment.TopLeft, saveFrame);
|
var tagTickBox = new GUITickBox(new Rectangle(tagX, y + tagY, 20, 20), tagStr, Alignment.TopLeft, saveFrame);
|
||||||
tagTickBox.Selected = Submarine.MainSub == null ? false : Submarine.MainSub.HasTag(tag);
|
tagTickBox.Selected = Submarine.MainSub == null ? false : Submarine.MainSub.HasTag(tag);
|
||||||
tagTickBox.UserData = tag;
|
tagTickBox.UserData = tag;
|
||||||
|
|
||||||
@@ -508,6 +517,73 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
y += tagY;
|
||||||
|
|
||||||
|
new GUITextBlock(new Rectangle(0, y, 100, 20), TextManager.Get("RecommendedCrewSize"), "", Alignment.TopLeft, Alignment.CenterLeft, saveFrame);
|
||||||
|
|
||||||
|
var crewSizeMin = new GUINumberInput(new Rectangle(230, y, 50, 20), "", GUINumberInput.NumberType.Int, saveFrame);
|
||||||
|
crewSizeMin.MinValueInt = 1;
|
||||||
|
crewSizeMin.MaxValueInt = 128;
|
||||||
|
|
||||||
|
|
||||||
|
new GUITextBlock(new Rectangle(285, y, 10, 20), "-", "", Alignment.TopLeft, Alignment.Center, saveFrame);
|
||||||
|
|
||||||
|
var crewSizeMax = new GUINumberInput(new Rectangle(300, y, 50, 20), "", GUINumberInput.NumberType.Int, saveFrame);
|
||||||
|
crewSizeMax.MinValueInt = 1;
|
||||||
|
crewSizeMax.MaxValueInt = 128;
|
||||||
|
|
||||||
|
crewSizeMin.OnValueChanged += (numberInput) =>
|
||||||
|
{
|
||||||
|
crewSizeMax.IntValue = Math.Max(crewSizeMax.IntValue, numberInput.IntValue);
|
||||||
|
Submarine.MainSub.RecommendedCrewSizeMin = crewSizeMin.IntValue;
|
||||||
|
Submarine.MainSub.RecommendedCrewSizeMax = crewSizeMax.IntValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
crewSizeMax.OnValueChanged += (numberInput) =>
|
||||||
|
{
|
||||||
|
crewSizeMin.IntValue = Math.Min(crewSizeMin.IntValue, numberInput.IntValue);
|
||||||
|
Submarine.MainSub.RecommendedCrewSizeMin = crewSizeMin.IntValue;
|
||||||
|
Submarine.MainSub.RecommendedCrewSizeMax = crewSizeMax.IntValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
y += 20;
|
||||||
|
|
||||||
|
new GUITextBlock(new Rectangle(0, y, 100, 20), TextManager.Get("RecommendedCrewExperience"), "", Alignment.TopLeft, Alignment.CenterLeft, saveFrame);
|
||||||
|
|
||||||
|
var toggleExpLeft = new GUIButton(new Rectangle(230, y, 20, 20), "<", "", saveFrame);
|
||||||
|
var toggleExpRight = new GUIButton(new Rectangle(350, y, 20, 20), ">", "", saveFrame);
|
||||||
|
var experienceText = new GUITextBlock(new Rectangle(250, y, 100, 20), crewExperienceLevels[0], "", Alignment.TopLeft, Alignment.Center, saveFrame);
|
||||||
|
|
||||||
|
toggleExpLeft.OnClicked += (btn, userData) =>
|
||||||
|
{
|
||||||
|
int currentIndex = Array.IndexOf(crewExperienceLevels, experienceText.Text);
|
||||||
|
currentIndex--;
|
||||||
|
if (currentIndex < 0) currentIndex = crewExperienceLevels.Length - 1;
|
||||||
|
experienceText.Text = crewExperienceLevels[currentIndex];
|
||||||
|
Submarine.MainSub.RecommendedCrewExperience = experienceText.Text;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
toggleExpRight.OnClicked += (btn, userData) =>
|
||||||
|
{
|
||||||
|
int currentIndex = Array.IndexOf(crewExperienceLevels, experienceText.Text);
|
||||||
|
currentIndex++;
|
||||||
|
if (currentIndex >= crewExperienceLevels.Length) currentIndex = 0;
|
||||||
|
experienceText.Text = crewExperienceLevels[currentIndex];
|
||||||
|
Submarine.MainSub.RecommendedCrewExperience = experienceText.Text;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (Submarine.MainSub != null)
|
||||||
|
{
|
||||||
|
int min = Submarine.MainSub.RecommendedCrewSizeMin;
|
||||||
|
int max = Submarine.MainSub.RecommendedCrewSizeMax;
|
||||||
|
crewSizeMin.IntValue = min;
|
||||||
|
crewSizeMax.IntValue = max;
|
||||||
|
experienceText.Text = string.IsNullOrEmpty(Submarine.MainSub.RecommendedCrewExperience) ?
|
||||||
|
crewExperienceLevels[0] : Submarine.MainSub.RecommendedCrewExperience;
|
||||||
|
}
|
||||||
|
|
||||||
var saveButton = new GUIButton(new Rectangle(-90, 0, 80, 20), TextManager.Get("SaveSubButton"), Alignment.Right | Alignment.Bottom, "", saveFrame);
|
var saveButton = new GUIButton(new Rectangle(-90, 0, 80, 20), TextManager.Get("SaveSubButton"), Alignment.Right | Alignment.Bottom, "", saveFrame);
|
||||||
saveButton.OnClicked = SaveSub;
|
saveButton.OnClicked = SaveSub;
|
||||||
|
|
||||||
@@ -1273,6 +1349,11 @@ namespace Barotrauma
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Update(double deltaTime)
|
public override void Update(double deltaTime)
|
||||||
{
|
{
|
||||||
|
if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.T))
|
||||||
|
{
|
||||||
|
SaveScreenShot(256, 128, "screenshottest.png");
|
||||||
|
}
|
||||||
|
|
||||||
if (tutorial != null) tutorial.Update((float)deltaTime);
|
if (tutorial != null) tutorial.Update((float)deltaTime);
|
||||||
|
|
||||||
hullVolumeFrame.Visible = MapEntity.SelectedList.Any(s => s is Hull);
|
hullVolumeFrame.Visible = MapEntity.SelectedList.Any(s => s is Hull);
|
||||||
@@ -1482,5 +1563,54 @@ namespace Barotrauma
|
|||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CreateImage(int width, int height, Stream stream)
|
||||||
|
{
|
||||||
|
MapEntity.SelectedList.Clear();
|
||||||
|
|
||||||
|
RenderTarget2D rt = new RenderTarget2D(
|
||||||
|
GameMain.Instance.GraphicsDevice,
|
||||||
|
width, height, false, SurfaceFormat.Color, DepthFormat.None);
|
||||||
|
|
||||||
|
var prevScissorRect = GameMain.Instance.GraphicsDevice.ScissorRectangle;
|
||||||
|
|
||||||
|
Rectangle subDimensions = Submarine.MainSub.CalculateDimensions(false);
|
||||||
|
Vector2 viewPos = subDimensions.Center.ToVector2();
|
||||||
|
float scale = Math.Min(width / (float)subDimensions.Width, height / (float)subDimensions.Height);
|
||||||
|
|
||||||
|
var viewMatrix = Matrix.CreateTranslation(new Vector3(width / 2.0f, height / 2.0f, 0));
|
||||||
|
var transform = Matrix.CreateTranslation(
|
||||||
|
new Vector3(-viewPos.X, viewPos.Y, 0)) *
|
||||||
|
Matrix.CreateScale(new Vector3(scale, scale, 1)) *
|
||||||
|
viewMatrix;
|
||||||
|
|
||||||
|
GameMain.Instance.GraphicsDevice.SetRenderTarget(rt);
|
||||||
|
SpriteBatch spriteBatch = new SpriteBatch(GameMain.Instance.GraphicsDevice);
|
||||||
|
|
||||||
|
spriteBatch.Begin();
|
||||||
|
LevelRenderer.BackgroundTop.Draw(spriteBatch, Vector2.Zero, new Color(0.025f, 0.075f, 0.131f, 1.0f));
|
||||||
|
spriteBatch.End();
|
||||||
|
|
||||||
|
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, transform);
|
||||||
|
Submarine.Draw(spriteBatch, false);
|
||||||
|
Submarine.DrawFront(spriteBatch);
|
||||||
|
Submarine.DrawDamageable(spriteBatch, null);
|
||||||
|
spriteBatch.End();
|
||||||
|
|
||||||
|
GameMain.Instance.GraphicsDevice.SetRenderTarget(null);
|
||||||
|
rt.SaveAsPng(stream, width, height);
|
||||||
|
rt.Dispose();
|
||||||
|
|
||||||
|
//for some reason setting the rendertarget changes the size of the viewport
|
||||||
|
//but it doesn't change back to default when setting it back to null
|
||||||
|
GameMain.Instance.ResetViewPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveScreenShot(int width, int height, string filePath)
|
||||||
|
{
|
||||||
|
Stream stream = File.OpenWrite(filePath);
|
||||||
|
CreateImage(width, height, stream);
|
||||||
|
stream.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
using (Stream fileStream = File.OpenRead(path))
|
using (Stream fileStream = File.OpenRead(path))
|
||||||
{
|
{
|
||||||
var texture = Texture2D.FromStream(_graphicsDevice, fileStream);
|
var texture = Texture2D.FromStream(_graphicsDevice, fileStream);
|
||||||
@@ -54,10 +53,24 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("Loading texture \""+path+"\" failed!", e);
|
DebugConsole.ThrowError("Loading texture \"" + path + "\" failed!", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Texture2D FromStream(Stream fileStream, bool preMultiplyAlpha = true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var texture = Texture2D.FromStream(_graphicsDevice, fileStream);
|
||||||
|
texture = PreMultiplyAlpha(texture);
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Loading texture from stream failed!", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Texture2D PreMultiplyAlpha(Texture2D texture)
|
private static Texture2D PreMultiplyAlpha(Texture2D texture)
|
||||||
|
|||||||
@@ -91,6 +91,7 @@
|
|||||||
<Editing>Editing</Editing>
|
<Editing>Editing</Editing>
|
||||||
<Error>Error</Error>
|
<Error>Error</Error>
|
||||||
<Warning>Warning</Warning>
|
<Warning>Warning</Warning>
|
||||||
|
<Unknown>Unknown</Unknown>
|
||||||
<None>None</None>
|
<None>None</None>
|
||||||
<Close>Close</Close>
|
<Close>Close</Close>
|
||||||
<Cancel>Cancel</Cancel>
|
<Cancel>Cancel</Cancel>
|
||||||
@@ -240,6 +241,17 @@
|
|||||||
<NoCargoSpawnpointWarning>"The submarine does not have spawnpoints for cargo (which are used for determining where to place bought items). To fix this, create a new spawnpoint and change its "spawn type" parameter to "cargo".</NoCargoSpawnpointWarning>
|
<NoCargoSpawnpointWarning>"The submarine does not have spawnpoints for cargo (which are used for determining where to place bought items). To fix this, create a new spawnpoint and change its "spawn type" parameter to "cargo".</NoCargoSpawnpointWarning>
|
||||||
<FarAwayEntitiesWarning>One or more structures have been placed very far from the submarine. Show the structures?</FarAwayEntitiesWarning>
|
<FarAwayEntitiesWarning>One or more structures have been placed very far from the submarine. Show the structures?</FarAwayEntitiesWarning>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Sub description -->
|
||||||
|
<Dimensions>Dimensions</Dimensions>
|
||||||
|
<DimensionsFormat>[width]x[height] m</DimensionsFormat>
|
||||||
|
<SubPreviewImageNotFound>Preview image not found</SubPreviewImageNotFound>
|
||||||
|
<RecommendedCrewSize>Recommended crew size</RecommendedCrewSize>
|
||||||
|
<RecommendedCrewExperience>Recommended crew experience</RecommendedCrewExperience>
|
||||||
|
<CrewExperienceLow>Beginner</CrewExperienceLow>
|
||||||
|
<CrewExperienceMid>Intermediate</CrewExperienceMid>
|
||||||
|
<CrewExperienceHigh>Experienced</CrewExperienceHigh>
|
||||||
|
|
||||||
<!-- Waypoints -->
|
<!-- Waypoints -->
|
||||||
<Waypoint>Waypoint</Waypoint>
|
<Waypoint>Waypoint</Waypoint>
|
||||||
<LinkWaypoint>Hold space to link to another waypoint</LinkWaypoint>
|
<LinkWaypoint>Hold space to link to another waypoint</LinkWaypoint>
|
||||||
|
|||||||
@@ -223,17 +223,22 @@
|
|||||||
</GUITickBox>
|
</GUITickBox>
|
||||||
|
|
||||||
<GUIMessageBox
|
<GUIMessageBox
|
||||||
padding="40.0, 40.0, 40.0, 40.0"
|
padding="40.0, 20.0, 40.0, 20.0"
|
||||||
color="1.0, 1.0, 1.0, 1.0"
|
color="1.0, 1.0, 1.0, 1.0"
|
||||||
|
|
||||||
textcolor="0.0, 0.0, 0.0, 1.0"
|
textcolor="0.0, 0.0, 0.0, 1.0"
|
||||||
|
|
||||||
hovercolor="0.8, 0.8, 0.8, 1.0"
|
hovercolor="0.8, 0.8, 0.8, 1.0"
|
||||||
selectedcolor="1.0, 0.82, 0.05, 1.0"
|
selectedcolor="1.0, 0.82, 0.05, 1.0"
|
||||||
|
|
||||||
outlinecolor="0.5, 0.57, 0.6, 1.0">
|
outlinecolor="0.5, 0.57, 0.6, 1.0">
|
||||||
|
<GUIFrame
|
||||||
|
padding="40.0, 20.0, 40.0, 20.0"
|
||||||
|
color="1.0,1.0,1.0,1.0"
|
||||||
|
hovercolor="1.0,1.0,1.0,1.0"
|
||||||
|
selectedcolor="1.0,1.0,1.0,1.0"
|
||||||
|
|
||||||
<Sprite texture="Content/UI/UI_Atlas.png" sourcerect ="32, 541, 420, 454" slice="87,576,430,960"/>
|
textcolor="0.0, 0.0, 0.0, 1.0">
|
||||||
|
|
||||||
|
<Sprite texture="Content/UI/UI_Atlas.png" size="0.0, 0.0" sourcerect ="32, 541, 420, 220" slice="87,576,430,687"/>
|
||||||
|
</GUIFrame>
|
||||||
</GUIMessageBox>
|
</GUIMessageBox>
|
||||||
|
|
||||||
<GUIProgressBar
|
<GUIProgressBar
|
||||||
|
|||||||
@@ -85,6 +85,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private EntityGrid entityGrid = null;
|
private EntityGrid entityGrid = null;
|
||||||
|
|
||||||
|
public int RecommendedCrewSizeMin = 1, RecommendedCrewSizeMax = 2;
|
||||||
|
public string RecommendedCrewExperience;
|
||||||
|
|
||||||
//properties ----------------------------------------------------
|
//properties ----------------------------------------------------
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
@@ -159,9 +162,15 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector2 Dimensions
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
public override Vector2 Position
|
public override Vector2 Position
|
||||||
{
|
{
|
||||||
get { return subBody==null ? Vector2.Zero : subBody.Position - HiddenSubPosition; }
|
get { return subBody == null ? Vector2.Zero : subBody.Position - HiddenSubPosition; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Vector2 WorldPosition
|
public override Vector2 WorldPosition
|
||||||
@@ -271,12 +280,26 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
Description = doc.Root.GetAttributeString("description", "");
|
Description = doc.Root.GetAttributeString("description", "");
|
||||||
Enum.TryParse(doc.Root.GetAttributeString("tags", ""), out tags);
|
Enum.TryParse(doc.Root.GetAttributeString("tags", ""), out tags);
|
||||||
|
Dimensions = doc.Root.GetAttributeVector2("dimensions", Vector2.Zero);
|
||||||
|
RecommendedCrewSizeMin = doc.Root.GetAttributeInt("recommendedcrewsizemin", 0);
|
||||||
|
RecommendedCrewSizeMax = doc.Root.GetAttributeInt("recommendedcrewsizemax", 0);
|
||||||
|
RecommendedCrewExperience = doc.Root.GetAttributeString("recommendedcrewexperience", "Unknown");
|
||||||
|
|
||||||
|
#if CLIENT
|
||||||
|
string previewImageData = doc.Root.GetAttributeString("previewimage", "");
|
||||||
|
if (!string.IsNullOrEmpty(previewImageData))
|
||||||
|
{
|
||||||
|
using (MemoryStream mem = new MemoryStream(Convert.FromBase64String(previewImageData)))
|
||||||
|
{
|
||||||
|
PreviewImage = new Sprite(TextureLoader.FromStream(mem), null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DockedTo = new List<Submarine>();
|
DockedTo = new List<Submarine>();
|
||||||
|
|
||||||
|
|
||||||
ID = ushort.MaxValue;
|
ID = ushort.MaxValue;
|
||||||
base.Remove();
|
base.Remove();
|
||||||
}
|
}
|
||||||
@@ -475,6 +498,28 @@ namespace Barotrauma
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Rectangle CalculateDimensions(bool onlyHulls = true)
|
||||||
|
{
|
||||||
|
List<MapEntity> entities = onlyHulls ?
|
||||||
|
Hull.hullList.FindAll(h => h.Submarine == this).Cast<MapEntity>().ToList() :
|
||||||
|
MapEntity.mapEntityList.FindAll(me => me.Submarine == this);
|
||||||
|
|
||||||
|
if (entities.Count == 0) return Rectangle.Empty;
|
||||||
|
|
||||||
|
float minX = entities[0].Rect.X, minY = entities[0].Rect.Y - entities[0].Rect.Height;
|
||||||
|
float maxX = entities[0].Rect.Right, maxY = entities[0].Rect.Y;
|
||||||
|
|
||||||
|
for (int i = 1; i < entities.Count; i++)
|
||||||
|
{
|
||||||
|
minX = Math.Min(minX, entities[i].Rect.X);
|
||||||
|
minY = Math.Min(minY, entities[i].Rect.Y - entities[i].Rect.Height);
|
||||||
|
maxX = Math.Max(maxX, entities[i].Rect.Right);
|
||||||
|
maxY = Math.Max(maxY, entities[i].Rect.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY));
|
||||||
|
}
|
||||||
|
|
||||||
public static Rectangle AbsRect(Vector2 pos, Vector2 size)
|
public static Rectangle AbsRect(Vector2 pos, Vector2 size)
|
||||||
{
|
{
|
||||||
if (size.X < 0.0f)
|
if (size.X < 0.0f)
|
||||||
@@ -871,10 +916,10 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
SavedSubmarines.Add(new Submarine(path));
|
SavedSubmarines.Add(new Submarine(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (GameMain.NetLobbyScreen!=null) GameMain.NetLobbyScreen.UpdateSubList(Submarine.SavedSubmarines);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static readonly string TempFolder = Path.Combine("Submarine", "Temp");
|
||||||
|
|
||||||
public static XDocument OpenFile(string file)
|
public static XDocument OpenFile(string file)
|
||||||
{
|
{
|
||||||
XDocument doc = null;
|
XDocument doc = null;
|
||||||
@@ -1112,26 +1157,22 @@ namespace Barotrauma
|
|||||||
Submarine sub = new Submarine(path);
|
Submarine sub = new Submarine(path);
|
||||||
sub.Load(unloadPrevious);
|
sub.Load(unloadPrevious);
|
||||||
|
|
||||||
//Entity.dictionary.Add(int.MaxValue, sub);
|
|
||||||
|
|
||||||
return sub;
|
return sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SaveAs(string filePath, MemoryStream previewImage = null)
|
||||||
public bool Save()
|
|
||||||
{
|
{
|
||||||
return SaveAs(filePath);
|
name = Path.GetFileNameWithoutExtension(filePath);
|
||||||
}
|
|
||||||
|
|
||||||
public bool SaveAs(string filePath)
|
|
||||||
{
|
|
||||||
name = System.IO.Path.GetFileNameWithoutExtension(filePath);
|
|
||||||
|
|
||||||
XDocument doc = new XDocument(new XElement("Submarine"));
|
XDocument doc = new XDocument(new XElement("Submarine"));
|
||||||
SaveToXElement(doc.Root);
|
SaveToXElement(doc.Root);
|
||||||
|
|
||||||
hash = new Md5Hash(doc);
|
hash = new Md5Hash(doc);
|
||||||
doc.Root.Add(new XAttribute("md5hash", hash.Hash));
|
doc.Root.Add(new XAttribute("md5hash", hash.Hash));
|
||||||
|
if (previewImage != null)
|
||||||
|
{
|
||||||
|
doc.Root.Add(new XAttribute("previewimage", Convert.ToBase64String(previewImage.ToArray())));
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -1149,10 +1190,15 @@ namespace Barotrauma
|
|||||||
public void SaveToXElement(XElement element)
|
public void SaveToXElement(XElement element)
|
||||||
{
|
{
|
||||||
element.Add(new XAttribute("name", name));
|
element.Add(new XAttribute("name", name));
|
||||||
element.Add(new XAttribute("description", Description == null ? "" : Description));
|
element.Add(new XAttribute("description", Description ?? ""));
|
||||||
|
|
||||||
element.Add(new XAttribute("tags", tags.ToString()));
|
element.Add(new XAttribute("tags", tags.ToString()));
|
||||||
|
|
||||||
|
Rectangle dimensions = CalculateDimensions();
|
||||||
|
element.Add(new XAttribute("dimensions", XMLExtensions.Vector2ToString(dimensions.Size.ToVector2())));
|
||||||
|
element.Add(new XAttribute("recommendedcrewsizemin", RecommendedCrewSizeMin));
|
||||||
|
element.Add(new XAttribute("recommendedcrewsizemax", RecommendedCrewSizeMax));
|
||||||
|
element.Add(new XAttribute("recommendedcrewexperience", RecommendedCrewExperience ?? ""));
|
||||||
|
|
||||||
foreach (MapEntity e in MapEntity.mapEntityList)
|
foreach (MapEntity e in MapEntity.mapEntityList)
|
||||||
{
|
{
|
||||||
if (e.MoveWithLevel || e.Submarine != this) continue;
|
if (e.MoveWithLevel || e.Submarine != this) continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user