]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix issue where round could reset all job priorities to high (#24340)
authorKot <1192090+koteq@users.noreply.github.com>
Sat, 20 Jan 2024 22:03:10 +0000 (02:03 +0400)
committerGitHub <noreply@github.com>
Sat, 20 Jan 2024 22:03:10 +0000 (17:03 -0500)
* Update job priorities when job requirements are getting updated

* Sort jobs by weight and then by the name

* Sort departments too

Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs
Content.Shared/Roles/DepartmentPrototype.cs
Resources/Prototypes/Roles/Jobs/departments.yml

index c9a64eb0973dd6c74d169677b04b34218ddc2458..dc72cbc49e296f9d9b5c09398a7159b78d3fafdd 100644 (file)
@@ -523,7 +523,12 @@ namespace Content.Client.Preferences.UI
             _jobCategories.Clear();
             var firstCategory = true;
 
-            foreach (var department in _prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
+            var departments = _prototypeManager.EnumeratePrototypes<DepartmentPrototype>()
+                .OrderByDescending(department => department.Weight)
+                .ThenBy(department => Loc.GetString($"department-{department.ID}"))
+                .ToList();
+
+            foreach (var department in departments)
             {
                 var departmentName = Loc.GetString($"department-{department.ID}");
 
@@ -567,8 +572,11 @@ namespace Content.Client.Preferences.UI
                     _jobList.AddChild(category);
                 }
 
-                var jobs = department.Roles.Select(o => _prototypeManager.Index<JobPrototype>(o)).Where(o => o.SetPreference).ToList();
-                jobs.Sort((x, y) => -string.Compare(x.LocalizedName, y.LocalizedName, StringComparison.CurrentCultureIgnoreCase));
+                var jobs = department.Roles.Select(jobId => _prototypeManager.Index<JobPrototype>(jobId))
+                    .Where(job => job.SetPreference)
+                    .OrderByDescending(job => job.Weight)
+                    .ThenBy(job => job.LocalizedName)
+                    .ToList();
 
                 foreach (var job in jobs)
                 {
@@ -605,6 +613,11 @@ namespace Content.Client.Preferences.UI
 
                 }
             }
+
+            if (Profile is not null)
+            {
+                UpdateJobPriorities();
+            }
         }
 
         private void OnFlavorTextChange(string content)
index b3549d9584dad1957c65b39870e42b2109b0153a..f79b03f4a606a90138029ab2ceee479af2868dfb 100644 (file)
@@ -30,4 +30,10 @@ public sealed partial class DepartmentPrototype : IPrototype
     /// </summary>
     [DataField, ViewVariables(VVAccess.ReadWrite)]
     public bool Primary = true;
+
+    /// <summary>
+    /// Departments with a higher weight sorted before other departments in UI.
+    /// </summary>
+    [DataField("weight")]
+    public int Weight { get; private set; } = 0;
 }
index e1df3977219bf28a71f48d266520b7c1f3fbd623..20b1847699eeb9ac10abf8dcab89705140ed3937 100644 (file)
@@ -11,6 +11,7 @@
   id: Civilian
   description: department-Civilian-description
   color: "#9FED58"
+  weight: -10
   roles:
   - Bartender
   - Borg
@@ -44,6 +45,7 @@
   - ResearchDirector
   - Quartermaster
   primary: false
+  weight: 100
 
 - type: department
   id: Engineering
@@ -71,6 +73,7 @@
   id: Security
   description: department-Security-description
   color: "#DE3A3A"
+  weight: 20
   roles:
   - HeadOfSecurity
   - SecurityCadet
@@ -91,6 +94,7 @@
   id: Specific
   description: department-Specific-description
   color: "#9FED58"
+  weight: 10
   roles:
   - Boxer
   - Reporter