CatStation/Content.Shared/StationTeleporter/SharedStationTeleporterSystem.UI.cs
TheShuEd bdbc143e7f
Stationary teleporters (#32134)
* sprite, start work on systems

* Woah! Its work!

* Show gateways! Yay!

* Update ring.png

* Update portal.yml

* bububui

* Fuck UI

* draw lines!

* clear old links lines

* UI button work now!

* we can cut links via UI now!

* yay! linking via UI

* comfortable linking

* Update hand_teleporter.yml

* ambience, linked entities events

* nice connect and disconnect sounds!

* unpowering and memory

* power fix

* chip added

* chip linking & auto linking

* chip examined

* auto linked chips&gates variants

* Update meta.json

* Update computers.yml

* syndicate gateway console, portal coloring, realtime UI update

* QoL update

* Circuitboards

* Update StationGatewayNavMapControl.cs

* optimize Draw(), add Filled console variant

* documentation

* mass renaming bro

* resprited

* resprite agani

* Update tags.yml

* Update Resources/Prototypes/Entities/Structures/Machines/station_teleporter.yml

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Update Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Update Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Update Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Update Resources/Prototypes/Entities/Objects/Devices/teleporters_chips.yml

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Update Resources/Prototypes/Entities/Objects/Devices/Circuitboards/computer.yml

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Update Resources/Prototypes/Entities/Objects/Devices/Circuitboards/computer.yml

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Update Resources/Prototypes/Entities/Objects/Devices/Circuitboards/computer.yml

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Update Resources/Prototypes/Entities/Objects/Devices/Circuitboards/computer.yml

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Update Content.Server/StationTeleporter/Components/TeleporterChipComponent.cs

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Update Content.Shared/StationTeleporter/StationTeleporterComponent.cs

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* renaming renaming

* sharedization

* UI fix

* Data simplify

* remove autodeletion

* PostWallDrawingAction

* Update TeleporterChipComponent.cs

* fix lines offset

* labeler renaming, rebound restiction removed

* prevent link popup and sound spamming

* auto linking refactor

* RD handheld teleporter integration

* fix randomteleport bug

* Update hand_teleporter.yml

* Update SharedStationTeleporterSystem.cs

* Update SharedStationTeleporterSystem.UI.cs

* some clean up

* first smol review pass

* and that

* review pass 2

* Update station_teleporter.yml

* review pass 3

* review pass 4

* finally

* update protos

* another clean up

* fix bugs

* add to players

* remove unnecesary update loop lol.

* Update computers.yml

* fieldrance review apply

* Kazne resprite

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>
2026-07-28 11:39:26 +00:00

120 lines
5.2 KiB
C#

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<StationTeleporterConsoleComponent, BoundUIOpenedEvent>(OnUIOpened);
SubscribeLocalEvent<StationTeleporterConsoleComponent, StationTeleporterClickMessage>(OnUIPortalClicked);
SubscribeLocalEvent<StationTeleporterConsoleComponent, EntInsertedIntoContainerMessage>(OnChipStorageChanged);
SubscribeLocalEvent<StationTeleporterConsoleComponent, EntRemovedFromContainerMessage>(OnChipStorageChanged);
}
private void OnUIOpened(Entity<StationTeleporterConsoleComponent> ent, ref BoundUIOpenedEvent args)
{
UpdateUserInterface(ent);
}
private void OnUIPortalClicked(Entity<StationTeleporterConsoleComponent> ent,
ref StationTeleporterClickMessage args)
{
ToggleTeleporterLink(ent, ref args);
UpdateUserInterface(ent);
}
private void OnChipStorageChanged(Entity<StationTeleporterConsoleComponent> ent, ref EntInsertedIntoContainerMessage args)
{
if (args.Container.ID == ent.Comp.ChipStorageName)
UpdateUserInterface(ent);
}
private void OnChipStorageChanged(Entity<StationTeleporterConsoleComponent> ent, ref EntRemovedFromContainerMessage args)
{
if (args.Container.ID == ent.Comp.ChipStorageName)
UpdateUserInterface(ent);
}
private void UpdateUserInterface(Entity<StationTeleporterConsoleComponent> 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<NavMapComponent>(xform.GridUid.Value);
//Send data
var teleportersData = new List<StationTeleporterStatus>();
var cachedTeleporters = new HashSet<EntityUid>(); //Prevent UI teleporters duplication
if (_container.TryGetContainer(ent, ent.Comp.ChipStorageName, out var container))
{
foreach (var entity in container.ContainedEntities)
{
if (TryComp<TeleporterChipComponent>(entity, out var chipComp))
AddTeleporterFromChip((entity, chipComp), teleportersData, cachedTeleporters);
else if (TryComp<HandTeleporterComponent>(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<TeleporterChipComponent> chip, List<StationTeleporterStatus> teleportersData, HashSet<EntityUid> 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<HandTeleporterComponent> handTeleporter, List<StationTeleporterStatus> teleportersData, HashSet<EntityUid> 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);
}
/// <summary>
/// Builds and appends a <see cref="StationTeleporterStatus"/> entry for the given teleporter, unless it was already added.
/// </summary>
private void AddTeleporterStatus(EntityUid teleporter, string name, List<StationTeleporterStatus> teleportersData, HashSet<EntityUid> 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)));
}
}