Option to define multiple compatible content packages in submarine files, added extension methods for parsing string, float and int arrays from XML elements
This commit is contained in:
@@ -137,21 +137,21 @@ namespace Barotrauma
|
|||||||
TextManager.Get("DimensionsFormat").Replace("[width]", ((int)(realWorldDimensions.X)).ToString()).Replace("[height]", ((int)(realWorldDimensions.Y)).ToString());
|
TextManager.Get("DimensionsFormat").Replace("[width]", ((int)(realWorldDimensions.X)).ToString()).Replace("[height]", ((int)(realWorldDimensions.Y)).ToString());
|
||||||
|
|
||||||
new GUITextBlock(new Rectangle(246, 60, 100, 20),
|
new GUITextBlock(new Rectangle(246, 60, 100, 20),
|
||||||
TextManager.Get("ContentPackage") + ": " + (ContentPackage ?? "Unknown"),
|
|
||||||
"", frame, GUI.SmallFont);
|
|
||||||
|
|
||||||
new GUITextBlock(new Rectangle(246, 80, 100, 20),
|
|
||||||
TextManager.Get("Dimensions") + ": " + dimensionsStr,
|
TextManager.Get("Dimensions") + ": " + dimensionsStr,
|
||||||
"", frame, GUI.SmallFont);
|
"", frame, GUI.SmallFont);
|
||||||
|
|
||||||
new GUITextBlock(new Rectangle(246, 100, 100, 20),
|
new GUITextBlock(new Rectangle(246, 80, 100, 20),
|
||||||
TextManager.Get("RecommendedCrewSize") + ": " + (RecommendedCrewSizeMax == 0 ? TextManager.Get("Unknown") : RecommendedCrewSizeMin + " - " + RecommendedCrewSizeMax),
|
TextManager.Get("RecommendedCrewSize") + ": " + (RecommendedCrewSizeMax == 0 ? TextManager.Get("Unknown") : RecommendedCrewSizeMin + " - " + RecommendedCrewSizeMax),
|
||||||
"", frame, GUI.SmallFont);
|
"", frame, GUI.SmallFont);
|
||||||
|
|
||||||
new GUITextBlock(new Rectangle(246, 120, 100, 20),
|
new GUITextBlock(new Rectangle(246, 100, 100, 20),
|
||||||
TextManager.Get("RecommendedCrewExperience") + ": " + (string.IsNullOrEmpty(RecommendedCrewExperience) ? TextManager.Get("unknown") : RecommendedCrewExperience),
|
TextManager.Get("RecommendedCrewExperience") + ": " + (string.IsNullOrEmpty(RecommendedCrewExperience) ? TextManager.Get("unknown") : RecommendedCrewExperience),
|
||||||
"", frame, GUI.SmallFont);
|
"", frame, GUI.SmallFont);
|
||||||
|
|
||||||
|
new GUITextBlock(new Rectangle(246, 120, 100, 20),
|
||||||
|
TextManager.Get("CompatibleContentPackages") + ": " + string.Join(", ", CompatibleContentPackages),
|
||||||
|
"", Alignment.TopLeft, Alignment.TopLeft, frame, true, GUI.SmallFont);
|
||||||
|
|
||||||
var descr = new GUITextBlock(new Rectangle(0, 200, 0, 100), Description, "", Alignment.TopLeft, Alignment.TopLeft, frame, true, GUI.SmallFont);
|
var descr = new GUITextBlock(new Rectangle(0, 200, 0, 100), Description, "", Alignment.TopLeft, Alignment.TopLeft, frame, true, GUI.SmallFont);
|
||||||
descr.CanBeFocused = false;
|
descr.CanBeFocused = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,13 +59,12 @@ namespace Barotrauma
|
|||||||
if (selectedSub == null) return false;
|
if (selectedSub == null) return false;
|
||||||
|
|
||||||
string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
|
string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
|
||||||
if (selectedSub.HasTag(SubmarineTag.Shuttle) || GameMain.SelectedPackage.Name != selectedSub.ContentPackage)
|
if (selectedSub.HasTag(SubmarineTag.Shuttle) || !selectedSub.CompatibleContentPackages.Contains(GameMain.SelectedPackage.Name))
|
||||||
{
|
{
|
||||||
if (GameMain.SelectedPackage.Name != selectedSub.ContentPackage)
|
if (!selectedSub.CompatibleContentPackages.Contains(GameMain.SelectedPackage.Name))
|
||||||
{
|
{
|
||||||
var msgBox = new GUIMessageBox(TextManager.Get("ContentPackageMismatch"),
|
var msgBox = new GUIMessageBox(TextManager.Get("ContentPackageMismatch"),
|
||||||
TextManager.Get("ContentPackageMismatchWarning")
|
TextManager.Get("ContentPackageMismatchWarning")
|
||||||
.Replace("[subcontentpackage]", selectedSub.ContentPackage)
|
|
||||||
.Replace("[selectedcontentpackage]", GameMain.SelectedPackage.Name),
|
.Replace("[selectedcontentpackage]", GameMain.SelectedPackage.Name),
|
||||||
new string[] { TextManager.Get("Yes"), TextManager.Get("No") });
|
new string[] { TextManager.Get("Yes"), TextManager.Get("No") });
|
||||||
|
|
||||||
|
|||||||
@@ -422,7 +422,7 @@ namespace Barotrauma
|
|||||||
savePath = Path.Combine(Submarine.SavePath, savePath);
|
savePath = Path.Combine(Submarine.SavePath, savePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
Submarine.MainSub.ContentPackage = GameMain.Config.SelectedContentPackage.Name;
|
Submarine.MainSub.CompatibleContentPackages.Add(GameMain.Config.SelectedContentPackage.Name);
|
||||||
|
|
||||||
MemoryStream imgStream = new MemoryStream();
|
MemoryStream imgStream = new MemoryStream();
|
||||||
CreateImage(256, 128, imgStream);
|
CreateImage(256, 128, imgStream);
|
||||||
@@ -481,7 +481,7 @@ namespace Barotrauma
|
|||||||
y += descriptionBox.Rect.Height;
|
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 += 30;
|
||||||
|
|
||||||
int tagX = 10, tagY = 0;
|
int tagX = 10, tagY = 0;
|
||||||
foreach (SubmarineTag tag in Enum.GetValues(typeof(SubmarineTag)))
|
foreach (SubmarineTag tag in Enum.GetValues(typeof(SubmarineTag)))
|
||||||
@@ -519,7 +519,36 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
y += tagY;
|
y -= 30;
|
||||||
|
|
||||||
|
new GUITextBlock(new Rectangle(160, y, 100, 20), TextManager.Get("CompatibleContentPackages"), "", saveFrame);
|
||||||
|
var contentPackList = new GUIListBox(new Rectangle(160, y + 30, 0, 50), "", saveFrame);
|
||||||
|
List<string> contentPacks = Submarine.MainSub.CompatibleContentPackages.ToList();
|
||||||
|
foreach (ContentPackage contentPack in ContentPackage.list)
|
||||||
|
{
|
||||||
|
if (!contentPacks.Contains(contentPack.Name)) contentPacks.Add(contentPack.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string contentPackageName in contentPacks)
|
||||||
|
{
|
||||||
|
var cpTickBox = new GUITickBox(new Rectangle(0, 0, 15, 15), contentPackageName, Alignment.TopLeft, GUI.SmallFont, contentPackList);
|
||||||
|
cpTickBox.Selected = Submarine.MainSub.CompatibleContentPackages.Contains(contentPackageName);
|
||||||
|
cpTickBox.UserData = contentPackageName;
|
||||||
|
cpTickBox.OnSelected += (GUITickBox tickBox) =>
|
||||||
|
{
|
||||||
|
if (tickBox.Selected)
|
||||||
|
{
|
||||||
|
Submarine.MainSub.CompatibleContentPackages.Add((string)tickBox.UserData);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Submarine.MainSub.CompatibleContentPackages.Remove((string)tickBox.UserData);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
y += 90;
|
||||||
|
|
||||||
new GUITextBlock(new Rectangle(0, y, 100, 20), TextManager.Get("RecommendedCrewSize"), "", Alignment.TopLeft, Alignment.CenterLeft, saveFrame);
|
new GUITextBlock(new Rectangle(0, y, 100, 20), TextManager.Get("RecommendedCrewSize"), "", Alignment.TopLeft, Alignment.CenterLeft, saveFrame);
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@
|
|||||||
<ShuttleWarning>Most shuttles are not adequately equipped to deal with the dangers of the Europan depths. Are you sure you want to choose a shuttle as your vessel?</ShuttleWarning>
|
<ShuttleWarning>Most shuttles are not adequately equipped to deal with the dangers of the Europan depths. Are you sure you want to choose a shuttle as your vessel?</ShuttleWarning>
|
||||||
|
|
||||||
<ContentPackageMismatch>Mismatching content package</ContentPackageMismatch>
|
<ContentPackageMismatch>Mismatching content package</ContentPackageMismatch>
|
||||||
<ContentPackageMismatchWarning>The selected submarine has been saved using the content package "[subcontentpackage]". The submarine may not be compatible with the currently selected content package "[selectedcontentpackage]". Are you sure you want to choose the submarine?</ContentPackageMismatchWarning>
|
<ContentPackageMismatchWarning>The submarine may not be compatible with the currently selected content package "[selectedcontentpackage]". Are you sure you want to choose the submarine?</ContentPackageMismatchWarning>
|
||||||
|
|
||||||
<!-- Campaign menu -->
|
<!-- Campaign menu -->
|
||||||
<Map>Map</Map>
|
<Map>Map</Map>
|
||||||
@@ -263,6 +263,7 @@
|
|||||||
<SubPreviewImageNotFound>Preview image not found</SubPreviewImageNotFound>
|
<SubPreviewImageNotFound>Preview image not found</SubPreviewImageNotFound>
|
||||||
<RecommendedCrewSize>Recommended crew size</RecommendedCrewSize>
|
<RecommendedCrewSize>Recommended crew size</RecommendedCrewSize>
|
||||||
<RecommendedCrewExperience>Recommended crew experience</RecommendedCrewExperience>
|
<RecommendedCrewExperience>Recommended crew experience</RecommendedCrewExperience>
|
||||||
|
<CompatibleContentPackages>Compatible content packages</CompatibleContentPackages>
|
||||||
<CrewExperienceLow>Beginner</CrewExperienceLow>
|
<CrewExperienceLow>Beginner</CrewExperienceLow>
|
||||||
<CrewExperienceMid>Intermediate</CrewExperienceMid>
|
<CrewExperienceMid>Intermediate</CrewExperienceMid>
|
||||||
<CrewExperienceHigh>Experienced</CrewExperienceHigh>
|
<CrewExperienceHigh>Experienced</CrewExperienceHigh>
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ namespace Barotrauma
|
|||||||
public int RecommendedCrewSizeMin = 1, RecommendedCrewSizeMax = 2;
|
public int RecommendedCrewSizeMin = 1, RecommendedCrewSizeMax = 2;
|
||||||
public string RecommendedCrewExperience;
|
public string RecommendedCrewExperience;
|
||||||
|
|
||||||
public string ContentPackage;
|
public HashSet<string> CompatibleContentPackages = new HashSet<string>();
|
||||||
|
|
||||||
//properties ----------------------------------------------------
|
//properties ----------------------------------------------------
|
||||||
|
|
||||||
@@ -286,7 +286,11 @@ namespace Barotrauma
|
|||||||
RecommendedCrewSizeMin = doc.Root.GetAttributeInt("recommendedcrewsizemin", 0);
|
RecommendedCrewSizeMin = doc.Root.GetAttributeInt("recommendedcrewsizemin", 0);
|
||||||
RecommendedCrewSizeMax = doc.Root.GetAttributeInt("recommendedcrewsizemax", 0);
|
RecommendedCrewSizeMax = doc.Root.GetAttributeInt("recommendedcrewsizemax", 0);
|
||||||
RecommendedCrewExperience = doc.Root.GetAttributeString("recommendedcrewexperience", "Unknown");
|
RecommendedCrewExperience = doc.Root.GetAttributeString("recommendedcrewexperience", "Unknown");
|
||||||
ContentPackage = doc.Root.GetAttributeString("contentpackage", "Unknown");
|
string[] contentPackageNames = doc.Root.GetAttributeStringArray("compatiblecontentpackages", new string[0]);
|
||||||
|
foreach (string contentPackageName in contentPackageNames)
|
||||||
|
{
|
||||||
|
CompatibleContentPackages.Add(contentPackageName);
|
||||||
|
}
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
string previewImageData = doc.Root.GetAttributeString("previewimage", "");
|
string previewImageData = doc.Root.GetAttributeString("previewimage", "");
|
||||||
@@ -1201,7 +1205,7 @@ namespace Barotrauma
|
|||||||
element.Add(new XAttribute("recommendedcrewsizemin", RecommendedCrewSizeMin));
|
element.Add(new XAttribute("recommendedcrewsizemin", RecommendedCrewSizeMin));
|
||||||
element.Add(new XAttribute("recommendedcrewsizemax", RecommendedCrewSizeMax));
|
element.Add(new XAttribute("recommendedcrewsizemax", RecommendedCrewSizeMax));
|
||||||
element.Add(new XAttribute("recommendedcrewexperience", RecommendedCrewExperience ?? ""));
|
element.Add(new XAttribute("recommendedcrewexperience", RecommendedCrewExperience ?? ""));
|
||||||
element.Add(new XAttribute("contentpackage", ContentPackage ?? ""));
|
element.Add(new XAttribute("compatiblecontentpackages", string.Join(", ", CompatibleContentPackages)));
|
||||||
|
|
||||||
foreach (MapEntity e in MapEntity.mapEntityList)
|
foreach (MapEntity e in MapEntity.mapEntityList)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -75,6 +75,25 @@ namespace Barotrauma
|
|||||||
return String.IsNullOrEmpty(value) ? defaultValue : value;
|
return String.IsNullOrEmpty(value) ? defaultValue : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string[] GetAttributeStringArray(this XElement element, string name, string[] defaultValue, bool trim = true)
|
||||||
|
{
|
||||||
|
if (element?.Attribute(name) == null) return defaultValue;
|
||||||
|
|
||||||
|
string stringValue = element.Attribute(name).Value;
|
||||||
|
if (string.IsNullOrEmpty(stringValue)) return defaultValue;
|
||||||
|
|
||||||
|
string[] splitValue = stringValue.Split(',');
|
||||||
|
if (trim)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < splitValue.Length; i++)
|
||||||
|
{
|
||||||
|
splitValue[i] = splitValue[i].Trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return splitValue;
|
||||||
|
}
|
||||||
|
|
||||||
public static float GetAttributeFloat(this XElement element, float defaultValue, params string[] matchingAttributeName)
|
public static float GetAttributeFloat(this XElement element, float defaultValue, params string[] matchingAttributeName)
|
||||||
{
|
{
|
||||||
if (element == null) return defaultValue;
|
if (element == null) return defaultValue;
|
||||||
@@ -143,6 +162,31 @@ namespace Barotrauma
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float[] GetAttributeFloatArray(this XElement element, string name, float[] defaultValue)
|
||||||
|
{
|
||||||
|
if (element?.Attribute(name) == null) return defaultValue;
|
||||||
|
|
||||||
|
string stringValue = element.Attribute(name).Value;
|
||||||
|
if (string.IsNullOrEmpty(stringValue)) return defaultValue;
|
||||||
|
|
||||||
|
string[] splitValue = stringValue.Split(',');
|
||||||
|
float[] floatValue = new float[splitValue.Length];
|
||||||
|
for (int i = 0; i < splitValue.Length; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
float val = Single.Parse(splitValue[i], CultureInfo.InvariantCulture);
|
||||||
|
floatValue[i] = val;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Error in " + element + "! ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return floatValue;
|
||||||
|
}
|
||||||
|
|
||||||
public static int GetAttributeInt(this XElement element, string name, int defaultValue)
|
public static int GetAttributeInt(this XElement element, string name, int defaultValue)
|
||||||
{
|
{
|
||||||
if (element?.Attribute(name) == null) return defaultValue;
|
if (element?.Attribute(name) == null) return defaultValue;
|
||||||
@@ -161,6 +205,31 @@ namespace Barotrauma
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int[] GetAttributeIntArray(this XElement element, string name, int[] defaultValue)
|
||||||
|
{
|
||||||
|
if (element?.Attribute(name) == null) return defaultValue;
|
||||||
|
|
||||||
|
string stringValue = element.Attribute(name).Value;
|
||||||
|
if (string.IsNullOrEmpty(stringValue)) return defaultValue;
|
||||||
|
|
||||||
|
string[] splitValue = stringValue.Split(',');
|
||||||
|
int[] intValue = new int[splitValue.Length];
|
||||||
|
for (int i = 0; i < splitValue.Length; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int val = Int32.Parse(splitValue[i]);
|
||||||
|
intValue[i] = val;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Error in " + element + "! ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return intValue;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool GetAttributeBool(this XElement element, string name, bool defaultValue)
|
public static bool GetAttributeBool(this XElement element, string name, bool defaultValue)
|
||||||
{
|
{
|
||||||
if (element?.Attribute(name) == null) return defaultValue;
|
if (element?.Attribute(name) == null) return defaultValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user