forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
criminal records revival (space-wizards#22510)
- Loading branch information
1 parent
c856dd7
commit 683591a
Showing
34 changed files
with
1,550 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
105 changes: 105 additions & 0 deletions
105
Content.Client/CriminalRecords/CrimeHistoryWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
Content.Client/CriminalRecords/CriminalRecordsConsoleBoundUserInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Content.Client/CriminalRecords/CriminalRecordsConsoleWindow.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Oops, something went wrong.