DepartmentPrototype.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Robust.Shared.Prototypes;
  2. namespace Content.Shared.Roles;
  3. [Prototype]
  4. public sealed partial class DepartmentPrototype : IPrototype
  5. {
  6. [IdDataField]
  7. public string ID { get; private set; } = string.Empty;
  8. /// <summary>
  9. /// The name LocId of the department that will be displayed in the various menus.
  10. /// </summary>
  11. [DataField(required: true)]
  12. public LocId Name = string.Empty;
  13. /// <summary>
  14. /// A description LocId to display in the character menu as an explanation of the department's function.
  15. /// </summary>
  16. [DataField(required: true)]
  17. public LocId Description = string.Empty;
  18. /// <summary>
  19. /// A color representing this department to use for text.
  20. /// </summary>
  21. [DataField(required: true)]
  22. public Color Color;
  23. [DataField, ViewVariables(VVAccess.ReadWrite)]
  24. public List<ProtoId<JobPrototype>> Roles = new();
  25. /// <summary>
  26. /// Whether this is a primary department or not.
  27. /// For example, CE's primary department is engineering since Command has primary: false.
  28. /// </summary>
  29. [DataField, ViewVariables(VVAccess.ReadWrite)]
  30. public bool Primary = true;
  31. /// <summary>
  32. /// Departments with a higher weight sorted before other departments in UI.
  33. /// </summary>
  34. [DataField]
  35. public int Weight { get; private set; }
  36. /// <summary>
  37. /// Toggles the display of the department in the priority setting menu in the character editor.
  38. /// </summary>
  39. [DataField]
  40. public bool EditorHidden;
  41. }
  42. /// <summary>
  43. /// Sorts <see cref="DepartmentPrototype"/> appropriately for display in the UI,
  44. /// respecting their <see cref="DepartmentPrototype.Weight"/>.
  45. /// </summary>
  46. public sealed class DepartmentUIComparer : IComparer<DepartmentPrototype>
  47. {
  48. public static readonly DepartmentUIComparer Instance = new();
  49. public int Compare(DepartmentPrototype? x, DepartmentPrototype? y)
  50. {
  51. if (ReferenceEquals(x, y))
  52. return 0;
  53. if (ReferenceEquals(null, y))
  54. return 1;
  55. if (ReferenceEquals(null, x))
  56. return -1;
  57. var cmp = -x.Weight.CompareTo(y.Weight);
  58. return cmp != 0 ? cmp : string.Compare(x.ID, y.ID, StringComparison.Ordinal);
  59. }
  60. }