Files
tbd-station-14/Content.Server/Pinpointer/StationMapSystem.cs
metalgearsloth 5896e68752 Content update for UI prediction (#27214)
* Content update for UI refactor

* Big update

* Sharing

* Remaining content updates

* First big update

* Prototype updates

* AUGH

* Fix UI comp ref

* Cleanup

- Fix predicted message, fix item slots, fix interaction range check.

* Fix regressions

* Make this predictive

idk why it wasn't.

* Fix slime merge

* Merge conflict

* Fix merge
2024-04-26 18:16:24 +10:00

47 lines
1.5 KiB
C#

using Content.Server.PowerCell;
using Content.Shared.Pinpointer;
using Robust.Server.GameObjects;
using Robust.Shared.Player;
namespace Content.Server.Pinpointer;
public sealed class StationMapSystem : EntitySystem
{
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly PowerCellSystem _cell = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StationMapUserComponent, EntParentChangedMessage>(OnUserParentChanged);
Subs.BuiEvents<StationMapComponent>(StationMapUiKey.Key, subs =>
{
subs.Event<BoundUIOpenedEvent>(OnStationMapOpened);
subs.Event<BoundUIClosedEvent>(OnStationMapClosed);
});
}
private void OnStationMapClosed(EntityUid uid, StationMapComponent component, BoundUIClosedEvent args)
{
if (!Equals(args.UiKey, StationMapUiKey.Key))
return;
RemCompDeferred<StationMapUserComponent>(args.Actor);
}
private void OnUserParentChanged(EntityUid uid, StationMapUserComponent component, ref EntParentChangedMessage args)
{
_ui.CloseUi(component.Map, StationMapUiKey.Key, uid);
}
private void OnStationMapOpened(EntityUid uid, StationMapComponent component, BoundUIOpenedEvent args)
{
if (!_cell.TryUseActivatableCharge(uid))
return;
var comp = EnsureComp<StationMapUserComponent>(args.Actor);
comp.Map = uid;
}
}