Makes accept cloning message use Eui (#2910)

This commit is contained in:
Vera Aguilera Puerto
2021-01-03 17:20:17 +01:00
committed by GitHub
parent c04a0270e1
commit 9c2aaef73a
11 changed files with 129 additions and 154 deletions

View File

@@ -1,5 +1,6 @@
#nullable enable
using System;
using Content.Server.Eui;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Observer;
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
@@ -35,6 +36,7 @@ namespace Content.Server.GameObjects.Components.Medical
{
[Dependency] private readonly IServerPreferencesManager _prefsManager = null!;
[Dependency] private readonly IPlayerManager _playerManager = null!;
[Dependency] private readonly EuiManager _euiManager = null!;
[ViewVariables]
private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
@@ -179,9 +181,11 @@ namespace Content.Server.GameObjects.Components.Medical
_bodyContainer.Insert(mob);
_capturedMind = mind;
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local,
new CloningStartedMessage(_capturedMind));
_status = CloningPodStatus.NoMind;
var acceptMessage = new AcceptCloningEui(mob);
_euiManager.OpenEui(acceptMessage, client);
UpdateAppearance();
break;
@@ -201,17 +205,6 @@ namespace Content.Server.GameObjects.Components.Medical
}
}
public class CloningStartedMessage : EntitySystemMessage
{
public CloningStartedMessage(Mind capturedMind)
{
CapturedMind = capturedMind;
}
public Mind CapturedMind { get; }
}
private HumanoidCharacterProfile GetPlayerProfileAsync(NetUserId userId)
{
return (HumanoidCharacterProfile) _prefsManager.GetPreferences(userId).SelectedCharacter;

View File

@@ -38,7 +38,6 @@ namespace Content.Server.GameObjects.Components.Medical
public class MedicalScannerComponent : SharedMedicalScannerComponent, IActivate, IDragDropOn, IDestroyAct
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IPlayerManager _playerManager = null!;
private static readonly TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5);
private TimeSpan _lastInternalOpenAttempt;
@@ -280,16 +279,11 @@ namespace Content.Server.GameObjects.Components.Medical
{
//TODO: Show a 'ERROR: Body is completely devoid of soul' if no Mind owns the entity.
var cloningSystem = EntitySystem.Get<CloningSystem>();
cloningSystem.AddToDnaScans(_playerManager
.GetPlayersBy(playerSession =>
{
var mindOwnedMob = playerSession.ContentData()?.Mind?.OwnedEntity;
return mindOwnedMob != null && mindOwnedMob ==
_bodyContainer.ContainedEntity;
}).Single()
.ContentData()
?.Mind);
if (!_bodyContainer.ContainedEntity.TryGetComponent(out MindComponent? mind) || !mind.HasMind)
break;
cloningSystem.AddToDnaScans(mind.Mind);
}
break;

View File

@@ -59,48 +59,6 @@ namespace Content.Server.GameObjects.Components.Mobs
[ViewVariables(VVAccess.ReadWrite)]
public bool GhostOnShutdown { get; set; }
[ViewVariables]
private BoundUserInterface? UserInterface =>
Owner.GetUIOrNull(SharedAcceptCloningComponent.AcceptCloningUiKey.Key);
public override void Initialize()
{
base.Initialize();
Owner.EntityManager.EventBus.SubscribeEvent<CloningPodComponent.CloningStartedMessage>(
EventSource.Local, this,
HandleCloningStartedMessage);
if (UserInterface != null)
{
UserInterface.OnReceiveMessage += OnUiAcceptCloningMessage;
}
}
private void HandleCloningStartedMessage(CloningPodComponent.CloningStartedMessage ev)
{
if (ev.CapturedMind == Mind)
{
UserInterface?.Open(Mind.Session);
}
}
private void OnUiAcceptCloningMessage(ServerBoundUserInterfaceMessage obj)
{
if (obj.Message is not SharedAcceptCloningComponent.UiButtonPressedMessage) return;
if (Mind != null)
{
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new GhostComponent.GhostReturnMessage(Mind));
}
}
public override void OnRemove()
{
base.OnRemove();
Owner.EntityManager.EventBus.UnsubscribeEvent<CloningPodComponent.CloningStartedMessage>(EventSource.Local, this);
if (UserInterface != null) UserInterface.OnReceiveMessage -= OnUiAcceptCloningMessage;
}
/// <summary>
/// Don't call this unless you know what the hell you're doing.
/// Use <see cref="Mind.TransferTo(IEntity)"/> instead.

View File

@@ -0,0 +1,38 @@
#nullable enable
using Content.Server.Eui;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.Players;
using Content.Shared.Eui;
using Content.Shared.GameObjects.Components.Observer;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Log;
namespace Content.Server.GameObjects.Components.Observer
{
public class AcceptCloningEui : BaseEui
{
private readonly IEntity _newMob;
public AcceptCloningEui(IEntity newMob)
{
_newMob = newMob;
}
public override void HandleMessage(EuiMessageBase msg)
{
base.HandleMessage(msg);
if (msg is not AcceptCloningChoiceMessage choice
|| choice.Button == AcceptCloningUiButton.Deny
|| _newMob.Deleted)
{
Close();
return;
}
Player.ContentData()?.Mind?.TransferTo(_newMob);
Close();
}
}
}