(44694344e) Don't allow deleting vanilla subs in the sub editor

This commit is contained in:
Joonas Rikkonen
2019-06-04 16:44:10 +03:00
parent 43dcc98b8e
commit 2b7649bd2b
2 changed files with 22 additions and 45 deletions
@@ -847,6 +847,20 @@ namespace Barotrauma
GameMain.World.ProcessChanges();
}
private bool IsVanillaSub(Submarine sub)
{
if (sub == null) { return false; }
var vanilla = GameMain.VanillaContent;
if (vanilla != null)
{
var vanillaSubs = vanilla.GetFilesOfType(ContentType.Submarine);
string pathToCompare = sub.FilePath.Replace(@"\", @"/").ToLowerInvariant();
return (vanillaSubs.Any(s => s.Replace(@"\", @"/").ToLowerInvariant() == pathToCompare));
}
return false;
}
private bool SaveSub(GUIButton button, object obj)
{
if (string.IsNullOrWhiteSpace(nameBox.Text))
@@ -1328,7 +1342,14 @@ namespace Barotrauma
ScrollBarVisible = true,
OnSelected = (GUIComponent selected, object userData) =>
{
if (deleteButtonHolder.FindChild("delete") is GUIButton deleteBtn) deleteBtn.Enabled = true;
if (deleteButtonHolder.FindChild("delete") is GUIButton deleteBtn)
{
#if DEBUG
deleteBtn.Enabled = true;
#else
deleteBtn.Enabled = !IsVanillaSub(userData as Submarine);
#endif
}
return true;
}
};