Surveillance cameras (#8246)
* cameras but i didn't feel like git stashing them * Adds more functionality server-side for surveillance cameras * rider moment * Adds skeleton for SurveillanceCameraMonitorBoundUi on client * whoops * makes surveillance camera monitor UI more defined * removes tree from SurveillanceCameraMonitorWindow * surveillance camera active flag, other routing things * actually sets how SurveillanceCameraMonitorSystem sends camera info to clients * adds entity yaml, changes field * adds the camera/monitor entities, makes the UI open * SurveillanceCameraRouters (not implemented fully) * subnets for cameras, server-side * it works! * fixes rotation in cameras * whoops restores surveillance cameras to ignored components makes it so that switching cameras now lerps the other camera * makes the UI work * makes it so that cameras actually refresh now * cleanup * adds camera.rsi * cleans up prototypes a bit * adds camera subnet frequencies, cameras in subnets * adds surveillance camera router subnets * might fix testing errors * adds the circuit board to the surveillance camera monitor * fixes up the camera monitor (the detective will get his tv soon) * adds heartbeat, ensures subnet data is passed into cameras to send * fixes up a few things * whoops * changes to UI internals * fixes subnet selection issue * localized strings for UI * changes 'test' id to 'camera' for cameras * whoops * missing s * camera static! * adds a delay to camera switching * adjusts a few things in camera timing * adds setup for cameras/routers, localization for frequency names * adds setup ui for routers, makes subnet names in monitor window follow frequency name in prototype * localization, some cleanup * ui adjustments * adds surveillance camera visuals * fixes a bug when closing the UI for monitors * adds disconnect message to UI * adds construction graph to cameras * adds the camera to the construction menu * fixes network selection for setup, tweak to assembly * adds surveillance camera router construction, fixes up surveillance camera wire cutting * adds disconnect button to monitor UI * switches around the status text * tweaks monitor UI * makes the address actually show * might make tests pass * UI adjustments, hard name limit * ok, that didn't work * adds wireless cameras * makes the television work/look nicer * adds tripod cameras in addition to mobile cameras * makes wireless cameras constructable * fixes up those prototypes * reorganization in C#, small cleanup * ensures that power changes deactivate some devices * adds a component to the television, comments out a function * actually, never mind, i forgot that wireless cameras existed/are creatable for a second * tweaks to router construction, removes SubnetTest from prototypes * removes it from frequencies too * Apply suggestions from code review Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * type serializers into components * setup window opens centered, enum is now byte * replaces active monitor list with ActiveSurveillanceCameraMonitorComponent * adds paused/deleted entity checks, changes how verbs are given * removes EntitySystem.Get<T>() references * fixes bug related to selecting network from setup, alphabet-orders network listing in setup * rider moment * adds minwidth to surveillance camera setup window * addresses reviews * should fix the issue with camera visuals not updating properly * addresses some reviews * addresses further review * addresses reviews related to RSIs * never needed a key there anyways * changes a few things with routers to ensure that they're active * whoops * ensurecomp over addcomp * whoops Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
namespace Content.Client.SurveillanceCamera;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class ActiveSurveillanceCameraMonitorVisualsComponent : Component
|
||||
{
|
||||
public float TimeLeft = 30f;
|
||||
|
||||
public Action? OnFinish;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.SurveillanceCamera;
|
||||
|
||||
public sealed class SurveillanceCameraMonitorSystem : EntitySystem
|
||||
{
|
||||
private readonly RemQueue<EntityUid> _toRemove = new();
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var comp in EntityQuery<ActiveSurveillanceCameraMonitorVisualsComponent>())
|
||||
{
|
||||
if (Paused(comp.Owner))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
comp.TimeLeft -= frameTime;
|
||||
|
||||
if (comp.TimeLeft <= 0 || Deleted(comp.Owner))
|
||||
{
|
||||
if (comp.OnFinish != null)
|
||||
{
|
||||
comp.OnFinish();
|
||||
}
|
||||
|
||||
_toRemove.Add(comp.Owner);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var uid in _toRemove)
|
||||
{
|
||||
EntityManager.RemoveComponent<ActiveSurveillanceCameraMonitorVisualsComponent>(uid);
|
||||
}
|
||||
|
||||
_toRemove.List?.Clear();
|
||||
}
|
||||
|
||||
public void AddTimer(EntityUid uid, Action onFinish)
|
||||
{
|
||||
var comp = EnsureComp<ActiveSurveillanceCameraMonitorVisualsComponent>(uid);
|
||||
comp.OnFinish = onFinish;
|
||||
}
|
||||
|
||||
public void RemoveTimer(EntityUid uid)
|
||||
{
|
||||
EntityManager.RemoveComponent<ActiveSurveillanceCameraMonitorVisualsComponent>(uid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Content.Shared.SurveillanceCamera;
|
||||
|
||||
namespace Content.Client.SurveillanceCamera;
|
||||
|
||||
// Dummy component so that targetted events work on client for
|
||||
// appearance events.
|
||||
[RegisterComponent]
|
||||
public sealed class SurveillanceCameraVisualsComponent : Component
|
||||
{
|
||||
[DataField("sprites")]
|
||||
public readonly Dictionary<SurveillanceCameraVisuals, string> CameraSprites = new();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Content.Shared.SurveillanceCamera;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.SurveillanceCamera;
|
||||
|
||||
public sealed class SurveillanceCameraVisualsSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SurveillanceCameraVisualsComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
||||
}
|
||||
|
||||
private void OnAppearanceChange(EntityUid uid, SurveillanceCameraVisualsComponent component,
|
||||
ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (!args.AppearanceData.TryGetValue(SurveillanceCameraVisualsKey.Key, out var data)
|
||||
|| data is not SurveillanceCameraVisuals key
|
||||
|| args.Sprite == null
|
||||
|| !args.Sprite.LayerMapTryGet(SurveillanceCameraVisualsKey.Layer, out int layer)
|
||||
|| !component.CameraSprites.TryGetValue(key, out var state))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
args.Sprite.LayerSetState(layer, state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
using Content.Client.Eye;
|
||||
using Content.Shared.SurveillanceCamera;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.SurveillanceCamera.UI;
|
||||
|
||||
public sealed class SurveillanceCameraMonitorBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
private readonly EyeLerpingSystem _eyeLerpingSystem;
|
||||
private readonly SurveillanceCameraMonitorSystem _surveillanceCameraMonitorSystem;
|
||||
|
||||
private SurveillanceCameraMonitorWindow? _window;
|
||||
private EntityUid? _currentCamera;
|
||||
|
||||
public SurveillanceCameraMonitorBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_eyeLerpingSystem = _entityManager.EntitySysManager.GetEntitySystem<EyeLerpingSystem>();
|
||||
_surveillanceCameraMonitorSystem = _entityManager.EntitySysManager.GetEntitySystem<SurveillanceCameraMonitorSystem>();
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_window = new SurveillanceCameraMonitorWindow();
|
||||
|
||||
if (State != null)
|
||||
{
|
||||
UpdateState(State);
|
||||
}
|
||||
|
||||
_window.OpenCentered();
|
||||
|
||||
_window.CameraSelected += OnCameraSelected;
|
||||
_window.SubnetOpened += OnSubnetRequest;
|
||||
_window.CameraRefresh += OnCameraRefresh;
|
||||
_window.SubnetRefresh += OnSubnetRefresh;
|
||||
_window.OnClose += Close;
|
||||
_window.CameraSwitchTimer += OnCameraSwitchTimer;
|
||||
_window.CameraDisconnect += OnCameraDisconnect;
|
||||
}
|
||||
|
||||
private void OnCameraSelected(string address)
|
||||
{
|
||||
SendMessage(new SurveillanceCameraMonitorSwitchMessage(address));
|
||||
}
|
||||
|
||||
private void OnSubnetRequest(string subnet)
|
||||
{
|
||||
SendMessage(new SurveillanceCameraMonitorSubnetRequestMessage(subnet));
|
||||
}
|
||||
|
||||
private void OnCameraSwitchTimer()
|
||||
{
|
||||
_surveillanceCameraMonitorSystem.AddTimer(Owner.Owner, _window!.OnSwitchTimerComplete);
|
||||
}
|
||||
|
||||
private void OnCameraRefresh()
|
||||
{
|
||||
SendMessage(new SurveillanceCameraRefreshCamerasMessage());
|
||||
}
|
||||
|
||||
private void OnSubnetRefresh()
|
||||
{
|
||||
SendMessage(new SurveillanceCameraRefreshSubnetsMessage());
|
||||
}
|
||||
|
||||
private void OnCameraDisconnect()
|
||||
{
|
||||
SendMessage(new SurveillanceCameraDisconnectMessage());
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
if (_window == null || state is not SurveillanceCameraMonitorUiState cast)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (cast.ActiveCamera == null)
|
||||
{
|
||||
_window.UpdateState(null, cast.Subnets, cast.ActiveAddress, cast.ActiveSubnet, cast.Cameras);
|
||||
|
||||
if (_currentCamera != null)
|
||||
{
|
||||
_surveillanceCameraMonitorSystem.RemoveTimer(Owner.Owner);
|
||||
_eyeLerpingSystem.RemoveEye(_currentCamera.Value);
|
||||
_currentCamera = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_currentCamera == null)
|
||||
{
|
||||
_eyeLerpingSystem.AddEye(cast.ActiveCamera.Value);
|
||||
_currentCamera = cast.ActiveCamera;
|
||||
}
|
||||
else if (_currentCamera != cast.ActiveCamera)
|
||||
{
|
||||
_eyeLerpingSystem.RemoveEye(_currentCamera.Value);
|
||||
_eyeLerpingSystem.AddEye(cast.ActiveCamera.Value);
|
||||
_currentCamera = cast.ActiveCamera;
|
||||
}
|
||||
|
||||
if (_entityManager.TryGetComponent(cast.ActiveCamera, out EyeComponent eye))
|
||||
{
|
||||
_window.UpdateState(eye.Eye, cast.Subnets, cast.ActiveAddress, cast.ActiveSubnet, cast.Cameras);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
_window?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<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" />
|
||||
</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>
|
||||
@@ -0,0 +1,188 @@
|
||||
using System.Linq;
|
||||
using Content.Client.Resources;
|
||||
using Content.Client.Viewport;
|
||||
using Content.Shared.DeviceNetwork;
|
||||
using Content.Shared.SurveillanceCamera;
|
||||
using Robust.Client.AutoGenerated;
|
||||
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.Prototypes;
|
||||
|
||||
namespace Content.Client.SurveillanceCamera.UI;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class SurveillanceCameraMonitorWindow : DefaultWindow
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
|
||||
public event Action<string>? CameraSelected;
|
||||
public event Action<string>? SubnetOpened;
|
||||
public event Action? CameraRefresh;
|
||||
public event Action? SubnetRefresh;
|
||||
public event Action? CameraSwitchTimer;
|
||||
public event Action? CameraDisconnect;
|
||||
|
||||
private string _currentAddress = string.Empty;
|
||||
private readonly FixedEye _defaultEye = new();
|
||||
private readonly Dictionary<string, int> _subnetMap = new();
|
||||
|
||||
private string? SelectedSubnet
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SubnetSelector.ItemCount == 0
|
||||
|| SubnetSelector.SelectedMetadata == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) SubnetSelector.SelectedMetadata;
|
||||
}
|
||||
}
|
||||
|
||||
public SurveillanceCameraMonitorWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
// 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 shader = _prototypeManager.Index<ShaderPrototype>("CameraStatic").Instance().Duplicate();
|
||||
|
||||
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!();
|
||||
}
|
||||
|
||||
|
||||
// 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)
|
||||
{
|
||||
_currentAddress = activeAddress;
|
||||
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)
|
||||
{
|
||||
CameraView.Eye = eye ?? _defaultEye;
|
||||
CameraView.Visible = eye != null;
|
||||
CameraViewBackground.Visible = true;
|
||||
CameraDisconnectButton.Disabled = eye == null;
|
||||
|
||||
if (eye != null)
|
||||
{
|
||||
CameraStatus.Text = Loc.GetString("surveillance-camera-monitor-ui-status",
|
||||
("status", Loc.GetString("surveillance-camera-monitor-ui-status-connecting")),
|
||||
("address", _currentAddress));
|
||||
CameraSwitchTimer!();
|
||||
}
|
||||
else
|
||||
{
|
||||
CameraStatus.Text = Loc.GetString("surveillance-camera-monitor-ui-status-disconnected");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSwitchTimerComplete()
|
||||
{
|
||||
CameraViewBackground.Visible = false;
|
||||
CameraStatus.Text = Loc.GetString("surveillance-camera-monitor-ui-status",
|
||||
("status", Loc.GetString("surveillance-camera-monitor-ui-status-connected")),
|
||||
("address", _currentAddress));
|
||||
}
|
||||
|
||||
private int AddSubnet(string subnet)
|
||||
{
|
||||
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!);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using Content.Shared.SurveillanceCamera;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.SurveillanceCamera.UI;
|
||||
|
||||
public sealed class SurveillanceCameraSetupBoundUi : BoundUserInterface
|
||||
{
|
||||
private SurveillanceCameraSetupWindow? _window;
|
||||
private SurveillanceCameraSetupUiKey _type;
|
||||
|
||||
public SurveillanceCameraSetupBoundUi(ClientUserInterfaceComponent component, object uiKey) : base(component, uiKey)
|
||||
{
|
||||
if (uiKey is not SurveillanceCameraSetupUiKey key)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_type = key;
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
_window = new();
|
||||
|
||||
if (_type == SurveillanceCameraSetupUiKey.Router)
|
||||
{
|
||||
_window.HideNameSelector();
|
||||
}
|
||||
|
||||
_window.OpenCentered();
|
||||
_window.OnNameConfirm += SendDeviceName;
|
||||
_window.OnNetworkConfirm += SendSelectedNetwork;
|
||||
|
||||
}
|
||||
|
||||
private void SendSelectedNetwork(int idx)
|
||||
{
|
||||
SendMessage(new SurveillanceCameraSetupSetNetwork(idx));
|
||||
}
|
||||
|
||||
private void SendDeviceName(string name)
|
||||
{
|
||||
SendMessage(new SurveillanceCameraSetupSetName(name));
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (_window == null || state is not SurveillanceCameraSetupBoundUiState cast)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_window.UpdateState(cast.Name, cast.NameDisabled, cast.NetworkDisabled);
|
||||
_window.LoadAvailableNetworks(cast.Network, cast.Networks);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
_window!.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
Title="{Loc 'surveillance-camera-setup'}"
|
||||
MinWidth="400">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<BoxContainer Name="NamingSection">
|
||||
<LineEdit HorizontalExpand="True" Name="DeviceName" />
|
||||
<Button Name="NameConfirm" Text="{Loc 'surveillance-camera-setup-ui-set'}"/>
|
||||
</BoxContainer>
|
||||
<BoxContainer Name="NetworkSection">
|
||||
<OptionButton HorizontalExpand="True" Name="NetworkSelector" />
|
||||
<Button Name="NetworkConfirm" Text="{Loc 'surveillance-camera-setup-ui-set'}" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</DefaultWindow>
|
||||
@@ -0,0 +1,78 @@
|
||||
using Content.Shared.DeviceNetwork;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.SurveillanceCamera.UI;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class SurveillanceCameraSetupWindow : DefaultWindow
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
public Action<string>? OnNameConfirm;
|
||||
public Action<int>? OnNetworkConfirm;
|
||||
|
||||
public SurveillanceCameraSetupWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
NetworkConfirm.OnPressed += _ => OnNetworkConfirm!(NetworkSelector.SelectedId);
|
||||
NameConfirm.OnPressed += _ => OnNameConfirm!(DeviceName.Text);
|
||||
NetworkSelector.OnItemSelected += args => NetworkSelector.SelectId(args.Id);
|
||||
}
|
||||
|
||||
public void HideNameSelector() => NamingSection.Visible = false;
|
||||
|
||||
public void UpdateState(string name, bool disableNaming, bool disableNetworkSelector)
|
||||
{
|
||||
DeviceName.Text = name;
|
||||
DeviceName.Editable = !disableNaming;
|
||||
NameConfirm.Disabled = disableNaming;
|
||||
|
||||
NetworkSelector.Disabled = disableNetworkSelector;
|
||||
NetworkConfirm.Disabled = disableNetworkSelector;
|
||||
}
|
||||
|
||||
// Pass in a list of frequency prototype IDs.
|
||||
public void LoadAvailableNetworks(uint currentNetwork, List<string> networks)
|
||||
{
|
||||
NetworkSelector.Clear();
|
||||
|
||||
if (networks.Count == 0)
|
||||
{
|
||||
NetworkSection.Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var id = 0;
|
||||
var idList = new List<(int id, string networkName)>();
|
||||
foreach (var network in networks)
|
||||
{
|
||||
idList.Add((id, network));
|
||||
id++;
|
||||
}
|
||||
|
||||
idList.Sort((a, b) => a.networkName.CompareTo(b.networkName));
|
||||
|
||||
foreach (var (networkId, network) in idList)
|
||||
{
|
||||
if (!_prototypeManager.TryIndex(network, out DeviceFrequencyPrototype? frequency)
|
||||
|| frequency.Name == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
NetworkSelector.AddItem(Loc.GetString(frequency.Name), networkId);
|
||||
if (frequency.Frequency == currentNetwork)
|
||||
{
|
||||
NetworkSelector.SelectId(networkId);
|
||||
}
|
||||
|
||||
id++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user