Station maps (#13027)
This commit is contained in:
43
Content.Server/Pinpointer/StationMapSystem.cs
Normal file
43
Content.Server/Pinpointer/StationMapSystem.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Pinpointer;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
namespace Content.Server.Pinpointer;
|
||||
|
||||
public sealed class StationMapSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<StationMapUserComponent, EntParentChangedMessage>(OnUserParentChanged);
|
||||
SubscribeLocalEvent<StationMapComponent, BoundUIOpenedEvent>(OnStationMapOpened);
|
||||
SubscribeLocalEvent<StationMapComponent, BoundUIClosedEvent>(OnStationMapClosed);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
var comp = EnsureComp<StationMapUserComponent>(args.Session.AttachedEntity.Value);
|
||||
comp.Map = uid;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user