Files
crystall-punk-14/Content.Server/Pinpointer/StationMapSystem.cs

47 lines
1.5 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))
2023-04-13 16:21:24 +10:00
return;
RemCompDeferred<StationMapUserComponent>(args.Actor);
2023-04-13 16:21:24 +10:00
}
private void OnUserParentChanged(EntityUid uid, StationMapUserComponent component, ref EntParentChangedMessage args)
{
_ui.CloseUi(component.Map, StationMapUiKey.Key, uid);
2023-04-13 16:21:24 +10:00
}
private void OnStationMapOpened(EntityUid uid, StationMapComponent component, BoundUIOpenedEvent args)
{
if (!_cell.TryUseActivatableCharge(uid))
return;
var comp = EnsureComp<StationMapUserComponent>(args.Actor);
2023-04-13 16:21:24 +10:00
comp.Map = uid;
}
}