]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Record deletion (#27883)
authornikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com>
Sun, 12 May 2024 15:07:54 +0000 (15:07 +0000)
committerGitHub <noreply@github.com>
Sun, 12 May 2024 15:07:54 +0000 (17:07 +0200)
* 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

Content.Client/StationRecords/GeneralRecord.xaml [new file with mode: 0644]
Content.Client/StationRecords/GeneralRecord.xaml.cs [new file with mode: 0644]
Content.Client/StationRecords/GeneralStationRecordConsoleBoundUserInterface.cs
Content.Client/StationRecords/GeneralStationRecordConsoleWindow.xaml
Content.Client/StationRecords/GeneralStationRecordConsoleWindow.xaml.cs
Content.Server/StationRecords/Components/GeneralStationRecordConsoleComponent.cs
Content.Server/StationRecords/Systems/GeneralStationRecordConsoleSystem.cs
Content.Shared/StationRecords/GeneralRecordsUi.cs
Resources/Locale/en-US/station-records/general-station-records.ftl
Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml

diff --git a/Content.Client/StationRecords/GeneralRecord.xaml b/Content.Client/StationRecords/GeneralRecord.xaml
new file mode 100644 (file)
index 0000000..add688c
--- /dev/null
@@ -0,0 +1,13 @@
+<Control xmlns="https://spacestation14.io">
+    <BoxContainer Orientation="Vertical" Margin="5">
+        <Label Name="RecordName" StyleClasses="LabelBig"/>
+        <Label Name="Age"/>
+        <Label Name="Title"/>
+        <Label Name="Job"/>
+        <Label Name="Species"/>
+        <Label Name="Gender"/>
+        <Label Name="Fingerprint"/>
+        <Label Name="Dna"/>
+        <Button Visible="False" Name="DeleteButton" Text="{Loc 'general-station-record-console-delete'}"/>
+    </BoxContainer>
+</Control>
diff --git a/Content.Client/StationRecords/GeneralRecord.xaml.cs b/Content.Client/StationRecords/GeneralRecord.xaml.cs
new file mode 100644 (file)
index 0000000..6a2622f
--- /dev/null
@@ -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<uint>? 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);
+        }
+    }
+}
index 3be3d98778db829fe94dd10e06f3236e80d51ecb..720a2efb9ddea3dc9835f2ac01a6074aeb5a2811 100644 (file)
@@ -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();
index a915d329bc3bdc7e35354c8c29fd160a2f0604bd..3615eb8e0089b784ba73246306b3f3428c66f933 100644 (file)
@@ -19,7 +19,7 @@
             </BoxContainer>
             <BoxContainer Orientation="Vertical" Margin="5">
                 <Label Name="RecordContainerStatus" Visible="False" Text="{Loc 'general-station-record-console-select-record-info'}"/>
-                <BoxContainer Name="RecordContainer" Orientation="Vertical" />
+                <Control Name="RecordContainer" Visible="False"/>
             </BoxContainer>
         </BoxContainer>
     </BoxContainer>
index fbdd6c2f0b526c3903137f61b873056b35fbfd1f..272e6c3b251b35e9500c76ca19ca33dcce150d32 100644 (file)
@@ -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<uint?>? OnKeySelected;
 
     public Action<StationRecordFilterType, string>? OnFiltersChanged;
+    public Action<uint>? 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()))
-
-            },
-            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")))
-            }
-        };
+        var newRecord = new GeneralRecord(record, enableDelete, id);
+        newRecord.OnDeletePressed = OnDeleted;
 
-        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");
     }
+
 }
index 9076bee436fe6ee29f7e9d43a328b833af5fc9cf..a6356f0baa33246e0d0b6e5de886eca186a597dd 100644 (file)
@@ -18,4 +18,10 @@ public sealed partial class GeneralStationRecordConsoleComponent : Component
     /// </summary>
     [DataField]
     public StationRecordsFilter? Filter;
+
+    /// <summary>
+    /// Whether this Records Console is able to delete entries.
+    /// </summary>
+    [DataField]
+    public bool CanDeleteEntries;
 }
index a5202285d9916cae1b878fb52cfdf37c7919155e..87246ab67578b1f29ab1581bad7d6dbdd6d772bf 100644 (file)
@@ -23,9 +23,22 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
             subs.Event<BoundUIOpenedEvent>(UpdateUserInterface);
             subs.Event<SelectStationRecord>(OnKeySelected);
             subs.Event<SetStationRecordFilter>(OnFiltersChanged);
+            subs.Event<DeleteStationRecord>(OnRecordDelete);
         });
     }
 
+    private void OnRecordDelete(Entity<GeneralStationRecordConsoleComponent> 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<T>(Entity<GeneralStationRecordConsoleComponent> 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<GeneralStationRecord>(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);
     }
 }
index 860454efde51b52c4bf7fc8f7ff46dbe7f01d06f..2105c53df25f51558f560a0f157e378b4af05fae 100644 (file)
@@ -37,17 +37,22 @@ public sealed class GeneralStationRecordConsoleState : BoundUserInterfaceState
     public readonly GeneralStationRecord? Record;
     public readonly Dictionary<uint, string>? RecordListing;
     public readonly StationRecordsFilter? Filter;
+    public readonly bool CanDeleteEntries;
 
-    public GeneralStationRecordConsoleState(uint? key, GeneralStationRecord? record,
-        Dictionary<uint, string>? recordListing, StationRecordsFilter? newFilter)
+    public GeneralStationRecordConsoleState(uint? key,
+        GeneralStationRecord? record,
+        Dictionary<uint, string>? 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;
+}
index e36bfac7cb36027ba71e0737e6f7374876e99fc1..4516a547f4d32fbd8485fc9a93c0723516a7bbc7 100644 (file)
@@ -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
index 38092e3aa7e4b5edc8295ec807c52f7e28bb55c6..8171ec0053caa5e96cf53f85f87a5c0ecbd46efc 100644 (file)
@@ -70,6 +70,7 @@
   - type: CargoOrderConsole
   - type: CrewMonitoringConsole
   - type: GeneralStationRecordConsole
+    canDeleteEntries: true
   - type: DeviceNetwork
     deviceNetId: Wireless
     receiveFrequencyId: CrewMonitor