using Content.Shared.Pinpointer; using Content.Shared.StationTeleporter.Components; using Content.Shared.Teleportation.Components; using Robust.Shared.Containers; using Robust.Shared.Map; namespace Content.Shared.StationTeleporter; public abstract partial class SharedStationTeleporterSystem { private void InitializeUI() { SubscribeLocalEvent(OnUIOpened); SubscribeLocalEvent(OnUIPortalClicked); SubscribeLocalEvent(OnChipStorageChanged); SubscribeLocalEvent(OnChipStorageChanged); } private void OnUIOpened(Entity ent, ref BoundUIOpenedEvent args) { UpdateUserInterface(ent); } private void OnUIPortalClicked(Entity ent, ref StationTeleporterClickMessage args) { ToggleTeleporterLink(ent, ref args); UpdateUserInterface(ent); } private void OnChipStorageChanged(Entity ent, ref EntInsertedIntoContainerMessage args) { if (args.Container.ID == ent.Comp.ChipStorageName) UpdateUserInterface(ent); } private void OnChipStorageChanged(Entity ent, ref EntRemovedFromContainerMessage args) { if (args.Container.ID == ent.Comp.ChipStorageName) UpdateUserInterface(ent); } private void UpdateUserInterface(Entity ent) { if (!_uiSystem.IsUiOpen(ent.Owner, StationTeleporterConsoleUIKey.Key)) return; // The grid must have a NavMapComponent to visualize the map in the UI var xform = Transform(ent); if (xform.GridUid != null) EnsureComp(xform.GridUid.Value); //Send data var teleportersData = new List(); var cachedTeleporters = new HashSet(); //Prevent UI teleporters duplication if (_container.TryGetContainer(ent, ent.Comp.ChipStorageName, out var container)) { foreach (var entity in container.ContainedEntities) { if (TryComp(entity, out var chipComp)) AddTeleporterFromChip((entity, chipComp), teleportersData, cachedTeleporters); else if (TryComp(entity, out var handTeleporterComp)) AddPortalsFromHandTeleporter((entity, handTeleporterComp), teleportersData, cachedTeleporters); } } _uiSystem.SetUiState(ent.Owner, StationTeleporterConsoleUIKey.Key, new StationTeleporterState(teleportersData, GetNetEntity(ent.Comp.SelectedTeleporter))); } private void AddTeleporterFromChip(Entity chip, List teleportersData, HashSet cachedTeleporters) { //Teleporter chips get portal links if (Deleted(chip.Comp.ConnectedTeleporter)) return; if (chip.Comp.ConnectedTeleporter is null) return; var teleporterName = _labelQuery.TryComp(chip.Comp.ConnectedTeleporter.Value, out var label) ? label.CurrentLabel ?? Loc.GetString("teleporter-name-unknown") : Loc.GetString("teleporter-name-unknown"); AddTeleporterStatus(chip.Comp.ConnectedTeleporter.Value, teleporterName, teleportersData, cachedTeleporters); } private void AddPortalsFromHandTeleporter(Entity handTeleporter, List teleportersData, HashSet cachedTeleporters) { //RD handheld teleporter portals if (handTeleporter.Comp.FirstPortal is not null && Exists(handTeleporter.Comp.FirstPortal)) AddTeleporterStatus(handTeleporter.Comp.FirstPortal.Value, Loc.GetString("teleporter-name-rd-first"), teleportersData, cachedTeleporters); if (handTeleporter.Comp.SecondPortal is not null && Exists(handTeleporter.Comp.SecondPortal)) AddTeleporterStatus(handTeleporter.Comp.SecondPortal.Value, Loc.GetString("teleporter-name-rd-second"), teleportersData, cachedTeleporters); } /// /// Builds and appends a entry for the given teleporter, unless it was already added. /// private void AddTeleporterStatus(EntityUid teleporter, string name, List teleportersData, HashSet cachedTeleporters) { if (!cachedTeleporters.Add(teleporter)) return; _link.GetLink(teleporter, out var linkedTeleporter); EntityCoordinates? linkCoord = null; if (linkedTeleporter is not null) linkCoord = Transform(linkedTeleporter.Value).Coordinates; teleportersData.Add( new StationTeleporterStatus(GetNetEntity(teleporter), GetNetCoordinates(Transform(teleporter).Coordinates), GetNetCoordinates(linkCoord), name, _power.IsPowered(teleporter))); } }