diff --git a/Content.Client/LateJoin/LateJoinGui.cs b/Content.Client/LateJoin/LateJoinGui.cs index b99d30015ef8e1..d6a028d6c45d4d 100644 --- a/Content.Client/LateJoin/LateJoinGui.cs +++ b/Content.Client/LateJoin/LateJoinGui.cs @@ -33,7 +33,7 @@ public sealed class LateJoinGui : DefaultWindow private readonly SpriteSystem _sprites; private readonly CrewManifestSystem _crewManifest; - private readonly Dictionary> _jobButtons = new(); + private readonly Dictionary>> _jobButtons = new(); private readonly Dictionary> _jobCategories = new(); private readonly List _jobLists = new(); @@ -139,7 +139,7 @@ private void RebuildUI() var jobListScroll = new ScrollContainer() { VerticalExpand = true, - Children = {jobList}, + Children = { jobList }, Visible = false, }; @@ -163,11 +163,12 @@ private void RebuildUI() var departments = _prototypeManager.EnumeratePrototypes().ToArray(); Array.Sort(departments, DepartmentUIComparer.Instance); + _jobButtons[id] = new Dictionary>(); + foreach (var department in departments) { var departmentName = Loc.GetString($"department-{department.ID}"); _jobCategories[id] = new Dictionary(); - _jobButtons[id] = new Dictionary(); var stationAvailable = _gameTicker.JobsAvailable[id]; var jobsAvailable = new List(); @@ -223,7 +224,13 @@ private void RebuildUI() 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 @@ private void RebuildUI() 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 @@ private void RebuildUI() jobButton.Disabled = true; } - _jobButtons[id][prototype.ID] = jobButton; + if (!_jobButtons[id].ContainsKey(prototype.ID)) + { + _jobButtons[id][prototype.ID] = new List(); + } + + _jobButtons[id][prototype.ID].Add(jobButton); } } } } - private void JobsAvailableUpdated(IReadOnlyDictionary> _) + private void JobsAvailableUpdated(IReadOnlyDictionary> 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 @@ protected override void Dispose(bool disposing) 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)); } } }