Hiding and clearing department prototype code (#28114)

This commit is contained in:
Tornado Tech
2024-06-02 09:49:34 +10:00
committed by GitHub
parent ad1fc0cdba
commit 07dfefc4a2
4 changed files with 49 additions and 28 deletions

View File

@@ -147,7 +147,7 @@ public sealed partial class BanPanel : DefaultWindow
var prototypeManager = IoCManager.Resolve<IPrototypeManager>(); var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var proto in prototypeManager.EnumeratePrototypes<DepartmentPrototype>()) 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); CreateRoleGroup("Antagonist", prototypeManager.EnumeratePrototypes<AntagPrototype>().Select(p => p.ID), Color.Red);

View File

@@ -719,8 +719,17 @@ namespace Content.Client.Lobby.UI
_jobPriorities.Clear(); _jobPriorities.Clear();
var firstCategory = true; var firstCategory = true;
var departments = _prototypeManager.EnumeratePrototypes<DepartmentPrototype>().ToArray(); // Get all displayed departments
Array.Sort(departments, DepartmentUIComparer.Instance); 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[] var items = new[]
{ {
@@ -774,7 +783,7 @@ namespace Content.Client.Lobby.UI
JobList.AddChild(category); 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) .Where(job => job.SetPreference)
.ToArray(); .ToArray();
@@ -821,13 +830,15 @@ namespace Content.Client.Lobby.UI
if (jobId == job.ID) if (jobId == job.ID)
{ {
other.Select(selectedPrio); other.Select(selectedPrio);
continue;
} }
else if (selectedJobPrio == JobPriority.High && (JobPriority) other.Selected == JobPriority.High)
{ if (selectedJobPrio != JobPriority.High || (JobPriority) other.Selected != JobPriority.High)
// Lower any other high priorities to medium. continue;
other.Select((int) JobPriority.Medium);
Profile = Profile?.WithJobPriority(jobId, JobPriority.Medium); // 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). // TODO: Only reload on high change (either to or from).
@@ -932,6 +943,11 @@ namespace Content.Client.Lobby.UI
SetDirty(); SetDirty();
ReloadPreview(); ReloadPreview();
}; };
if (Profile is null)
return;
UpdateJobPriorities();
} }
private void OnFlavorTextChange(string content) private void OnFlavorTextChange(string content)

View File

@@ -43,7 +43,7 @@ public sealed partial class BuyerDepartmentCondition : ListingCondition
{ {
foreach (var department in prototypeManager.EnumeratePrototypes<DepartmentPrototype>()) 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; return false;
} }
} }
@@ -56,7 +56,7 @@ public sealed partial class BuyerDepartmentCondition : ListingCondition
{ {
foreach (var department in prototypeManager.EnumeratePrototypes<DepartmentPrototype>()) 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; found = true;
break; break;

View File

@@ -1,28 +1,27 @@
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
namespace Content.Shared.Roles; namespace Content.Shared.Roles;
[Prototype("department")] [Prototype("department")]
public sealed partial class DepartmentPrototype : IPrototype public sealed partial class DepartmentPrototype : IPrototype
{ {
[IdDataField] public string ID { get; } = default!; [IdDataField]
public string ID { get; } = string.Empty;
/// <summary> /// <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> /// </summary>
[DataField("description", required: true)] [DataField(required: true)]
public string Description = default!; public string Description = string.Empty;
/// <summary> /// <summary>
/// A color representing this department to use for text. /// A color representing this department to use for text.
/// </summary> /// </summary>
[DataField("color", required: true)] [DataField(required: true)]
public Color Color = default!; public Color Color;
[ViewVariables(VVAccess.ReadWrite), [DataField, ViewVariables(VVAccess.ReadWrite)]
DataField("roles", customTypeSerializer: typeof(PrototypeIdListSerializer<JobPrototype>))] public List<ProtoId<JobPrototype>> Roles = new();
public List<string> Roles = new();
/// <summary> /// <summary>
/// Whether this is a primary department or not. /// Whether this is a primary department or not.
@@ -34,8 +33,14 @@ public sealed partial class DepartmentPrototype : IPrototype
/// <summary> /// <summary>
/// Departments with a higher weight sorted before other departments in UI. /// Departments with a higher weight sorted before other departments in UI.
/// </summary> /// </summary>
[DataField("weight")] [DataField]
public int Weight { get; private set; } = 0; 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> /// <summary>
@@ -50,14 +55,14 @@ public sealed class DepartmentUIComparer : IComparer<DepartmentPrototype>
{ {
if (ReferenceEquals(x, y)) if (ReferenceEquals(x, y))
return 0; return 0;
if (ReferenceEquals(null, y)) if (ReferenceEquals(null, y))
return 1; return 1;
if (ReferenceEquals(null, x)) if (ReferenceEquals(null, x))
return -1; return -1;
var cmp = -x.Weight.CompareTo(y.Weight); var cmp = -x.Weight.CompareTo(y.Weight);
if (cmp != 0) return cmp != 0 ? cmp : string.Compare(x.ID, y.ID, StringComparison.Ordinal);
return cmp;
return string.Compare(x.ID, y.ID, StringComparison.Ordinal);
} }
} }