diff --git a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs index ac29a9b23..7770494ae 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs @@ -137,21 +137,21 @@ namespace Barotrauma TextManager.Get("DimensionsFormat").Replace("[width]", ((int)(realWorldDimensions.X)).ToString()).Replace("[height]", ((int)(realWorldDimensions.Y)).ToString()); 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, "", 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), "", 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), "", 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); descr.CanBeFocused = false; } diff --git a/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs b/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs index 070f096a3..9b5417693 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs @@ -59,13 +59,12 @@ namespace Barotrauma if (selectedSub == null) return false; 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"), TextManager.Get("ContentPackageMismatchWarning") - .Replace("[subcontentpackage]", selectedSub.ContentPackage) .Replace("[selectedcontentpackage]", GameMain.SelectedPackage.Name), new string[] { TextManager.Get("Yes"), TextManager.Get("No") }); diff --git a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs index 8e9209156..4bfd11254 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs @@ -422,7 +422,7 @@ namespace Barotrauma 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(); CreateImage(256, 128, imgStream); @@ -481,7 +481,7 @@ namespace Barotrauma y += descriptionBox.Rect.Height; new GUITextBlock(new Rectangle(0, y, 150, 20), TextManager.Get("SaveSubDialogSettings"), "", saveFrame); - y += 20; + y += 30; int tagX = 10, tagY = 0; 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 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); diff --git a/Barotrauma/BarotraumaShared/Content/Texts.xml b/Barotrauma/BarotraumaShared/Content/Texts.xml index a2bc3f7f3..6efcbac89 100644 --- a/Barotrauma/BarotraumaShared/Content/Texts.xml +++ b/Barotrauma/BarotraumaShared/Content/Texts.xml @@ -138,7 +138,7 @@ 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? Mismatching content package - 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? + The submarine may not be compatible with the currently selected content package "[selectedcontentpackage]". Are you sure you want to choose the submarine? Map @@ -263,6 +263,7 @@ Preview image not found Recommended crew size Recommended crew experience + Compatible content packages Beginner Intermediate Experienced diff --git a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs index 8ae42e37b..89390c9f2 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs @@ -88,7 +88,7 @@ namespace Barotrauma public int RecommendedCrewSizeMin = 1, RecommendedCrewSizeMax = 2; public string RecommendedCrewExperience; - public string ContentPackage; + public HashSet CompatibleContentPackages = new HashSet(); //properties ---------------------------------------------------- @@ -286,7 +286,11 @@ namespace Barotrauma RecommendedCrewSizeMin = doc.Root.GetAttributeInt("recommendedcrewsizemin", 0); RecommendedCrewSizeMax = doc.Root.GetAttributeInt("recommendedcrewsizemax", 0); 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 string previewImageData = doc.Root.GetAttributeString("previewimage", ""); @@ -1201,7 +1205,7 @@ namespace Barotrauma element.Add(new XAttribute("recommendedcrewsizemin", RecommendedCrewSizeMin)); element.Add(new XAttribute("recommendedcrewsizemax", RecommendedCrewSizeMax)); 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) { diff --git a/Barotrauma/BarotraumaShared/Source/Serialization/XMLExtensions.cs b/Barotrauma/BarotraumaShared/Source/Serialization/XMLExtensions.cs index 89e936b27..f656af3c2 100644 --- a/Barotrauma/BarotraumaShared/Source/Serialization/XMLExtensions.cs +++ b/Barotrauma/BarotraumaShared/Source/Serialization/XMLExtensions.cs @@ -75,6 +75,25 @@ namespace Barotrauma 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) { if (element == null) return defaultValue; @@ -143,6 +162,31 @@ namespace Barotrauma 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) { if (element?.Attribute(name) == null) return defaultValue; @@ -161,6 +205,31 @@ namespace Barotrauma 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) { if (element?.Attribute(name) == null) return defaultValue;