Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -3,7 +3,7 @@ namespace Content.Client.SurveillanceCamera;
|
||||
[RegisterComponent]
|
||||
public sealed partial class ActiveSurveillanceCameraMonitorVisualsComponent : Component
|
||||
{
|
||||
public float TimeLeft = 10f;
|
||||
public float TimeLeft = 0.5f;
|
||||
|
||||
public Action? OnFinish;
|
||||
}
|
||||
|
||||
@@ -14,18 +14,30 @@ public sealed class SurveillanceCameraMonitorBoundUserInterface : BoundUserInter
|
||||
|
||||
[ViewVariables]
|
||||
private EntityUid? _currentCamera;
|
||||
private readonly IEntityManager _entManager;
|
||||
|
||||
public SurveillanceCameraMonitorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
_eyeLerpingSystem = EntMan.System<EyeLerpingSystem>();
|
||||
_surveillanceCameraMonitorSystem = EntMan.System<SurveillanceCameraMonitorSystem>();
|
||||
IoCManager.InjectDependencies(this);
|
||||
_entManager = IoCManager.Resolve<IEntityManager>();
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_window = new SurveillanceCameraMonitorWindow();
|
||||
// Sunrise-start
|
||||
EntityUid? gridUid = null;
|
||||
|
||||
if (_entManager.TryGetComponent<TransformComponent>(Owner, out var xform))
|
||||
{
|
||||
gridUid = xform.GridUid;
|
||||
}
|
||||
|
||||
_window = new SurveillanceCameraMonitorWindow(gridUid);
|
||||
// Sunrise-end
|
||||
|
||||
if (State != null)
|
||||
{
|
||||
@@ -35,7 +47,6 @@ public sealed class SurveillanceCameraMonitorBoundUserInterface : BoundUserInter
|
||||
_window.OpenCentered();
|
||||
|
||||
_window.CameraSelected += OnCameraSelected;
|
||||
_window.SubnetOpened += OnSubnetRequest;
|
||||
_window.CameraRefresh += OnCameraRefresh;
|
||||
_window.SubnetRefresh += OnSubnetRefresh;
|
||||
_window.OnClose += Close;
|
||||
@@ -43,14 +54,9 @@ public sealed class SurveillanceCameraMonitorBoundUserInterface : BoundUserInter
|
||||
_window.CameraDisconnect += OnCameraDisconnect;
|
||||
}
|
||||
|
||||
private void OnCameraSelected(string address)
|
||||
private void OnCameraSelected(NetEntity camera)
|
||||
{
|
||||
SendMessage(new SurveillanceCameraMonitorSwitchMessage(address));
|
||||
}
|
||||
|
||||
private void OnSubnetRequest(string subnet)
|
||||
{
|
||||
SendMessage(new SurveillanceCameraMonitorSubnetRequestMessage(subnet));
|
||||
SendMessage(new SurveillanceCameraMonitorSwitchMessage(camera));
|
||||
}
|
||||
|
||||
private void OnCameraSwitchTimer()
|
||||
@@ -82,9 +88,11 @@ public sealed class SurveillanceCameraMonitorBoundUserInterface : BoundUserInter
|
||||
|
||||
var active = EntMan.GetEntity(cast.ActiveCamera);
|
||||
|
||||
_entManager.TryGetComponent<TransformComponent>(Owner, out var xform);
|
||||
|
||||
if (active == null)
|
||||
{
|
||||
_window.UpdateState(null, cast.Subnets, cast.ActiveAddress, cast.ActiveSubnet, cast.Cameras);
|
||||
_window.UpdateState(null, cast.ActiveAddress, cast.ActiveCamera);
|
||||
|
||||
if (_currentCamera != null)
|
||||
{
|
||||
@@ -109,9 +117,11 @@ public sealed class SurveillanceCameraMonitorBoundUserInterface : BoundUserInter
|
||||
|
||||
if (EntMan.TryGetComponent<EyeComponent>(active, out var eye))
|
||||
{
|
||||
_window.UpdateState(eye.Eye, cast.Subnets, cast.ActiveAddress, cast.ActiveSubnet, cast.Cameras);
|
||||
_window.UpdateState(eye.Eye, cast.ActiveAddress, cast.ActiveCamera);
|
||||
}
|
||||
}
|
||||
|
||||
_window.ShowCameras(cast.Cameras, xform?.Coordinates);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
||||
@@ -1,25 +1,41 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
xmlns:viewport="clr-namespace:Content.Client.Viewport"
|
||||
Title="{Loc 'surveillance-camera-monitor-ui-window'}">
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<BoxContainer Orientation="Vertical" MinWidth="350" VerticalExpand="True">
|
||||
<!-- lazy -->
|
||||
<OptionButton Name="SubnetSelector" />
|
||||
<Button Name="SubnetRefreshButton" Text="{Loc 'surveillance-camera-monitor-ui-refresh-subnets'}" />
|
||||
<ScrollContainer VerticalExpand="True">
|
||||
<ItemList Name="SubnetList" />
|
||||
</ScrollContainer>
|
||||
<Button Name="CameraRefreshButton" Text="{Loc 'surveillance-camera-monitor-ui-refresh-cameras'}" />
|
||||
<Button Name="CameraDisconnectButton" Text="{Loc 'surveillance-camera-monitor-ui-disconnect'}" />
|
||||
<Label Name="CameraStatus" />
|
||||
<controls:FancyWindow xmlns="https://spacestation14.io"
|
||||
xmlns:viewport="clr-namespace:Content.Client.Viewport"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
xmlns:ui="clr-namespace:Content.Client.SurveillanceCamera.UI"
|
||||
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
|
||||
Title="{Loc 'surveillance-camera-monitor-ui-window'}"
|
||||
Resizable="False"
|
||||
MinSize="1300 750">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<BoxContainer Orientation="Horizontal" VerticalExpand="True" HorizontalExpand="True">
|
||||
<ui:SurveillanceCameraNavMapControl Name="NavMap" HorizontalExpand="True" VerticalExpand="True" MinSize="600 700" VerticalAlignment="Top"/>
|
||||
<customControls:VSeparator/>
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<Control VerticalExpand="True" HorizontalExpand="True" Margin="5 5 5 5" Name="CameraViewBox">
|
||||
<viewport:ScalingViewport Name="CameraView"
|
||||
VerticalExpand="True"
|
||||
HorizontalExpand="True"
|
||||
MinSize="700 700"
|
||||
MouseFilter="Ignore" />
|
||||
<TextureRect VerticalExpand="True" HorizontalExpand="True" MinSize="700 700" Name="CameraViewBackground" />
|
||||
</Control>
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<Button Name="SubnetRefreshButton" Text="{Loc 'surveillance-camera-monitor-ui-refresh-subnets'}" />
|
||||
<Button Name="CameraRefreshButton" Text="{Loc 'surveillance-camera-monitor-ui-refresh-cameras'}" />
|
||||
<Button Name="CameraDisconnectButton" Text="{Loc 'surveillance-camera-monitor-ui-disconnect'}" />
|
||||
<Label Name="CameraStatus" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<PanelContainer StyleClasses="LowDivider" />
|
||||
<BoxContainer Orientation="Horizontal" Margin="10 2 5 0" VerticalAlignment="Bottom">
|
||||
<Label Text="{Loc 'surveillance-camera-monitor-ui-flavor-left'}" StyleClasses="WindowFooterText" />
|
||||
<Label Text="{Loc 'surveillance-camera-monitor-ui-flavor-right'}" StyleClasses="WindowFooterText"
|
||||
HorizontalAlignment="Right" HorizontalExpand="True" Margin="0 0 5 0" />
|
||||
<TextureRect StyleClasses="NTLogoDark" Stretch="KeepAspectCentered"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Right" SetSize="19 19"/>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<Control VerticalExpand="True" HorizontalExpand="True" Margin="5 5 5 5" Name="CameraViewBox">
|
||||
<viewport:ScalingViewport Name="CameraView"
|
||||
VerticalExpand="True"
|
||||
HorizontalExpand="True"
|
||||
MinSize="500 500"
|
||||
MouseFilter="Ignore" />
|
||||
<TextureRect VerticalExpand="True" HorizontalExpand="True" MinSize="500 500" Name="CameraViewBackground" />
|
||||
</Control>
|
||||
</BoxContainer>
|
||||
</DefaultWindow>
|
||||
</controls:FancyWindow>
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
using System.Linq;
|
||||
using Content.Client.Pinpointer.UI;
|
||||
using Content.Client.Resources;
|
||||
using Content.Client.Viewport;
|
||||
using Content.Shared.DeviceNetwork;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.SurveillanceCamera;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Graphics;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.SurveillanceCamera.UI;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class SurveillanceCameraMonitorWindow : DefaultWindow
|
||||
public sealed partial class SurveillanceCameraMonitorWindow : FancyWindow
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
private readonly IPrototypeManager _prototypeManager;
|
||||
private readonly IEntityManager _entManager;
|
||||
|
||||
public event Action<string>? CameraSelected;
|
||||
public event Action<string>? SubnetOpened;
|
||||
public event Action<NetEntity>? CameraSelected;
|
||||
public event Action? CameraRefresh;
|
||||
public event Action? SubnetRefresh;
|
||||
public event Action? CameraSwitchTimer;
|
||||
@@ -30,110 +31,96 @@ public sealed partial class SurveillanceCameraMonitorWindow : DefaultWindow
|
||||
private string _currentAddress = string.Empty;
|
||||
private bool _isSwitching;
|
||||
private readonly FixedEye _defaultEye = new();
|
||||
private readonly Dictionary<string, int> _subnetMap = new();
|
||||
private Dictionary<NetEntity, CameraData> _cameras = new();
|
||||
private Texture? _blipTexture;
|
||||
private NetEntity? _trackedEntity;
|
||||
|
||||
private string? SelectedSubnet
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SubnetSelector.ItemCount == 0
|
||||
|| SubnetSelector.SelectedMetadata == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) SubnetSelector.SelectedMetadata;
|
||||
}
|
||||
}
|
||||
|
||||
public SurveillanceCameraMonitorWindow()
|
||||
public SurveillanceCameraMonitorWindow(EntityUid? mapUid)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
var resourceCache = IoCManager.Resolve<IResourceCache>();
|
||||
_entManager = IoCManager.Resolve<IEntityManager>();
|
||||
var spriteSystem = _entManager.System<SpriteSystem>();
|
||||
|
||||
// This could be done better. I don't want to deal with stylesheets at the moment.
|
||||
var texture = _resourceCache.GetTexture("/Textures/Interface/Nano/square_black.png");
|
||||
var texture = resourceCache.GetTexture("/Textures/Interface/Nano/square_black.png");
|
||||
var shader = _prototypeManager.Index<ShaderPrototype>("CameraStatic").Instance().Duplicate();
|
||||
|
||||
_blipTexture = spriteSystem.Frame0(new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/NavMap/beveled_circle.png")));
|
||||
|
||||
CameraView.ViewportSize = new Vector2i(500, 500);
|
||||
CameraView.Eye = _defaultEye; // sure
|
||||
CameraViewBackground.Stretch = TextureRect.StretchMode.Scale;
|
||||
CameraViewBackground.Texture = texture;
|
||||
CameraViewBackground.ShaderOverride = shader;
|
||||
|
||||
SubnetList.OnItemSelected += OnSubnetListSelect;
|
||||
|
||||
SubnetSelector.OnItemSelected += args =>
|
||||
{
|
||||
// piss
|
||||
SubnetOpened!((string) args.Button.GetItemMetadata(args.Id)!);
|
||||
};
|
||||
SubnetRefreshButton.OnPressed += _ => SubnetRefresh!();
|
||||
CameraRefreshButton.OnPressed += _ => CameraRefresh!();
|
||||
CameraDisconnectButton.OnPressed += _ => CameraDisconnect!();
|
||||
|
||||
NavMap.TrackedEntitySelectedAction += SetTrackedEntityFromNavMap;
|
||||
|
||||
_entManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (_entManager.TryGetComponent<TransformComponent>(mapUid, out var xform))
|
||||
NavMap.MapUid = xform.GridUid;
|
||||
else
|
||||
NavMap.Visible = false;
|
||||
}
|
||||
|
||||
// Sunrise-start
|
||||
private void SetTrackedEntityFromNavMap(NetEntity? netEntity)
|
||||
{
|
||||
NavMap.Focus = _trackedEntity;
|
||||
|
||||
if (netEntity != null)
|
||||
{
|
||||
CameraSelected!(netEntity.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowCameras(Dictionary<NetEntity, CameraData> cameras, EntityCoordinates? monitorCoords)
|
||||
{
|
||||
ClearAllCamerasPoint();
|
||||
|
||||
_cameras = cameras;
|
||||
|
||||
foreach (var camera in cameras)
|
||||
{
|
||||
NavMap.LocalizedNames.TryAdd(camera.Key, camera.Value.Name);
|
||||
|
||||
var coordinates = _entManager.GetCoordinates(camera.Value.Coordinates);
|
||||
|
||||
if (NavMap.Visible && _blipTexture != null)
|
||||
{
|
||||
NavMap.TrackedEntities.TryAdd(camera.Key,
|
||||
new NavMapBlip(coordinates,
|
||||
_blipTexture,
|
||||
camera.Key == _trackedEntity ? Color.LimeGreen : camera.Value.SubnetColor,
|
||||
camera.Key == _trackedEntity));
|
||||
|
||||
NavMap.Focus = _trackedEntity;
|
||||
}
|
||||
}
|
||||
|
||||
// Show monitor point
|
||||
if (monitorCoords != null)
|
||||
NavMap.TrackedCoordinates.Add(monitorCoords.Value, (true, StyleNano.PointMagenta));
|
||||
}
|
||||
// Sunrise-end
|
||||
|
||||
|
||||
// The UI class should get the eye from the entity, and then
|
||||
// pass it here so that the UI can change its view.
|
||||
public void UpdateState(IEye? eye, HashSet<string> subnets, string activeAddress, string activeSubnet, Dictionary<string, string> cameras)
|
||||
public void UpdateState(IEye? eye, string activeAddress, NetEntity? activeCamera)
|
||||
{
|
||||
_currentAddress = activeAddress;
|
||||
_trackedEntity = activeCamera;
|
||||
SetCameraView(eye);
|
||||
|
||||
if (subnets.Count == 0)
|
||||
{
|
||||
SubnetSelector.AddItem(Loc.GetString("surveillance-camera-monitor-ui-no-subnets"));
|
||||
SubnetSelector.Disabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (SubnetSelector.Disabled && subnets.Count != 0)
|
||||
{
|
||||
SubnetSelector.Clear();
|
||||
SubnetSelector.Disabled = false;
|
||||
}
|
||||
|
||||
// That way, we have *a* subnet selected if this is ever opened.
|
||||
if (string.IsNullOrEmpty(activeSubnet))
|
||||
{
|
||||
SubnetOpened!(subnets.First());
|
||||
return;
|
||||
}
|
||||
|
||||
// if the subnet count is unequal, that means
|
||||
// we have to rebuild the subnet selector
|
||||
if (SubnetSelector.ItemCount != subnets.Count)
|
||||
{
|
||||
SubnetSelector.Clear();
|
||||
_subnetMap.Clear();
|
||||
|
||||
foreach (var subnet in subnets)
|
||||
{
|
||||
var id = AddSubnet(subnet);
|
||||
_subnetMap.Add(subnet, id);
|
||||
}
|
||||
}
|
||||
|
||||
if (_subnetMap.TryGetValue(activeSubnet, out var subnetId))
|
||||
{
|
||||
SubnetSelector.Select(subnetId);
|
||||
}
|
||||
|
||||
PopulateCameraList(cameras);
|
||||
}
|
||||
|
||||
private void PopulateCameraList(Dictionary<string, string> cameras)
|
||||
{
|
||||
SubnetList.Clear();
|
||||
|
||||
foreach (var (address, name) in cameras)
|
||||
{
|
||||
AddCameraToList(name, address);
|
||||
}
|
||||
|
||||
SubnetList.SortItemsByText();
|
||||
}
|
||||
|
||||
private void SetCameraView(IEye? eye)
|
||||
{
|
||||
@@ -173,28 +160,9 @@ public sealed partial class SurveillanceCameraMonitorWindow : DefaultWindow
|
||||
("address", _currentAddress));
|
||||
}
|
||||
|
||||
private int AddSubnet(string subnet)
|
||||
private void ClearAllCamerasPoint()
|
||||
{
|
||||
var name = subnet;
|
||||
if (_prototypeManager.TryIndex<DeviceFrequencyPrototype>(subnet, out var frequency))
|
||||
{
|
||||
name = Loc.GetString(frequency.Name ?? subnet);
|
||||
}
|
||||
|
||||
SubnetSelector.AddItem(name);
|
||||
SubnetSelector.SetItemMetadata(SubnetSelector.ItemCount - 1, subnet);
|
||||
|
||||
return SubnetSelector.ItemCount - 1;
|
||||
}
|
||||
|
||||
private void AddCameraToList(string name, string address)
|
||||
{
|
||||
var item = SubnetList.AddItem($"{name}: {address}");
|
||||
item.Metadata = address;
|
||||
}
|
||||
|
||||
private void OnSubnetListSelect(ItemList.ItemListSelectedEventArgs args)
|
||||
{
|
||||
CameraSelected!((string) SubnetList[args.ItemIndex].Metadata!);
|
||||
NavMap.TrackedCoordinates.Clear();
|
||||
NavMap.TrackedEntities.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
using Content.Client.Pinpointer.UI;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
|
||||
namespace Content.Client.SurveillanceCamera.UI;
|
||||
|
||||
public sealed partial class SurveillanceCameraNavMapControl : NavMapControl
|
||||
{
|
||||
public NetEntity? Focus;
|
||||
public Dictionary<NetEntity, string> LocalizedNames = new();
|
||||
|
||||
private Label _trackedEntityLabel;
|
||||
private PanelContainer _trackedEntityPanel;
|
||||
|
||||
public SurveillanceCameraNavMapControl()
|
||||
{
|
||||
WallColor = new Color(192, 122, 196);
|
||||
TileColor = new(71, 42, 72);
|
||||
BackgroundColor = Color.FromSrgb(TileColor.WithAlpha(BackgroundOpacity));
|
||||
|
||||
_trackedEntityLabel = new Label
|
||||
{
|
||||
Margin = new Thickness(10f, 8f),
|
||||
HorizontalAlignment = HAlignment.Center,
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
Modulate = Color.White,
|
||||
};
|
||||
|
||||
_trackedEntityPanel = new PanelContainer
|
||||
{
|
||||
PanelOverride = new StyleBoxFlat
|
||||
{
|
||||
BackgroundColor = BackgroundColor,
|
||||
},
|
||||
|
||||
Margin = new Thickness(5f, 45f),
|
||||
HorizontalAlignment = HAlignment.Left,
|
||||
VerticalAlignment = VAlignment.Bottom,
|
||||
Visible = false,
|
||||
};
|
||||
|
||||
_trackedEntityPanel.AddChild(_trackedEntityLabel);
|
||||
AddChild(_trackedEntityPanel);
|
||||
VerticalExpand = true;
|
||||
VerticalAlignment = VAlignment.Stretch;
|
||||
|
||||
}
|
||||
|
||||
protected override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
base.Draw(handle);
|
||||
|
||||
if (Focus == null)
|
||||
{
|
||||
_trackedEntityLabel.Text = string.Empty;
|
||||
_trackedEntityPanel.Visible = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ((var netEntity, var blip) in TrackedEntities)
|
||||
{
|
||||
if (netEntity != Focus)
|
||||
continue;
|
||||
|
||||
if (!LocalizedNames.TryGetValue(netEntity, out var name))
|
||||
name = "Unknown";
|
||||
|
||||
var message = name + "\nLocation: [x = " + MathF.Round(blip.Coordinates.X) + ", y = " + MathF.Round(blip.Coordinates.Y) + "]";
|
||||
|
||||
_trackedEntityLabel.Text = message;
|
||||
_trackedEntityPanel.Visible = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_trackedEntityLabel.Text = string.Empty;
|
||||
_trackedEntityPanel.Visible = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user