Cleaner BoundUserInterfaces (#17736)
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Timing;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Medical.Components;
|
||||
using Content.Server.Cloning.Components;
|
||||
using Content.Server.DeviceLinking.Events;
|
||||
using Content.Server.DeviceLinking.Systems;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Mind.Components;
|
||||
@@ -62,12 +60,12 @@ namespace Content.Server.Cloning
|
||||
TryClone(uid, consoleComponent.CloningPod.Value, consoleComponent.GeneticScanner.Value, consoleComponent: consoleComponent);
|
||||
break;
|
||||
}
|
||||
UpdateUserInterface(consoleComponent);
|
||||
UpdateUserInterface(uid, consoleComponent);
|
||||
}
|
||||
|
||||
private void OnPowerChanged(EntityUid uid, CloningConsoleComponent component, ref PowerChangedEvent args)
|
||||
{
|
||||
UpdateUserInterface(component);
|
||||
UpdateUserInterface(uid, component);
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, CloningConsoleComponent component, MapInitEvent args)
|
||||
@@ -115,12 +113,12 @@ namespace Content.Server.Cloning
|
||||
if (args.Port == CloningConsoleComponent.PodPort)
|
||||
component.CloningPod = null;
|
||||
|
||||
UpdateUserInterface(component);
|
||||
UpdateUserInterface(uid, component);
|
||||
}
|
||||
|
||||
private void OnUIOpen(EntityUid uid, CloningConsoleComponent component, AfterActivatableUIOpenEvent args)
|
||||
{
|
||||
UpdateUserInterface(component);
|
||||
UpdateUserInterface(uid, component);
|
||||
}
|
||||
|
||||
private void OnAnchorChanged(EntityUid uid, CloningConsoleComponent component, ref AnchorStateChangedEvent args)
|
||||
@@ -130,27 +128,27 @@ namespace Content.Server.Cloning
|
||||
RecheckConnections(uid, component.CloningPod, component.GeneticScanner, component);
|
||||
return;
|
||||
}
|
||||
UpdateUserInterface(component);
|
||||
UpdateUserInterface(uid, component);
|
||||
}
|
||||
|
||||
public void UpdateUserInterface(CloningConsoleComponent consoleComponent)
|
||||
public void UpdateUserInterface(EntityUid consoleUid, CloningConsoleComponent consoleComponent)
|
||||
{
|
||||
var ui = _uiSystem.GetUiOrNull(consoleComponent.Owner, CloningConsoleUiKey.Key);
|
||||
if (ui == null)
|
||||
if (!_uiSystem.TryGetUi(consoleUid, CloningConsoleUiKey.Key, out var ui))
|
||||
return;
|
||||
if (!_powerReceiverSystem.IsPowered(consoleComponent.Owner))
|
||||
|
||||
if (!_powerReceiverSystem.IsPowered(consoleUid))
|
||||
{
|
||||
_uiSystem.CloseAll(ui);
|
||||
return;
|
||||
}
|
||||
|
||||
var newState = GetUserInterfaceState(consoleComponent);
|
||||
_uiSystem.SetUiState(ui, newState);
|
||||
UserInterfaceSystem.SetUiState(ui, newState);
|
||||
}
|
||||
|
||||
public void TryClone(EntityUid uid, EntityUid cloningPodUid, EntityUid scannerUid, CloningPodComponent? cloningPod = null, MedicalScannerComponent? scannerComp = null, CloningConsoleComponent? consoleComponent = null)
|
||||
{
|
||||
if (!Resolve(uid, ref consoleComponent) || !Resolve(cloningPodUid, ref cloningPod) || !Resolve(scannerUid, ref scannerComp))
|
||||
if (!Resolve(uid, ref consoleComponent) || !Resolve(cloningPodUid, ref cloningPod) || !Resolve(scannerUid, ref scannerComp))
|
||||
return;
|
||||
|
||||
if (!Transform(cloningPodUid).Anchored || !Transform(scannerUid).Anchored)
|
||||
@@ -192,7 +190,7 @@ namespace Content.Server.Cloning
|
||||
consoleComp.CloningPodInRange = podDistance <= consoleComp.MaxDistance;
|
||||
}
|
||||
|
||||
UpdateUserInterface(consoleComp);
|
||||
UpdateUserInterface(console, consoleComp);
|
||||
}
|
||||
private CloningConsoleBoundUserInterfaceState GetUserInterfaceState(CloningConsoleComponent consoleComponent)
|
||||
{
|
||||
|
||||
@@ -33,7 +33,6 @@ using Robust.Shared.Random;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Content.Shared.Humanoid;
|
||||
using Content.Shared.Doors.Components;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -66,6 +65,7 @@ namespace Content.Server.Cloning
|
||||
[Dependency] private readonly MaterialStorageSystem _material = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly MindSystem _mindSystem = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
|
||||
|
||||
public readonly Dictionary<Mind.Mind, EntityUid> ClonesWaitingForMind = new();
|
||||
public const float EasyModeCloningCost = 0.7f;
|
||||
@@ -87,7 +87,7 @@ namespace Content.Server.Cloning
|
||||
|
||||
private void OnComponentInit(EntityUid uid, CloningPodComponent clonePod, ComponentInit args)
|
||||
{
|
||||
clonePod.BodyContainer = _containerSystem.EnsureContainer<ContainerSlot>(clonePod.Owner, "clonepod-bodyContainer");
|
||||
clonePod.BodyContainer = _containerSystem.EnsureContainer<ContainerSlot>(uid, "clonepod-bodyContainer");
|
||||
_signalSystem.EnsureSinkPorts(uid, CloningPodComponent.PodPort);
|
||||
}
|
||||
|
||||
@@ -124,12 +124,12 @@ namespace Content.Server.Cloning
|
||||
if (clonedComponent.Parent == EntityUid.Invalid ||
|
||||
!EntityManager.EntityExists(clonedComponent.Parent) ||
|
||||
!TryComp<CloningPodComponent>(clonedComponent.Parent, out var cloningPodComponent) ||
|
||||
clonedComponent.Owner != cloningPodComponent.BodyContainer.ContainedEntity)
|
||||
uid != cloningPodComponent.BodyContainer.ContainedEntity)
|
||||
{
|
||||
EntityManager.RemoveComponent<BeingClonedComponent>(clonedComponent.Owner);
|
||||
EntityManager.RemoveComponent<BeingClonedComponent>(uid);
|
||||
return;
|
||||
}
|
||||
UpdateStatus(CloningPodStatus.Cloning, cloningPodComponent);
|
||||
UpdateStatus(clonedComponent.Parent, CloningPodStatus.Cloning, cloningPodComponent);
|
||||
}
|
||||
|
||||
private void OnPortDisconnected(EntityUid uid, CloningPodComponent pod, PortDisconnectedEvent args)
|
||||
@@ -147,7 +147,7 @@ namespace Content.Server.Cloning
|
||||
_cloningConsoleSystem.RecheckConnections(component.ConnectedConsole.Value, uid, console.GeneticScanner, console);
|
||||
return;
|
||||
}
|
||||
_cloningConsoleSystem.UpdateUserInterface(console);
|
||||
_cloningConsoleSystem.UpdateUserInterface(component.ConnectedConsole.Value, console);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, CloningPodComponent component, ExaminedEvent args)
|
||||
@@ -230,11 +230,11 @@ namespace Content.Server.Cloning
|
||||
chance *= failChanceModifier;
|
||||
|
||||
if (cellularDmg > 0 && clonePod.ConnectedConsole != null)
|
||||
_chatSystem.TrySendInGameICMessage(clonePod.ConnectedConsole.Value, Loc.GetString("cloning-console-cellular-warning", ("percent", Math.Round(100 - (chance * 100)))), InGameICChatType.Speak, false);
|
||||
_chatSystem.TrySendInGameICMessage(clonePod.ConnectedConsole.Value, Loc.GetString("cloning-console-cellular-warning", ("percent", Math.Round(100 - chance * 100))), InGameICChatType.Speak, false);
|
||||
|
||||
if (_robustRandom.Prob(chance))
|
||||
{
|
||||
UpdateStatus(CloningPodStatus.Gore, clonePod);
|
||||
UpdateStatus(uid, CloningPodStatus.Gore, clonePod);
|
||||
clonePod.FailedClone = true;
|
||||
AddComp<ActiveCloningPodComponent>(uid);
|
||||
return true;
|
||||
@@ -242,21 +242,21 @@ namespace Content.Server.Cloning
|
||||
}
|
||||
// end of genetic damage checks
|
||||
|
||||
var mob = Spawn(speciesPrototype.Prototype, Transform(clonePod.Owner).MapPosition);
|
||||
var mob = Spawn(speciesPrototype.Prototype, Transform(uid).MapPosition);
|
||||
_humanoidSystem.CloneAppearance(bodyToClone, mob);
|
||||
|
||||
var ev = new CloningEvent(bodyToClone, mob);
|
||||
RaiseLocalEvent(bodyToClone, ref ev);
|
||||
|
||||
if (!ev.NameHandled)
|
||||
MetaData(mob).EntityName = MetaData(bodyToClone).EntityName;
|
||||
_metaSystem.SetEntityName(mob, MetaData(bodyToClone).EntityName);
|
||||
|
||||
var cloneMindReturn = EntityManager.AddComponent<BeingClonedComponent>(mob);
|
||||
cloneMindReturn.Mind = mind;
|
||||
cloneMindReturn.Parent = clonePod.Owner;
|
||||
cloneMindReturn.Parent = uid;
|
||||
clonePod.BodyContainer.Insert(mob);
|
||||
ClonesWaitingForMind.Add(mind, mob);
|
||||
UpdateStatus(CloningPodStatus.NoMind, clonePod);
|
||||
UpdateStatus(uid, CloningPodStatus.NoMind, clonePod);
|
||||
_euiManager.OpenEui(new AcceptCloningEui(mind, this), client);
|
||||
|
||||
AddComp<ActiveCloningPodComponent>(uid);
|
||||
@@ -276,17 +276,18 @@ namespace Content.Server.Cloning
|
||||
return true;
|
||||
}
|
||||
|
||||
public void UpdateStatus(CloningPodStatus status, CloningPodComponent cloningPod)
|
||||
public void UpdateStatus(EntityUid podUid, CloningPodStatus status, CloningPodComponent cloningPod)
|
||||
{
|
||||
cloningPod.Status = status;
|
||||
_appearance.SetData(cloningPod.Owner, CloningPodVisuals.Status, cloningPod.Status);
|
||||
_appearance.SetData(podUid, CloningPodVisuals.Status, cloningPod.Status);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var (_, cloning) in EntityManager.EntityQuery<ActiveCloningPodComponent, CloningPodComponent>())
|
||||
var query = EntityQueryEnumerator<ActiveCloningPodComponent, CloningPodComponent>();
|
||||
while (query.MoveNext(out var uid, out var _, out var cloning))
|
||||
{
|
||||
if (!_powerReceiverSystem.IsPowered(cloning.Owner))
|
||||
if (!_powerReceiverSystem.IsPowered(uid))
|
||||
continue;
|
||||
|
||||
if (cloning.BodyContainer.ContainedEntity == null && !cloning.FailedClone)
|
||||
@@ -297,9 +298,9 @@ namespace Content.Server.Cloning
|
||||
continue;
|
||||
|
||||
if (cloning.FailedClone)
|
||||
EndFailedCloning(cloning.Owner, cloning);
|
||||
EndFailedCloning(uid, cloning);
|
||||
else
|
||||
Eject(cloning.Owner, cloning);
|
||||
Eject(uid, cloning);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,14 +322,14 @@ namespace Content.Server.Cloning
|
||||
if (!Resolve(uid, ref clonePod))
|
||||
return;
|
||||
|
||||
if (clonePod.BodyContainer.ContainedEntity is not {Valid: true} entity || clonePod.CloningProgress < clonePod.CloningTime)
|
||||
if (clonePod.BodyContainer.ContainedEntity is not { Valid: true } entity || clonePod.CloningProgress < clonePod.CloningTime)
|
||||
return;
|
||||
|
||||
EntityManager.RemoveComponent<BeingClonedComponent>(entity);
|
||||
clonePod.BodyContainer.Remove(entity);
|
||||
clonePod.CloningProgress = 0f;
|
||||
clonePod.UsedBiomass = 0;
|
||||
UpdateStatus(CloningPodStatus.Idle, clonePod);
|
||||
UpdateStatus(uid, CloningPodStatus.Idle, clonePod);
|
||||
RemCompDeferred<ActiveCloningPodComponent>(uid);
|
||||
}
|
||||
|
||||
@@ -336,7 +337,7 @@ namespace Content.Server.Cloning
|
||||
{
|
||||
clonePod.FailedClone = false;
|
||||
clonePod.CloningProgress = 0f;
|
||||
UpdateStatus(CloningPodStatus.Idle, clonePod);
|
||||
UpdateStatus(uid, CloningPodStatus.Idle, clonePod);
|
||||
var transform = Transform(uid);
|
||||
var indices = _transformSystem.GetGridOrMapTilePosition(uid);
|
||||
|
||||
@@ -350,7 +351,7 @@ namespace Content.Server.Cloning
|
||||
|
||||
Solution bloodSolution = new();
|
||||
|
||||
int i = 0;
|
||||
var i = 0;
|
||||
while (i < 1)
|
||||
{
|
||||
tileMix?.AdjustMoles(Gas.Miasma, 6f);
|
||||
@@ -362,7 +363,7 @@ namespace Content.Server.Cloning
|
||||
|
||||
if (!HasComp<EmaggedComponent>(uid))
|
||||
{
|
||||
_material.SpawnMultipleFromMaterial(_robustRandom.Next(1, (int) (clonePod.UsedBiomass / 2.5)), clonePod.RequiredMaterial, Transform(uid).Coordinates);
|
||||
_material.SpawnMultipleFromMaterial(_robustRandom.Next(1, (int) (clonePod.UsedBiomass / 2.5)), clonePod.RequiredMaterial, Transform(uid).Coordinates);
|
||||
}
|
||||
|
||||
clonePod.UsedBiomass = 0;
|
||||
@@ -386,7 +387,8 @@ namespace Content.Server.Cloning
|
||||
public readonly EntityUid Source;
|
||||
public readonly EntityUid Target;
|
||||
|
||||
public CloningEvent(EntityUid source, EntityUid target) {
|
||||
public CloningEvent(EntityUid source, EntityUid target)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user