(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)

This commit is contained in:
Joonas Rikkonen
2019-04-23 11:17:20 +03:00
parent a044313347
commit f774694154
2 changed files with 9 additions and 3 deletions
@@ -849,8 +849,10 @@ namespace Barotrauma
} }
string savePath = nameBox.Text + ".sub"; string savePath = nameBox.Text + ".sub";
string prevSavePath = null;
if (Submarine.MainSub != null) if (Submarine.MainSub != null)
{ {
prevSavePath = Submarine.MainSub.FilePath;
savePath = Path.Combine(Path.GetDirectoryName(Submarine.MainSub.FilePath), savePath); savePath = Path.Combine(Path.GetDirectoryName(Submarine.MainSub.FilePath), savePath);
} }
else else
@@ -889,6 +891,10 @@ namespace Barotrauma
GUI.AddMessage(TextManager.Get("SubSavedNotification").Replace("[filepath]", Submarine.MainSub.FilePath), Color.Green); GUI.AddMessage(TextManager.Get("SubSavedNotification").Replace("[filepath]", Submarine.MainSub.FilePath), Color.Green);
Submarine.RefreshSavedSub(savePath); Submarine.RefreshSavedSub(savePath);
if (prevSavePath != null && prevSavePath != savePath)
{
Submarine.RefreshSavedSub(prevSavePath);
}
linkedSubBox.ClearChildren(); linkedSubBox.ClearChildren();
foreach (Submarine sub in Submarine.SavedSubmarines) foreach (Submarine sub in Submarine.SavedSubmarines)
@@ -1280,9 +1286,7 @@ namespace Barotrauma
{ {
if (CharacterMode) SetCharacterMode(false); if (CharacterMode) SetCharacterMode(false);
if (WiringMode) SetWiringMode(false); if (WiringMode) SetWiringMode(false);
Submarine.RefreshSavedSubs();
loadFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker") 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; }, OnClicked = (btn, userdata) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) loadFrame = null; return true; },
@@ -1432,6 +1436,7 @@ namespace Barotrauma
{ {
sub.Remove(); sub.Remove();
File.Delete(sub.FilePath); File.Delete(sub.FilePath);
Submarine.RefreshSavedSubs();
CreateLoadScreen(); CreateLoadScreen();
} }
catch (Exception e) catch (Exception e)
@@ -1117,6 +1117,7 @@ namespace Barotrauma
} }
} }
savedSubmarines.Add(new Submarine(filePath)); savedSubmarines.Add(new Submarine(filePath));
savedSubmarines = savedSubmarines.OrderBy(s => s.filePath ?? "").ToList();
} }
public static void RefreshSavedSubs() public static void RefreshSavedSubs()