From c8b55e5e449fc4f43206c3a6a5a84ef53023cd18 Mon Sep 17 00:00:00 2001
From: nikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com>
Date: Sun, 12 May 2024 15:07:54 +0000
Subject: [PATCH] Record deletion (#27883)
* Allow for Station Records interface for aghosts to delete records
* Fix record consoles not working when there are more than 2 crew members.
HOW DID NOONE NOTICE THIS SOONER???
* Stop being unconventional
---
.../StationRecords/GeneralRecord.xaml | 13 +++++
.../StationRecords/GeneralRecord.xaml.cs | 33 ++++++++++++
...lStationRecordConsoleBoundUserInterface.cs | 1 +
.../GeneralStationRecordConsoleWindow.xaml | 2 +-
.../GeneralStationRecordConsoleWindow.xaml.cs | 51 +++----------------
.../GeneralStationRecordConsoleComponent.cs | 6 +++
.../GeneralStationRecordConsoleSystem.cs | 20 ++++++--
.../StationRecords/GeneralRecordsUi.cs | 23 +++++++--
.../general-station-records.ftl | 1 +
.../Entities/Mobs/Player/admin_ghost.yml | 1 +
10 files changed, 100 insertions(+), 51 deletions(-)
create mode 100644 Content.Client/StationRecords/GeneralRecord.xaml
create mode 100644 Content.Client/StationRecords/GeneralRecord.xaml.cs
diff --git a/Content.Client/StationRecords/GeneralRecord.xaml b/Content.Client/StationRecords/GeneralRecord.xaml
new file mode 100644
index 0000000000..add688c3f3
--- /dev/null
+++ b/Content.Client/StationRecords/GeneralRecord.xaml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Content.Client/StationRecords/GeneralRecord.xaml.cs b/Content.Client/StationRecords/GeneralRecord.xaml.cs
new file mode 100644
index 0000000000..6a2622fba9
--- /dev/null
+++ b/Content.Client/StationRecords/GeneralRecord.xaml.cs
@@ -0,0 +1,33 @@
+using Content.Shared.StationRecords;
+using Robust.Client.AutoGenerated;
+using Robust.Client.UserInterface;
+using Robust.Client.UserInterface.XAML;
+
+namespace Content.Client.StationRecords;
+
+[GenerateTypedNameReferences]
+public sealed partial class GeneralRecord : Control
+{
+ public Action? OnDeletePressed;
+ public GeneralRecord(GeneralStationRecord record, bool canDelete, uint? id)
+ {
+ RobustXamlLoader.Load(this);
+ RecordName.Text = record.Name;
+ Age.Text = Loc.GetString("general-station-record-console-record-age", ("age", record.Age.ToString()));
+ Title.Text = Loc.GetString("general-station-record-console-record-title",
+ ("job", Loc.GetString(record.JobTitle)));
+ Species.Text = Loc.GetString("general-station-record-console-record-species", ("species", record.Species));
+ Gender.Text = Loc.GetString("general-station-record-console-record-gender",
+ ("gender", record.Gender.ToString()));
+ Fingerprint.Text = Loc.GetString("general-station-record-console-record-fingerprint",
+ ("fingerprint", record.Fingerprint ?? Loc.GetString("generic-not-available-shorthand")));
+ Dna.Text = Loc.GetString("general-station-record-console-record-dna",
+ ("dna", record.DNA ?? Loc.GetString("generic-not-available-shorthand")));
+
+ if (canDelete && id != null )
+ {
+ DeleteButton.Visible = true;
+ DeleteButton.OnPressed += _ => OnDeletePressed?.Invoke(id.Value);
+ }
+ }
+}
diff --git a/Content.Client/StationRecords/GeneralStationRecordConsoleBoundUserInterface.cs b/Content.Client/StationRecords/GeneralStationRecordConsoleBoundUserInterface.cs
index 3be3d98778..720a2efb9d 100644
--- a/Content.Client/StationRecords/GeneralStationRecordConsoleBoundUserInterface.cs
+++ b/Content.Client/StationRecords/GeneralStationRecordConsoleBoundUserInterface.cs
@@ -20,6 +20,7 @@ public sealed class GeneralStationRecordConsoleBoundUserInterface : BoundUserInt
SendMessage(new SelectStationRecord(key));
_window.OnFiltersChanged += (type, filterValue) =>
SendMessage(new SetStationRecordFilter(type, filterValue));
+ _window.OnDeleted += id => SendMessage(new DeleteStationRecord(id));
_window.OnClose += Close;
_window.OpenCentered();
diff --git a/Content.Client/StationRecords/GeneralStationRecordConsoleWindow.xaml b/Content.Client/StationRecords/GeneralStationRecordConsoleWindow.xaml
index a915d329bc..3615eb8e00 100644
--- a/Content.Client/StationRecords/GeneralStationRecordConsoleWindow.xaml
+++ b/Content.Client/StationRecords/GeneralStationRecordConsoleWindow.xaml
@@ -19,7 +19,7 @@
-
+
diff --git a/Content.Client/StationRecords/GeneralStationRecordConsoleWindow.xaml.cs b/Content.Client/StationRecords/GeneralStationRecordConsoleWindow.xaml.cs
index fbdd6c2f0b..272e6c3b25 100644
--- a/Content.Client/StationRecords/GeneralStationRecordConsoleWindow.xaml.cs
+++ b/Content.Client/StationRecords/GeneralStationRecordConsoleWindow.xaml.cs
@@ -1,7 +1,5 @@
using Content.Shared.StationRecords;
using Robust.Client.AutoGenerated;
-using Robust.Client.UserInterface;
-using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
@@ -13,6 +11,7 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
public Action? OnKeySelected;
public Action? OnFiltersChanged;
+ public Action? OnDeleted;
private bool _isPopulating;
@@ -112,11 +111,10 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
RecordContainerStatus.Text = state.SelectedKey == null
? Loc.GetString("general-station-record-console-no-record-found")
: Loc.GetString("general-station-record-console-select-record-info");
- PopulateRecordContainer(state.Record);
+ PopulateRecordContainer(state.Record, state.CanDeleteEntries, state.SelectedKey);
}
else
{
- RecordContainer.DisposeAllChildren();
RecordContainer.RemoveAllChildren();
}
}
@@ -138,49 +136,13 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
RecordListing.SortItemsByText();
}
- private void PopulateRecordContainer(GeneralStationRecord record)
+ private void PopulateRecordContainer(GeneralStationRecord record, bool enableDelete, uint? id)
{
- RecordContainer.DisposeAllChildren();
RecordContainer.RemoveAllChildren();
- // sure
- var recordControls = new Control[]
- {
- new Label()
- {
- Text = record.Name,
- StyleClasses = { "LabelBig" }
- },
- new Label()
- {
- Text = Loc.GetString("general-station-record-console-record-age", ("age", record.Age.ToString()))
+ var newRecord = new GeneralRecord(record, enableDelete, id);
+ newRecord.OnDeletePressed = OnDeleted;
- },
- new Label()
- {
- Text = Loc.GetString("general-station-record-console-record-title", ("job", Loc.GetString(record.JobTitle)))
- },
- new Label()
- {
- Text = Loc.GetString("general-station-record-console-record-species", ("species", record.Species))
- },
- new Label()
- {
- Text = Loc.GetString("general-station-record-console-record-gender", ("gender", record.Gender.ToString()))
- },
- new Label()
- {
- Text = Loc.GetString("general-station-record-console-record-fingerprint", ("fingerprint", record.Fingerprint ?? Loc.GetString("generic-not-available-shorthand")))
- },
- new Label()
- {
- Text = Loc.GetString("general-station-record-console-record-dna", ("dna", record.DNA ?? Loc.GetString("generic-not-available-shorthand")))
- }
- };
-
- foreach (var control in recordControls)
- {
- RecordContainer.AddChild(control);
- }
+ RecordContainer.AddChild(newRecord);
}
private void FilterListingOfRecords(string text = "")
@@ -195,4 +157,5 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
{
return Loc.GetString($"general-station-record-{type.ToString().ToLower()}-filter");
}
+
}
diff --git a/Content.Server/StationRecords/Components/GeneralStationRecordConsoleComponent.cs b/Content.Server/StationRecords/Components/GeneralStationRecordConsoleComponent.cs
index 9076bee436..a6356f0baa 100644
--- a/Content.Server/StationRecords/Components/GeneralStationRecordConsoleComponent.cs
+++ b/Content.Server/StationRecords/Components/GeneralStationRecordConsoleComponent.cs
@@ -18,4 +18,10 @@ public sealed partial class GeneralStationRecordConsoleComponent : Component
///
[DataField]
public StationRecordsFilter? Filter;
+
+ ///
+ /// Whether this Records Console is able to delete entries.
+ ///
+ [DataField]
+ public bool CanDeleteEntries;
}
diff --git a/Content.Server/StationRecords/Systems/GeneralStationRecordConsoleSystem.cs b/Content.Server/StationRecords/Systems/GeneralStationRecordConsoleSystem.cs
index a5202285d9..87246ab675 100644
--- a/Content.Server/StationRecords/Systems/GeneralStationRecordConsoleSystem.cs
+++ b/Content.Server/StationRecords/Systems/GeneralStationRecordConsoleSystem.cs
@@ -23,9 +23,22 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
subs.Event(UpdateUserInterface);
subs.Event(OnKeySelected);
subs.Event(OnFiltersChanged);
+ subs.Event(OnRecordDelete);
});
}
+ private void OnRecordDelete(Entity ent, ref DeleteStationRecord args)
+ {
+ if (!ent.Comp.CanDeleteEntries)
+ return;
+
+ var owning = _station.GetOwningStation(ent.Owner);
+
+ if (owning != null)
+ _stationRecords.RemoveRecord(new StationRecordKey(args.Id, owning.Value));
+ UpdateUserInterface(ent); // Apparently an event does not get raised for this.
+ }
+
private void UpdateUserInterface(Entity ent, ref T args)
{
UpdateUserInterface(ent);
@@ -68,8 +81,9 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
case 0:
_ui.SetUiState(uid, GeneralStationRecordConsoleKey.Key, new GeneralStationRecordConsoleState());
return;
- case 1:
- console.ActiveKey = listing.Keys.First();
+ default:
+ if (console.ActiveKey == null)
+ console.ActiveKey = listing.Keys.First();
break;
}
@@ -79,7 +93,7 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
var key = new StationRecordKey(id, owningStation.Value);
_stationRecords.TryGetRecord(key, out var record, stationRecords);
- GeneralStationRecordConsoleState newState = new(id, record, listing, console.Filter);
+ GeneralStationRecordConsoleState newState = new(id, record, listing, console.Filter, ent.Comp.CanDeleteEntries);
_ui.SetUiState(uid, GeneralStationRecordConsoleKey.Key, newState);
}
}
diff --git a/Content.Shared/StationRecords/GeneralRecordsUi.cs b/Content.Shared/StationRecords/GeneralRecordsUi.cs
index 860454efde..2105c53df2 100644
--- a/Content.Shared/StationRecords/GeneralRecordsUi.cs
+++ b/Content.Shared/StationRecords/GeneralRecordsUi.cs
@@ -37,17 +37,22 @@ public sealed class GeneralStationRecordConsoleState : BoundUserInterfaceState
public readonly GeneralStationRecord? Record;
public readonly Dictionary? RecordListing;
public readonly StationRecordsFilter? Filter;
+ public readonly bool CanDeleteEntries;
- public GeneralStationRecordConsoleState(uint? key, GeneralStationRecord? record,
- Dictionary? recordListing, StationRecordsFilter? newFilter)
+ public GeneralStationRecordConsoleState(uint? key,
+ GeneralStationRecord? record,
+ Dictionary? recordListing,
+ StationRecordsFilter? newFilter,
+ bool canDeleteEntries)
{
SelectedKey = key;
Record = record;
RecordListing = recordListing;
Filter = newFilter;
+ CanDeleteEntries = canDeleteEntries;
}
- public GeneralStationRecordConsoleState() : this(null, null, null, null)
+ public GeneralStationRecordConsoleState() : this(null, null, null, null, false)
{
}
@@ -69,3 +74,15 @@ public sealed class SelectStationRecord : BoundUserInterfaceMessage
SelectedKey = selectedKey;
}
}
+
+
+[Serializable, NetSerializable]
+public sealed class DeleteStationRecord : BoundUserInterfaceMessage
+{
+ public DeleteStationRecord(uint id)
+ {
+ Id = id;
+ }
+
+ public readonly uint Id;
+}
diff --git a/Resources/Locale/en-US/station-records/general-station-records.ftl b/Resources/Locale/en-US/station-records/general-station-records.ftl
index e36bfac7cb..4516a547f4 100644
--- a/Resources/Locale/en-US/station-records/general-station-records.ftl
+++ b/Resources/Locale/en-US/station-records/general-station-records.ftl
@@ -16,3 +16,4 @@ general-station-record-prints-filter = Fingerprints
general-station-record-dna-filter = DNA
general-station-record-console-search-records = Search
general-station-record-console-reset-filters = Reset
+general-station-record-console-delete = Delete
diff --git a/Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml b/Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml
index 38092e3aa7..8171ec0053 100644
--- a/Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml
+++ b/Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml
@@ -70,6 +70,7 @@
- type: CargoOrderConsole
- type: CrewMonitoringConsole
- type: GeneralStationRecordConsole
+ canDeleteEntries: true
- type: DeviceNetwork
deviceNetId: Wireless
receiveFrequencyId: CrewMonitor