2020-08-13 14:40:27 +02:00
|
|
|
|
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
|
|
|
|
|
using Content.Server.GameObjects.EntitySystems;
|
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;
|
2020-06-02 12:32:18 +01:00
|
|
|
|
using Robust.Server.GameObjects.Components.UserInterface;
|
|
|
|
|
|
using Robust.Server.Interfaces.GameObjects;
|
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
|
|
|
|
|
#pragma warning disable 649
|
|
|
|
|
|
[Dependency] private IEntitySystemManager _entitySystemManager;
|
|
|
|
|
|
#pragma warning restore 649
|
|
|
|
|
|
|
|
|
|
|
|
private BoundUserInterface _userInterface;
|
2020-06-28 09:23:26 -06:00
|
|
|
|
private PowerReceiverComponent _powerReceiver;
|
2020-06-02 12:32:18 +01:00
|
|
|
|
private PowerSolarSystem _powerSolarSystem;
|
2020-06-28 09:23:26 -06:00
|
|
|
|
private bool Powered => _powerReceiver.Powered;
|
2020-06-02 12:32:18 +01:00
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>().GetBoundUserInterface(SolarControlConsoleUiKey.Key);
|
|
|
|
|
|
_userInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
|
2020-06-28 09:23:26 -06:00
|
|
|
|
_powerReceiver = Owner.GetComponent<PowerReceiverComponent>();
|
2020-06-02 12:32:18 +01:00
|
|
|
|
_powerSolarSystem = _entitySystemManager.GetEntitySystem<PowerSolarSystem>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateUIState()
|
|
|
|
|
|
{
|
|
|
|
|
|
_userInterface.SetState(new SolarControlConsoleBoundInterfaceState(_powerSolarSystem.TargetPanelRotation, _powerSolarSystem.TargetPanelVelocity, _powerSolarSystem.TotalPanelPower, _powerSolarSystem.TowardsSun));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!eventArgs.User.TryGetComponent(out IActorComponent actor))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!Powered)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// always update the UI immediately before opening, just in case
|
|
|
|
|
|
UpdateUIState();
|
|
|
|
|
|
_userInterface.Open(actor.playerSession);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|