From ed5039c43c4102f261944ac8df441c1af9cad922 Mon Sep 17 00:00:00 2001 From: CommanderMark Date: Sat, 10 Jun 2017 22:17:16 -0400 Subject: [PATCH] The ordering of job preferences in net lobby are saved in config.xml. - Added a coroutine which will save the current settings to the config.xml file if no further changes to the preferences are applied after 10 seconds. -The default ordering is now Engineer, Mechanic, Captain, Security, Doctor and Assistant. --- Barotrauma/Content/Jobs.xml | 6 +-- Barotrauma/Source/GameMain.cs | 5 +++ Barotrauma/Source/GameSettings.cs | 46 +++++++++++++++++++++ Barotrauma/Source/Screens/NetLobbyScreen.cs | 14 +++++-- Barotrauma/config.xml | 10 +++++ 5 files changed, 75 insertions(+), 6 deletions(-) diff --git a/Barotrauma/Content/Jobs.xml b/Barotrauma/Content/Jobs.xml index 15abeb486..86b9ab96c 100644 --- a/Barotrauma/Content/Jobs.xml +++ b/Barotrauma/Content/Jobs.xml @@ -32,7 +32,7 @@ - + @@ -50,11 +50,11 @@ - + - + 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..7f969eb44 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,12 @@ namespace Barotrauma public ContentPackage SelectedContentPackage { get; set; } + public List JobNamePreferences + { + get { return jobNamePreferences; } + set { UnsavedSettings = true; jobNamePreferences = value; } + } + public string MasterServerUrl { get; set; } public bool AutoCheckUpdates { get; set; } public bool WasGameUpdated { get; set; } @@ -73,6 +81,13 @@ namespace Barotrauma private set { unsavedSettings = value; + // Beging saving coroutine. Remove any existing save coroutines if one is running. + if (CoroutineManager.IsCoroutineRunning("saveCoroutine")) { CoroutineManager.StopCoroutines("saveCoroutine"); } + if (unsavedSettings == true) + { + CoroutineManager.StartCoroutine(ApplyUnsavedChanges(), "saveCoroutine"); + } + if (applyButton != null) { //applyButton.Selected = unsavedSettings; @@ -124,6 +139,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 +229,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 +319,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 +539,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..fb77c397a 100644 --- a/Barotrauma/Source/Screens/NetLobbyScreen.cs +++ b/Barotrauma/Source/Screens/NetLobbyScreen.cs @@ -540,9 +540,12 @@ 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+" ", + 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