Fix bug with pipe color (#30645)

Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
This commit is contained in:
IgorAnt028
2025-07-20 01:10:38 +03:00
committed by GitHub
parent f21803bfd8
commit 41a175636b
7 changed files with 105 additions and 59 deletions

View File

@@ -1,11 +1,46 @@
using Content.Client.Atmos.Components; using Content.Client.Atmos.Components;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Content.Client.UserInterface.Systems.Storage.Controls;
using Content.Shared.Atmos.Piping; using Content.Shared.Atmos.Piping;
using Content.Shared.Hands;
using Content.Shared.Atmos.Components;
using Content.Shared.Item;
namespace Content.Client.Atmos.EntitySystems; namespace Content.Client.Atmos.EntitySystems;
public sealed class PipeColorVisualizerSystem : VisualizerSystem<PipeColorVisualsComponent> 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) protected override void OnAppearanceChange(EntityUid uid, PipeColorVisualsComponent component, ref AppearanceChangeEvent args)
{ {
if (TryComp<SpriteComponent>(uid, out var sprite) if (TryComp<SpriteComponent>(uid, out var sprite)
@@ -15,6 +50,8 @@ public sealed class PipeColorVisualizerSystem : VisualizerSystem<PipeColorVisual
var layer = sprite[PipeVisualLayers.Pipe]; var layer = sprite[PipeVisualLayers.Pipe];
layer.Color = color.WithAlpha(layer.Color.A); layer.Color = color.WithAlpha(layer.Color.A);
} }
_itemSystem.VisualsChanged(uid);
} }
} }

View File

@@ -185,7 +185,12 @@ public sealed class ItemGridPiece : Control, IEntityControl
handle.SetTransform(pos, iconRotation); handle.SetTransform(pos, iconRotation);
var box = new UIBox2(root, root + sprite.Size * scale); 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); handle.SetTransform(GlobalPixelPosition, Angle.Zero);
} }
else else
@@ -298,6 +303,19 @@ public sealed class ItemGridPiece : Control, IEntityControl
public EntityUid? UiEntity => Entity; 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 public enum ItemGridPieceMarks
{ {
First, First,

View File

@@ -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);
}
}
}

View File

@@ -1,6 +1,6 @@
using Content.Server.Administration.Managers; using Content.Server.Administration.Managers;
using Content.Server.Atmos.Piping.Components; using Content.Shared.Atmos.Components;
using Content.Server.Atmos.Piping.EntitySystems; using Content.Shared.Atmos.EntitySystems;
using Content.Shared.Administration; using Content.Shared.Administration;
using Content.Shared.NodeContainer; using Content.Shared.NodeContainer;
using Content.Shared.NodeContainer.NodeGroups; using Content.Shared.NodeContainer.NodeGroups;
@@ -78,7 +78,7 @@ namespace Content.Server.Sandbox.Commands
if (!EntityManager.TryGetComponent(x.Owner, out AtmosPipeColorComponent? atmosPipeColorComponent)) if (!EntityManager.TryGetComponent(x.Owner, out AtmosPipeColorComponent? atmosPipeColorComponent))
continue; continue;
_pipeColorSystem.SetColor(x.Owner, atmosPipeColorComponent, color); _pipeColorSystem.SetColor((x.Owner, atmosPipeColorComponent), color);
} }
} }
} }

View File

@@ -1,5 +1,5 @@
using Content.Server.Atmos.Piping.Components; using Content.Shared.Atmos.Components;
using Content.Server.Atmos.Piping.EntitySystems; using Content.Shared.Atmos.EntitySystems;
using Content.Server.Charges; using Content.Server.Charges;
using Content.Server.Decals; using Content.Server.Decals;
using Content.Server.Destructible; using Content.Server.Destructible;
@@ -147,7 +147,7 @@ public sealed class SprayPainterSystem : SharedSprayPainterSystem
return; return;
Audio.PlayPvs(ent.Comp.SpraySound, ent); Audio.PlayPvs(ent.Comp.SpraySound, ent);
_pipeColor.SetColor(target, color, args.Color); _pipeColor.SetColor((target, color), args.Color);
args.Handled = true; args.Handled = true;
} }

View File

@@ -1,19 +1,22 @@
using Content.Server.Atmos.Piping.EntitySystems; using Content.Shared.Atmos.EntitySystems;
using Robust.Shared.GameStates;
using JetBrains.Annotations; using JetBrains.Annotations;
namespace Content.Server.Atmos.Piping.Components; namespace Content.Shared.Atmos.Components;
[RegisterComponent] [RegisterComponent, NetworkedComponent]
[AutoGenerateComponentState]
public sealed partial class AtmosPipeColorComponent : Component public sealed partial class AtmosPipeColorComponent : Component
{ {
[DataField] [DataField]
[AutoNetworkedField]
public Color Color { get; set; } = Color.White; public Color Color { get; set; } = Color.White;
[ViewVariables(VVAccess.ReadWrite), UsedImplicitly] [ViewVariables(VVAccess.ReadWrite), UsedImplicitly]
public Color ColorVV public Color ColorVV
{ {
get => Color; get => Color;
set => IoCManager.Resolve<IEntityManager>().System<AtmosPipeColorSystem>().SetColor(Owner, this, value); set => IoCManager.Resolve<IEntityManager>().System<AtmosPipeColorSystem>().SetColor((Owner, this), value);
} }
} }

View File

@@ -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);
}
}