using Content.Server.Station.Systems; using Content.Shared.StationRecords; using Robust.Server.GameObjects; namespace Content.Server.StationRecords.Systems; public sealed class GeneralStationRecordConsoleSystem : EntitySystem { [Dependency] private readonly UserInterfaceSystem _userInterface = default!; [Dependency] private readonly StationSystem _stationSystem = default!; [Dependency] private readonly StationRecordsSystem _stationRecordsSystem = default!; public override void Initialize() { SubscribeLocalEvent(UpdateUserInterface); SubscribeLocalEvent(OnKeySelected); SubscribeLocalEvent(UpdateUserInterface); SubscribeLocalEvent(UpdateUserInterface); } private void UpdateUserInterface(EntityUid uid, GeneralStationRecordConsoleComponent component, T ev) { UpdateUserInterface(uid, component); } private void OnKeySelected(EntityUid uid, GeneralStationRecordConsoleComponent component, SelectGeneralStationRecord msg) { component.ActiveKey = msg.SelectedKey; UpdateUserInterface(uid, component); } private void UpdateUserInterface(EntityUid uid, GeneralStationRecordConsoleComponent? console = null) { if (!Resolve(uid, ref console)) { return; } var owningStation = _stationSystem.GetOwningStation(uid); if (!TryComp(owningStation, out var stationRecordsComponent)) { _userInterface.GetUiOrNull(uid, GeneralStationRecordConsoleKey.Key)?.SetState(new GeneralStationRecordConsoleState(null, null, null)); return; } var enumerator = _stationRecordsSystem.GetRecordsOfType(owningStation.Value, stationRecordsComponent); var listing = new Dictionary(); foreach (var pair in enumerator) { listing.Add(pair.Item1, pair.Item2.Name); } if (listing.Count == 0) { _userInterface.GetUiOrNull(uid, GeneralStationRecordConsoleKey.Key)?.SetState(new GeneralStationRecordConsoleState(null, null, null)); return; } GeneralStationRecord? record = null; if (console.ActiveKey != null) { _stationRecordsSystem.TryGetRecord(owningStation.Value, console.ActiveKey.Value, out record, stationRecordsComponent); } _userInterface .GetUiOrNull(uid, GeneralStationRecordConsoleKey.Key)? .SetState(new GeneralStationRecordConsoleState(console.ActiveKey, record, listing)); } }