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
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Shared.StationRecords;
|
||||
using Robust.Server.GameObjects;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.StationRecords.Systems;
|
||||
|
||||
@@ -14,6 +15,7 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
|
||||
{
|
||||
SubscribeLocalEvent<GeneralStationRecordConsoleComponent, BoundUIOpenedEvent>(UpdateUserInterface);
|
||||
SubscribeLocalEvent<GeneralStationRecordConsoleComponent, SelectGeneralStationRecord>(OnKeySelected);
|
||||
SubscribeLocalEvent<GeneralStationRecordConsoleComponent, GeneralStationRecordsFilterMsg>(OnFiltersChanged);
|
||||
SubscribeLocalEvent<GeneralStationRecordConsoleComponent, RecordModifiedEvent>(UpdateUserInterface);
|
||||
SubscribeLocalEvent<GeneralStationRecordConsoleComponent, AfterGeneralRecordCreatedEvent>(UpdateUserInterface);
|
||||
}
|
||||
@@ -30,7 +32,19 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
|
||||
UpdateUserInterface(uid, component);
|
||||
}
|
||||
|
||||
private void UpdateUserInterface(EntityUid uid, GeneralStationRecordConsoleComponent? console = null)
|
||||
private void OnFiltersChanged(EntityUid uid,
|
||||
GeneralStationRecordConsoleComponent component, GeneralStationRecordsFilterMsg msg)
|
||||
{
|
||||
if (component.Filter == null ||
|
||||
component.Filter.Type != msg.Type || component.Filter.Value != msg.Value)
|
||||
{
|
||||
component.Filter = new GeneralStationRecordsFilter(msg.Type, msg.Value);
|
||||
UpdateUserInterface(uid, component);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateUserInterface(EntityUid uid,
|
||||
GeneralStationRecordConsoleComponent? console = null)
|
||||
{
|
||||
if (!Resolve(uid, ref console))
|
||||
{
|
||||
@@ -39,27 +53,39 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
|
||||
|
||||
var owningStation = _stationSystem.GetOwningStation(uid);
|
||||
|
||||
|
||||
|
||||
if (!TryComp<StationRecordsComponent>(owningStation, out var stationRecordsComponent))
|
||||
{
|
||||
_userInterface.GetUiOrNull(uid, GeneralStationRecordConsoleKey.Key)?.SetState(new GeneralStationRecordConsoleState(null, null, null));
|
||||
GeneralStationRecordConsoleState state = new(null, null, null, null);
|
||||
SetStateForInterface(uid, state);
|
||||
return;
|
||||
}
|
||||
|
||||
var enumerator = _stationRecordsSystem.GetRecordsOfType<GeneralStationRecord>(owningStation.Value, stationRecordsComponent);
|
||||
var consoleRecords =
|
||||
_stationRecordsSystem.GetRecordsOfType<GeneralStationRecord>(owningStation.Value, stationRecordsComponent);
|
||||
|
||||
var listing = new Dictionary<StationRecordKey, string>();
|
||||
foreach (var pair in enumerator)
|
||||
|
||||
foreach (var pair in consoleRecords)
|
||||
{
|
||||
if (console != null && console.Filter != null
|
||||
&& IsSkippedRecord(console.Filter, pair.Item2))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
listing.Add(pair.Item1, pair.Item2.Name);
|
||||
}
|
||||
|
||||
if (listing.Count == 0)
|
||||
{
|
||||
_userInterface.GetUiOrNull(uid, GeneralStationRecordConsoleKey.Key)?.SetState(new GeneralStationRecordConsoleState(null, null, null));
|
||||
GeneralStationRecordConsoleState state = new(null, null, null, console.Filter);
|
||||
SetStateForInterface(uid, state);
|
||||
return;
|
||||
}
|
||||
else if (listing.Count == 1)
|
||||
{
|
||||
console.ActiveKey = listing.Keys.First();
|
||||
}
|
||||
|
||||
GeneralStationRecord? record = null;
|
||||
if (console.ActiveKey != null)
|
||||
@@ -68,8 +94,41 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
|
||||
stationRecordsComponent);
|
||||
}
|
||||
|
||||
GeneralStationRecordConsoleState newState = new(console.ActiveKey, record, listing, console.Filter);
|
||||
SetStateForInterface(uid, newState);
|
||||
}
|
||||
|
||||
private void SetStateForInterface(EntityUid uid, GeneralStationRecordConsoleState newState)
|
||||
{
|
||||
_userInterface
|
||||
.GetUiOrNull(uid, GeneralStationRecordConsoleKey.Key)?
|
||||
.SetState(new GeneralStationRecordConsoleState(console.ActiveKey, record, listing));
|
||||
.GetUiOrNull(uid, GeneralStationRecordConsoleKey.Key)
|
||||
?.SetState(newState);
|
||||
}
|
||||
|
||||
private bool IsSkippedRecord(GeneralStationRecordsFilter filter,
|
||||
GeneralStationRecord someRecord)
|
||||
{
|
||||
bool isFilter = filter.Value.Length > 0;
|
||||
string filterLowerCaseValue = "";
|
||||
|
||||
if (!isFilter)
|
||||
return false;
|
||||
|
||||
filterLowerCaseValue = filter.Value.ToLower();
|
||||
|
||||
return filter.Type switch
|
||||
{
|
||||
GeneralStationRecordFilterType.Name =>
|
||||
!someRecord.Name.ToLower().Contains(filterLowerCaseValue),
|
||||
GeneralStationRecordFilterType.Prints => someRecord.Fingerprint != null
|
||||
&& IsFilterWithSomeCodeValue(someRecord.Fingerprint, filterLowerCaseValue),
|
||||
GeneralStationRecordFilterType.DNA => someRecord.DNA != null
|
||||
&& IsFilterWithSomeCodeValue(someRecord.DNA, filterLowerCaseValue),
|
||||
};
|
||||
}
|
||||
|
||||
private bool IsFilterWithSomeCodeValue(string value, string filter)
|
||||
{
|
||||
return !value.ToLower().StartsWith(filter);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user