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:
13
Content.Client/StationRecords/GeneralRecord.xaml
Normal file
13
Content.Client/StationRecords/GeneralRecord.xaml
Normal 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>
|
||||
33
Content.Client/StationRecords/GeneralRecord.xaml.cs
Normal file
33
Content.Client/StationRecords/GeneralRecord.xaml.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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()))
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,7 +81,8 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
|
||||
case 0:
|
||||
_ui.SetUiState(uid, GeneralStationRecordConsoleKey.Key, new GeneralStationRecordConsoleState());
|
||||
return;
|
||||
case 1:
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
- type: CargoOrderConsole
|
||||
- type: CrewMonitoringConsole
|
||||
- type: GeneralStationRecordConsole
|
||||
canDeleteEntries: true
|
||||
- type: DeviceNetwork
|
||||
deviceNetId: Wireless
|
||||
receiveFrequencyId: CrewMonitor
|
||||
|
||||
Reference in New Issue
Block a user