SUPER CAMERA(OCHKO) (#501)
* SUPER CAMERA(OCHKO) * Удобный монитор камер и портативный мониторинг для детектива. (#25) * Улучшение мониторинга камер * Портативный монитор камер для дека * чейнжлог * Revert "Удобный монитор камер и портативный мониторинг для детектива. (#25)" This reverts commit adf35bb8f6ddd6256b18841a81b330224ebff103. * Revert "Revert "Удобный монитор камер и портативный мониторинг для детектива. (#25)"" This reverts commit bd30fe45046b7b8508e8277f8c186d03338354cd. * cleanups * its so over --------- Co-authored-by: Vigers Ray <60344369+VigersRay@users.noreply.github.com> Co-authored-by: drdth <drdtheuser@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a1f562d181
commit
3ed0f2c4bb
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user