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
This commit is contained in:
nikthechampiongr
2024-05-12 15:07:54 +00:00
committed by GitHub
parent ed7075942d
commit c8b55e5e44
10 changed files with 100 additions and 51 deletions

View File

@@ -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>

View File

@@ -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);
}
}
}

View File

@@ -20,6 +20,7 @@ public sealed class GeneralStationRecordConsoleBoundUserInterface : BoundUserInt
SendMessage(new SelectStationRecord(key)); SendMessage(new SelectStationRecord(key));
_window.OnFiltersChanged += (type, filterValue) => _window.OnFiltersChanged += (type, filterValue) =>
SendMessage(new SetStationRecordFilter(type, filterValue)); SendMessage(new SetStationRecordFilter(type, filterValue));
_window.OnDeleted += id => SendMessage(new DeleteStationRecord(id));
_window.OnClose += Close; _window.OnClose += Close;
_window.OpenCentered(); _window.OpenCentered();

View File

@@ -19,7 +19,7 @@
</BoxContainer> </BoxContainer>
<BoxContainer Orientation="Vertical" Margin="5"> <BoxContainer Orientation="Vertical" Margin="5">
<Label Name="RecordContainerStatus" Visible="False" Text="{Loc 'general-station-record-console-select-record-info'}"/> <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> </BoxContainer>
</BoxContainer> </BoxContainer>

View File

@@ -1,7 +1,5 @@
using Content.Shared.StationRecords; using Content.Shared.StationRecords;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
@@ -13,6 +11,7 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
public Action<uint?>? OnKeySelected; public Action<uint?>? OnKeySelected;
public Action<StationRecordFilterType, string>? OnFiltersChanged; public Action<StationRecordFilterType, string>? OnFiltersChanged;
public Action<uint>? OnDeleted;
private bool _isPopulating; private bool _isPopulating;
@@ -112,11 +111,10 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
RecordContainerStatus.Text = state.SelectedKey == null RecordContainerStatus.Text = state.SelectedKey == null
? Loc.GetString("general-station-record-console-no-record-found") ? Loc.GetString("general-station-record-console-no-record-found")
: Loc.GetString("general-station-record-console-select-record-info"); : Loc.GetString("general-station-record-console-select-record-info");
PopulateRecordContainer(state.Record); PopulateRecordContainer(state.Record, state.CanDeleteEntries, state.SelectedKey);
} }
else else
{ {
RecordContainer.DisposeAllChildren();
RecordContainer.RemoveAllChildren(); RecordContainer.RemoveAllChildren();
} }
} }
@@ -138,49 +136,13 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
RecordListing.SortItemsByText(); RecordListing.SortItemsByText();
} }
private void PopulateRecordContainer(GeneralStationRecord record) private void PopulateRecordContainer(GeneralStationRecord record, bool enableDelete, uint? id)
{ {
RecordContainer.DisposeAllChildren();
RecordContainer.RemoveAllChildren(); RecordContainer.RemoveAllChildren();
// sure var newRecord = new GeneralRecord(record, enableDelete, id);
var recordControls = new Control[] newRecord.OnDeletePressed = OnDeleted;
{
new Label()
{
Text = record.Name,
StyleClasses = { "LabelBig" }
},
new Label()
{
Text = Loc.GetString("general-station-record-console-record-age", ("age", record.Age.ToString()))
}, RecordContainer.AddChild(newRecord);
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);
}
} }
private void FilterListingOfRecords(string text = "") 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"); return Loc.GetString($"general-station-record-{type.ToString().ToLower()}-filter");
} }
} }

View File

@@ -18,4 +18,10 @@ public sealed partial class GeneralStationRecordConsoleComponent : Component
/// </summary> /// </summary>
[DataField] [DataField]
public StationRecordsFilter? Filter; public StationRecordsFilter? Filter;
/// <summary>
/// Whether this Records Console is able to delete entries.
/// </summary>
[DataField]
public bool CanDeleteEntries;
} }

View File

@@ -23,9 +23,22 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
subs.Event<BoundUIOpenedEvent>(UpdateUserInterface); subs.Event<BoundUIOpenedEvent>(UpdateUserInterface);
subs.Event<SelectStationRecord>(OnKeySelected); subs.Event<SelectStationRecord>(OnKeySelected);
subs.Event<SetStationRecordFilter>(OnFiltersChanged); 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) private void UpdateUserInterface<T>(Entity<GeneralStationRecordConsoleComponent> ent, ref T args)
{ {
UpdateUserInterface(ent); UpdateUserInterface(ent);
@@ -68,7 +81,8 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
case 0: case 0:
_ui.SetUiState(uid, GeneralStationRecordConsoleKey.Key, new GeneralStationRecordConsoleState()); _ui.SetUiState(uid, GeneralStationRecordConsoleKey.Key, new GeneralStationRecordConsoleState());
return; return;
case 1: default:
if (console.ActiveKey == null)
console.ActiveKey = listing.Keys.First(); console.ActiveKey = listing.Keys.First();
break; break;
} }
@@ -79,7 +93,7 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
var key = new StationRecordKey(id, owningStation.Value); var key = new StationRecordKey(id, owningStation.Value);
_stationRecords.TryGetRecord<GeneralStationRecord>(key, out var record, stationRecords); _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); _ui.SetUiState(uid, GeneralStationRecordConsoleKey.Key, newState);
} }
} }

View File

@@ -37,17 +37,22 @@ public sealed class GeneralStationRecordConsoleState : BoundUserInterfaceState
public readonly GeneralStationRecord? Record; public readonly GeneralStationRecord? Record;
public readonly Dictionary<uint, string>? RecordListing; public readonly Dictionary<uint, string>? RecordListing;
public readonly StationRecordsFilter? Filter; public readonly StationRecordsFilter? Filter;
public readonly bool CanDeleteEntries;
public GeneralStationRecordConsoleState(uint? key, GeneralStationRecord? record, public GeneralStationRecordConsoleState(uint? key,
Dictionary<uint, string>? recordListing, StationRecordsFilter? newFilter) GeneralStationRecord? record,
Dictionary<uint, string>? recordListing,
StationRecordsFilter? newFilter,
bool canDeleteEntries)
{ {
SelectedKey = key; SelectedKey = key;
Record = record; Record = record;
RecordListing = recordListing; RecordListing = recordListing;
Filter = newFilter; 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; SelectedKey = selectedKey;
} }
} }
[Serializable, NetSerializable]
public sealed class DeleteStationRecord : BoundUserInterfaceMessage
{
public DeleteStationRecord(uint id)
{
Id = id;
}
public readonly uint Id;
}

View File

@@ -16,3 +16,4 @@ general-station-record-prints-filter = Fingerprints
general-station-record-dna-filter = DNA general-station-record-dna-filter = DNA
general-station-record-console-search-records = Search general-station-record-console-search-records = Search
general-station-record-console-reset-filters = Reset general-station-record-console-reset-filters = Reset
general-station-record-console-delete = Delete

View File

@@ -70,6 +70,7 @@
- type: CargoOrderConsole - type: CargoOrderConsole
- type: CrewMonitoringConsole - type: CrewMonitoringConsole
- type: GeneralStationRecordConsole - type: GeneralStationRecordConsole
canDeleteEntries: true
- type: DeviceNetwork - type: DeviceNetwork
deviceNetId: Wireless deviceNetId: Wireless
receiveFrequencyId: CrewMonitor receiveFrequencyId: CrewMonitor