Skip to content

Commit

Permalink
Station Records: Populate job list whenever possible (#1954)
Browse files Browse the repository at this point in the history
* station rcrds: populate all args when possible

* Assign jobList properly

---------

Co-authored-by: Dvir <[email protected]>
  • Loading branch information
whatston3 and dvir001 committed Sep 14, 2024
1 parent 3ae595d commit 753435e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
private bool _isPopulating;

private StationRecordFilterType _currentFilterType;
[Dependency] private readonly IPrototypeManager _prototype = default!; // Frontier

public GeneralStationRecordConsoleWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); // Frontier

_currentFilterType = StationRecordFilterType.Name;

Expand Down Expand Up @@ -178,10 +180,21 @@ private void PopulateJobsContainer(IReadOnlyDictionary<ProtoId<JobPrototype>, in
JobListing.RemoveAllChildren();
foreach (var (job, amount) in jobList)
{
// Skip overflow jobs.
if (amount < 0 || amount is null)
continue;

// Get proper job names when possible
string jobName;
if (_prototype.TryIndex(job, out var jobProto))
jobName = jobProto.LocalizedName;
else
jobName = job;

var jobEntry = new JobRow
{
Job = job,
JobName = { Text = job },
JobName = { Text = jobName },
JobAmount = { Text = amount.ToString() },
};
jobEntry.DecreaseJobSlot.OnPressed += (args) => { OnJobSubtract?.Invoke(args); };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Robust.Server.GameObjects;
using System.Linq;
using Content.Shared.Roles;
using Robust.Shared.Prototypes; // Frontier

namespace Content.Server.StationRecords.Systems;

Expand Down Expand Up @@ -82,20 +83,23 @@ private void UpdateUserInterface(Entity<GeneralStationRecordConsoleComponent> en
var (uid, console) = ent;
var owningStation = _station.GetOwningStation(uid);

IReadOnlyDictionary<ProtoId<JobPrototype>, int?>? jobList = null; // Frontier
if (owningStation != null) // Frontier
jobList = _stationJobsSystem.GetJobs(owningStation.Value); // Frontier: moved this up - populate whenever possible.

if (!TryComp<StationRecordsComponent>(owningStation, out var stationRecords))
{
_ui.SetUiState(uid, GeneralStationRecordConsoleKey.Key, new GeneralStationRecordConsoleState());
_ui.SetUiState(uid, GeneralStationRecordConsoleKey.Key, new GeneralStationRecordConsoleState(null, null, null, jobList, console.Filter, ent.Comp.CanDeleteEntries)); // Frontier: add as many args as we can
return;
}

var jobList = _stationJobsSystem.GetJobs(owningStation.Value);

var listing = _stationRecords.BuildListing((owningStation.Value, stationRecords), console.Filter);

switch (listing.Count)
{
case 0:
_ui.SetUiState(uid, GeneralStationRecordConsoleKey.Key, new GeneralStationRecordConsoleState());
var consoleState = new GeneralStationRecordConsoleState(null, null, null, jobList, console.Filter, ent.Comp.CanDeleteEntries); // Frontier: add as many args as we can
_ui.SetUiState(uid, GeneralStationRecordConsoleKey.Key, consoleState);
return;
default:
if (console.ActiveKey == null)
Expand All @@ -104,7 +108,10 @@ private void UpdateUserInterface(Entity<GeneralStationRecordConsoleComponent> en
}

if (console.ActiveKey is not { } id)
{
_ui.SetUiState(uid, GeneralStationRecordConsoleKey.Key, new GeneralStationRecordConsoleState(null, null, listing, jobList, console.Filter, ent.Comp.CanDeleteEntries)); // Frontier: add as many args as we can
return;
}

var key = new StationRecordKey(id, owningStation.Value);
_stationRecords.TryGetRecord<GeneralStationRecord>(key, out var record, stationRecords);
Expand Down

0 comments on commit 753435e

Please sign in to comment.