]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Hiding and clearing department prototype code (#28114)
authorTornado Tech <54727692+Tornado-Technology@users.noreply.github.com>
Sat, 1 Jun 2024 23:49:34 +0000 (09:49 +1000)
committerGitHub <noreply@github.com>
Sat, 1 Jun 2024 23:49:34 +0000 (19:49 -0400)
Content.Client/Administration/UI/BanPanel/BanPanel.xaml.cs
Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Content.Server/Store/Conditions/BuyerDepartmentCondition.cs
Content.Shared/Roles/DepartmentPrototype.cs

index dc263d6055cef0f3aec5de1a654724273b51aa7f..588d62e56036c4b915134b1117e086e991ddc57b 100644 (file)
@@ -147,7 +147,7 @@ public sealed partial class BanPanel : DefaultWindow
         var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
         foreach (var proto in prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
         {
-            CreateRoleGroup(proto.ID, proto.Roles, proto.Color);
+            CreateRoleGroup(proto.ID, proto.Roles.Select(p =>  p.Id), proto.Color);
         }
 
         CreateRoleGroup("Antagonist", prototypeManager.EnumeratePrototypes<AntagPrototype>().Select(p => p.ID), Color.Red);
index a0e32a3a49974a4991d233ebc262c145af5f6189..eb182c83ee115f45870ebe916eada9237170be30 100644 (file)
@@ -719,8 +719,17 @@ namespace Content.Client.Lobby.UI
             _jobPriorities.Clear();
             var firstCategory = true;
 
-            var departments = _prototypeManager.EnumeratePrototypes<DepartmentPrototype>().ToArray();
-            Array.Sort(departments, DepartmentUIComparer.Instance);
+            // Get all displayed departments
+            var departments = new List<DepartmentPrototype>();
+            foreach (var department in _prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
+            {
+                if (department.EditorHidden)
+                    continue;
+
+                departments.Add(department);
+            }
+
+            departments.Sort(DepartmentUIComparer.Instance);
 
             var items = new[]
             {
@@ -774,7 +783,7 @@ namespace Content.Client.Lobby.UI
                     JobList.AddChild(category);
                 }
 
-                var jobs = department.Roles.Select(jobId => _prototypeManager.Index<JobPrototype>(jobId))
+                var jobs = department.Roles.Select(jobId => _prototypeManager.Index(jobId))
                     .Where(job => job.SetPreference)
                     .ToArray();
 
@@ -821,13 +830,15 @@ namespace Content.Client.Lobby.UI
                             if (jobId == job.ID)
                             {
                                 other.Select(selectedPrio);
+                                continue;
                             }
-                            else if (selectedJobPrio == JobPriority.High && (JobPriority) other.Selected == JobPriority.High)
-                            {
-                                // Lower any other high priorities to medium.
-                                other.Select((int) JobPriority.Medium);
-                                Profile = Profile?.WithJobPriority(jobId, JobPriority.Medium);
-                            }
+
+                            if (selectedJobPrio != JobPriority.High || (JobPriority) other.Selected != JobPriority.High)
+                                continue;
+
+                            // Lower any other high priorities to medium.
+                            other.Select((int)JobPriority.Medium);
+                            Profile = Profile?.WithJobPriority(jobId, JobPriority.Medium);
                         }
 
                         // TODO: Only reload on high change (either to or from).
@@ -932,6 +943,11 @@ namespace Content.Client.Lobby.UI
                 SetDirty();
                 ReloadPreview();
             };
+
+            if (Profile is null)
+                return;
+
+            UpdateJobPriorities();
         }
 
         private void OnFlavorTextChange(string content)
index 4e5e504aec4be6568416935b4068b028583a3742..ea8de4a9ccd6c3604331f00ea62cb5c518b96448 100644 (file)
@@ -43,7 +43,7 @@ public sealed partial class BuyerDepartmentCondition : ListingCondition
         {
             foreach (var department in prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
             {
-                if (department.Roles.Contains(job.Prototype) && Blacklist.Contains(department.ID))
+                if (department.Roles.Contains(job.Prototype.Value) && Blacklist.Contains(department.ID))
                     return false;
             }
         }
@@ -56,7 +56,7 @@ public sealed partial class BuyerDepartmentCondition : ListingCondition
             {
                 foreach (var department in prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
                 {
-                    if (department.Roles.Contains(job.Prototype) && Whitelist.Contains(department.ID))
+                    if (department.Roles.Contains(job.Prototype.Value) && Whitelist.Contains(department.ID))
                     {
                         found = true;
                         break;
index 024eca37fa2d9528da702ddc5254e46fdb88e582..d6288bec90984ae8913b3b19233fbc394fb67545 100644 (file)
@@ -1,28 +1,27 @@
 using Robust.Shared.Prototypes;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
 
 namespace Content.Shared.Roles;
 
 [Prototype("department")]
 public sealed partial class DepartmentPrototype : IPrototype
 {
-    [IdDataField] public string ID { get; } = default!;
+    [IdDataField]
+    public string ID { get; } = string.Empty;
 
     /// <summary>
-    ///     A description string to display in the character menu as an explanation of the department's function.
+    /// A description string to display in the character menu as an explanation of the department's function.
     /// </summary>
-    [DataField("description", required: true)]
-    public string Description = default!;
+    [DataField(required: true)]
+    public string Description = string.Empty;
 
     /// <summary>
-    ///     A color representing this department to use for text.
+    /// A color representing this department to use for text.
     /// </summary>
-    [DataField("color", required: true)]
-    public Color Color = default!;
+    [DataField(required: true)]
+    public Color Color;
 
-    [ViewVariables(VVAccess.ReadWrite),
-     DataField("roles", customTypeSerializer: typeof(PrototypeIdListSerializer<JobPrototype>))]
-    public List<string> Roles = new();
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public List<ProtoId<JobPrototype>> Roles = new();
 
     /// <summary>
     /// Whether this is a primary department or not.
@@ -34,8 +33,14 @@ public sealed partial class DepartmentPrototype : IPrototype
     /// <summary>
     /// Departments with a higher weight sorted before other departments in UI.
     /// </summary>
-    [DataField("weight")]
-    public int Weight { get; private set; } = 0;
+    [DataField]
+    public int Weight { get; private set; }
+
+    /// <summary>
+    /// Toggles the display of the department in the priority setting menu in the character editor.
+    /// </summary>
+    [DataField]
+    public bool EditorHidden;
 }
 
 /// <summary>
@@ -50,14 +55,14 @@ public sealed class DepartmentUIComparer : IComparer<DepartmentPrototype>
     {
         if (ReferenceEquals(x, y))
             return 0;
+
         if (ReferenceEquals(null, y))
             return 1;
+
         if (ReferenceEquals(null, x))
             return -1;
 
         var cmp = -x.Weight.CompareTo(y.Weight);
-        if (cmp != 0)
-            return cmp;
-        return string.Compare(x.ID, y.ID, StringComparison.Ordinal);
+        return cmp != 0 ? cmp : string.Compare(x.ID, y.ID, StringComparison.Ordinal);
     }
 }