-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1869 from space-syndicate/upstream-sync
Upstream sync
- Loading branch information
Showing
742 changed files
with
13,476 additions
and
8,715 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
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
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
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
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
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
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> |
107 changes: 107 additions & 0 deletions
107
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,107 @@ | ||
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 _maxLength; | ||
private uint? _index; | ||
private DialogWindow? _dialog; | ||
|
||
public CrimeHistoryWindow(uint maxLength) | ||
{ | ||
RobustXamlLoader.Load(this); | ||
|
||
_maxLength = maxLength; | ||
|
||
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]; | ||
if (line.Length < 1 || line.Length > _maxLength) | ||
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; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
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,81 @@ | ||
using Content.Shared.Access.Systems; | ||
using Content.Shared.CriminalRecords; | ||
using Content.Shared.CriminalRecords.Components; | ||
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(); | ||
|
||
var comp = EntMan.GetComponent<CriminalRecordsConsoleComponent>(Owner); | ||
|
||
_window = new(Owner, comp.MaxStringLength, _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(comp.MaxStringLength); | ||
_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(); | ||
} | ||
} |
Oops, something went wrong.