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();
var jobListScroll = new ScrollContainer()
{
VerticalExpand = true,
- Children = {jobList},
+ Children = { jobList },
Visible = false,
};
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>();
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
{
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);
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)
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));
}
}
}