mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
Some camera map fixes and improvements (#44446)
This commit is contained in:
parent
d7f7a91183
commit
01dda0b5ae
5 changed files with 29 additions and 24 deletions
|
|
@ -36,7 +36,7 @@ public sealed class SurveillanceCameraMonitorBoundUserInterface : BoundUserInter
|
|||
_window.CameraDisconnect += OnCameraDisconnect;
|
||||
|
||||
var xform = EntMan.GetComponent<TransformComponent>(Owner);
|
||||
var gridUid = xform.GridUid ?? xform.MapUid;
|
||||
var gridUid = xform.GridUid;
|
||||
|
||||
if (gridUid is not null)
|
||||
_window?.SetMap(gridUid.Value);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public sealed partial class SurveillanceCameraMonitorWindow : DefaultWindow
|
|||
[Dependency] private IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private IResourceCache _resourceCache = default!;
|
||||
[Dependency] private IEntityManager _entityManager = default!;
|
||||
[Dependency] private IEntityNetworkManager _entityNetManager = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when a camera is selected.
|
||||
|
|
@ -224,6 +225,6 @@ public sealed partial class SurveillanceCameraMonitorWindow : DefaultWindow
|
|||
if (!string.IsNullOrEmpty(marker.Address))
|
||||
CameraSelected?.Invoke(marker.Address, marker.Subnet);
|
||||
else
|
||||
_entityManager.RaisePredictiveEvent(new RequestCameraMarkerUpdateMessage(netEntity));
|
||||
_entityNetManager.SendSystemNetworkMessage(new RequestCameraMarkerUpdateMessage(netEntity));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public sealed partial class SurveillanceCameraNavMapControl : NavMapControl
|
|||
private readonly Texture _invalidTexture;
|
||||
|
||||
private string _activeCameraAddress = string.Empty;
|
||||
private HashSet<string> _availableSubnets = new();
|
||||
private HashSet<string> _availableSubnets = [];
|
||||
private (Dictionary<NetEntity, CameraMarker> Cameras, string ActiveAddress, HashSet<string> AvailableSubnets) _lastState;
|
||||
|
||||
public bool EnableCameraSelection { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Numerics;
|
||||
using Content.Server.DeviceNetwork.Systems;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.DeviceNetwork.Components;
|
||||
using Content.Shared.SurveillanceCamera.Components;
|
||||
|
|
@ -11,40 +12,42 @@ public sealed partial class SurveillanceCameraMapSystem : EntitySystem
|
|||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SurveillanceCameraComponent, MapInitEvent>(OnCameraInit, after: [typeof(DeviceNetworkSystem)]);
|
||||
SubscribeLocalEvent<SurveillanceCameraComponent, MoveEvent>(OnCameraMoved);
|
||||
SubscribeLocalEvent<SurveillanceCameraComponent, EntityUnpausedEvent>(OnCameraUnpaused);
|
||||
|
||||
SubscribeNetworkEvent<RequestCameraMarkerUpdateMessage>(OnRequestCameraMarkerUpdate);
|
||||
}
|
||||
|
||||
private void OnCameraUnpaused(EntityUid uid, SurveillanceCameraComponent comp, ref EntityUnpausedEvent args)
|
||||
private void OnCameraInit(Entity<SurveillanceCameraComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
if (Terminating(uid))
|
||||
return;
|
||||
|
||||
UpdateCameraMarker((uid, comp));
|
||||
UpdateCameraMarker(ent);
|
||||
}
|
||||
|
||||
private void OnCameraMoved(EntityUid uid, SurveillanceCameraComponent comp, ref MoveEvent args)
|
||||
private void OnCameraMoved(Entity<SurveillanceCameraComponent> ent, ref MoveEvent args)
|
||||
{
|
||||
if (Terminating(uid))
|
||||
if (!args.ParentChanged)
|
||||
{
|
||||
UpdateCameraMarker(ent);
|
||||
return;
|
||||
}
|
||||
|
||||
var oldGridUid = _transform.GetGrid(args.OldPosition);
|
||||
var newGridUid = _transform.GetGrid(args.NewPosition);
|
||||
var newGridUid = args.Component.GridUid;
|
||||
|
||||
if (oldGridUid != newGridUid && oldGridUid is not null && !Terminating(oldGridUid.Value))
|
||||
if (oldGridUid != newGridUid && oldGridUid is not null && !TerminatingOrDeleted(oldGridUid.Value))
|
||||
{
|
||||
if (TryComp<SurveillanceCameraMapComponent>(oldGridUid, out var oldMapComp))
|
||||
{
|
||||
var netEntity = GetNetEntity(uid);
|
||||
var netEntity = GetNetEntity(ent.Owner);
|
||||
if (oldMapComp.Cameras.Remove(netEntity))
|
||||
Dirty(oldGridUid.Value, oldMapComp);
|
||||
}
|
||||
}
|
||||
|
||||
if (newGridUid is not null && !Terminating(newGridUid.Value))
|
||||
UpdateCameraMarker((uid, comp));
|
||||
if (newGridUid is not null && !TerminatingOrDeleted(newGridUid.Value))
|
||||
UpdateCameraMarker(ent);
|
||||
}
|
||||
|
||||
private void OnRequestCameraMarkerUpdate(RequestCameraMarkerUpdateMessage args)
|
||||
|
|
@ -63,13 +66,13 @@ public sealed partial class SurveillanceCameraMapSystem : EntitySystem
|
|||
{
|
||||
var (uid, comp) = camera;
|
||||
|
||||
if (Terminating(uid))
|
||||
if (TerminatingOrDeleted(uid))
|
||||
return;
|
||||
|
||||
if (!TryComp(uid, out TransformComponent? xform) || !TryComp(uid, out DeviceNetworkComponent? deviceNet))
|
||||
return;
|
||||
|
||||
var gridUid = xform.GridUid ?? xform.MapUid;
|
||||
var gridUid = xform.GridUid;
|
||||
if (gridUid is null)
|
||||
return;
|
||||
|
||||
|
|
@ -85,7 +88,7 @@ public sealed partial class SurveillanceCameraMapSystem : EntitySystem
|
|||
var powered = CompOrNull<ApcPowerReceiverComponent>(uid)?.Powered ?? true;
|
||||
var active = comp.Active && powered;
|
||||
|
||||
bool exists = mapComp.Cameras.TryGetValue(netEntity, out var existing);
|
||||
var exists = mapComp.Cameras.TryGetValue(netEntity, out var existing);
|
||||
|
||||
if (exists &&
|
||||
existing.Position.Equals(localPos) &&
|
||||
|
|
@ -117,12 +120,12 @@ public sealed partial class SurveillanceCameraMapSystem : EntitySystem
|
|||
if (!TryComp(cameraUid, out TransformComponent? xform))
|
||||
return;
|
||||
|
||||
var gridUid = xform.GridUid ?? xform.MapUid;
|
||||
if (gridUid == null || !TryComp<SurveillanceCameraMapComponent>(gridUid.Value, out var mapComp))
|
||||
var gridUid = xform.GridUid;
|
||||
if (gridUid is null || !TryComp<SurveillanceCameraMapComponent>(gridUid.Value, out var mapComp))
|
||||
return;
|
||||
|
||||
var netEntity = GetNetEntity(cameraUid);
|
||||
if (mapComp.Cameras.TryGetValue(netEntity, out var marker))
|
||||
if (mapComp.Cameras.TryGetValue(netEntity, out var marker) && marker.Visible != visible)
|
||||
{
|
||||
marker.Visible = visible;
|
||||
mapComp.Cameras[netEntity] = marker;
|
||||
|
|
@ -138,8 +141,8 @@ public sealed partial class SurveillanceCameraMapSystem : EntitySystem
|
|||
if (!TryComp(cameraUid, out TransformComponent? xform))
|
||||
return false;
|
||||
|
||||
var gridUid = xform.GridUid ?? xform.MapUid;
|
||||
if (gridUid == null || !TryComp<SurveillanceCameraMapComponent>(gridUid, out var mapComp))
|
||||
var gridUid = xform.GridUid;
|
||||
if (gridUid is null || !TryComp<SurveillanceCameraMapComponent>(gridUid, out var mapComp))
|
||||
return false;
|
||||
|
||||
var netEntity = GetNetEntity(cameraUid);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ public sealed partial class SurveillanceCameraMapComponent : Component
|
|||
/// <summary>
|
||||
/// Dictionary of cameras on on the current grid.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[AutoNetworkedField]
|
||||
public Dictionary<NetEntity, CameraMarker> Cameras = new();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue