Files
OldThink/Content.Server/Pinpointer/StationMapSystem.cs

53 lines
1.7 KiB
C#
Raw Normal View History

using Content.Server.PowerCell;
2023-04-13 16:21:24 +10:00
using Content.Shared.Pinpointer;
using Robust.Server.GameObjects;
2023-10-29 04:21:02 +11:00
using Robust.Shared.Player;
2023-04-13 16:21:24 +10:00
namespace Content.Server.Pinpointer;
public sealed class StationMapSystem : EntitySystem
{
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly PowerCellSystem _cell = default!;
2023-04-13 16:21:24 +10:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StationMapUserComponent, EntParentChangedMessage>(OnUserParentChanged);
Subs.BuiEvents<StationMapComponent>(StationMapUiKey.Key, subs =>
{
subs.Event<BoundUIOpenedEvent>(OnStationMapOpened);
subs.Event<BoundUIClosedEvent>(OnStationMapClosed);
});
2023-04-13 16:21:24 +10:00
}
private void OnStationMapClosed(EntityUid uid, StationMapComponent component, BoundUIClosedEvent args)
{
if (!Equals(args.UiKey, StationMapUiKey.Key) || args.Session.AttachedEntity == null)
return;
RemCompDeferred<StationMapUserComponent>(args.Session.AttachedEntity.Value);
}
private void OnUserParentChanged(EntityUid uid, StationMapUserComponent component, ref EntParentChangedMessage args)
{
if (TryComp<ActorComponent>(uid, out var actor))
{
_ui.TryClose(component.Map, StationMapUiKey.Key, actor.PlayerSession);
}
}
private void OnStationMapOpened(EntityUid uid, StationMapComponent component, BoundUIOpenedEvent args)
{
if (args.Session.AttachedEntity == null)
return;
if (!_cell.TryUseActivatableCharge(uid))
return;
2023-04-13 16:21:24 +10:00
var comp = EnsureComp<StationMapUserComponent>(args.Session.AttachedEntity.Value);
comp.Map = uid;
}
}