2021-03-31 12:41:23 -07:00
|
|
|
|
using Content.Shared.GameObjects.Components.MachineLinking;
|
|
|
|
|
|
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
2020-08-29 03:33:42 -07:00
|
|
|
|
using Content.Shared.GameObjects.Verbs;
|
2020-11-18 14:53:46 +01:00
|
|
|
|
using Content.Shared.Interfaces;
|
2020-08-29 03:33:42 -07:00
|
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
|
|
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.Localization;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-08-29 03:33:42 -07:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.MachineLinking
|
|
|
|
|
|
{
|
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
|
public class SignalSwitchComponent : Component, IInteractHand, IActivate
|
|
|
|
|
|
{
|
|
|
|
|
|
public override string Name => "SignalSwitch";
|
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("on")]
|
2020-08-29 03:33:42 -07:00
|
|
|
|
private bool _on;
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
UpdateSprite();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
|
void IActivate.Activate(ActivateEventArgs eventArgs)
|
2020-08-29 03:33:42 -07:00
|
|
|
|
{
|
|
|
|
|
|
TransmitSignal(eventArgs.User);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
|
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
2020-08-29 03:33:42 -07:00
|
|
|
|
{
|
|
|
|
|
|
TransmitSignal(eventArgs.User);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void TransmitSignal(IEntity user)
|
|
|
|
|
|
{
|
|
|
|
|
|
_on = !_on;
|
|
|
|
|
|
|
|
|
|
|
|
UpdateSprite();
|
|
|
|
|
|
|
|
|
|
|
|
if (!Owner.TryGetComponent<SignalTransmitterComponent>(out var transmitter))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-18 14:53:46 +01:00
|
|
|
|
if (!transmitter.TransmitSignal(_on))
|
|
|
|
|
|
{
|
|
|
|
|
|
Owner.PopupMessage(user, Loc.GetString("No receivers connected."));
|
|
|
|
|
|
}
|
2020-08-29 03:33:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateSprite()
|
|
|
|
|
|
{
|
2021-03-31 12:41:23 -07:00
|
|
|
|
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
2020-08-29 03:33:42 -07:00
|
|
|
|
{
|
2021-03-31 12:41:23 -07:00
|
|
|
|
appearance.SetData(SignalSwitchVisuals.On, _on);
|
2020-08-29 03:33:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Verb]
|
|
|
|
|
|
private sealed class ToggleSwitchVerb : Verb<SignalSwitchComponent>
|
|
|
|
|
|
{
|
|
|
|
|
|
protected override void Activate(IEntity user, SignalSwitchComponent component)
|
|
|
|
|
|
{
|
|
|
|
|
|
component.TransmitSignal(user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void GetData(IEntity user, SignalSwitchComponent component, VerbData data)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!ActionBlockerSystem.CanInteract(user))
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Visibility = VerbVisibility.Invisible;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data.Text = Loc.GetString("Toggle Switch");
|
|
|
|
|
|
data.Visibility = VerbVisibility.Visible;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|