From 9ace52a6c1067351e4b70ca76d4d09c76221f556 Mon Sep 17 00:00:00 2001 From: Flipp Syder <76629141+vulppine@users.noreply.github.com> Date: Mon, 5 Sep 2022 17:55:44 -0700 Subject: [PATCH] Device link visualizer (#11054) * shuffles devicelist to shared, adds an overlay for devicelist * adds space property to overlay * moves networkconfigurator to shared, makes devicelistsystem clientside check activedevicelist * dirties components upon change, adds networkedcomponent to sharednetworkconfigurator * state handlers for networked components * whoops * lots of shuffling, renaming, and access changes * randomizes color for every new entity added to the overlay * adds a client-side action to clear all network overlays if they're active * clones action (oops) * localization, adds a command for clearing network link overlays (in case the action disappears) * moves the entity manager up into the bui fields * makes that a dependency * attempts to just directly get the color from the dict when drawing, now * fixes up a few comments * adds dirty on init to devicelistcomponent * hacky solution related to mapping with a networkconfigurator * more stricter bound on that hacky solution * just checks if the life stage is initialized instead of if the entity was initialized * moves getalldevices to shared * readds linq import * tries to ensure that the show button is toggled on if the device we're trying to configure is currently being tracked by the overlay * some reorganization --- ...kConfiguratorActiveLinkOverlayComponent.cs | 15 +++ .../NetworkConfiguratorBoundUserInterface.cs | 48 +++++++- .../NetworkConfiguratorConfigurationMenu.xaml | 2 +- .../NetworkConfiguratorLinkOverlay.cs | 65 ++++++++++ .../Systems/DeviceListSystem.cs | 9 ++ .../Systems/NetworkConfiguratorSystem.cs | 116 ++++++++++++++++++ .../Atmos/Monitor/Systems/AirAlarmSystem.cs | 1 + .../Atmos/Monitor/Systems/FireAlarmSystem.cs | 1 + .../DeviceNetwork/Systems/DeviceListSystem.cs | 40 +----- .../Systems/NetworkConfiguratorSystem.cs | 25 +++- .../Components/DeviceListComponent.cs | 23 +++- .../NetworkConfiguratorComponent.cs | 31 +++-- .../Systems/SharedDeviceListSystem.cs | 72 +++++++++++ .../SharedNetworkConfiguratorSystem.cs | 52 ++++++++ .../en-US/devices/network-configurator.ftl | 2 + Resources/Prototypes/Actions/types.yml | 7 ++ 16 files changed, 454 insertions(+), 55 deletions(-) create mode 100644 Content.Client/NetworkConfigurator/NetworkConfiguratorActiveLinkOverlayComponent.cs create mode 100644 Content.Client/NetworkConfigurator/NetworkConfiguratorLinkOverlay.cs create mode 100644 Content.Client/NetworkConfigurator/Systems/DeviceListSystem.cs create mode 100644 Content.Client/NetworkConfigurator/Systems/NetworkConfiguratorSystem.cs rename {Content.Server => Content.Shared}/DeviceNetwork/Components/DeviceListComponent.cs (53%) rename {Content.Server => Content.Shared}/DeviceNetwork/Components/NetworkConfiguratorComponent.cs (58%) create mode 100644 Content.Shared/DeviceNetwork/Systems/SharedDeviceListSystem.cs create mode 100644 Content.Shared/DeviceNetwork/Systems/SharedNetworkConfiguratorSystem.cs diff --git a/Content.Client/NetworkConfigurator/NetworkConfiguratorActiveLinkOverlayComponent.cs b/Content.Client/NetworkConfigurator/NetworkConfiguratorActiveLinkOverlayComponent.cs new file mode 100644 index 0000000000..b74f8f9af5 --- /dev/null +++ b/Content.Client/NetworkConfigurator/NetworkConfiguratorActiveLinkOverlayComponent.cs @@ -0,0 +1,15 @@ +namespace Content.Client.NetworkConfigurator; + +/// +/// This is used for... +/// +[RegisterComponent] +public sealed class NetworkConfiguratorActiveLinkOverlayComponent : Component +{ + /// + /// The entities linked to this network configurator. + /// This could just... couldn't this just be grabbed + /// if DeviceList was shared? + /// + public HashSet Devices = new(); +} diff --git a/Content.Client/NetworkConfigurator/NetworkConfiguratorBoundUserInterface.cs b/Content.Client/NetworkConfigurator/NetworkConfiguratorBoundUserInterface.cs index 86490b5147..168615ca0b 100644 --- a/Content.Client/NetworkConfigurator/NetworkConfiguratorBoundUserInterface.cs +++ b/Content.Client/NetworkConfigurator/NetworkConfiguratorBoundUserInterface.cs @@ -1,16 +1,24 @@ using Content.Shared.DeviceNetwork; using JetBrains.Annotations; using Robust.Client.GameObjects; +using Robust.Client.UserInterface.Controls; namespace Content.Client.NetworkConfigurator; public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface { + [Dependency] private readonly IEntityManager _entityManager = default!; private NetworkConfiguratorListMenu? _listMenu; private NetworkConfiguratorConfigurationMenu? _configurationMenu; + private NetworkConfiguratorSystem _netConfig; + private DeviceListSystem _deviceList; + public NetworkConfiguratorBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) { + IoCManager.InjectDependencies(this); + _netConfig = _entityManager.System(); + _deviceList = _entityManager.System(); } public void OnRemoveButtonPressed(string address) @@ -38,12 +46,31 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface //_configurationMenu.Edit.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Edit); _configurationMenu.Clear.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Clear); _configurationMenu.Copy.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Copy); - _configurationMenu.Show.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Show); + _configurationMenu.Show.OnPressed += OnShowPressed; + _configurationMenu.Show.Pressed = _netConfig.ConfiguredListIsTracked(Owner.Owner); _configurationMenu.OpenCentered(); break; } } + private void OnShowPressed(BaseButton.ButtonEventArgs args) + { + if (!args.Button.Pressed) + { + _netConfig.ToggleVisualization(Owner.Owner, false); + return; + } + + if (_entityManager.GetComponent(Owner.Owner).EntityLifeStage == EntityLifeStage.Initialized) + { + // We're in mapping mode. Do something hacky. + SendMessage(new ManualDeviceListSyncMessage(null, null)); + return; + } + + _netConfig.ToggleVisualization(Owner.Owner, true); + } + protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); @@ -52,6 +79,25 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface _listMenu?.UpdateState(castState); } + protected override void ReceiveMessage(BoundUserInterfaceMessage message) + { + base.ReceiveMessage(message); + + if (_configurationMenu == null + || _entityManager.GetComponent(Owner.Owner).EntityLifeStage > EntityLifeStage.Initialized + || message is not ManualDeviceListSyncMessage cast + || cast.Device == null + || cast.Devices == null) + { + return; + } + + _netConfig.SetActiveDeviceList(Owner.Owner, cast.Device.Value); + _deviceList.UpdateDeviceList(cast.Device.Value, cast.Devices); + _netConfig.ToggleVisualization(Owner.Owner, true); + _configurationMenu.Show.Pressed = true; + } + protected override void Dispose(bool disposing) { base.Dispose(disposing); diff --git a/Content.Client/NetworkConfigurator/NetworkConfiguratorConfigurationMenu.xaml b/Content.Client/NetworkConfigurator/NetworkConfiguratorConfigurationMenu.xaml index 0c1affe6a3..7be6c47b7a 100644 --- a/Content.Client/NetworkConfigurator/NetworkConfiguratorConfigurationMenu.xaml +++ b/Content.Client/NetworkConfigurator/NetworkConfiguratorConfigurationMenu.xaml @@ -11,7 +11,7 @@