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:
Pieter-Jan Briers
2024-02-23 05:04:44 +01:00
committed by GitHub
parent b1de6dd601
commit 715794dd41
11 changed files with 103 additions and 60 deletions

View File

@@ -1,18 +1,14 @@
using Content.Shared.CCVar;
using Content.Shared.CrewManifest;
using Content.Shared.CrewManifest;
using Content.Shared.Roles;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using System.Linq;
namespace Content.Client.CrewManifest.UI;
public sealed class CrewManifestListing : BoxContainer
{
[Dependency] private readonly IConfigurationManager _configManager = default!;
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private readonly SpriteSystem _spriteSystem;
@@ -25,7 +21,7 @@ public sealed class CrewManifestListing : BoxContainer
public void AddCrewManifestEntries(CrewManifestEntries entries)
{
var entryDict = new Dictionary<string, List<CrewManifestEntry>>();
var entryDict = new Dictionary<DepartmentPrototype, List<CrewManifestEntry>>();
foreach (var entry in entries.Entries)
{
@@ -34,37 +30,19 @@ public sealed class CrewManifestListing : BoxContainer
// this is a little expensive, and could be better
if (department.Roles.Contains(entry.JobPrototype))
{
entryDict.GetOrNew(department.ID).Add(entry);
entryDict.GetOrNew(department).Add(entry);
}
}
}
var entryList = new List<(string section, List<CrewManifestEntry> entries)>();
var entryList = new List<(DepartmentPrototype section, List<CrewManifestEntry> entries)>();
foreach (var (section, listing) in entryDict)
{
entryList.Add((section, listing));
}
var sortOrder = _configManager.GetCVar(CCVars.CrewManifestOrdering).Split(",").ToList();
entryList.Sort((a, b) =>
{
var ai = sortOrder.IndexOf(a.section);
var bi = sortOrder.IndexOf(b.section);
// this is up here so -1 == -1 occurs first
if (ai == bi)
return 0;
if (ai == -1)
return -1;
if (bi == -1)
return 1;
return ai.CompareTo(bi);
});
entryList.Sort((a, b) => DepartmentUIComparer.Instance.Compare(a.section, b.section));
foreach (var item in entryList)
{

View File

@@ -4,24 +4,25 @@ using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Prototypes;
using System.Numerics;
using Content.Shared.Roles;
namespace Content.Client.CrewManifest.UI;
public sealed class CrewManifestSection : BoxContainer
{
public CrewManifestSection(IPrototypeManager prototypeManager, SpriteSystem spriteSystem, string sectionTitle,
public CrewManifestSection(
IPrototypeManager prototypeManager,
SpriteSystem spriteSystem,
DepartmentPrototype section,
List<CrewManifestEntry> entries)
{
Orientation = LayoutOrientation.Vertical;
HorizontalExpand = true;
if (Loc.TryGetString($"department-{sectionTitle}", out var localizedDepart))
sectionTitle = localizedDepart;
AddChild(new Label()
{
StyleClasses = { "LabelBig" },
Text = Loc.GetString(sectionTitle)
Text = Loc.GetString($"department-{section.ID}")
});
var gridContainer = new GridContainer()
@@ -55,8 +56,9 @@ public sealed class CrewManifestSection : BoxContainer
var icon = new TextureRect()
{
TextureScale = new Vector2(2, 2),
Stretch = TextureRect.StretchMode.KeepCentered,
VerticalAlignment = VAlignment.Center,
Texture = spriteSystem.Frame0(jobIcon.Icon),
Margin = new Thickness(0, 0, 4, 0)
};
titleContainer.AddChild(icon);

View File

@@ -1,3 +1,4 @@
using System.Linq;
using System.Numerics;
using Content.Client.CrewManifest;
using Content.Client.GameTicking.Managers;
@@ -159,8 +160,10 @@ namespace Content.Client.LateJoin
};
var firstCategory = true;
var departments = _prototypeManager.EnumeratePrototypes<DepartmentPrototype>().ToArray();
Array.Sort(departments, DepartmentUIComparer.Instance);
foreach (var department in _prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
foreach (var department in departments)
{
var departmentName = Loc.GetString($"department-{department.ID}");
_jobCategories[id] = new Dictionary<string, BoxContainer>();
@@ -176,7 +179,7 @@ namespace Content.Client.LateJoin
jobsAvailable.Add(_prototypeManager.Index<JobPrototype>(jobId));
}
jobsAvailable.Sort((x, y) => -string.Compare(x.LocalizedName, y.LocalizedName, StringComparison.CurrentCultureIgnoreCase));
jobsAvailable.Sort(JobUIComparer.Instance);
// Do not display departments with no jobs available.
if (jobsAvailable.Count == 0)
@@ -231,7 +234,7 @@ namespace Content.Client.LateJoin
var icon = new TextureRect
{
TextureScale = new Vector2(2, 2),
Stretch = TextureRect.StretchMode.KeepCentered
VerticalAlignment = VAlignment.Center
};
var jobIcon = _prototypeManager.Index<StatusIconPrototype>(prototype.Icon);

View File

@@ -265,7 +265,7 @@ public sealed partial class CrewMonitoringWindow : FancyWindow
var jobIcon = new TextureRect()
{
TextureScale = new Vector2(2f, 2f),
Stretch = TextureRect.StretchMode.KeepCentered,
VerticalAlignment = VAlignment.Center,
Texture = _spriteSystem.Frame0(proto.Icon),
Margin = new Thickness(5, 0, 5, 0),
};

View File

@@ -539,10 +539,8 @@ namespace Content.Client.Preferences.UI
_jobCategories.Clear();
var firstCategory = true;
var departments = _prototypeManager.EnumeratePrototypes<DepartmentPrototype>()
.OrderByDescending(department => department.Weight)
.ThenBy(department => Loc.GetString($"department-{department.ID}"))
.ToList();
var departments = _prototypeManager.EnumeratePrototypes<DepartmentPrototype>().ToArray();
Array.Sort(departments, DepartmentUIComparer.Instance);
foreach (var department in departments)
{
@@ -588,11 +586,8 @@ namespace Content.Client.Preferences.UI
_jobList.AddChild(category);
}
var jobs = department.Roles.Select(jobId => _prototypeManager.Index<JobPrototype>(jobId))
.Where(job => job.SetPreference)
.OrderByDescending(job => job.Weight)
.ThenBy(job => job.LocalizedName)
.ToList();
var jobs = department.Roles.Select(jobId => _prototypeManager.Index<JobPrototype>(jobId)).ToArray();
Array.Sort(jobs, JobUIComparer.Instance);
foreach (var job in jobs)
{
@@ -1315,7 +1310,7 @@ namespace Content.Client.Preferences.UI
var icon = new TextureRect
{
TextureScale = new Vector2(2, 2),
Stretch = TextureRect.StretchMode.KeepCentered
VerticalAlignment = VAlignment.Center
};
var jobIcon = protoMan.Index<StatusIconPrototype>(proto.Icon);
icon.Texture = jobIcon.Icon.Frame0();