From f774694154efd5ce0f32a360e3ae8a56482866f0 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 23 Apr 2019 11:17:20 +0300 Subject: [PATCH] (4246de267) Fixed saving a submarine with a new name causing the previous sub file to disappear from sub lists until saved subs are refreshed, fixed new subs appearing at the end of the list (instead of being sorted alphabetically) --- .../Source/Screens/SubEditorScreen.cs | 11 ++++++++--- Barotrauma/BarotraumaShared/Source/Map/Submarine.cs | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs index e60e94f64..e173b0c9f 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs @@ -849,8 +849,10 @@ namespace Barotrauma } string savePath = nameBox.Text + ".sub"; + string prevSavePath = null; if (Submarine.MainSub != null) { + prevSavePath = Submarine.MainSub.FilePath; savePath = Path.Combine(Path.GetDirectoryName(Submarine.MainSub.FilePath), savePath); } else @@ -889,6 +891,10 @@ namespace Barotrauma GUI.AddMessage(TextManager.Get("SubSavedNotification").Replace("[filepath]", Submarine.MainSub.FilePath), Color.Green); Submarine.RefreshSavedSub(savePath); + if (prevSavePath != null && prevSavePath != savePath) + { + Submarine.RefreshSavedSub(prevSavePath); + } linkedSubBox.ClearChildren(); foreach (Submarine sub in Submarine.SavedSubmarines) @@ -1280,9 +1286,7 @@ namespace Barotrauma { if (CharacterMode) SetCharacterMode(false); if (WiringMode) SetWiringMode(false); - - Submarine.RefreshSavedSubs(); - + loadFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker") { OnClicked = (btn, userdata) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) loadFrame = null; return true; }, @@ -1432,6 +1436,7 @@ namespace Barotrauma { sub.Remove(); File.Delete(sub.FilePath); + Submarine.RefreshSavedSubs(); CreateLoadScreen(); } catch (Exception e) diff --git a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs index a0fd7465d..ab486666c 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs @@ -1117,6 +1117,7 @@ namespace Barotrauma } } savedSubmarines.Add(new Submarine(filePath)); + savedSubmarines = savedSubmarines.OrderBy(s => s.filePath ?? "").ToList(); } public static void RefreshSavedSubs()