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

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