Pipe painter (now with airlock painter) (#19031)

* Add a pipe painting function to the airlock painter

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Rename engineer painter to omnipainter

Signed-off-by: c4llv07e <kseandi@gmail.com>

* review changes

Signed-off-by: c4llv07e <kseandi@gmail.com>

* fix migration duplicate

Signed-off-by: c4llv07e <kseandi@gmail.com>

---------

Signed-off-by: c4llv07e <kseandi@gmail.com>
This commit is contained in:
c4llv07e
2023-08-14 12:06:21 +00:00
committed by GitHub
parent 3b7a23bde4
commit d7eb3bfb44
36 changed files with 649 additions and 446 deletions

View File

@@ -1,19 +0,0 @@
using Robust.Shared.Audio;
namespace Content.Server.AirlockPainter
{
[RegisterComponent]
public sealed class AirlockPainterComponent : Component
{
[DataField("spraySound")]
public SoundSpecifier SpraySound = new SoundPathSpecifier("/Audio/Effects/spray2.ogg");
[DataField("sprayTime")]
public float SprayTime = 3.0f;
[DataField("isSpraying")]
public bool IsSpraying = false;
public int Index = default!;
}
}

View File

@@ -1,118 +0,0 @@
using Content.Server.Administration.Logs;
using Content.Server.Popups;
using Content.Server.UserInterface;
using Content.Shared.AirlockPainter;
using Content.Shared.AirlockPainter.Prototypes;
using Content.Shared.DoAfter;
using Content.Shared.Database;
using Content.Shared.Doors.Components;
using Content.Shared.Interaction;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
namespace Content.Server.AirlockPainter
{
/// <summary>
/// A system for painting airlocks using airlock painter
/// </summary>
[UsedImplicitly]
public sealed class AirlockPainterSystem : SharedAirlockPainterSystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AirlockPainterComponent, AfterInteractEvent>(AfterInteractOn);
SubscribeLocalEvent<AirlockPainterComponent, ActivateInWorldEvent>(OnActivate);
SubscribeLocalEvent<AirlockPainterComponent, AirlockPainterSpritePickedMessage>(OnSpritePicked);
SubscribeLocalEvent<AirlockPainterComponent, AirlockPainterDoAfterEvent>(OnDoAfter);
}
private void OnDoAfter(EntityUid uid, AirlockPainterComponent component, AirlockPainterDoAfterEvent args)
{
component.IsSpraying = false;
if (args.Handled || args.Cancelled)
return;
if (args.Args.Target != null)
{
_audio.PlayPvs(component.SpraySound, uid);
_appearance.SetData(args.Args.Target.Value, DoorVisuals.BaseRSI, args.Sprite);
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.Args.User):user} painted {ToPrettyString(args.Args.Target.Value):target}");
}
args.Handled = true;
}
private void OnActivate(EntityUid uid, AirlockPainterComponent component, ActivateInWorldEvent args)
{
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
return;
DirtyUI(uid, component);
if (_userInterfaceSystem.TryGetUi(uid, AirlockPainterUiKey.Key, out var bui))
_userInterfaceSystem.OpenUi(bui, actor.PlayerSession);
args.Handled = true;
}
private void AfterInteractOn(EntityUid uid, AirlockPainterComponent component, AfterInteractEvent args)
{
if (component.IsSpraying || args.Target is not { Valid: true } target || !args.CanReach)
return;
if (!EntityManager.TryGetComponent<PaintableAirlockComponent>(target, out var airlock))
return;
if (!_prototypeManager.TryIndex<AirlockGroupPrototype>(airlock.Group, out var grp))
{
Log.Error("Group not defined: %s", airlock.Group);
return;
}
string style = Styles[component.Index];
if (!grp.StylePaths.TryGetValue(style, out var sprite))
{
string msg = Loc.GetString("airlock-painter-style-not-available");
_popupSystem.PopupEntity(msg, args.User, args.User);
return;
}
component.IsSpraying = true;
var doAfterEventArgs = new DoAfterArgs(args.User, component.SprayTime, new AirlockPainterDoAfterEvent(sprite), uid, target: target, used: uid)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnDamage = true,
NeedHand = true,
};
_doAfterSystem.TryStartDoAfter(doAfterEventArgs);
// Log attempt
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} is painting {ToPrettyString(uid):target} to '{style}' at {Transform(uid).Coordinates:targetlocation}");
}
private void OnSpritePicked(EntityUid uid, AirlockPainterComponent component, AirlockPainterSpritePickedMessage args)
{
component.Index = args.Index;
DirtyUI(uid, component);
}
private void DirtyUI(EntityUid uid,
AirlockPainterComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
_userInterfaceSystem.TrySetUiState(uid, AirlockPainterUiKey.Key,
new AirlockPainterBoundUserInterfaceState(component.Index));
}
}
}

View File

@@ -0,0 +1,28 @@
using Robust.Shared.Audio;
namespace Content.Server.SprayPainter;
[RegisterComponent]
public sealed class SprayPainterComponent : Component
{
[DataField("spraySound")]
public SoundSpecifier SpraySound = new SoundPathSpecifier("/Audio/Effects/spray2.ogg");
[DataField("airlockSprayTime")]
public float AirlockSprayTime = 3.0f;
[DataField("pipeSprayTime")]
public float PipeSprayTime = 1.0f;
[DataField("isSpraying")]
public bool IsSpraying = false;
[ViewVariables(VVAccess.ReadWrite)]
public string? PickedColor;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("colorPalette")]
public Dictionary<string, Color> ColorPalette = new();
public int Index = default!;
}

View File

@@ -0,0 +1,182 @@
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Atmos.Piping.Components;
using Content.Server.Atmos.Piping.EntitySystems;
using Content.Server.Popups;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Doors.Components;
using Content.Shared.SprayPainter.Prototypes;
using Content.Shared.SprayPainter;
using Content.Shared.Interaction;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
namespace Content.Server.SprayPainter;
/// <summary>
/// A system for painting airlocks and pipes using enginner painter
/// </summary>
[UsedImplicitly]
public sealed class SprayPainterSystem : SharedSprayPainterSystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly AtmosPipeColorSystem _pipeColorSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SprayPainterComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<SprayPainterComponent, AfterInteractEvent>(AfterInteractOn);
SubscribeLocalEvent<SprayPainterComponent, ActivateInWorldEvent>(OnActivate);
SubscribeLocalEvent<SprayPainterComponent, SprayPainterSpritePickedMessage>(OnSpritePicked);
SubscribeLocalEvent<SprayPainterComponent, SprayPainterColorPickedMessage>(OnColorPicked);
SubscribeLocalEvent<SprayPainterComponent, SprayPainterDoAfterEvent>(OnDoAfter);
}
private void OnInit(EntityUid uid, SprayPainterComponent component, ComponentInit args)
{
if (component.ColorPalette.Count == 0)
return;
SetColor(uid, component, component.ColorPalette.First().Key);
}
private void OnDoAfter(EntityUid uid, SprayPainterComponent component, SprayPainterDoAfterEvent args)
{
component.IsSpraying = false;
if (args.Handled || args.Cancelled)
return;
if (args.Args.Target == null)
return;
EntityUid target = (EntityUid) args.Args.Target;
_audio.PlayPvs(component.SpraySound, uid);
if (TryComp<AtmosPipeColorComponent>(target, out var atmosPipeColorComp))
{
_pipeColorSystem.SetColor(target, atmosPipeColorComp, args.Color ?? Color.White);
} else { // Target is an airlock
if (args.Sprite != null)
{
_appearance.SetData(target, DoorVisuals.BaseRSI, args.Sprite);
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.Args.User):user} painted {ToPrettyString(args.Args.Target.Value):target}");
}
}
args.Handled = true;
}
private void OnActivate(EntityUid uid, SprayPainterComponent component, ActivateInWorldEvent args)
{
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
return;
DirtyUI(uid, component);
_userInterfaceSystem.TryOpen(uid, SprayPainterUiKey.Key, actor.PlayerSession);
args.Handled = true;
}
private void AfterInteractOn(EntityUid uid, SprayPainterComponent component, AfterInteractEvent args)
{
if (component.IsSpraying || args.Target is not { Valid: true } target || !args.CanReach)
return;
if (EntityManager.TryGetComponent<PaintableAirlockComponent>(target, out var airlock))
{
if (!_prototypeManager.TryIndex<AirlockGroupPrototype>(airlock.Group, out var grp))
{
Log.Error("Group not defined: %s", airlock.Group);
return;
}
string style = Styles[component.Index];
if (!grp.StylePaths.TryGetValue(style, out var sprite))
{
string msg = Loc.GetString("spray-painter-style-not-available");
_popupSystem.PopupEntity(msg, args.User, args.User);
return;
}
component.IsSpraying = true;
var doAfterEventArgs = new DoAfterArgs(args.User, component.AirlockSprayTime, new SprayPainterDoAfterEvent(sprite, null), uid, target: target, used: uid)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnDamage = true,
NeedHand = true,
};
_doAfterSystem.TryStartDoAfter(doAfterEventArgs);
// Log attempt
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} is painting {ToPrettyString(uid):target} to '{style}' at {Transform(uid).Coordinates:targetlocation}");
} else { // Painting pipes
if(component.PickedColor is null)
return;
if (!EntityManager.HasComponent<AtmosPipeColorComponent>(target))
return;
if(!component.ColorPalette.TryGetValue(component.PickedColor, out var color))
return;
var doAfterEventArgs = new DoAfterArgs(args.User, component.PipeSprayTime, new SprayPainterDoAfterEvent(null, color), uid, target, uid)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnDamage = true,
CancelDuplicate = true,
DuplicateCondition = DuplicateConditions.SameTarget,
NeedHand = true,
};
_doAfterSystem.TryStartDoAfter(doAfterEventArgs);
}
}
private void OnColorPicked(EntityUid uid, SprayPainterComponent component, SprayPainterColorPickedMessage args)
{
SetColor(uid, component, args.Key);
}
private void OnSpritePicked(EntityUid uid, SprayPainterComponent component, SprayPainterSpritePickedMessage args)
{
component.Index = args.Index;
DirtyUI(uid, component);
}
private void SetColor(EntityUid uid, SprayPainterComponent component, string? paletteKey)
{
if (paletteKey == null)
return;
if (!component.ColorPalette.ContainsKey(paletteKey) || paletteKey == component.PickedColor)
return;
component.PickedColor = paletteKey;
DirtyUI(uid, component);
}
private void DirtyUI(EntityUid uid, SprayPainterComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
_userInterfaceSystem.TrySetUiState(
uid,
SprayPainterUiKey.Key,
new SprayPainterBoundUserInterfaceState(
component.Index,
component.PickedColor,
component.ColorPalette));
}
}