Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
using Content.Shared.Medical.CrewMonitoring;
using Content.Shared.Silicons.StationAi;
using Robust.Client.UserInterface;
using Robust.Shared.Map;
using Robust.Shared.Player;

namespace Content.Client.Medical.CrewMonitoring;

public sealed class CrewMonitoringBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly ISharedPlayerManager _playerManager = default!;

[ViewVariables]
private CrewMonitoringWindow? _menu;

public CrewMonitoringBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
IoCManager.InjectDependencies(this);
}

protected override void Open()
{
base.Open();

if (_menu != null)
_menu.MapClicked -= OnMapClicked;

EntityUid? gridUid = null;
var stationName = string.Empty;

Expand All @@ -31,6 +40,7 @@ protected override void Open()

_menu = this.CreateWindow<CrewMonitoringWindow>();
_menu.Set(stationName, gridUid);
_menu.MapClicked += OnMapClicked;
}

protected override void UpdateState(BoundUserInterfaceState state)
Expand All @@ -45,4 +55,29 @@ protected override void UpdateState(BoundUserInterfaceState state)
break;
}
}

private void OnMapClicked(EntityCoordinates coordinates)
{
var local = _playerManager.LocalEntity;

if (local is null || !EntMan.HasComponent<StationAiHeldComponent>(local.Value))
return;

var netCoordinates = EntMan.GetNetCoordinates(coordinates);
SendMessage(new CrewMonitoringWarpRequestMessage(netCoordinates));
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
if (_menu != null)
{
_menu.MapClicked -= OnMapClicked;
_menu = null;
}
}

base.Dispose(disposing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
using Robust.Shared.Map;
using Robust.Shared.Localization;

namespace Content.Client.Medical.CrewMonitoring;

public sealed partial class CrewMonitoringNavMapControl : NavMapControl
{
public NetEntity? Focus;
public Dictionary<NetEntity, string> LocalizedNames = new();
public event Action<EntityCoordinates>? MapClicked;

private Label _trackedEntityLabel;
private PanelContainer _trackedEntityPanel;
Expand Down Expand Up @@ -42,6 +45,7 @@ public CrewMonitoringNavMapControl() : base()

_trackedEntityPanel.AddChild(_trackedEntityLabel);
this.AddChild(_trackedEntityPanel);
MapClickedAction += coords => MapClicked?.Invoke(coords);
}

protected override void FrameUpdate(FrameEventArgs args)
Expand All @@ -62,7 +66,7 @@ protected override void FrameUpdate(FrameEventArgs args)
continue;

if (!LocalizedNames.TryGetValue(netEntity, out var name))
name = Loc.GetString("navmap-unknown-entity");
name = Loc.GetString("navmap-unknown-target");

var message = name + "\n" + Loc.GetString("navmap-location",
("x", MathF.Round(blip.Coordinates.X)),
Expand Down
18 changes: 18 additions & 0 deletions Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public sealed partial class CrewMonitoringWindow : FancyWindow
private NetEntity? _trackedEntity;
private bool _tryToScrollToListFocus;
private Texture? _blipTexture;
public event Action<EntityCoordinates>? MapClicked;

public CrewMonitoringWindow()
{
Expand All @@ -41,6 +42,7 @@ public CrewMonitoringWindow()
_spriteSystem = _entManager.System<SpriteSystem>();

NavMap.TrackedEntitySelectedAction += SetTrackedEntityFromNavMap;
NavMap.MapClicked += OnNavMapClicked;
}

public void Set(string stationName, EntityUid? mapUid)
Expand Down Expand Up @@ -354,6 +356,22 @@ private void SetTrackedEntityFromNavMap(NetEntity? netEntity)
UpdateSensorsTable(_trackedEntity, prevTrackedEntity);
}

private void OnNavMapClicked(EntityCoordinates coordinates)
{
MapClicked?.Invoke(coordinates);
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
NavMap.TrackedEntitySelectedAction -= SetTrackedEntityFromNavMap;
NavMap.MapClicked -= OnNavMapClicked;
}

base.Dispose(disposing);
}

private void UpdateSensorsTable(NetEntity? currTrackedEntity, NetEntity? prevTrackedEntity)
{
foreach (var sensor in SensorsTable.Children)
Expand Down
56 changes: 38 additions & 18 deletions Content.Client/Pinpointer/UI/NavMapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public partial class NavMapControl : MapGridControl

// Actions
public event Action<NetEntity?>? TrackedEntitySelectedAction;
public event Action<EntityCoordinates>? MapClickedAction;
public event Action<DrawingHandleScreen>? PostWallDrawingAction;

// Tracked data
Expand Down Expand Up @@ -203,10 +204,7 @@ protected override void KeyBindUp(GUIBoundKeyEventArgs args)

if (args.Function == EngineKeyFunctions.UIClick)
{
if (TrackedEntitySelectedAction == null)
return;

if (_xform == null || _physics == null || TrackedEntities.Count == 0)
if (_xform == null || _physics == null)
return;

// If the cursor has moved a significant distance, exit
Expand All @@ -221,28 +219,50 @@ protected override void KeyBindUp(GUIBoundKeyEventArgs args)
var unscaledPosition = (localPosition - MidPointVector) / MinimapScale;
var worldPosition = Vector2.Transform(new Vector2(unscaledPosition.X, -unscaledPosition.Y) + offset, _transformSystem.GetWorldMatrix(_xform));

// Find closest tracked entity in range
var closestEntity = NetEntity.Invalid;
var closestDistance = float.PositiveInfinity;
EntityCoordinates? clickCoords = null;
if (MapClickedAction != null)
{
var mapCoordinates = new MapCoordinates(worldPosition, _xform.MapID);
var coordinates = _transformSystem.ToCoordinates(mapCoordinates);

if (_transformSystem.IsValid(coordinates))
clickCoords = coordinates;
}

var invokedSelection = false;

foreach ((var currentEntity, var blip) in TrackedEntities)
if (TrackedEntitySelectedAction != null && TrackedEntities.Count != 0)
{
if (!blip.Selectable)
continue;
// Find closest tracked entity in range
var closestEntity = NetEntity.Invalid;
var closestDistance = float.PositiveInfinity;

foreach ((var currentEntity, var blip) in TrackedEntities)
{
if (!blip.Selectable)
continue;

var currentDistance = (_transformSystem.ToMapCoordinates(blip.Coordinates).Position - worldPosition).Length();
var currentDistance = (_transformSystem.ToMapCoordinates(blip.Coordinates).Position - worldPosition).Length();

if (closestDistance < currentDistance || currentDistance * MinimapScale > MaxSelectableDistance)
continue;
if (closestDistance < currentDistance || currentDistance * MinimapScale > MaxSelectableDistance)
continue;

closestEntity = currentEntity;
closestDistance = currentDistance;
}

closestEntity = currentEntity;
closestDistance = currentDistance;
if (closestEntity.IsValid() && closestDistance <= MaxSelectableDistance)
{
TrackedEntitySelectedAction?.Invoke(closestEntity);
invokedSelection = true;
}
}

if (closestDistance > MaxSelectableDistance || !closestEntity.IsValid())
return;
if (clickCoords != null)
MapClickedAction?.Invoke(clickCoords.Value);

TrackedEntitySelectedAction.Invoke(closestEntity);
if (!invokedSelection && clickCoords == null)
return;
}

else if (args.Function == EngineKeyFunctions.UIRightClick)
Expand Down
80 changes: 80 additions & 0 deletions Content.Client/Silicons/StationAi/StationAiSystem.Warp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using Content.Shared.Silicons.StationAi;
using Robust.Client.Player;
using Robust.Shared.Player;

namespace Content.Client.Silicons.StationAi;

public sealed partial class StationAiSystem
{
private StationAiWarpWindow? _warpWindow;

private void InitializeWarp()
{
SubscribeNetworkEvent<StationAiWarpTargetsEvent>(OnWarpTargets);
}

private void ShutdownWarp()
{
if (_warpWindow != null)
{
_warpWindow.TargetSelected -= OnWarpTargetSelected;
_warpWindow.OnClose -= OnWarpWindowClosed;
_warpWindow.Close();
_warpWindow = null;
}

}

protected override void OnOpenWarpAction(Entity<StationAiHeldComponent> ent, ref StationAiOpenWarpActionEvent args)
{
base.OnOpenWarpAction(ent, ref args);

if (_player.LocalEntity != ent.Owner)
return;

EnsureWarpWindow();
_warpWindow?.SetLoading(true);
RaiseNetworkEvent(new StationAiWarpRequestEvent());
}

private void OnWarpTargets(StationAiWarpTargetsEvent msg, EntitySessionEventArgs args)
{
if (_player.LocalEntity is not { } local || !HasComp<StationAiHeldComponent>(local))
return;

EnsureWarpWindow();
_warpWindow?.SetTargets(msg.Targets);
}

private void OnWarpTargetSelected(StationAiWarpTarget target)
{
RaiseNetworkEvent(new StationAiWarpToTargetEvent(target.Target));
_warpWindow?.Close();
}

private void OnWarpWindowClosed()
{
if (_warpWindow == null)
return;

_warpWindow.TargetSelected -= OnWarpTargetSelected;
_warpWindow.OnClose -= OnWarpWindowClosed;
_warpWindow = null;
}

private void EnsureWarpWindow()
{
if (_warpWindow != null)
{
if (!_warpWindow.IsOpen)
_warpWindow.OpenCentered();
return;
}

_warpWindow = new StationAiWarpWindow();
_warpWindow.TargetSelected += OnWarpTargetSelected;
_warpWindow.OnClose += OnWarpWindowClosed;
_warpWindow.OpenCentered();
}
}
2 changes: 2 additions & 0 deletions Content.Client/Silicons/StationAi/StationAiSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public override void Initialize()
base.Initialize();
InitializeAirlock();
InitializePowerToggle();
InitializeWarp();

SubscribeLocalEvent<StationAiOverlayComponent, LocalPlayerAttachedEvent>(OnAiAttached);
SubscribeLocalEvent<StationAiOverlayComponent, LocalPlayerDetachedEvent>(OnAiDetached);
Expand Down Expand Up @@ -90,6 +91,7 @@ private void OnAppearanceChange(Entity<StationAiCoreComponent> entity, ref Appea
public override void Shutdown()
{
base.Shutdown();
ShutdownWarp();
_overlayMgr.RemoveOverlay<StationAiOverlay>();
}
}
Loading
Loading