Decouple panels and wires (#24840)
decouple panels and wires (cherry picked from commit 5db6a3eafc08132b7415be23eb40506ca2f550a9)
This commit is contained in:
parent
aded2ef145
commit
49a1b47c09
|
|
@ -1,51 +1,39 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Construction;
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.UserInterface;
|
||||
using Content.Shared.Database;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Tools;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Content.Shared.UserInterface;
|
||||
using Content.Shared.Wires;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||
using Content.Server.UserInterface;
|
||||
|
||||
namespace Content.Server.Wires;
|
||||
|
||||
public sealed class WiresSystem : SharedWiresSystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly ActivatableUISystem _activatableUI = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
||||
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly ConstructionSystem _construction = default!;
|
||||
|
||||
// This is where all the wire layouts are stored.
|
||||
[ViewVariables] private readonly Dictionary<string, WireLayout> _layouts = new();
|
||||
|
||||
private const float ScrewTime = 1f;
|
||||
private float _toolTime = 0f;
|
||||
|
||||
#region Initialization
|
||||
|
|
@ -56,8 +44,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
||||
|
||||
// this is a broadcast event
|
||||
SubscribeLocalEvent<WiresPanelComponent, WirePanelDoAfterEvent>(OnPanelDoAfter);
|
||||
SubscribeLocalEvent<WiresComponent, ComponentStartup>(OnWiresStartup);
|
||||
SubscribeLocalEvent<WiresComponent, PanelChangedEvent>(OnPanelChanged);
|
||||
SubscribeLocalEvent<WiresComponent, WiresActionMessage>(OnWiresActionMessage);
|
||||
SubscribeLocalEvent<WiresComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<WiresComponent, MapInitEvent>(OnMapInit);
|
||||
|
|
@ -68,6 +55,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
SubscribeLocalEvent<ActivatableUIRequiresPanelComponent, PanelChangedEvent>(OnActivatableUIPanelChanged);
|
||||
SubscribeLocalEvent<WiresPanelSecurityComponent, WiresPanelSecurityEvent>(SetWiresPanelSecurity);
|
||||
}
|
||||
|
||||
private void SetOrCreateWireLayout(EntityUid uid, WiresComponent? wires = null)
|
||||
{
|
||||
if (!Resolve(uid, ref wires))
|
||||
|
|
@ -246,11 +234,6 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
position,
|
||||
action);
|
||||
}
|
||||
|
||||
private void OnWiresStartup(EntityUid uid, WiresComponent component, ComponentStartup args)
|
||||
{
|
||||
EnsureComp<WiresPanelComponent>(uid);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DoAfters
|
||||
|
|
@ -464,49 +447,28 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!TryComp<ToolComponent>(args.Used, out var tool) || !TryComp<WiresPanelComponent>(uid, out var panel))
|
||||
if (!TryComp<ToolComponent>(args.Used, out var tool))
|
||||
return;
|
||||
|
||||
if (panel.Open &&
|
||||
(_toolSystem.HasQuality(args.Used, "Cutting", tool) ||
|
||||
_toolSystem.HasQuality(args.Used, "Pulsing", tool)))
|
||||
{
|
||||
if (TryComp<WiresPanelSecurityComponent>(uid, out var wiresPanelSecurity) &&
|
||||
!wiresPanelSecurity.WiresAccessible)
|
||||
return;
|
||||
if (!IsPanelOpen(uid))
|
||||
return;
|
||||
|
||||
if (Tool.HasQuality(args.Used, "Cutting", tool) ||
|
||||
Tool.HasQuality(args.Used, "Pulsing", tool))
|
||||
{
|
||||
if (TryComp(args.User, out ActorComponent? actor))
|
||||
{
|
||||
_uiSystem.TryOpen(uid, WiresUiKey.Key, actor.PlayerSession);
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
else if (_toolSystem.UseTool(args.Used, args.User, uid, ScrewTime, "Screwing", new WirePanelDoAfterEvent(), toolComponent: tool))
|
||||
{
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Low,
|
||||
$"{ToPrettyString(args.User):user} is screwing {ToPrettyString(uid):target}'s {(panel.Open ? "open" : "closed")} maintenance panel at {Transform(uid).Coordinates:targetlocation}");
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPanelDoAfter(EntityUid uid, WiresPanelComponent panel, WirePanelDoAfterEvent args)
|
||||
private void OnPanelChanged(Entity<WiresComponent> ent, ref PanelChangedEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
if (args.Open)
|
||||
return;
|
||||
|
||||
TogglePanel(uid, panel, !panel.Open);
|
||||
UpdateAppearance(uid, panel);
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} screwed {ToPrettyString(uid):target}'s maintenance panel {(panel.Open ? "open" : "closed")}");
|
||||
|
||||
if (panel.Open)
|
||||
{
|
||||
_audio.PlayPvs(panel.ScrewdriverOpenSound, uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
_audio.PlayPvs(panel.ScrewdriverCloseSound, uid);
|
||||
_uiSystem.TryCloseAll(uid, WiresUiKey.Key);
|
||||
}
|
||||
_uiSystem.TryCloseAll(ent, WiresUiKey.Key);
|
||||
}
|
||||
|
||||
private void OnAttemptOpenActivatableUI(EntityUid uid, ActivatableUIRequiresPanelComponent component, ActivatableUIOpenAttemptEvent args)
|
||||
|
|
@ -665,16 +627,6 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
public void TogglePanel(EntityUid uid, WiresPanelComponent component, bool open)
|
||||
{
|
||||
component.Open = open;
|
||||
UpdateAppearance(uid, component);
|
||||
Dirty(uid, component);
|
||||
|
||||
var ev = new PanelChangedEvent(component.Open);
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
}
|
||||
|
||||
public void SetWiresPanelSecurity(EntityUid uid, WiresPanelSecurityComponent component, WiresPanelSecurityEvent args)
|
||||
{
|
||||
component.Examine = args.Examine;
|
||||
|
|
@ -688,12 +640,6 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
}
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, WiresPanelComponent panel)
|
||||
{
|
||||
if (TryComp<AppearanceComponent>(uid, out var appearance))
|
||||
_appearance.SetData(uid, WiresVisuals.MaintenancePanelState, panel.Open && panel.Visible, appearance);
|
||||
}
|
||||
|
||||
private void TryDoWireAction(EntityUid target, EntityUid user, EntityUid toolEntity, int id, WiresAction action, WiresComponent? wires = null, ToolComponent? tool = null)
|
||||
{
|
||||
if (!Resolve(target, ref wires)
|
||||
|
|
@ -711,7 +657,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
switch (action)
|
||||
{
|
||||
case WiresAction.Cut:
|
||||
if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
|
||||
if (!Tool.HasQuality(toolEntity, "Cutting", tool))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
|
||||
return;
|
||||
|
|
@ -725,7 +671,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
|
||||
break;
|
||||
case WiresAction.Mend:
|
||||
if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
|
||||
if (!Tool.HasQuality(toolEntity, "Cutting", tool))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
|
||||
return;
|
||||
|
|
@ -739,7 +685,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
|
||||
break;
|
||||
case WiresAction.Pulse:
|
||||
if (!_toolSystem.HasQuality(toolEntity, "Pulsing", tool))
|
||||
if (!Tool.HasQuality(toolEntity, "Pulsing", tool))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), user);
|
||||
return;
|
||||
|
|
@ -798,7 +744,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
switch (action)
|
||||
{
|
||||
case WiresAction.Cut:
|
||||
if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
|
||||
if (!Tool.HasQuality(toolEntity, "Cutting", tool))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
|
||||
break;
|
||||
|
|
@ -810,7 +756,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
break;
|
||||
}
|
||||
|
||||
_toolSystem.PlayToolSound(toolEntity, tool, user);
|
||||
Tool.PlayToolSound(toolEntity, tool, user);
|
||||
if (wire.Action == null || wire.Action.Cut(user, wire))
|
||||
{
|
||||
wire.IsCut = true;
|
||||
|
|
@ -819,7 +765,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
UpdateUserInterface(used);
|
||||
break;
|
||||
case WiresAction.Mend:
|
||||
if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
|
||||
if (!Tool.HasQuality(toolEntity, "Cutting", tool))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
|
||||
break;
|
||||
|
|
@ -831,7 +777,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
break;
|
||||
}
|
||||
|
||||
_toolSystem.PlayToolSound(toolEntity, tool, user);
|
||||
Tool.PlayToolSound(toolEntity, tool, user);
|
||||
if (wire.Action == null || wire.Action.Mend(user, wire))
|
||||
{
|
||||
wire.IsCut = false;
|
||||
|
|
@ -840,7 +786,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
UpdateUserInterface(used);
|
||||
break;
|
||||
case WiresAction.Pulse:
|
||||
if (!_toolSystem.HasQuality(toolEntity, "Pulsing", tool))
|
||||
if (!Tool.HasQuality(toolEntity, "Pulsing", tool))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), user);
|
||||
break;
|
||||
|
|
@ -855,7 +801,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
|||
wire.Action?.Pulse(user, wire);
|
||||
|
||||
UpdateUserInterface(used);
|
||||
_audio.PlayPvs(wires.PulseSound, used);
|
||||
Audio.PlayPvs(wires.PulseSound, used);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +1,71 @@
|
|||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Tools.Systems;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
|
||||
namespace Content.Shared.Wires;
|
||||
|
||||
public abstract class SharedWiresSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly ISharedAdminLogManager AdminLogger = default!;
|
||||
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
|
||||
[Dependency] protected readonly SharedAudioSystem Audio = default!;
|
||||
[Dependency] protected readonly SharedToolSystem Tool = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<WiresPanelComponent, WirePanelDoAfterEvent>(OnPanelDoAfter);
|
||||
SubscribeLocalEvent<WiresPanelComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<WiresPanelComponent, ExaminedEvent>(OnExamine);
|
||||
}
|
||||
|
||||
private void OnPanelDoAfter(EntityUid uid, WiresPanelComponent panel, WirePanelDoAfterEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
return;
|
||||
|
||||
TogglePanel(uid, panel, !panel.Open);
|
||||
AdminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} screwed {ToPrettyString(uid):target}'s maintenance panel {(panel.Open ? "open" : "closed")}");
|
||||
|
||||
var sound = panel.Open ? panel.ScrewdriverOpenSound : panel.ScrewdriverCloseSound;
|
||||
Audio.PlayPredicted(sound, uid, args.User);
|
||||
}
|
||||
|
||||
private void OnInteractUsing(Entity<WiresPanelComponent> ent, ref InteractUsingEvent args)
|
||||
{
|
||||
if (!Tool.UseTool(
|
||||
args.Used,
|
||||
args.User,
|
||||
ent,
|
||||
(float) ent.Comp.OpenDelay.TotalSeconds,
|
||||
ent.Comp.OpeningTool,
|
||||
new WirePanelDoAfterEvent()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AdminLogger.Add(LogType.Action, LogImpact.Low,
|
||||
$"{ToPrettyString(args.User):user} is screwing {ToPrettyString(ent):target}'s {(ent.Comp.Open ? "open" : "closed")} maintenance panel at {Transform(ent).Coordinates:targetlocation}");
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, WiresPanelComponent component, ExaminedEvent args)
|
||||
{
|
||||
using (args.PushGroup(nameof(WiresPanelComponent)))
|
||||
{
|
||||
if (!component.Open)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("wires-panel-component-on-examine-closed"));
|
||||
if (!string.IsNullOrEmpty(component.ExamineTextClosed))
|
||||
args.PushMarkup(Loc.GetString(component.ExamineTextClosed));
|
||||
}
|
||||
else
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("wires-panel-component-on-examine-open"));
|
||||
if (!string.IsNullOrEmpty(component.ExamineTextOpen))
|
||||
args.PushMarkup(Loc.GetString(component.ExamineTextOpen));
|
||||
|
||||
if (TryComp<WiresPanelSecurityComponent>(uid, out var wiresPanelSecurity) &&
|
||||
wiresPanelSecurity.Examine != null)
|
||||
|
|
@ -33,4 +75,34 @@ public abstract class SharedWiresSystem : EntitySystem
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateAppearance(EntityUid uid, WiresPanelComponent panel)
|
||||
{
|
||||
if (TryComp<AppearanceComponent>(uid, out var appearance))
|
||||
Appearance.SetData(uid, WiresVisuals.MaintenancePanelState, panel.Open && panel.Visible, appearance);
|
||||
}
|
||||
|
||||
public void TogglePanel(EntityUid uid, WiresPanelComponent component, bool open)
|
||||
{
|
||||
component.Open = open;
|
||||
UpdateAppearance(uid, component);
|
||||
Dirty(uid, component);
|
||||
|
||||
var ev = new PanelChangedEvent(component.Open);
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
}
|
||||
|
||||
public bool IsPanelOpen(Entity<WiresPanelComponent?> entity)
|
||||
{
|
||||
if (!Resolve(entity, ref entity.Comp, false))
|
||||
return true;
|
||||
|
||||
// Listen, i don't know what the fuck this component does. it's stapled on shit for airlocks
|
||||
// but it looks like an almost direct duplication of WiresPanelComponent except with a shittier API.
|
||||
if (TryComp<WiresPanelSecurityComponent>(entity, out var wiresPanelSecurity) &&
|
||||
!wiresPanelSecurity.WiresAccessible)
|
||||
return false;
|
||||
|
||||
return entity.Comp.Open;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using Content.Shared.Tools;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Wires;
|
||||
|
||||
|
|
@ -27,6 +29,32 @@ public sealed partial class WiresPanelComponent : Component
|
|||
|
||||
[DataField("screwdriverCloseSound")]
|
||||
public SoundSpecifier ScrewdriverCloseSound = new SoundPathSpecifier("/Audio/Machines/screwdriverclose.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// Amount of times in seconds it takes to open
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan OpenDelay = TimeSpan.FromSeconds(1);
|
||||
|
||||
/// <summary>
|
||||
/// The tool quality needed to open this panel.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public ProtoId<ToolQualityPrototype> OpeningTool = "Screwing";
|
||||
|
||||
/// <summary>
|
||||
/// Text showed on examine when the panel is closed.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[DataField]
|
||||
public LocId? ExamineTextClosed = "wires-panel-component-on-examine-closed";
|
||||
|
||||
/// <summary>
|
||||
/// Text showed on examine when the panel is open.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[DataField]
|
||||
public LocId? ExamineTextOpen = "wires-panel-component-on-examine-open";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue