From 576459decc856c51a2798ae88af84740873de631 Mon Sep 17 00:00:00 2001 From: Jake Huxell Date: Wed, 27 Mar 2024 12:48:43 -0400 Subject: [PATCH 1/3] When another player late joins it will correctly update the UI locally --- Content.Client/LateJoin/LateJoinGui.cs | 84 ++++++++++++++++++++------ 1 file changed, 66 insertions(+), 18 deletions(-) diff --git a/Content.Client/LateJoin/LateJoinGui.cs b/Content.Client/LateJoin/LateJoinGui.cs index b99d30015ef8e1..4800311e3b1528 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,47 @@ 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); + + if (matchingJobButton.Amount == 0) + { + matchingJobButton.Disabled = true; + } + } + } + } + } + } + } } protected override void Dispose(bool disposing) @@ -307,14 +338,31 @@ 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; } - 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); } + + public void RefreshLabel(uint? amount) + { + if (Amount == amount) + { + return; + } + Amount = amount; + + JobLabel.Text = JobId != null ? + Loc.GetString("late-join-gui-job-slot-capped", ("jobName", JobLocalisedName), ("amount", Amount != null ? Amount : 0)) : + Loc.GetString("late-join-gui-job-slot-uncapped", ("jobName", JobLocalisedName)); + } } } From 0d1c2834ec345cd0cbd70c26e4105501ccf2458f Mon Sep 17 00:00:00 2001 From: Jake Huxell Date: Wed, 27 Mar 2024 19:44:03 -0400 Subject: [PATCH 2/3] Resolve passengers not displaying the correct message in late join --- Content.Client/LateJoin/LateJoinGui.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Content.Client/LateJoin/LateJoinGui.cs b/Content.Client/LateJoin/LateJoinGui.cs index 4800311e3b1528..2092b4630678e4 100644 --- a/Content.Client/LateJoin/LateJoinGui.cs +++ b/Content.Client/LateJoin/LateJoinGui.cs @@ -342,6 +342,7 @@ sealed class JobButton : ContainerButton public string JobId { get; } public string JobLocalisedName { get; } public uint? Amount { get; private set; } + private bool _initialised = false; public JobButton(Label jobLabel, string jobId, string jobLocalisedName, uint? amount) { @@ -350,18 +351,19 @@ public JobButton(Label jobLabel, string jobId, string jobLocalisedName, uint? am JobLocalisedName = jobLocalisedName; RefreshLabel(amount); AddStyleClass(StyleClassButton); + _initialised = true; } public void RefreshLabel(uint? amount) { - if (Amount == amount) + if (Amount == amount && _initialised) { return; } Amount = amount; - JobLabel.Text = JobId != null ? - Loc.GetString("late-join-gui-job-slot-capped", ("jobName", JobLocalisedName), ("amount", Amount != null ? Amount : 0)) : + 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)); } } From de6474806b8ad4548ed3af61edff3606d34151c1 Mon Sep 17 00:00:00 2001 From: Jake Huxell Date: Wed, 27 Mar 2024 19:52:47 -0400 Subject: [PATCH 3/3] Improve final boolean comparison of button disabled state to be a bit neater --- Content.Client/LateJoin/LateJoinGui.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Content.Client/LateJoin/LateJoinGui.cs b/Content.Client/LateJoin/LateJoinGui.cs index 2092b4630678e4..d6a028d6c45d4d 100644 --- a/Content.Client/LateJoin/LateJoinGui.cs +++ b/Content.Client/LateJoin/LateJoinGui.cs @@ -309,11 +309,7 @@ private void JobsAvailableUpdated(IReadOnlyDictionary