Spray Paint (Review Ready) (#23003)
* Spray Paint (Draft) * paint colors, paints in maints loot, cargo crate of paints. * fix * remove paint (sort of) * moved paintcleaner into own system * Moved paint to server (had to unfortunately) * doafter now breaks when moving away. * cant paint mobstatecomp * loads of fixes * fixes * fixes * nopaintshadercomp * fixes * fix * use locale for paint remove string * remove nopaintshadercomponent and use blacklist * remove enabled.true from visualizer * paint doafter event. * add verbs for paint and remove paint and icon for paint verb. * fixes * no longer replaces shader when shader exists. * replace forloop with foreach, check shader before adding and removing. * paint doafter now separate so no copy paste code * Entities in sprayed targets item slots are also now correctly sprayed. * fix * fix * fix airlock psray painter now removes painted before painting door. * spray paints now use openablecomponent. * fix * fix damn accesstypes. * fix * fix
This commit is contained in:
120
Content.Client/Paint/PaintVisualizerSystem.cs
Normal file
120
Content.Client/Paint/PaintVisualizerSystem.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using System.Linq;
|
||||
using Robust.Client.GameObjects;
|
||||
using static Robust.Client.GameObjects.SpriteComponent;
|
||||
using Content.Shared.Clothing;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Paint;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Paint
|
||||
{
|
||||
public sealed class PaintedVisualizerSystem : VisualizerSystem<PaintedComponent>
|
||||
{
|
||||
/// <summary>
|
||||
/// Visualizer for Paint which applies a shader and colors the entity.
|
||||
/// </summary>
|
||||
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
||||
|
||||
public ShaderInstance? Shader; // in Robust.Client.Graphics so cannot move to shared component.
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<PaintedComponent, HeldVisualsUpdatedEvent>(OnHeldVisualsUpdated);
|
||||
SubscribeLocalEvent<PaintedComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<PaintedComponent, EquipmentVisualsUpdatedEvent>(OnEquipmentVisualsUpdated);
|
||||
}
|
||||
|
||||
protected override void OnAppearanceChange(EntityUid uid, PaintedComponent component, ref AppearanceChangeEvent args)
|
||||
{
|
||||
// ShaderPrototype sadly in Robust.Client, cannot move to shared component.
|
||||
Shader = _protoMan.Index<ShaderPrototype>(component.ShaderName).Instance();
|
||||
|
||||
if (args.Sprite == null)
|
||||
return;
|
||||
|
||||
if (!_appearance.TryGetData<bool>(uid, PaintVisuals.Painted, out bool isPainted))
|
||||
return;
|
||||
|
||||
var sprite = args.Sprite;
|
||||
|
||||
|
||||
foreach (var spriteLayer in sprite.AllLayers)
|
||||
{
|
||||
if (spriteLayer is not Layer layer)
|
||||
continue;
|
||||
|
||||
if (layer.Shader == null) // If shader isn't null we dont want to replace the original shader.
|
||||
{
|
||||
layer.Shader = Shader;
|
||||
layer.Color = component.Color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHeldVisualsUpdated(EntityUid uid, PaintedComponent component, HeldVisualsUpdatedEvent args)
|
||||
{
|
||||
if (args.RevealedLayers.Count == 0)
|
||||
return;
|
||||
|
||||
if (!TryComp(args.User, out SpriteComponent? sprite))
|
||||
return;
|
||||
|
||||
foreach (var revealed in args.RevealedLayers)
|
||||
{
|
||||
if (!sprite.LayerMapTryGet(revealed, out var layer) || sprite[layer] is not Layer notlayer)
|
||||
continue;
|
||||
|
||||
sprite.LayerSetShader(layer, component.ShaderName);
|
||||
sprite.LayerSetColor(layer, component.Color);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEquipmentVisualsUpdated(EntityUid uid, PaintedComponent component, EquipmentVisualsUpdatedEvent args)
|
||||
{
|
||||
if (args.RevealedLayers.Count == 0)
|
||||
return;
|
||||
|
||||
if (!TryComp(args.Equipee, out SpriteComponent? sprite))
|
||||
return;
|
||||
|
||||
foreach (var revealed in args.RevealedLayers)
|
||||
{
|
||||
if (!sprite.LayerMapTryGet(revealed, out var layer) || sprite[layer] is not Layer notlayer)
|
||||
continue;
|
||||
|
||||
sprite.LayerSetShader(layer, component.ShaderName);
|
||||
sprite.LayerSetColor(layer, component.Color);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, PaintedComponent component, ref ComponentShutdown args)
|
||||
{
|
||||
if (!TryComp(uid, out SpriteComponent? sprite))
|
||||
return;
|
||||
|
||||
component.BeforeColor = sprite.Color;
|
||||
Shader = _protoMan.Index<ShaderPrototype>(component.ShaderName).Instance();
|
||||
|
||||
if (!Terminating(uid))
|
||||
{
|
||||
foreach (var spriteLayer in sprite.AllLayers)
|
||||
{
|
||||
if (spriteLayer is not Layer layer)
|
||||
continue;
|
||||
|
||||
if (layer.Shader == Shader) // If shader isn't same as one in component we need to ignore it.
|
||||
{
|
||||
layer.Shader = null;
|
||||
if (layer.Color == component.Color) // If color isn't the same as one in component we don't want to change it.
|
||||
layer.Color = component.BeforeColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user