Airlock visuals (#7261)
This commit is contained in:
22
Content.Server/AirlockPainter/AirlockPainterComponent.cs
Normal file
22
Content.Server/AirlockPainter/AirlockPainterComponent.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.AirlockPainter;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
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!;
|
||||
}
|
||||
}
|
||||
138
Content.Server/AirlockPainter/AirlockPainterSystem.cs
Normal file
138
Content.Server/AirlockPainter/AirlockPainterSystem.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.AirlockPainter;
|
||||
using Content.Shared.AirlockPainter.Prototypes;
|
||||
using Content.Shared.Doors.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.AirlockPainter
|
||||
{
|
||||
/// <summary>
|
||||
/// A system for painting airlocks using airlock painter
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public sealed class AirlockPainterSystem : SharedAirlockPainterSystem
|
||||
{
|
||||
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
||||
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<AirlockPainterComponent, AfterInteractEvent>(AfterInteractOn);
|
||||
SubscribeLocalEvent<AirlockPainterComponent, ActivateInWorldEvent>(OnActivate);
|
||||
SubscribeLocalEvent<AirlockPainterComponent, AirlockPainterSpritePickedMessage>(OnSpritePicked);
|
||||
SubscribeLocalEvent<AirlockPainterDoAfterComplete>(OnDoAfterComplete);
|
||||
SubscribeLocalEvent<AirlockPainterDoAfterCancelled>(OnDoAfterCancelled);
|
||||
}
|
||||
|
||||
private void OnDoAfterComplete(AirlockPainterDoAfterComplete ev)
|
||||
{
|
||||
ev.Component.IsSpraying = false;
|
||||
if (TryComp<AppearanceComponent>(ev.Target, out var appearance) &&
|
||||
TryComp<PaintableAirlockComponent>(ev.Target, out PaintableAirlockComponent? airlock))
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(ev.User, entityManager:EntityManager), ev.Component.SpraySound.GetSound(), ev.User);
|
||||
appearance.SetData(DoorVisuals.BaseRSI, ev.Sprite);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDoAfterCancelled(AirlockPainterDoAfterCancelled ev)
|
||||
{
|
||||
ev.Component.IsSpraying = false;
|
||||
}
|
||||
|
||||
private void OnActivate(EntityUid uid, AirlockPainterComponent component, ActivateInWorldEvent args)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
|
||||
return;
|
||||
DirtyUI(uid, component);
|
||||
component.Owner.GetUIOrNull(AirlockPainterUiKey.Key)?.Open(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))
|
||||
{
|
||||
Logger.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, Filter.Entities(args.User));
|
||||
return;
|
||||
}
|
||||
component.IsSpraying = true;
|
||||
var doAfterEventArgs = new DoAfterEventArgs(args.User, component.SprayTime, default, target)
|
||||
{
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
BreakOnDamage = true,
|
||||
BreakOnStun = true,
|
||||
NeedHand = true,
|
||||
BroadcastFinishedEvent = new AirlockPainterDoAfterComplete(uid, target, sprite, component),
|
||||
BroadcastCancelledEvent = new AirlockPainterDoAfterCancelled(component),
|
||||
};
|
||||
_doAfterSystem.DoAfter(doAfterEventArgs);
|
||||
}
|
||||
|
||||
private sealed class AirlockPainterDoAfterComplete : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid User;
|
||||
public readonly EntityUid Target;
|
||||
public readonly string Sprite;
|
||||
public readonly AirlockPainterComponent Component;
|
||||
|
||||
public AirlockPainterDoAfterComplete(EntityUid user, EntityUid target, string sprite, AirlockPainterComponent component)
|
||||
{
|
||||
User = user;
|
||||
Target = target;
|
||||
Sprite = sprite;
|
||||
Component = component;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class AirlockPainterDoAfterCancelled : EntityEventArgs
|
||||
{
|
||||
public readonly AirlockPainterComponent Component;
|
||||
|
||||
public AirlockPainterDoAfterCancelled(AirlockPainterComponent component)
|
||||
{
|
||||
Component = component;
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user