Submarine preview window with a preview image & some extra information of the subs
This commit is contained in:
@@ -84,6 +84,9 @@ namespace Barotrauma
|
||||
private float networkUpdateTimer;
|
||||
|
||||
private EntityGrid entityGrid = null;
|
||||
|
||||
public int RecommendedCrewSizeMin = 1, RecommendedCrewSizeMax = 2;
|
||||
public string RecommendedCrewExperience;
|
||||
|
||||
//properties ----------------------------------------------------
|
||||
|
||||
@@ -100,7 +103,7 @@ namespace Barotrauma
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public static Vector2 LastPickedPosition
|
||||
{
|
||||
get { return lastPickedPosition; }
|
||||
@@ -154,14 +157,20 @@ namespace Barotrauma
|
||||
public Rectangle Borders
|
||||
{
|
||||
get
|
||||
{
|
||||
return subBody.Borders;
|
||||
{
|
||||
return subBody.Borders;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Vector2 Dimensions
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -271,12 +280,26 @@ namespace Barotrauma
|
||||
{
|
||||
Description = doc.Root.GetAttributeString("description", "");
|
||||
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>();
|
||||
|
||||
|
||||
ID = ushort.MaxValue;
|
||||
base.Remove();
|
||||
}
|
||||
@@ -474,6 +497,28 @@ namespace Barotrauma
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -871,10 +916,10 @@ namespace Barotrauma
|
||||
{
|
||||
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)
|
||||
{
|
||||
XDocument doc = null;
|
||||
@@ -962,7 +1007,7 @@ namespace Barotrauma
|
||||
|
||||
Description = submarineElement.GetAttributeString("description", "");
|
||||
Enum.TryParse(submarineElement.GetAttributeString("tags", ""), out tags);
|
||||
|
||||
|
||||
//place the sub above the top of the level
|
||||
HiddenSubPosition = HiddenSubStartPosition;
|
||||
if (GameMain.GameSession != null && GameMain.GameSession.Level != null)
|
||||
@@ -1111,27 +1156,23 @@ namespace Barotrauma
|
||||
|
||||
Submarine sub = new Submarine(path);
|
||||
sub.Load(unloadPrevious);
|
||||
|
||||
//Entity.dictionary.Add(int.MaxValue, sub);
|
||||
|
||||
|
||||
return sub;
|
||||
}
|
||||
|
||||
|
||||
public bool Save()
|
||||
|
||||
public bool SaveAs(string filePath, MemoryStream previewImage = null)
|
||||
{
|
||||
return SaveAs(filePath);
|
||||
}
|
||||
|
||||
public bool SaveAs(string filePath)
|
||||
{
|
||||
name = System.IO.Path.GetFileNameWithoutExtension(filePath);
|
||||
name = Path.GetFileNameWithoutExtension(filePath);
|
||||
|
||||
XDocument doc = new XDocument(new XElement("Submarine"));
|
||||
SaveToXElement(doc.Root);
|
||||
|
||||
hash = new Md5Hash(doc);
|
||||
doc.Root.Add(new XAttribute("md5hash", hash.Hash));
|
||||
if (previewImage != null)
|
||||
{
|
||||
doc.Root.Add(new XAttribute("previewimage", Convert.ToBase64String(previewImage.ToArray())));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
@@ -1149,10 +1190,15 @@ namespace Barotrauma
|
||||
public void SaveToXElement(XElement element)
|
||||
{
|
||||
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()));
|
||||
|
||||
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)
|
||||
{
|
||||
if (e.MoveWithLevel || e.Submarine != this) continue;
|
||||
|
||||
Reference in New Issue
Block a user