using Content.Client._Sunrise.StationRecords; using Content.Client.Lobby; using Content.Client.Roles; using Content.Shared.StationRecords; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface; using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; using Robust.Shared.Prototypes; namespace Content.Client.StationRecords; [GenerateTypedNameReferences] public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow { public Action? OnKeySelected; public Action? OnFiltersChanged; public Action? OnDeleted; private bool _isPopulating; private StationRecordFilterType _currentFilterType; // Sunrise added start public Action? OnSaved; public Action? OnPrinted; private readonly IEntityManager _entity; private readonly IPrototypeManager _prototype; private readonly ILocalizationManager _loc; private readonly JobSystem _job; private readonly LobbyUIController _controller; // Sunrise added end public GeneralStationRecordConsoleWindow() { RobustXamlLoader.Load(this); // Sunrise added start _entity = IoCManager.Resolve(); _prototype = IoCManager.Resolve(); _loc = IoCManager.Resolve(); var interfaceManager = IoCManager.Resolve(); _job = _entity.System(); _controller = interfaceManager.GetUIController(); // Sunrise added end _currentFilterType = StationRecordFilterType.Name; foreach (var item in Enum.GetValues()) { StationRecordsFilterType.AddItem(GetTypeFilterLocals(item), (int)item); } RecordListing.OnItemSelected += args => { if (_isPopulating || RecordListing[args.ItemIndex].Metadata is not uint cast) return; OnKeySelected?.Invoke(cast); }; RecordListing.OnItemDeselected += _ => { if (!_isPopulating) OnKeySelected?.Invoke(null); }; StationRecordsFilterType.OnItemSelected += eventArgs => { var type = (StationRecordFilterType) eventArgs.Id; if (_currentFilterType != type) { _currentFilterType = type; FilterListingOfRecords(); } }; StationRecordsFiltersValue.OnTextEntered += args => { FilterListingOfRecords(args.Text); }; StationRecordsFilters.OnPressed += _ => { FilterListingOfRecords(StationRecordsFiltersValue.Text); }; StationRecordsFiltersReset.OnPressed += _ => { StationRecordsFiltersValue.Text = ""; FilterListingOfRecords(); }; } public void UpdateState(GeneralStationRecordConsoleState state) { if (state.Filter != null) { if (state.Filter.Type != _currentFilterType) { _currentFilterType = state.Filter.Type; } if (state.Filter.Value != StationRecordsFiltersValue.Text) { StationRecordsFiltersValue.Text = state.Filter.Value; } } StationRecordsFilterType.SelectId((int)_currentFilterType); if (state.RecordListing == null) { RecordListingStatus.Visible = true; RecordListing.Visible = false; RecordListingStatus.Text = Loc.GetString("general-station-record-console-empty-state"); RecordContainer.Visible = false; RecordContainerStatus.Visible = false; return; } RecordListingStatus.Visible = false; RecordListing.Visible = true; RecordContainer.Visible = true; PopulateRecordListing(state.RecordListing!, state.SelectedKey); RecordContainerStatus.Visible = state.Record == null; if (state.Record != null) { RecordContainerStatus.Visible = state.SelectedKey == null; RecordContainerStatus.Text = state.SelectedKey == null ? Loc.GetString("general-station-record-console-no-record-found") : Loc.GetString("general-station-record-console-select-record-info"); // Sunrise edit PopulateRecordContainer(state.Record, state.CanDeleteEntries, state.CanRedactSensitiveData, state.HasAccess, state.SelectedKey); } else { RecordContainer.RemoveAllChildren(); } } private void PopulateRecordListing(Dictionary listing, uint? selected) { RecordListing.Clear(); RecordListing.ClearSelected(); _isPopulating = true; foreach (var (key, name) in listing) { var item = RecordListing.AddItem(name); item.Metadata = key; item.Selected = key == selected; } _isPopulating = false; RecordListing.SortItemsByText(); } // Sunrise edit private void PopulateRecordContainer(GeneralStationRecord record, bool enableDelete, bool canRedactSensitiveData, bool hasAccess, uint? id) { RecordContainer.RemoveAllChildren(); // Sunrise edit start var newRecord = new SunriseGeneralRecord(record, enableDelete, canRedactSensitiveData, hasAccess, id, in _entity, in _prototype, in _loc, in _job, in _controller); // Sunrise edit end newRecord.OnDeletePressed = OnDeleted; newRecord.OnPrintPressed = OnPrinted; newRecord.OnSaveButtonPressed = OnSaved; RecordContainer.AddChild(newRecord); } private void FilterListingOfRecords(string text = "") { if (!_isPopulating) { OnFiltersChanged?.Invoke(_currentFilterType, text); } } private string GetTypeFilterLocals(StationRecordFilterType type) { return Loc.GetString($"general-station-record-{type.ToString().ToLower()}-filter"); } }