Files
OldThink/Content.Server/StationRecords/Systems/GeneralStationRecordConsoleSystem.cs

86 lines
3.4 KiB
C#
Raw Normal View History

using System.Linq;
using Content.Server.Station.Systems;
2024-02-04 23:29:35 +00:00
using Content.Server.StationRecords.Components;
using Content.Shared.StationRecords;
using Robust.Server.GameObjects;
namespace Content.Server.StationRecords.Systems;
public sealed class GeneralStationRecordConsoleSystem : EntitySystem
{
2024-02-04 23:29:35 +00:00
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly StationRecordsSystem _stationRecords = default!;
public override void Initialize()
{
SubscribeLocalEvent<GeneralStationRecordConsoleComponent, RecordModifiedEvent>(UpdateUserInterface);
SubscribeLocalEvent<GeneralStationRecordConsoleComponent, AfterGeneralRecordCreatedEvent>(UpdateUserInterface);
SubscribeLocalEvent<GeneralStationRecordConsoleComponent, RecordRemovedEvent>(UpdateUserInterface);
2024-02-04 23:29:35 +00:00
Subs.BuiEvents<GeneralStationRecordConsoleComponent>(GeneralStationRecordConsoleKey.Key, subs =>
{
subs.Event<BoundUIOpenedEvent>(UpdateUserInterface);
subs.Event<SelectStationRecord>(OnKeySelected);
subs.Event<SetStationRecordFilter>(OnFiltersChanged);
});
}
2024-02-04 23:29:35 +00:00
private void UpdateUserInterface<T>(Entity<GeneralStationRecordConsoleComponent> ent, ref T args)
{
2024-02-04 23:29:35 +00:00
UpdateUserInterface(ent);
}
2024-02-04 23:29:35 +00:00
// TODO: instead of copy paste shitcode for each record console, have a shared records console comp they all use
// then have this somehow play nicely with creating ui state
// if that gets done put it in StationRecordsSystem console helpers section :)
private void OnKeySelected(Entity<GeneralStationRecordConsoleComponent> ent, ref SelectStationRecord msg)
{
2024-02-04 23:29:35 +00:00
ent.Comp.ActiveKey = msg.SelectedKey;
UpdateUserInterface(ent);
}
2024-02-04 23:29:35 +00:00
private void OnFiltersChanged(Entity<GeneralStationRecordConsoleComponent> ent, ref SetStationRecordFilter msg)
Fingerprints filter for records station computer (#15017) * add new labels and buttons for records stantion console * add fingerprint fields for server * set buttons and updates for fingerPrints filters * set fingerprints filters * final set for finger prints filters * add new trhaslates for station records computer * some fix for the PR * refactor server side station record console system * add message for filters * add tranlates * add new ui with several filters * updetes prints with server side logic * resolve conflicts with DNA * resolve conflicts with DNA * deleted unused variable and rename some fields * added description for new state * added select for filter * set multiplay filters for the console * added new translates * add class filters & fixed issue with reset line edit * fix dublicate with set the selectId for option button * fixed review notes * fixed review notes forget changet fix name * add event TextEntered for better usability * fixed review notes 3 * fixed formating in xaml * fixed array with _filterTypes * fixed ui and made it in minimalistic style * fixed generalstationRecordFilter class, move method * delete margin after line edit * fix placeholder for lineEdit * fix placeholder for lineEdit, the review note * Revert "fixed generalstationRecordFilter class, move method" This reverts commit 1b35c6ac44e7dafe9a1f0560eb177152b822f20b. * impliment short swith in method IsSkippedRecord * fixed review notes, remaked method IsSkipped and fix casing * fixed the review note about check null record name
2023-04-12 17:27:13 +03:00
{
2024-02-04 23:29:35 +00:00
if (ent.Comp.Filter == null ||
ent.Comp.Filter.Type != msg.Type || ent.Comp.Filter.Value != msg.Value)
Fingerprints filter for records station computer (#15017) * add new labels and buttons for records stantion console * add fingerprint fields for server * set buttons and updates for fingerPrints filters * set fingerprints filters * final set for finger prints filters * add new trhaslates for station records computer * some fix for the PR * refactor server side station record console system * add message for filters * add tranlates * add new ui with several filters * updetes prints with server side logic * resolve conflicts with DNA * resolve conflicts with DNA * deleted unused variable and rename some fields * added description for new state * added select for filter * set multiplay filters for the console * added new translates * add class filters & fixed issue with reset line edit * fix dublicate with set the selectId for option button * fixed review notes * fixed review notes forget changet fix name * add event TextEntered for better usability * fixed review notes 3 * fixed formating in xaml * fixed array with _filterTypes * fixed ui and made it in minimalistic style * fixed generalstationRecordFilter class, move method * delete margin after line edit * fix placeholder for lineEdit * fix placeholder for lineEdit, the review note * Revert "fixed generalstationRecordFilter class, move method" This reverts commit 1b35c6ac44e7dafe9a1f0560eb177152b822f20b. * impliment short swith in method IsSkippedRecord * fixed review notes, remaked method IsSkipped and fix casing * fixed the review note about check null record name
2023-04-12 17:27:13 +03:00
{
2024-02-04 23:29:35 +00:00
ent.Comp.Filter = new StationRecordsFilter(msg.Type, msg.Value);
UpdateUserInterface(ent);
Fingerprints filter for records station computer (#15017) * add new labels and buttons for records stantion console * add fingerprint fields for server * set buttons and updates for fingerPrints filters * set fingerprints filters * final set for finger prints filters * add new trhaslates for station records computer * some fix for the PR * refactor server side station record console system * add message for filters * add tranlates * add new ui with several filters * updetes prints with server side logic * resolve conflicts with DNA * resolve conflicts with DNA * deleted unused variable and rename some fields * added description for new state * added select for filter * set multiplay filters for the console * added new translates * add class filters & fixed issue with reset line edit * fix dublicate with set the selectId for option button * fixed review notes * fixed review notes forget changet fix name * add event TextEntered for better usability * fixed review notes 3 * fixed formating in xaml * fixed array with _filterTypes * fixed ui and made it in minimalistic style * fixed generalstationRecordFilter class, move method * delete margin after line edit * fix placeholder for lineEdit * fix placeholder for lineEdit, the review note * Revert "fixed generalstationRecordFilter class, move method" This reverts commit 1b35c6ac44e7dafe9a1f0560eb177152b822f20b. * impliment short swith in method IsSkippedRecord * fixed review notes, remaked method IsSkipped and fix casing * fixed the review note about check null record name
2023-04-12 17:27:13 +03:00
}
}
2024-02-04 23:29:35 +00:00
private void UpdateUserInterface(Entity<GeneralStationRecordConsoleComponent> ent)
{
2024-02-04 23:29:35 +00:00
var (uid, console) = ent;
var owningStation = _station.GetOwningStation(uid);
2024-02-04 23:29:35 +00:00
if (!TryComp<StationRecordsComponent>(owningStation, out var stationRecords))
{
2024-02-04 23:29:35 +00:00
_ui.TrySetUiState(uid, GeneralStationRecordConsoleKey.Key, new GeneralStationRecordConsoleState());
return;
}
2024-02-04 23:29:35 +00:00
var listing = _stationRecords.BuildListing((owningStation.Value, stationRecords), console.Filter);
Fingerprints filter for records station computer (#15017) * add new labels and buttons for records stantion console * add fingerprint fields for server * set buttons and updates for fingerPrints filters * set fingerprints filters * final set for finger prints filters * add new trhaslates for station records computer * some fix for the PR * refactor server side station record console system * add message for filters * add tranlates * add new ui with several filters * updetes prints with server side logic * resolve conflicts with DNA * resolve conflicts with DNA * deleted unused variable and rename some fields * added description for new state * added select for filter * set multiplay filters for the console * added new translates * add class filters & fixed issue with reset line edit * fix dublicate with set the selectId for option button * fixed review notes * fixed review notes forget changet fix name * add event TextEntered for better usability * fixed review notes 3 * fixed formating in xaml * fixed array with _filterTypes * fixed ui and made it in minimalistic style * fixed generalstationRecordFilter class, move method * delete margin after line edit * fix placeholder for lineEdit * fix placeholder for lineEdit, the review note * Revert "fixed generalstationRecordFilter class, move method" This reverts commit 1b35c6ac44e7dafe9a1f0560eb177152b822f20b. * impliment short swith in method IsSkippedRecord * fixed review notes, remaked method IsSkipped and fix casing * fixed the review note about check null record name
2023-04-12 17:27:13 +03:00
2024-02-04 23:29:35 +00:00
switch (listing.Count)
{
2024-02-04 23:29:35 +00:00
case 0:
_ui.TrySetUiState(uid, GeneralStationRecordConsoleKey.Key, new GeneralStationRecordConsoleState());
return;
case 1:
console.ActiveKey = listing.Keys.First();
break;
}
2024-02-04 23:29:35 +00:00
if (console.ActiveKey is not { } id)
return;
2024-02-04 23:29:35 +00:00
var key = new StationRecordKey(id, owningStation.Value);
_stationRecords.TryGetRecord<GeneralStationRecord>(key, out var record, stationRecords);
2024-02-04 23:29:35 +00:00
GeneralStationRecordConsoleState newState = new(id, record, listing, console.Filter);
_ui.TrySetUiState(uid, GeneralStationRecordConsoleKey.Key, newState);
}
}