From 09e4687cd0d2bca7f84d71fcf3cab0139acb207c Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 25 Jan 2018 12:19:47 +0200 Subject: [PATCH] The content package a submarine was saved with is included in the submarine preview, added a warning when attempting to start a campaign using a sub with a mismatching content package --- .../BarotraumaClient/Source/Map/Submarine.cs | 12 +++-- .../Source/Screens/CampaignSetupUI.cs | 44 ++++++++++++++----- .../Source/Screens/SubEditorScreen.cs | 5 ++- Barotrauma/BarotraumaShared/Content/Texts.xml | 3 ++ .../BarotraumaShared/Source/Map/Submarine.cs | 4 ++ 5 files changed, 51 insertions(+), 17 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs index ca2119dcb..ac29a9b23 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs @@ -123,7 +123,7 @@ namespace Barotrauma 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); + var txtBlock = new GUITextBlock(new Rectangle(-20, 60, 256, 128), TextManager.Get("SubPreviewImageNotFound"), Color.Black * 0.5f, null, Alignment.Center, "", frame, true); txtBlock.OutlineColor = txtBlock.TextColor; } else @@ -135,16 +135,20 @@ namespace Barotrauma 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(246, 60, 100, 20), + TextManager.Get("ContentPackage") + ": " + (ContentPackage ?? "Unknown"), + "", frame, GUI.SmallFont); - new GUITextBlock(new Rectangle(256, 60, 100, 20), + new GUITextBlock(new Rectangle(246, 80, 100, 20), TextManager.Get("Dimensions") + ": " + dimensionsStr, "", frame, GUI.SmallFont); - new GUITextBlock(new Rectangle(256, 80, 100, 20), + new GUITextBlock(new Rectangle(246, 100, 100, 20), TextManager.Get("RecommendedCrewSize") + ": " + (RecommendedCrewSizeMax == 0 ? TextManager.Get("Unknown") : RecommendedCrewSizeMin + " - " + RecommendedCrewSizeMax), "", frame, GUI.SmallFont); - new GUITextBlock(new Rectangle(256, 100, 100, 20), + new GUITextBlock(new Rectangle(246, 120, 100, 20), TextManager.Get("RecommendedCrewExperience") + ": " + (string.IsNullOrEmpty(RecommendedCrewExperience) ? TextManager.Get("unknown") : RecommendedCrewExperience), "", frame, GUI.SmallFont); diff --git a/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs b/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs index c8231743e..070f096a3 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs @@ -54,24 +54,46 @@ namespace Barotrauma saveNameBox.Flash(Color.Red); return false; } - + Submarine selectedSub = subList.SelectedData as Submarine; - if (selectedSub != null && selectedSub.HasTag(SubmarineTag.Shuttle)) + 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) { - var msgBox = new GUIMessageBox(TextManager.Get("ShuttleSelected"), - TextManager.Get("ShuttleWarning"), - new string[] { TextManager.Get("Yes"), TextManager.Get("No") }); + if (GameMain.SelectedPackage.Name != selectedSub.ContentPackage) + { + 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") }); - string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text); - msgBox.Buttons[0].OnClicked = (button, obj) => { StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text); return true; }; - msgBox.Buttons[0].OnClicked += msgBox.Close; + msgBox.Buttons[0].OnClicked = msgBox.Close; + msgBox.Buttons[0].OnClicked += (button, obj) => + { + if (GUIMessageBox.MessageBoxes.Count == 0) StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text); + return true; + }; - msgBox.Buttons[1].OnClicked = msgBox.Close; - return false; + msgBox.Buttons[1].OnClicked = msgBox.Close; + } + + if (selectedSub.HasTag(SubmarineTag.Shuttle)) + { + var msgBox = new GUIMessageBox(TextManager.Get("ShuttleSelected"), + TextManager.Get("ShuttleWarning"), + new string[] { TextManager.Get("Yes"), TextManager.Get("No") }); + + msgBox.Buttons[0].OnClicked = (button, obj) => { StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text); return true; }; + msgBox.Buttons[0].OnClicked += msgBox.Close; + + msgBox.Buttons[1].OnClicked = msgBox.Close; + return false; + } } else { - string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text); StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text); } diff --git a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs index 4400b681c..8e9209156 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs @@ -411,7 +411,7 @@ namespace Barotrauma return false; } } - + string savePath = nameBox.Text + ".sub"; if (Submarine.MainSub != null) { @@ -422,6 +422,8 @@ namespace Barotrauma savePath = Path.Combine(Submarine.SavePath, savePath); } + Submarine.MainSub.ContentPackage = GameMain.Config.SelectedContentPackage.Name; + MemoryStream imgStream = new MemoryStream(); CreateImage(256, 128, imgStream); @@ -525,7 +527,6 @@ namespace Barotrauma 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); diff --git a/Barotrauma/BarotraumaShared/Content/Texts.xml b/Barotrauma/BarotraumaShared/Content/Texts.xml index cba733152..528e2323e 100644 --- a/Barotrauma/BarotraumaShared/Content/Texts.xml +++ b/Barotrauma/BarotraumaShared/Content/Texts.xml @@ -129,6 +129,9 @@ Shuttle selected 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? Map diff --git a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs index 13e7b07e8..8ae42e37b 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs @@ -87,6 +87,8 @@ namespace Barotrauma public int RecommendedCrewSizeMin = 1, RecommendedCrewSizeMax = 2; public string RecommendedCrewExperience; + + public string ContentPackage; //properties ---------------------------------------------------- @@ -284,6 +286,7 @@ 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"); #if CLIENT string previewImageData = doc.Root.GetAttributeString("previewimage", ""); @@ -1198,6 +1201,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 ?? "")); foreach (MapEntity e in MapEntity.mapEntityList) {