* Work on cartridges * Work on PDA UI * Work on PDA UIs program list * Work on PDA UI borders * Add DeviceNetworkingComponent to the pda base prototype * Fix submodule version * Fix cartridge loader ui key * Fix pda menu xaml * Implement relaying ui messages * Finish implementing the notekeeper cartridge * Fix submodule version * Fix errors from merging master * Fix test failing * Implement setting preinstalled programs * Add some documentation to CartridgeLoaderSystem * Add more doc comments * Add localization to program names * Implement review suggestions * Fix background programs receiving events twice when active
148 lines
4.5 KiB
C#
148 lines
4.5 KiB
C#
using Content.Shared.Containers.ItemSlots;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.GameStates;
|
|
using Robust.Shared.Map;
|
|
|
|
namespace Content.Shared.CartridgeLoader;
|
|
|
|
public abstract class SharedCartridgeLoaderSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<SharedCartridgeLoaderComponent, ComponentInit>(OnComponentInit);
|
|
SubscribeLocalEvent<SharedCartridgeLoaderComponent, ComponentRemove>(OnComponentRemove);
|
|
|
|
SubscribeLocalEvent<SharedCartridgeLoaderComponent, EntInsertedIntoContainerMessage>(OnItemInserted);
|
|
SubscribeLocalEvent<SharedCartridgeLoaderComponent, EntRemovedFromContainerMessage>(OnItemRemoved);
|
|
|
|
SubscribeLocalEvent<CartridgeComponent, ComponentGetState>(OnGetState);
|
|
SubscribeLocalEvent<CartridgeComponent, ComponentHandleState>(OnHandleState);
|
|
|
|
}
|
|
|
|
private void OnComponentInit(EntityUid uid, SharedCartridgeLoaderComponent loader, ComponentInit args)
|
|
{
|
|
_itemSlotsSystem.AddItemSlot(uid, SharedCartridgeLoaderComponent.CartridgeSlotId, loader.CartridgeSlot);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks installed program entities for deletion when the component gets removed
|
|
/// </summary>
|
|
private void OnComponentRemove(EntityUid uid, SharedCartridgeLoaderComponent loader, ComponentRemove args)
|
|
{
|
|
_itemSlotsSystem.RemoveItemSlot(uid, loader.CartridgeSlot);
|
|
|
|
foreach (var program in loader.InstalledPrograms)
|
|
{
|
|
EntityManager.QueueDeleteEntity(program);
|
|
}
|
|
}
|
|
|
|
protected virtual void OnItemInserted(EntityUid uid, SharedCartridgeLoaderComponent loader, EntInsertedIntoContainerMessage args)
|
|
{
|
|
UpdateAppearanceData(uid, loader);
|
|
}
|
|
|
|
protected virtual void OnItemRemoved(EntityUid uid, SharedCartridgeLoaderComponent loader, EntRemovedFromContainerMessage args)
|
|
{
|
|
UpdateAppearanceData(uid, loader);
|
|
}
|
|
|
|
private void OnGetState(EntityUid uid, CartridgeComponent component, ref ComponentGetState args)
|
|
{
|
|
var state = new CartridgeComponentState();
|
|
state.InstallationStatus = component.InstallationStatus;
|
|
|
|
args.State = state;
|
|
}
|
|
|
|
private void OnHandleState(EntityUid uid, CartridgeComponent component, ref ComponentHandleState args)
|
|
{
|
|
if (args.Current is not CartridgeComponentState state)
|
|
return;
|
|
|
|
component.InstallationStatus = state.InstallationStatus;
|
|
}
|
|
|
|
private void UpdateAppearanceData(EntityUid uid, SharedCartridgeLoaderComponent loader)
|
|
{
|
|
_appearanceSystem.SetData(uid, CartridgeLoaderVisuals.CartridgeInserted, loader.CartridgeSlot.HasItem);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets sent to program / cartridge entities when they get inserted or installed
|
|
/// </summary>
|
|
public sealed class CartridgeAddedEvent : EntityEventArgs
|
|
{
|
|
public readonly EntityUid Loader;
|
|
|
|
public CartridgeAddedEvent(EntityUid loader)
|
|
{
|
|
Loader = loader;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets sent to cartridge entities when they get ejected
|
|
/// </summary>
|
|
public sealed class CartridgeRemovedEvent : EntityEventArgs
|
|
{
|
|
public readonly EntityUid Loader;
|
|
|
|
public CartridgeRemovedEvent(EntityUid loader)
|
|
{
|
|
Loader = loader;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets sent to program / cartridge entities when they get activated
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Don't update the programs ui state in this events listener
|
|
/// </remarks>
|
|
public sealed class CartridgeActivatedEvent : EntityEventArgs
|
|
{
|
|
public readonly EntityUid Loader;
|
|
|
|
public CartridgeActivatedEvent(EntityUid loader)
|
|
{
|
|
Loader = loader;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets sent to program / cartridge entities when they get deactivated
|
|
/// </summary>
|
|
public sealed class CartridgeDeactivatedEvent : EntityEventArgs
|
|
{
|
|
public readonly EntityUid Loader;
|
|
|
|
public CartridgeDeactivatedEvent(EntityUid loader)
|
|
{
|
|
Loader = loader;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets sent to program / cartridge entities when the ui is ready to be updated by the cartridge.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This is used for the initial ui state update because updating the ui in the activate event doesn't work
|
|
/// </remarks>
|
|
public sealed class CartridgeUiReadyEvent : EntityEventArgs
|
|
{
|
|
public readonly EntityUid Loader;
|
|
|
|
public CartridgeUiReadyEvent(EntityUid loader)
|
|
{
|
|
Loader = loader;
|
|
}
|
|
}
|