Submarine preview window with a preview image & some extra information of the subs

This commit is contained in:
Joonas Rikkonen
2018-01-17 17:01:44 +02:00
parent 8544dea9db
commit f5dbbf0735
11 changed files with 338 additions and 59 deletions
@@ -91,6 +91,7 @@
<Editing>Editing</Editing>
<Error>Error</Error>
<Warning>Warning</Warning>
<Unknown>Unknown</Unknown>
<None>None</None>
<Close>Close</Close>
<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>
<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 -->
<Waypoint>Waypoint</Waypoint>
<LinkWaypoint>Hold space to link to another waypoint</LinkWaypoint>
@@ -223,17 +223,22 @@
</GUITickBox>
<GUIMessageBox
padding="40.0, 40.0, 40.0, 40.0"
color="1.0, 1.0, 1.0, 1.0"
textcolor="0.0, 0.0, 0.0, 1.0"
padding="40.0, 20.0, 40.0, 20.0"
color="1.0, 1.0, 1.0, 1.0"
textcolor="0.0, 0.0, 0.0, 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">
<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"
textcolor="0.0, 0.0, 0.0, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" sourcerect ="32, 541, 420, 454" slice="87,576,430,960"/>
<Sprite texture="Content/UI/UI_Atlas.png" size="0.0, 0.0" sourcerect ="32, 541, 420, 220" slice="87,576,430,687"/>
</GUIFrame>
</GUIMessageBox>
<GUIProgressBar
@@ -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;