Refactoring of solar control console (#4072)
* Refactor/fix client-side of solar control computer (introduce ComputerBoundUserInterface & fix bugs) * Refactor server side of solar control computer (introduce BaseComputerUserInterfaceComponent) * If you can't interact, then messages to computers are blocked. * Add 'not powered' messages, migrate activation logic partially to an EntitySystem * Move solar control console to a XAML UI * Remove useless comment on UserInterfaceKey * BaseComputerUserInterfaceComponent: Remove EnsureComponent<PowerReceiver>, it's not necessary * Fix solar panel occlusion check direction * Solar Control Console refactors/etc. : Handle namespace renames
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
#nullable enable
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Solar.EntitySystems;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Interaction;
|
||||
#nullable enable
|
||||
using Content.Shared.Solar;
|
||||
using Content.Server.Solar.EntitySystems;
|
||||
using Content.Server.GameObjects.Components;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -12,26 +11,20 @@ using Robust.Shared.ViewVariables;
|
||||
namespace Content.Server.Solar.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public class SolarControlConsoleComponent : SharedSolarControlConsoleComponent, IActivate
|
||||
[ComponentReference(typeof(BaseComputerUserInterfaceComponent))]
|
||||
public class SolarControlConsoleComponent : BaseComputerUserInterfaceComponent
|
||||
{
|
||||
public override string Name => "SolarControlConsole";
|
||||
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
||||
|
||||
private PowerSolarSystem _powerSolarSystem = default!;
|
||||
private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(SolarControlConsoleUiKey.Key);
|
||||
public SolarControlConsoleComponent() : base(SolarControlConsoleUiKey.Key) { }
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (UserInterface != null)
|
||||
{
|
||||
UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
|
||||
}
|
||||
|
||||
Owner.EnsureComponent<PowerReceiverComponent>();
|
||||
_powerSolarSystem = _entitySystemManager.GetEntitySystem<PowerSolarSystem>();
|
||||
}
|
||||
|
||||
@@ -40,7 +33,7 @@ namespace Content.Server.Solar.Components
|
||||
UserInterface?.SetState(new SolarControlConsoleBoundInterfaceState(_powerSolarSystem.TargetPanelRotation, _powerSolarSystem.TargetPanelVelocity, _powerSolarSystem.TotalPanelPower, _powerSolarSystem.TowardsSun));
|
||||
}
|
||||
|
||||
private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
||||
protected override void OnReceiveUserInterfaceMessage(ServerBoundUserInterfaceMessage obj)
|
||||
{
|
||||
switch (obj.Message)
|
||||
{
|
||||
@@ -56,22 +49,5 @@ namespace Content.Server.Solar.Components
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.User.TryGetComponent(out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Powered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// always update the UI immediately before opening, just in case
|
||||
UpdateUIState();
|
||||
UserInterface?.Open(actor.PlayerSession);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user