diff --git a/Barotrauma/Content/Jobs.xml b/Barotrauma/Content/Jobs.xml index 15abeb486..0b98e6c24 100644 --- a/Barotrauma/Content/Jobs.xml +++ b/Barotrauma/Content/Jobs.xml @@ -1,6 +1,6 @@  - + @@ -18,7 +18,7 @@ - + @@ -32,11 +32,11 @@ - + - + @@ -50,11 +50,11 @@ - + - + @@ -74,7 +74,7 @@ - + diff --git a/Barotrauma/Source/GameMain.cs b/Barotrauma/Source/GameMain.cs index 9b3759882..6f291cd27 100644 --- a/Barotrauma/Source/GameMain.cs +++ b/Barotrauma/Source/GameMain.cs @@ -217,6 +217,11 @@ namespace Barotrauma yield return CoroutineStatus.Running; JobPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Jobs)); + // Add any missing jobs from the prefab into Config.JobNamePreferences. + foreach (JobPrefab job in JobPrefab.List) + { + if (!Config.JobNamePreferences.Contains(job.Name)) { Config.JobNamePreferences.Add(job.Name); } + } StructurePrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Structure)); TitleScreen.LoadState = 20.0f; yield return CoroutineStatus.Running; diff --git a/Barotrauma/Source/GameSettings.cs b/Barotrauma/Source/GameSettings.cs index 92031d217..c032645d5 100644 --- a/Barotrauma/Source/GameSettings.cs +++ b/Barotrauma/Source/GameSettings.cs @@ -23,6 +23,8 @@ namespace Barotrauma private WindowMode windowMode; + public List jobNamePreferences; + private KeyOrMouse[] keyMapping; private bool unsavedSettings; @@ -56,6 +58,19 @@ namespace Barotrauma public ContentPackage SelectedContentPackage { get; set; } + public List JobNamePreferences + { + get { return jobNamePreferences; } + set + { + // Begin saving coroutine. Remove any existing save coroutines if one is running. + if (CoroutineManager.IsCoroutineRunning("saveCoroutine")) { CoroutineManager.StopCoroutines("saveCoroutine"); } + CoroutineManager.StartCoroutine(ApplyUnsavedChanges(), "saveCoroutine"); + + jobNamePreferences = value; + } + } + public string MasterServerUrl { get; set; } public bool AutoCheckUpdates { get; set; } public bool WasGameUpdated { get; set; } @@ -73,6 +88,7 @@ namespace Barotrauma private set { unsavedSettings = value; + if (applyButton != null) { //applyButton.Selected = unsavedSettings; @@ -124,6 +140,12 @@ namespace Barotrauma SelectedContentPackage = ContentPackage.list.Any() ? ContentPackage.list[0] : new ContentPackage(""); + JobNamePreferences = new List(); + foreach (JobPrefab job in JobPrefab.List) + { + JobNamePreferences.Add(job.Name); + } + return; } @@ -208,6 +230,13 @@ namespace Barotrauma } } break; + case "gameplay": + JobNamePreferences = new List(); + foreach (XElement ele in subElement.Element("jobpreferences").Elements("job")) + { + JobNamePreferences.Add(ToolBox.GetAttributeString(ele, "name", "")); + } + break; } } @@ -291,6 +320,17 @@ namespace Barotrauma } + var gameplay = new XElement("gameplay"); + + var jobPreferences = new XElement("jobpreferences"); + foreach (string jobName in JobNamePreferences) + { + jobPreferences.Add(new XElement("job", new XAttribute("name", jobName))); + } + + gameplay.Add(jobPreferences); + doc.Root.Add(gameplay); + doc.Save(filePath); } @@ -500,6 +540,13 @@ namespace Barotrauma yield return CoroutineStatus.Success; } + private IEnumerable ApplyUnsavedChanges() + { + yield return new WaitForSeconds(10.0f); + + Save("config.xml"); + } + private bool ApplyClicked(GUIButton button, object userData) { Save("config.xml"); diff --git a/Barotrauma/Source/Screens/NetLobbyScreen.cs b/Barotrauma/Source/Screens/NetLobbyScreen.cs index f5b648cb2..8d1ea20ff 100644 --- a/Barotrauma/Source/Screens/NetLobbyScreen.cs +++ b/Barotrauma/Source/Screens/NetLobbyScreen.cs @@ -540,10 +540,13 @@ namespace Barotrauma int i = 1; - foreach (JobPrefab job in JobPrefab.List) + foreach (string jobName in GameMain.Config.JobNamePreferences) { - GUITextBlock jobText = new GUITextBlock(new Rectangle(0, 0, 0, 20), i + ". " + job.Name+" ", - "",Alignment.Left, Alignment.Right, jobList, false, + JobPrefab job = JobPrefab.List.First(x => x.Name == jobName); + if (job == null) { continue; } + + GUITextBlock jobText = new GUITextBlock(new Rectangle(0, 0, 0, 20), i + ". " + job.Name + " ", + "", Alignment.Left, Alignment.Right, jobList, false, GameMain.GraphicsWidth<1000 ? GUI.SmallFont : GUI.Font); jobText.UserData = job; @@ -1199,6 +1202,8 @@ namespace Barotrauma private void UpdateJobPreferences(GUIListBox listBox) { listBox.Deselect(); + List jobNamePreferences = new List(); + for (int i = 0; i < listBox.children.Count; i++) { float a = (float)(i - 1) / 3.0f; @@ -1210,8 +1215,11 @@ namespace Barotrauma listBox.children[i].SelectedColor = color; (listBox.children[i] as GUITextBlock).Text = (i+1) + ". " + (listBox.children[i].UserData as JobPrefab).Name; + + jobNamePreferences.Add((listBox.children[i].UserData as JobPrefab).Name); } - + + GameMain.Config.JobNamePreferences = jobNamePreferences; } public bool TrySelectSub(string subName, string md5Hash, GUIListBox subList) diff --git a/Barotrauma/config.xml b/Barotrauma/config.xml index b59175f88..131fbcafc 100644 --- a/Barotrauma/config.xml +++ b/Barotrauma/config.xml @@ -3,4 +3,14 @@ + + + + + + + + + + \ No newline at end of file