Make department / job list sorting consistent. (#25486)
* Make department / job list sorting consistent. This makes late join, crew manifest and character profile all apply consistent sorting for jobs and departments. We use the already-defined weights for departments (so command, then sec, then station specific, then just sort by prototype ID). Jobs also use weight (so heads are always at the top) then prototype ID, then character name (for manifest). Removed the crewmanifest.ordering CVar as doing it via prototype weight is just easier, and that CVar was already a mess anyways. * Fix jittery job icons in lists. They were set to KeepCentered in TextureRect. This has issues because the allocated space is actually an odd number of pixels, so it tries to position the draw at a half pixel offset. Now, yes, fixing this in TextureRect would make much more sense, but get off my back. (Ok seriously we need better helper functions for doing that in the engine. Don't wanna deal with that right now and I already have this patch made.) Instead I'm just gonna fix the issue by using VerticalAlignment in all these places instead which ends up doing exactly the same thing YIPPEE. Also gave a margin next to the icon on the crew manifest. Margins people!
This commit is contained in:
committed by
GitHub
parent
b1de6dd601
commit
715794dd41
@@ -37,3 +37,27 @@ public sealed partial class DepartmentPrototype : IPrototype
|
||||
[DataField("weight")]
|
||||
public int Weight { get; private set; } = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sorts <see cref="DepartmentPrototype"/> appropriately for display in the UI,
|
||||
/// respecting their <see cref="DepartmentPrototype.Weight"/>.
|
||||
/// </summary>
|
||||
public sealed class DepartmentUIComparer : IComparer<DepartmentPrototype>
|
||||
{
|
||||
public static readonly DepartmentUIComparer Instance = new();
|
||||
|
||||
public int Compare(DepartmentPrototype? x, DepartmentPrototype? y)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.Access;
|
||||
using Content.Shared.Players.PlayTimeTracking;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.StatusIcon;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
@@ -70,6 +71,16 @@ namespace Content.Shared.Roles
|
||||
[DataField("weight")]
|
||||
public int Weight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// How to sort this job relative to other jobs in the UI.
|
||||
/// Jobs with a higher value with sort before jobs with a lower value.
|
||||
/// If not set, <see cref="Weight"/> is used as a fallback.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public int? DisplayWeight { get; private set; }
|
||||
|
||||
public int RealDisplayWeight => DisplayWeight ?? Weight;
|
||||
|
||||
/// <summary>
|
||||
/// A numerical score for how much easier this job is for antagonists.
|
||||
/// For traitors, reduces starting TC by this amount. Other gamemodes can use it for whatever they find fitting.
|
||||
@@ -106,4 +117,28 @@ namespace Content.Shared.Roles
|
||||
[DataField("extendedAccessGroups", customTypeSerializer: typeof(PrototypeIdListSerializer<AccessGroupPrototype>))]
|
||||
public IReadOnlyCollection<string> ExtendedAccessGroups { get; private set; } = Array.Empty<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sorts <see cref="JobPrototype"/>s appropriately for display in the UI,
|
||||
/// respecting their <see cref="JobPrototype.Weight"/>.
|
||||
/// </summary>
|
||||
public sealed class JobUIComparer : IComparer<JobPrototype>
|
||||
{
|
||||
public static readonly JobUIComparer Instance = new();
|
||||
|
||||
public int Compare(JobPrototype? x, JobPrototype? y)
|
||||
{
|
||||
if (ReferenceEquals(x, y))
|
||||
return 0;
|
||||
if (ReferenceEquals(null, y))
|
||||
return 1;
|
||||
if (ReferenceEquals(null, x))
|
||||
return -1;
|
||||
|
||||
var cmp = -x.RealDisplayWeight.CompareTo(y.RealDisplayWeight);
|
||||
if (cmp != 0)
|
||||
return cmp;
|
||||
return string.Compare(x.ID, y.ID, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user