2020-08-22 22:29:20 +02:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
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-06-02 12:32:18 +01:00
|
|
|
|
using Content.Shared.GameObjects.Components.Power;
|
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;
|
2020-06-02 12:32:18 +01:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
2020-08-22 22:29:20 +02:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
2020-06-02 12:32:18 +01:00
|
|
|
|
|
2020-08-13 14:40:27 +02:00
|
|
|
|
namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
2020-06-02 12:32:18 +01:00
|
|
|
|
{
|
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
|
[ComponentReference(typeof(IActivate))]
|
|
|
|
|
|
public class SolarControlConsoleComponent : SharedSolarControlConsoleComponent, IActivate
|
|
|
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
|
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
2020-06-02 12:32:18 +01:00
|
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
|
private PowerSolarSystem _powerSolarSystem = default!;
|
|
|
|
|
|
private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
|
|
|
|
|
|
|
2020-08-24 20:47:17 +02:00
|
|
|
|
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(SolarControlConsoleUiKey.Key);
|
2020-06-02 12:32:18 +01:00
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
|
if (UserInterface != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Owner.EnsureComponent<PowerReceiverComponent>();
|
2020-06-02 12:32:18 +01:00
|
|
|
|
_powerSolarSystem = _entitySystemManager.GetEntitySystem<PowerSolarSystem>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateUIState()
|
|
|
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
|
UserInterface?.SetState(new SolarControlConsoleBoundInterfaceState(_powerSolarSystem.TargetPanelRotation, _powerSolarSystem.TargetPanelVelocity, _powerSolarSystem.TotalPanelPower, _powerSolarSystem.TowardsSun));
|
2020-06-02 12:32:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (obj.Message)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SolarControlConsoleAdjustMessage msg:
|
|
|
|
|
|
if (double.IsFinite(msg.Rotation))
|
|
|
|
|
|
{
|
|
|
|
|
|
_powerSolarSystem.TargetPanelRotation = msg.Rotation.Reduced();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (double.IsFinite(msg.AngularVelocity))
|
|
|
|
|
|
{
|
|
|
|
|
|
_powerSolarSystem.TargetPanelVelocity = msg.AngularVelocity.Reduced();
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IActivate.Activate(ActivateEventArgs eventArgs)
|
|
|
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
|
if (!eventArgs.User.TryGetComponent(out IActorComponent? actor))
|
2020-06-02 12:32:18 +01:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!Powered)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// always update the UI immediately before opening, just in case
|
|
|
|
|
|
UpdateUIState();
|
2020-08-22 22:29:20 +02:00
|
|
|
|
UserInterface?.Open(actor.playerSession);
|
2020-06-02 12:32:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|