]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix bug with pipe color (#30645)
authorIgorAnt028 <118114530+IgorAnt028@users.noreply.github.com>
Sat, 19 Jul 2025 22:10:38 +0000 (01:10 +0300)
committerGitHub <noreply@github.com>
Sat, 19 Jul 2025 22:10:38 +0000 (15:10 -0700)
Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
Content.Client/Atmos/EntitySystems/PipeColorVisualizerSystem.cs
Content.Client/UserInterface/Systems/Storage/Controls/ItemGridPiece.cs
Content.Server/Atmos/Piping/EntitySystems/AtmosPipeColorSystem.cs [deleted file]
Content.Server/Sandbox/Commands/ColorNetworkCommand.cs
Content.Server/SprayPainter/SprayPainterSystem.cs
Content.Shared/Atmos/Components/AtmosPipeColorComponent.cs [moved from Content.Server/Atmos/Piping/Components/AtmosPipeColorComponent.cs with 63% similarity]
Content.Shared/Atmos/EntitySystems/AtmosPipeColorSystem.cs [new file with mode: 0644]

index 5595f441f76882c6a8c61a9475f19fc77200c4a1..b23a44e403d0040e0f6c90e1357350e5643f0b3c 100644 (file)
@@ -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<PipeColorVisualsComponent>
 {
+    [Dependency] private readonly SharedItemSystem _itemSystem = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<PipeColorVisualsComponent, GetInhandVisualsEvent>(OnGetVisuals);
+        SubscribeLocalEvent<PipeColorVisualsComponent, BeforeRenderInGridEvent>(OnDrawInGrid);
+    }
+
+    /// <summary>
+    ///     This method is used to display the color changes of the pipe on the screen..
+    /// </summary>
+    private void OnGetVisuals(Entity<PipeColorVisualsComponent> item, ref GetInhandVisualsEvent args)
+    {
+        foreach (var (_, layerData) in args.Layers)
+        {
+            if (TryComp(item.Owner, out AtmosPipeColorComponent? pipeColor))
+                layerData.Color = pipeColor.Color;
+        }
+    }
+
+    /// <summary>
+    ///     This method is used to change the pipe's color in a container grid.
+    /// </summary>
+    private void OnDrawInGrid(Entity<PipeColorVisualsComponent> 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<SpriteComponent>(uid, out var sprite)
@@ -15,6 +50,8 @@ public sealed class PipeColorVisualizerSystem : VisualizerSystem<PipeColorVisual
             var layer = sprite[PipeVisualLayers.Pipe];
             layer.Color = color.WithAlpha(layer.Color.A);
         }
+
+        _itemSystem.VisualsChanged(uid);
     }
 }
 
index d07db112c8abaa599c0504580f6b5ca386d1e01e..60c74939f6f73d5609f261375f84fafc3f813950 100644 (file)
@@ -185,7 +185,12 @@ public sealed class ItemGridPiece : Control, IEntityControl
 
             handle.SetTransform(pos, iconRotation);
             var box = new UIBox2(root, root + sprite.Size * scale);
-            handle.DrawTextureRect(sprite, box);
+
+            var ev = new BeforeRenderInGridEvent(new Color(255, 255, 255));
+            _entityManager.EventBus.RaiseLocalEvent(Entity, ev);
+
+            handle.DrawTextureRect(sprite, box, ev.Color);
+
             handle.SetTransform(GlobalPixelPosition, Angle.Zero);
         }
         else
@@ -298,6 +303,19 @@ public sealed class ItemGridPiece : Control, IEntityControl
     public EntityUid? UiEntity => Entity;
 }
 
+/// <summary>
+///     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.
+/// </summary>
+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 (file)
index 91f7046..0000000
+++ /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<AtmosPipeColorComponent, ComponentStartup>(OnStartup);
-            SubscribeLocalEvent<AtmosPipeColorComponent, ComponentShutdown>(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);
-        }
-    }
-}
index 8237ccb2eb74845a2024ea6d5842eb77f41a2e78..89c1182eaef7f9a89f4da5cab91530e7132f19b3 100644 (file)
@@ -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);
             }
         }
     }
index 24ab5e0ea2903497afc145f1ff587cbc6836c168..a5e08a91a6fdbe2b43e05fac5a2dde05770c69a0 100644 (file)
@@ -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;
     }
similarity index 63%
rename from Content.Server/Atmos/Piping/Components/AtmosPipeColorComponent.cs
rename to Content.Shared/Atmos/Components/AtmosPipeColorComponent.cs
index a8edb07d31880abc84c9c0fbf81ae86c65773ccb..ee8e55491f3794b001ef908b7c29888b851ab1c2 100644 (file)
@@ -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<IEntityManager>().System<AtmosPipeColorSystem>().SetColor(Owner, this, value);
+        set => IoCManager.Resolve<IEntityManager>().System<AtmosPipeColorSystem>().SetColor((Owner, this), value);
     }
 }
 
diff --git a/Content.Shared/Atmos/EntitySystems/AtmosPipeColorSystem.cs b/Content.Shared/Atmos/EntitySystems/AtmosPipeColorSystem.cs
new file mode 100644 (file)
index 0000000..548136f
--- /dev/null
@@ -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<AtmosPipeColorComponent, ComponentStartup>(OnStartup);
+        SubscribeLocalEvent<AtmosPipeColorComponent, ComponentShutdown>(OnShutdown);
+    }
+
+    private void OnStartup(Entity<AtmosPipeColorComponent> item, ref ComponentStartup args)
+    {
+        _appearance.SetData(item.Owner, PipeColorVisuals.Color, item.Comp.Color);
+    }
+
+    private void OnShutdown(Entity<AtmosPipeColorComponent> item, ref ComponentShutdown args)
+    {
+        _appearance.SetData(item.Owner, PipeColorVisuals.Color, Color.White);
+    }
+
+    public void SetColor(Entity<AtmosPipeColorComponent> item, Color color)
+    {
+        item.Comp.Color = color;
+        _appearance.SetData(item.Owner, PipeColorVisuals.Color, color);
+        Dirty(item);
+    }
+}
+