diff --git a/Content.Client/Atmos/EntitySystems/PipeColorVisualizerSystem.cs b/Content.Client/Atmos/EntitySystems/PipeColorVisualizerSystem.cs index 5595f441f7..b23a44e403 100644 --- a/Content.Client/Atmos/EntitySystems/PipeColorVisualizerSystem.cs +++ b/Content.Client/Atmos/EntitySystems/PipeColorVisualizerSystem.cs @@ -1,11 +1,46 @@ using Content.Client.Atmos.Components; using Robust.Client.GameObjects; +using Content.Client.UserInterface.Systems.Storage.Controls; using Content.Shared.Atmos.Piping; +using Content.Shared.Hands; +using Content.Shared.Atmos.Components; +using Content.Shared.Item; namespace Content.Client.Atmos.EntitySystems; public sealed class PipeColorVisualizerSystem : VisualizerSystem { + [Dependency] private readonly SharedItemSystem _itemSystem = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnGetVisuals); + SubscribeLocalEvent(OnDrawInGrid); + } + + /// + /// This method is used to display the color changes of the pipe on the screen.. + /// + private void OnGetVisuals(Entity item, ref GetInhandVisualsEvent args) + { + foreach (var (_, layerData) in args.Layers) + { + if (TryComp(item.Owner, out AtmosPipeColorComponent? pipeColor)) + layerData.Color = pipeColor.Color; + } + } + + /// + /// This method is used to change the pipe's color in a container grid. + /// + private void OnDrawInGrid(Entity item, ref BeforeRenderInGridEvent args) + { + if (TryComp(item.Owner, out AtmosPipeColorComponent? pipeColor)) + args.Color = pipeColor.Color; + } + protected override void OnAppearanceChange(EntityUid uid, PipeColorVisualsComponent component, ref AppearanceChangeEvent args) { if (TryComp(uid, out var sprite) @@ -15,6 +50,8 @@ public sealed class PipeColorVisualizerSystem : VisualizerSystem Entity; } +/// +/// This event gets raised before a sprite gets drawn in a grid and lets to change the sprite color for several gameobjects that have special sprites to render in containers. +/// +public sealed class BeforeRenderInGridEvent : EntityEventArgs +{ + public Color Color { get; set; } + + public BeforeRenderInGridEvent(Color color) + { + Color = color; + } +} + public enum ItemGridPieceMarks { First, diff --git a/Content.Server/Atmos/Piping/EntitySystems/AtmosPipeColorSystem.cs b/Content.Server/Atmos/Piping/EntitySystems/AtmosPipeColorSystem.cs deleted file mode 100644 index 91f70467b4..0000000000 --- a/Content.Server/Atmos/Piping/EntitySystems/AtmosPipeColorSystem.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Content.Server.Atmos.Piping.Components; -using Content.Shared.Atmos.Piping; -using Robust.Server.GameObjects; - -namespace Content.Server.Atmos.Piping.EntitySystems -{ - public sealed class AtmosPipeColorSystem : EntitySystem - { - [Dependency] private readonly SharedAppearanceSystem _appearance = default!; - - public override void Initialize() - { - base.Initialize(); - - SubscribeLocalEvent(OnStartup); - SubscribeLocalEvent(OnShutdown); - } - - private void OnStartup(EntityUid uid, AtmosPipeColorComponent component, ComponentStartup args) - { - if (!TryComp(uid, out AppearanceComponent? appearance)) - return; - - _appearance.SetData(uid, PipeColorVisuals.Color, component.Color, appearance); - } - - private void OnShutdown(EntityUid uid, AtmosPipeColorComponent component, ComponentShutdown args) - { - if (!TryComp(uid, out AppearanceComponent? appearance)) - return; - - _appearance.SetData(uid, PipeColorVisuals.Color, Color.White, appearance); - } - - public void SetColor(EntityUid uid, AtmosPipeColorComponent component, Color color) - { - component.Color = color; - - if (!TryComp(uid, out AppearanceComponent? appearance)) - return; - - _appearance.SetData(uid, PipeColorVisuals.Color, color, appearance); - - var ev = new AtmosPipeColorChangedEvent(color); - RaiseLocalEvent(uid, ref ev); - } - } -} diff --git a/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs b/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs index 8237ccb2eb..89c1182eae 100644 --- a/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs +++ b/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs @@ -1,6 +1,6 @@ using Content.Server.Administration.Managers; -using Content.Server.Atmos.Piping.Components; -using Content.Server.Atmos.Piping.EntitySystems; +using Content.Shared.Atmos.Components; +using Content.Shared.Atmos.EntitySystems; using Content.Shared.Administration; using Content.Shared.NodeContainer; using Content.Shared.NodeContainer.NodeGroups; @@ -78,7 +78,7 @@ namespace Content.Server.Sandbox.Commands if (!EntityManager.TryGetComponent(x.Owner, out AtmosPipeColorComponent? atmosPipeColorComponent)) continue; - _pipeColorSystem.SetColor(x.Owner, atmosPipeColorComponent, color); + _pipeColorSystem.SetColor((x.Owner, atmosPipeColorComponent), color); } } } diff --git a/Content.Server/SprayPainter/SprayPainterSystem.cs b/Content.Server/SprayPainter/SprayPainterSystem.cs index 24ab5e0ea2..a5e08a91a6 100644 --- a/Content.Server/SprayPainter/SprayPainterSystem.cs +++ b/Content.Server/SprayPainter/SprayPainterSystem.cs @@ -1,5 +1,5 @@ -using Content.Server.Atmos.Piping.Components; -using Content.Server.Atmos.Piping.EntitySystems; +using Content.Shared.Atmos.Components; +using Content.Shared.Atmos.EntitySystems; using Content.Server.Charges; using Content.Server.Decals; using Content.Server.Destructible; @@ -147,7 +147,7 @@ public sealed class SprayPainterSystem : SharedSprayPainterSystem return; Audio.PlayPvs(ent.Comp.SpraySound, ent); - _pipeColor.SetColor(target, color, args.Color); + _pipeColor.SetColor((target, color), args.Color); args.Handled = true; } diff --git a/Content.Server/Atmos/Piping/Components/AtmosPipeColorComponent.cs b/Content.Shared/Atmos/Components/AtmosPipeColorComponent.cs similarity index 63% rename from Content.Server/Atmos/Piping/Components/AtmosPipeColorComponent.cs rename to Content.Shared/Atmos/Components/AtmosPipeColorComponent.cs index a8edb07d31..ee8e55491f 100644 --- a/Content.Server/Atmos/Piping/Components/AtmosPipeColorComponent.cs +++ b/Content.Shared/Atmos/Components/AtmosPipeColorComponent.cs @@ -1,19 +1,22 @@ -using Content.Server.Atmos.Piping.EntitySystems; +using Content.Shared.Atmos.EntitySystems; +using Robust.Shared.GameStates; using JetBrains.Annotations; -namespace Content.Server.Atmos.Piping.Components; +namespace Content.Shared.Atmos.Components; -[RegisterComponent] +[RegisterComponent, NetworkedComponent] +[AutoGenerateComponentState] public sealed partial class AtmosPipeColorComponent : Component { [DataField] + [AutoNetworkedField] public Color Color { get; set; } = Color.White; [ViewVariables(VVAccess.ReadWrite), UsedImplicitly] public Color ColorVV { get => Color; - set => IoCManager.Resolve().System().SetColor(Owner, this, value); + set => IoCManager.Resolve().System().SetColor((Owner, this), value); } } diff --git a/Content.Shared/Atmos/EntitySystems/AtmosPipeColorSystem.cs b/Content.Shared/Atmos/EntitySystems/AtmosPipeColorSystem.cs new file mode 100644 index 0000000000..548136fbfa --- /dev/null +++ b/Content.Shared/Atmos/EntitySystems/AtmosPipeColorSystem.cs @@ -0,0 +1,36 @@ +using Content.Shared.Atmos.Components; +using Content.Shared.Atmos.Piping; + +namespace Content.Shared.Atmos.EntitySystems; + +public sealed class AtmosPipeColorSystem : EntitySystem +{ + + [Dependency] private readonly SharedAppearanceSystem _appearance = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnShutdown); + } + + private void OnStartup(Entity item, ref ComponentStartup args) + { + _appearance.SetData(item.Owner, PipeColorVisuals.Color, item.Comp.Color); + } + + private void OnShutdown(Entity item, ref ComponentShutdown args) + { + _appearance.SetData(item.Owner, PipeColorVisuals.Color, Color.White); + } + + public void SetColor(Entity item, Color color) + { + item.Comp.Color = color; + _appearance.SetData(item.Owner, PipeColorVisuals.Color, color); + Dirty(item); + } +} +