From 9594ea67a7a3a050a520538e54173034b4acc636 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 8 Apr 2019 13:36:58 +0300 Subject: [PATCH] (bf037f9b0) Don't allow deleting vanilla subs or subs that are a part of some content package --- .../BarotraumaClient/Source/Map/Submarine.cs | 15 ++++++++++++ .../Source/Screens/SubEditorScreen.cs | 24 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs index 1172a2375..bcea54eb8 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs @@ -416,6 +416,21 @@ namespace Barotrauma } } + public bool IsVanillaSubmarine() + { + var vanilla = GameMain.VanillaContent; + if (vanilla != null) + { + var vanillaSubs = vanilla.GetFilesOfType(ContentType.Submarine); + string pathToCompare = filePath.Replace(@"\", @"/").ToLowerInvariant(); + if (vanillaSubs.Any(sub => sub.Replace(@"\", @"/").ToLowerInvariant() == pathToCompare)) + { + return true; + } + } + return false; + } + public void CheckForErrors() { List errorMsgs = new List(); diff --git a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs index c80c38413..f31eae330 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs @@ -1278,7 +1278,11 @@ namespace Barotrauma { OnSelected = (GUIComponent selected, object userData) => { - if (paddedLoadFrame.FindChild("delete") is GUIButton deleteBtn) deleteBtn.Enabled = true; + Submarine sub = userData as Submarine; + if (paddedLoadFrame.FindChild("delete") is GUIButton deleteBtn) + { + deleteBtn.Enabled = !sub.IsVanillaSubmarine(); + } return true; } }; @@ -1397,7 +1401,23 @@ namespace Barotrauma private void TryDeleteSub(Submarine sub) { - if (sub == null) return; + if (sub == null) { return; } + + if (sub.IsVanillaSubmarine()) + { + GUI.AddMessage(TextManager.Get("CannotEditVanillaSubs"), Color.Red, font: GUI.LargeFont); + return; + } + + string pathToCompare = sub.FilePath.Replace(@"\", @"/").ToLowerInvariant(); + foreach (ContentPackage cp in ContentPackage.List) + { + if (cp.Files.Any(f => f.Path.Replace(@"\", @"/").ToLowerInvariant() == pathToCompare)) + { + new GUIMessageBox("", TextManager.Get("CannotRemoveContentPackageSub").Replace("[contentpackage]", cp.Name)); + return; + } + } var msgBox = new GUIMessageBox( TextManager.Get("DeleteDialogLabel"),