Late Join Menu Properly Retains Position On New Player Joins (#26483)

* When another player late joins it will correctly update the UI locally

* Resolve passengers not displaying the correct message in late join

* Improve final boolean comparison of button disabled state to be a bit neater
This commit is contained in:
Jake Huxell
2024-03-27 21:43:55 -04:00
committed by GitHub
parent 92a444311f
commit bf7c1d647e

View File

@@ -33,7 +33,7 @@ namespace Content.Client.LateJoin
private readonly SpriteSystem _sprites;
private readonly CrewManifestSystem _crewManifest;
private readonly Dictionary<NetEntity, Dictionary<string, JobButton>> _jobButtons = new();
private readonly Dictionary<NetEntity, Dictionary<string, List<JobButton>>> _jobButtons = new();
private readonly Dictionary<NetEntity, Dictionary<string, BoxContainer>> _jobCategories = new();
private readonly List<ScrollContainer> _jobLists = new();
@@ -139,7 +139,7 @@ namespace Content.Client.LateJoin
var jobListScroll = new ScrollContainer()
{
VerticalExpand = true,
Children = {jobList},
Children = { jobList },
Visible = false,
};
@@ -163,11 +163,12 @@ namespace Content.Client.LateJoin
var departments = _prototypeManager.EnumeratePrototypes<DepartmentPrototype>().ToArray();
Array.Sort(departments, DepartmentUIComparer.Instance);
_jobButtons[id] = new Dictionary<string, List<JobButton>>();
foreach (var department in departments)
{
var departmentName = Loc.GetString($"department-{department.ID}");
_jobCategories[id] = new Dictionary<string, BoxContainer>();
_jobButtons[id] = new Dictionary<string, JobButton>();
var stationAvailable = _gameTicker.JobsAvailable[id];
var jobsAvailable = new List<JobPrototype>();
@@ -223,7 +224,13 @@ namespace Content.Client.LateJoin
foreach (var prototype in jobsAvailable)
{
var value = stationAvailable[prototype.ID];
var jobButton = new JobButton(prototype.ID, value);
var jobLabel = new Label
{
Margin = new Thickness(5f, 0, 0, 0)
};
var jobButton = new JobButton(jobLabel, prototype.ID, prototype.LocalizedName, value);
var jobSelector = new BoxContainer
{
@@ -241,14 +248,6 @@ namespace Content.Client.LateJoin
icon.Texture = _sprites.Frame0(jobIcon.Icon);
jobSelector.AddChild(icon);
var jobLabel = new Label
{
Margin = new Thickness(5f, 0, 0, 0),
Text = value != null ?
Loc.GetString("late-join-gui-job-slot-capped", ("jobName", prototype.LocalizedName), ("amount", value)) :
Loc.GetString("late-join-gui-job-slot-uncapped", ("jobName", prototype.LocalizedName)),
};
jobSelector.AddChild(jobLabel);
jobButton.AddChild(jobSelector);
category.AddChild(jobButton);
@@ -280,15 +279,43 @@ namespace Content.Client.LateJoin
jobButton.Disabled = true;
}
_jobButtons[id][prototype.ID] = jobButton;
if (!_jobButtons[id].ContainsKey(prototype.ID))
{
_jobButtons[id][prototype.ID] = new List<JobButton>();
}
_jobButtons[id][prototype.ID].Add(jobButton);
}
}
}
}
private void JobsAvailableUpdated(IReadOnlyDictionary<NetEntity, Dictionary<string, uint?>> _)
private void JobsAvailableUpdated(IReadOnlyDictionary<NetEntity, Dictionary<string, uint?>> updatedJobs)
{
RebuildUI();
foreach (var stationEntries in updatedJobs)
{
if (_jobButtons.ContainsKey(stationEntries.Key))
{
var jobsAvailable = stationEntries.Value;
var existingJobEntries = _jobButtons[stationEntries.Key];
foreach (var existingJobEntry in existingJobEntries)
{
if (jobsAvailable.ContainsKey(existingJobEntry.Key))
{
var updatedJobValue = jobsAvailable[existingJobEntry.Key];
foreach (var matchingJobButton in existingJobEntry.Value)
{
if (matchingJobButton.Amount != updatedJobValue)
{
matchingJobButton.RefreshLabel(updatedJobValue);
matchingJobButton.Disabled = matchingJobButton.Amount == 0;
}
}
}
}
}
}
}
protected override void Dispose(bool disposing)
@@ -307,14 +334,33 @@ namespace Content.Client.LateJoin
sealed class JobButton : ContainerButton
{
public Label JobLabel { get; }
public string JobId { get; }
public uint? Amount { get; }
public string JobLocalisedName { get; }
public uint? Amount { get; private set; }
private bool _initialised = false;
public JobButton(string jobId, uint? amount)
public JobButton(Label jobLabel, string jobId, string jobLocalisedName, uint? amount)
{
JobLabel = jobLabel;
JobId = jobId;
Amount = amount;
JobLocalisedName = jobLocalisedName;
RefreshLabel(amount);
AddStyleClass(StyleClassButton);
_initialised = true;
}
public void RefreshLabel(uint? amount)
{
if (Amount == amount && _initialised)
{
return;
}
Amount = amount;
JobLabel.Text = Amount != null ?
Loc.GetString("late-join-gui-job-slot-capped", ("jobName", JobLocalisedName), ("amount", Amount)) :
Loc.GetString("late-join-gui-job-slot-uncapped", ("jobName", JobLocalisedName));
}
}
}