criminal records revival (#22510)

This commit is contained in:
deltanedas
2024-02-04 23:29:35 +00:00
committed by GitHub
parent c856dd7506
commit 683591ab04
34 changed files with 1564 additions and 339 deletions

View File

@@ -0,0 +1,15 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'criminal-records-console-crime-history'}"
MinSize="660 400">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" Margin="5">
<BoxContainer Name="Editing" Orientation="Horizontal" HorizontalExpand="True" Align="Center" Margin="5">
<Button Name="AddButton" Text="{Loc 'criminal-records-add-history'}"/>
<Button Name="DeleteButton" Text="{Loc 'criminal-records-delete-history'}" Disabled="True"/>
</BoxContainer>
<Label Name="NoHistory" Text="{Loc 'criminal-records-no-history'}" HorizontalExpand="True" HorizontalAlignment="Center"/>
<ScrollContainer VerticalExpand="True">
<ItemList Name="History"/> <!-- Populated when window opened -->
</ScrollContainer>
</BoxContainer>
</controls:FancyWindow>

View File

@@ -0,0 +1,105 @@
using Content.Shared.Administration;
using Content.Shared.CriminalRecords;
using Content.Client.UserInterface.Controls;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.CriminalRecords;
/// <summary>
/// Window opened when Crime History button is pressed
/// </summary>
[GenerateTypedNameReferences]
public sealed partial class CrimeHistoryWindow : FancyWindow
{
public Action<string>? OnAddHistory;
public Action<uint>? OnDeleteHistory;
private uint? _index;
private DialogWindow? _dialog;
public CrimeHistoryWindow()
{
RobustXamlLoader.Load(this);
OnClose += () =>
{
_dialog?.Close();
// deselect so when reopening the window it doesnt try to use invalid index
_index = null;
};
AddButton.OnPressed += _ =>
{
if (_dialog != null)
{
_dialog.MoveToFront();
return;
}
var field = "line";
var prompt = Loc.GetString("criminal-records-console-reason");
var placeholder = Loc.GetString("criminal-records-history-placeholder");
var entry = new QuickDialogEntry(field, QuickDialogEntryType.LongText, prompt, placeholder);
var entries = new List<QuickDialogEntry> { entry };
_dialog = new DialogWindow(Title!, entries);
_dialog.OnConfirmed += responses =>
{
var line = responses[field];
// TODO: whenever the console is moved to shared unhardcode this
if (line.Length < 1 || line.Length > 256)
return;
OnAddHistory?.Invoke(line);
// adding deselects so prevent deleting yeah
_index = null;
DeleteButton.Disabled = true;
};
// prevent MoveToFront being called on a closed window and double closing
_dialog.OnClose += () => { _dialog = null; };
};
DeleteButton.OnPressed += _ =>
{
if (_index is not {} index)
return;
OnDeleteHistory?.Invoke(index);
// prevent total spam wiping
History.ClearSelected();
_index = null;
DeleteButton.Disabled = true;
};
History.OnItemSelected += args =>
{
_index = (uint) args.ItemIndex;
DeleteButton.Disabled = false;
};
History.OnItemDeselected += args =>
{
_index = null;
DeleteButton.Disabled = true;
};
}
public void UpdateHistory(CriminalRecord record, bool access)
{
History.Clear();
Editing.Visible = access;
NoHistory.Visible = record.History.Count == 0;
foreach (var entry in record.History)
{
var time = entry.AddTime;
var line = $"{time.Hours:00}:{time.Minutes:00}:{time.Seconds:00} - {entry.Crime}";
History.AddItem(line);
}
// deselect if something goes wrong
if (_index is {} index && record.History.Count >= index)
_index = null;
}
}

View File

@@ -0,0 +1,78 @@
using Content.Shared.Access.Systems;
using Content.Shared.CriminalRecords;
using Content.Shared.Security;
using Content.Shared.StationRecords;
using Robust.Client.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Client.CriminalRecords;
public sealed class CriminalRecordsConsoleBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
private readonly AccessReaderSystem _accessReader;
private CriminalRecordsConsoleWindow? _window;
private CrimeHistoryWindow? _historyWindow;
public CriminalRecordsConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_accessReader = EntMan.System<AccessReaderSystem>();
}
protected override void Open()
{
base.Open();
_window = new(Owner, _playerManager, _proto, _random, _accessReader);
_window.OnKeySelected += key =>
SendMessage(new SelectStationRecord(key));
_window.OnFiltersChanged += (type, filterValue) =>
SendMessage(new SetStationRecordFilter(type, filterValue));
_window.OnStatusSelected += status =>
SendMessage(new CriminalRecordChangeStatus(status, null));
_window.OnDialogConfirmed += (_, reason) =>
SendMessage(new CriminalRecordChangeStatus(SecurityStatus.Wanted, reason));
_window.OnHistoryUpdated += UpdateHistory;
_window.OnHistoryClosed += () => _historyWindow?.Close();
_window.OnClose += Close;
_historyWindow = new();
_historyWindow.OnAddHistory += line => SendMessage(new CriminalRecordAddHistory(line));
_historyWindow.OnDeleteHistory += index => SendMessage(new CriminalRecordDeleteHistory(index));
_historyWindow.Close(); // leave closed until user opens it
}
/// <summary>
/// Updates or opens a new history window.
/// </summary>
private void UpdateHistory(CriminalRecord record, bool access, bool open)
{
_historyWindow!.UpdateHistory(record, access);
if (open)
_historyWindow.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is not CriminalRecordsConsoleState cast)
return;
_window?.UpdateState(cast);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_window?.Close();
_historyWindow?.Close();
}
}

View File

@@ -0,0 +1,37 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'criminal-records-console-window-title'}"
MinSize="660 400">
<BoxContainer Orientation="Vertical">
<!-- Record search bar
TODO: make this into a control shared with general records -->
<BoxContainer Margin="5 5 5 10" HorizontalExpand="true" VerticalAlignment="Center">
<OptionButton Name="FilterType" MinWidth="200" Margin="0 0 10 0"/> <!-- Populated in constructor -->
<LineEdit Name="FilterText" PlaceHolder="{Loc 'criminal-records-filter-placeholder'}" HorizontalExpand="True"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal" VerticalExpand="True">
<!-- Record listing -->
<BoxContainer Orientation="Vertical" Margin="5" MinWidth="250" MaxWidth="250">
<Label Name="RecordListingTitle" Text="{Loc 'criminal-records-console-records-list-title'}" HorizontalExpand="True" Align="Center"/>
<Label Name="NoRecords" Text="{Loc 'criminal-records-console-no-records'}" HorizontalExpand="True" Align="Center" FontColorOverride="DarkGray"/>
<ScrollContainer VerticalExpand="True">
<ItemList Name="RecordListing"/> <!-- Populated when loading state -->
</ScrollContainer>
</BoxContainer>
<Label Name="RecordUnselected" Text="{Loc 'criminal-records-console-select-record-info'}" HorizontalExpand="True" Align="Center" FontColorOverride="DarkGray"/>
<!-- Selected record info -->
<BoxContainer Name="PersonContainer" Orientation="Vertical" Margin="5" Visible="False">
<Label Name="PersonName" StyleClasses="LabelBig"/>
<Label Name="PersonPrints"/>
<Label Name="PersonDna"/>
<PanelContainer StyleClasses="LowDivider" Margin="0 5 0 5" />
<BoxContainer Orientation="Horizontal" Margin="5 5 5 5">
<Label Name="StatusLabel" Text="{Loc 'criminal-records-console-status'}" FontColorOverride="DarkGray"/>
<OptionButton Name="StatusOptionButton"/> <!-- Populated in constructor -->
</BoxContainer>
<RichTextLabel Name="WantedReason" Visible="False"/>
<Button Name="HistoryButton" Text="{Loc 'criminal-records-console-crime-history'}"/>
</BoxContainer>
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>

View File

@@ -0,0 +1,263 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.Access.Systems;
using Content.Shared.Administration;
using Content.Shared.CriminalRecords;
using Content.Shared.Dataset;
using Content.Shared.Security;
using Content.Shared.StationRecords;
using Robust.Client.AutoGenerated;
using Robust.Client.Player;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;
namespace Content.Client.CriminalRecords;
// TODO: dedupe shitcode from general records theres a lot
[GenerateTypedNameReferences]
public sealed partial class CriminalRecordsConsoleWindow : FancyWindow
{
private readonly IPlayerManager _player;
private readonly IPrototypeManager _proto;
private readonly IRobustRandom _random;
private readonly AccessReaderSystem _accessReader;
public readonly EntityUid Console;
[ValidatePrototypeId<DatasetPrototype>]
private const string ReasonPlaceholders = "CriminalRecordsWantedReasonPlaceholders";
public Action<uint?>? OnKeySelected;
public Action<StationRecordFilterType, string>? OnFiltersChanged;
public Action<SecurityStatus>? OnStatusSelected;
public Action<CriminalRecord, bool, bool>? OnHistoryUpdated;
public Action? OnHistoryClosed;
public Action<SecurityStatus, string>? OnDialogConfirmed;
private bool _isPopulating;
private bool _access;
private uint? _selectedKey;
private CriminalRecord? _selectedRecord;
private DialogWindow? _reasonDialog;
private StationRecordFilterType _currentFilterType;
public CriminalRecordsConsoleWindow(EntityUid console, IPlayerManager playerManager, IPrototypeManager prototypeManager, IRobustRandom robustRandom, AccessReaderSystem accessReader)
{
RobustXamlLoader.Load(this);
Console = console;
_player = playerManager;
_proto = prototypeManager;
_random = robustRandom;
_accessReader = accessReader;
_currentFilterType = StationRecordFilterType.Name;
OpenCentered();
foreach (var item in Enum.GetValues<StationRecordFilterType>())
{
FilterType.AddItem(GetTypeFilterLocals(item), (int)item);
}
foreach (var status in Enum.GetValues<SecurityStatus>())
{
AddStatusSelect(status);
}
OnClose += () => _reasonDialog?.Close();
RecordListing.OnItemSelected += args =>
{
if (_isPopulating || RecordListing[args.ItemIndex].Metadata is not uint cast)
return;
OnKeySelected?.Invoke(cast);
};
RecordListing.OnItemDeselected += _ =>
{
if (!_isPopulating)
OnKeySelected?.Invoke(null);
};
FilterType.OnItemSelected += eventArgs =>
{
var type = (StationRecordFilterType)eventArgs.Id;
if (_currentFilterType != type)
{
_currentFilterType = type;
FilterListingOfRecords(FilterText.Text);
}
};
FilterText.OnTextEntered += args =>
{
FilterListingOfRecords(args.Text);
};
StatusOptionButton.OnItemSelected += args =>
{
SetStatus((SecurityStatus) args.Id);
};
HistoryButton.OnPressed += _ =>
{
if (_selectedRecord is {} record)
OnHistoryUpdated?.Invoke(record, _access, true);
};
}
public void UpdateState(CriminalRecordsConsoleState state)
{
if (state.Filter != null)
{
if (state.Filter.Type != _currentFilterType)
{
_currentFilterType = state.Filter.Type;
}
if (state.Filter.Value != FilterText.Text)
{
FilterText.Text = state.Filter.Value;
}
}
_selectedKey = state.SelectedKey;
FilterType.SelectId((int)_currentFilterType);
// set up the records listing panel
RecordListing.Clear();
var hasRecords = state.RecordListing != null && state.RecordListing.Count > 0;
NoRecords.Visible = !hasRecords;
if (hasRecords)
PopulateRecordListing(state.RecordListing!);
// set up the selected person's record
var selected = _selectedKey != null;
PersonContainer.Visible = selected;
RecordUnselected.Visible = !selected;
_access = _player.LocalSession?.AttachedEntity is {} player
&& _accessReader.IsAllowed(player, Console);
// hide access-required editing parts when no access
var editing = _access && selected;
StatusOptionButton.Disabled = !editing;
if (state is { CriminalRecord: not null, StationRecord: not null })
{
PopulateRecordContainer(state.StationRecord, state.CriminalRecord);
OnHistoryUpdated?.Invoke(state.CriminalRecord, _access, false);
_selectedRecord = state.CriminalRecord;
}
else
{
_selectedRecord = null;
OnHistoryClosed?.Invoke();
}
}
private void PopulateRecordListing(Dictionary<uint, string> listing)
{
_isPopulating = true;
foreach (var (key, name) in listing)
{
var item = RecordListing.AddItem(name);
item.Metadata = key;
item.Selected = key == _selectedKey;
}
_isPopulating = false;
RecordListing.SortItemsByText();
}
private void PopulateRecordContainer(GeneralStationRecord stationRecord, CriminalRecord criminalRecord)
{
var na = Loc.GetString("generic-not-available-shorthand");
PersonName.Text = stationRecord.Name;
PersonPrints.Text = Loc.GetString("general-station-record-console-record-fingerprint", ("fingerprint", stationRecord.Fingerprint ?? na));
PersonDna.Text = Loc.GetString("general-station-record-console-record-dna", ("dna", stationRecord.DNA ?? na));
StatusOptionButton.SelectId((int) criminalRecord.Status);
if (criminalRecord.Reason is {} reason)
{
var message = FormattedMessage.FromMarkup(Loc.GetString("criminal-records-console-wanted-reason"));
message.AddText($": {reason}");
WantedReason.SetMessage(message);
WantedReason.Visible = true;
}
else
{
WantedReason.Visible = false;
}
}
private void AddStatusSelect(SecurityStatus status)
{
var name = Loc.GetString($"criminal-records-status-{status.ToString().ToLower()}");
StatusOptionButton.AddItem(name, (int)status);
}
private void FilterListingOfRecords(string text = "")
{
if (!_isPopulating)
{
OnFiltersChanged?.Invoke(_currentFilterType, text);
}
}
private void SetStatus(SecurityStatus status)
{
if (status == SecurityStatus.Wanted)
{
GetWantedReason();
return;
}
OnStatusSelected?.Invoke(status);
}
private void GetWantedReason()
{
if (_reasonDialog != null)
{
_reasonDialog.MoveToFront();
return;
}
var field = "reason";
var title = Loc.GetString("criminal-records-status-wanted");
var placeholders = _proto.Index<DatasetPrototype>(ReasonPlaceholders);
var placeholder = Loc.GetString("criminal-records-console-reason-placeholder", ("placeholder", _random.Pick(placeholders.Values))); // just funny it doesn't actually get used
var prompt = Loc.GetString("criminal-records-console-reason");
var entry = new QuickDialogEntry(field, QuickDialogEntryType.LongText, prompt, placeholder);
var entries = new List<QuickDialogEntry>() { entry };
_reasonDialog = new DialogWindow(title, entries);
_reasonDialog.OnConfirmed += responses =>
{
var reason = responses[field];
// TODO: same as history unhardcode
if (reason.Length < 1 || reason.Length > 256)
return;
OnDialogConfirmed?.Invoke(SecurityStatus.Wanted, reason);
};
_reasonDialog.OnClose += () => { _reasonDialog = null; };
}
private string GetTypeFilterLocals(StationRecordFilterType type)
{
return Loc.GetString($"criminal-records-{type.ToString().ToLower()}-filter");
}
}

View File

@@ -1,5 +1,4 @@
using Content.Shared.StationRecords;
using Robust.Client.GameObjects;
namespace Content.Client.StationRecords;
@@ -17,33 +16,21 @@ public sealed class GeneralStationRecordConsoleBoundUserInterface : BoundUserInt
base.Open();
_window = new();
_window.OnKeySelected += OnKeySelected;
_window.OnFiltersChanged += OnFiltersChanged;
_window.OnKeySelected += key =>
SendMessage(new SelectStationRecord(key));
_window.OnFiltersChanged += (type, filterValue) =>
SendMessage(new SetStationRecordFilter(type, filterValue));
_window.OnClose += Close;
_window.OpenCentered();
}
private void OnKeySelected((NetEntity, uint)? key)
{
SendMessage(new SelectGeneralStationRecord(key));
}
private void OnFiltersChanged(
GeneralStationRecordFilterType type, string filterValue)
{
GeneralStationRecordsFilterMsg msg = new(type, filterValue);
SendMessage(msg);
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is not GeneralStationRecordConsoleState cast)
{
return;
}
_window?.UpdateState(cast);
}

View File

@@ -1,4 +1,3 @@
using System.Linq;
using Content.Shared.StationRecords;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
@@ -11,31 +10,29 @@ namespace Content.Client.StationRecords;
[GenerateTypedNameReferences]
public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
{
public Action<(NetEntity, uint)?>? OnKeySelected;
public Action<uint?>? OnKeySelected;
public Action<GeneralStationRecordFilterType, string>? OnFiltersChanged;
public Action<StationRecordFilterType, string>? OnFiltersChanged;
private bool _isPopulating;
private GeneralStationRecordFilterType _currentFilterType;
private StationRecordFilterType _currentFilterType;
public GeneralStationRecordConsoleWindow()
{
RobustXamlLoader.Load(this);
_currentFilterType = GeneralStationRecordFilterType.Name;
_currentFilterType = StationRecordFilterType.Name;
foreach (var item in Enum.GetValues<GeneralStationRecordFilterType>())
foreach (var item in Enum.GetValues<StationRecordFilterType>())
{
StationRecordsFilterType.AddItem(GetTypeFilterLocals(item), (int)item);
}
RecordListing.OnItemSelected += args =>
{
if (_isPopulating || RecordListing[args.ItemIndex].Metadata is not ValueTuple<NetEntity, uint> cast)
{
if (_isPopulating || RecordListing[args.ItemIndex].Metadata is not uint cast)
return;
}
OnKeySelected?.Invoke(cast);
};
@@ -48,7 +45,7 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
StationRecordsFilterType.OnItemSelected += eventArgs =>
{
var type = (GeneralStationRecordFilterType)eventArgs.Id;
var type = (StationRecordFilterType) eventArgs.Id;
if (_currentFilterType != type)
{
@@ -123,7 +120,7 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
RecordContainer.RemoveAllChildren();
}
}
private void PopulateRecordListing(Dictionary<(NetEntity, uint), string> listing, (NetEntity, uint)? selected)
private void PopulateRecordListing(Dictionary<uint, string> listing, uint? selected)
{
RecordListing.Clear();
RecordListing.ClearSelected();
@@ -134,10 +131,7 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
{
var item = RecordListing.AddItem(name);
item.Metadata = key;
if (selected != null && key.Item1 == selected.Value.Item1 && key.Item2 == selected.Value.Item2)
{
item.Selected = true;
}
item.Selected = key == selected;
}
_isPopulating = false;
@@ -197,7 +191,7 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
}
}
private string GetTypeFilterLocals(GeneralStationRecordFilterType type)
private string GetTypeFilterLocals(StationRecordFilterType type)
{
return Loc.GetString($"general-station-record-{type.ToString().ToLower()}-filter");
}