2020-12-18 11:42:02 +00:00
|
|
|
#nullable enable
|
2020-08-22 22:29:20 +02:00
|
|
|
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Server.GameObjects.EntitySystems;
|
2020-08-24 20:47:17 +02:00
|
|
|
using Content.Server.Utility;
|
2020-04-09 00:28:56 +02:00
|
|
|
using Content.Shared.GameObjects.Components.Command;
|
2020-07-18 22:51:56 -07:00
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
using Robust.Server.Player;
|
2020-04-09 00:28:56 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-08-22 22:29:20 +02:00
|
|
|
using Robust.Shared.ViewVariables;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Command
|
|
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
[ComponentReference(typeof(IActivate))]
|
|
|
|
|
public class CommunicationsConsoleComponent : SharedCommunicationsConsoleComponent, IActivate
|
|
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
2021-02-16 09:31:57 +01:00
|
|
|
private RoundEndSystem RoundEndSystem => EntitySystem.Get<RoundEndSystem>();
|
2020-04-09 00:28:56 +02:00
|
|
|
|
2020-08-24 20:47:17 +02:00
|
|
|
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(CommunicationsConsoleUiKey.Key);
|
2020-08-22 22:29:20 +02:00
|
|
|
|
2020-04-09 00:28:56 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
if (UserInterface != null)
|
|
|
|
|
{
|
|
|
|
|
UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;
|
|
|
|
|
}
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
|
|
|
RoundEndSystem.OnRoundEndCountdownStarted += UpdateBoundInterface;
|
|
|
|
|
RoundEndSystem.OnRoundEndCountdownCancelled += UpdateBoundInterface;
|
|
|
|
|
RoundEndSystem.OnRoundEndCountdownFinished += UpdateBoundInterface;
|
2021-02-16 09:31:57 +01:00
|
|
|
RoundEndSystem.OnCallCooldownEnded += UpdateBoundInterface;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Startup()
|
|
|
|
|
{
|
|
|
|
|
base.Startup();
|
|
|
|
|
|
|
|
|
|
UpdateBoundInterface();
|
2020-04-09 00:28:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateBoundInterface()
|
|
|
|
|
{
|
2020-11-26 17:07:46 +00:00
|
|
|
if (!Deleted)
|
2021-02-16 09:31:57 +01:00
|
|
|
{
|
|
|
|
|
var system = RoundEndSystem;
|
|
|
|
|
|
|
|
|
|
UserInterface?.SetState(new CommunicationsConsoleInterfaceState(system.CanCall(), system.ExpectedCountdownEnd));
|
|
|
|
|
}
|
2020-11-26 17:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnRemove()
|
|
|
|
|
{
|
|
|
|
|
RoundEndSystem.OnRoundEndCountdownStarted -= UpdateBoundInterface;
|
|
|
|
|
RoundEndSystem.OnRoundEndCountdownCancelled -= UpdateBoundInterface;
|
|
|
|
|
RoundEndSystem.OnRoundEndCountdownFinished -= UpdateBoundInterface;
|
|
|
|
|
base.OnRemove();
|
2020-04-09 00:28:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
|
|
|
|
{
|
|
|
|
|
switch (obj.Message)
|
|
|
|
|
{
|
|
|
|
|
case CommunicationsConsoleCallEmergencyShuttleMessage _:
|
|
|
|
|
RoundEndSystem.RequestRoundEnd();
|
|
|
|
|
break;
|
2020-04-09 01:43:28 +02:00
|
|
|
|
|
|
|
|
case CommunicationsConsoleRecallEmergencyShuttleMessage _:
|
|
|
|
|
RoundEndSystem.CancelRoundEndCountdown();
|
|
|
|
|
break;
|
2020-04-09 00:28:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenUserInterface(IPlayerSession session)
|
|
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
UserInterface?.Open(session);
|
2020-04-09 00:28:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IActivate.Activate(ActivateEventArgs eventArgs)
|
|
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
if (!eventArgs.User.TryGetComponent(out IActorComponent? actor))
|
2020-04-09 00:28:56 +02:00
|
|
|
return;
|
2020-12-18 11:42:02 +00:00
|
|
|
/*
|
2020-04-09 00:28:56 +02:00
|
|
|
if (!Powered)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-12-18 11:42:02 +00:00
|
|
|
*/
|
2020-04-09 00:28:56 +02:00
|
|
|
OpenUserInterface(actor.playerSession);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|