diff --git a/Content.Server/Chemistry/Components/SolutionTransferComponent.cs b/Content.Server/Chemistry/Components/SolutionTransferComponent.cs deleted file mode 100644 index 46cf733637..0000000000 --- a/Content.Server/Chemistry/Components/SolutionTransferComponent.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System.Threading.Tasks; -using Content.Server.Chemistry.Components.SolutionManager; -using Content.Server.Chemistry.EntitySystems; -using Content.Server.UserInterface; -using Content.Shared.Chemistry; -using Content.Shared.FixedPoint; -using Content.Shared.Interaction; -using Content.Shared.Popups; -using Robust.Server.GameObjects; - -namespace Content.Server.Chemistry.Components -{ - /// - /// Gives click behavior for transferring to/from other reagent containers. - /// - [RegisterComponent] - public sealed class SolutionTransferComponent : Component - { - /// - /// The amount of solution to be transferred from this solution when clicking on other solutions with it. - /// - [DataField("transferAmount")] - [ViewVariables(VVAccess.ReadWrite)] - public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(5); - - /// - /// The minimum amount of solution that can be transferred at once from this solution. - /// - [DataField("minTransferAmount")] - [ViewVariables(VVAccess.ReadWrite)] - public FixedPoint2 MinimumTransferAmount { get; set; } = FixedPoint2.New(5); - - /// - /// The maximum amount of solution that can be transferred at once from this solution. - /// - [DataField("maxTransferAmount")] - [ViewVariables(VVAccess.ReadWrite)] - public FixedPoint2 MaximumTransferAmount { get; set; } = FixedPoint2.New(50); - - /// - /// Can this entity take reagent from reagent tanks? - /// - [DataField("canReceive")] - [ViewVariables(VVAccess.ReadWrite)] - public bool CanReceive { get; set; } = true; - - /// - /// Can this entity give reagent to other reagent containers? - /// - [DataField("canSend")] - [ViewVariables(VVAccess.ReadWrite)] - public bool CanSend { get; set; } = true; - - /// - /// Whether you're allowed to change the transfer amount. - /// - [DataField("canChangeTransferAmount")] - [ViewVariables(VVAccess.ReadWrite)] - public bool CanChangeTransferAmount { get; set; } = false; - - [ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(TransferAmountUiKey.Key); - - protected override void Initialize() - { - base.Initialize(); - - if (UserInterface != null) - { - UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage; - } - } - - public void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg) - { - if (serverMsg.Session.AttachedEntity == null) - return; - - switch (serverMsg.Message) - { - case TransferAmountSetValueMessage svm: - var sval = svm.Value.Float(); - var amount = Math.Clamp(sval, MinimumTransferAmount.Float(), - MaximumTransferAmount.Float()); - - serverMsg.Session.AttachedEntity.Value.PopupMessage(Loc.GetString("comp-solution-transfer-set-amount", - ("amount", amount))); - SetTransferAmount(FixedPoint2.New(amount)); - break; - } - } - - public void SetTransferAmount(FixedPoint2 amount) - { - amount = FixedPoint2.New(Math.Clamp(amount.Int(), MinimumTransferAmount.Int(), - MaximumTransferAmount.Int())); - TransferAmount = amount; - } - } -} diff --git a/Content.Server/Chemistry/EntitySystems/SolutionTransferSystem.cs b/Content.Server/Chemistry/EntitySystems/SolutionTransferSystem.cs index 30636529f8..0f587e9294 100644 --- a/Content.Server/Chemistry/EntitySystems/SolutionTransferSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/SolutionTransferSystem.cs @@ -1,9 +1,9 @@ using Content.Server.Administration.Logs; using Content.Shared.Verbs; -using Content.Server.Chemistry.Components; using Content.Server.Chemistry.Components.SolutionManager; using JetBrains.Annotations; using Robust.Server.GameObjects; +using Content.Shared.Chemistry; using Content.Shared.Chemistry.Components; using Content.Shared.Database; using Content.Shared.FixedPoint; @@ -15,7 +15,9 @@ namespace Content.Server.Chemistry.EntitySystems [UsedImplicitly] public sealed class SolutionTransferSystem : EntitySystem { - [Dependency] private readonly SolutionContainerSystem _solutionContainer = default!; + [Dependency] private readonly SharedPopupSystem _popupSystem = default!; + [Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!; + [Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!; /// @@ -29,6 +31,16 @@ namespace Content.Server.Chemistry.EntitySystems SubscribeLocalEvent>(AddSetTransferVerbs); SubscribeLocalEvent(OnAfterInteract); + SubscribeLocalEvent(OnTransferAmountSetValueMessage); + } + + private void OnTransferAmountSetValueMessage(EntityUid uid, SolutionTransferComponent solutionTransfer, TransferAmountSetValueMessage message) + { + var newTransferAmount = FixedPoint2.Clamp(message.Value, solutionTransfer.MinimumTransferAmount, solutionTransfer.MaximumTransferAmount); + solutionTransfer.TransferAmount = newTransferAmount; + + if (message.Session.AttachedEntity is {Valid: true} user) + _popupSystem.PopupEntity(Loc.GetString("comp-solution-transfer-set-amount", ("amount", newTransferAmount)), uid, user); } private void AddSetTransferVerbs(EntityUid uid, SolutionTransferComponent component, GetVerbsEvent args) @@ -43,7 +55,7 @@ namespace Content.Server.Chemistry.EntitySystems AlternativeVerb custom = new(); custom.Text = Loc.GetString("comp-solution-transfer-verb-custom-amount"); custom.Category = VerbCategory.SetTransferAmount; - custom.Act = () => component.UserInterface?.Open(actor.PlayerSession); + custom.Act = () => _userInterfaceSystem.TryOpen(args.Target, TransferAmountUiKey.Key, actor.PlayerSession); custom.Priority = 1; args.Verbs.Add(custom); @@ -60,7 +72,7 @@ namespace Content.Server.Chemistry.EntitySystems verb.Act = () => { component.TransferAmount = FixedPoint2.New(amount); - args.User.PopupMessage(Loc.GetString("comp-solution-transfer-set-amount", ("amount", amount))); + _popupSystem.PopupEntity(Loc.GetString("comp-solution-transfer-set-amount", ("amount", amount)), uid, args.User); }; // we want to sort by size, not alphabetically by the verb text. @@ -80,9 +92,9 @@ namespace Content.Server.Chemistry.EntitySystems //Special case for reagent tanks, because normally clicking another container will give solution, not take it. if (component.CanReceive && !EntityManager.HasComponent(target) // target must not be refillable (e.g. Reagent Tanks) - && _solutionContainer.TryGetDrainableSolution(target, out var targetDrain) // target must be drainable + && _solutionContainerSystem.TryGetDrainableSolution(target, out var targetDrain) // target must be drainable && EntityManager.TryGetComponent(uid, out RefillableSolutionComponent? refillComp) - && _solutionContainer.TryGetRefillableSolution(uid, out var ownerRefill, refillable: refillComp)) + && _solutionContainerSystem.TryGetRefillableSolution(uid, out var ownerRefill, refillable: refillComp)) { @@ -101,8 +113,7 @@ namespace Content.Server.Chemistry.EntitySystems ? "comp-solution-transfer-fill-fully" : "comp-solution-transfer-fill-normal"; - target.PopupMessage(args.User, - Loc.GetString(msg, ("owner", args.Target), ("amount", transferred), ("target", uid))); + _popupSystem.PopupEntity(Loc.GetString(msg, ("owner", args.Target), ("amount", transferred), ("target", uid)), uid, args.User); args.Handled = true; return; @@ -110,8 +121,8 @@ namespace Content.Server.Chemistry.EntitySystems } // if target is refillable, and owner is drainable - if (component.CanSend && _solutionContainer.TryGetRefillableSolution(target, out var targetRefill) - && _solutionContainer.TryGetDrainableSolution(uid, out var ownerDrain)) + if (component.CanSend && _solutionContainerSystem.TryGetRefillableSolution(target, out var targetRefill) + && _solutionContainerSystem.TryGetDrainableSolution(uid, out var ownerDrain)) { var transferAmount = component.TransferAmount; @@ -124,10 +135,8 @@ namespace Content.Server.Chemistry.EntitySystems if (transferred > 0) { - uid.PopupMessage(args.User, - Loc.GetString("comp-solution-transfer-transfer-solution", - ("amount", transferred), - ("target", target))); + var message = Loc.GetString("comp-solution-transfer-transfer-solution", ("amount", transferred), ("target", target)); + _popupSystem.PopupEntity(message, uid, args.User); args.Handled = true; } @@ -148,40 +157,37 @@ namespace Content.Server.Chemistry.EntitySystems var transferAttempt = new SolutionTransferAttemptEvent(sourceEntity, targetEntity); // Check if the source is cancelling the transfer - RaiseLocalEvent(sourceEntity, transferAttempt, true); + RaiseLocalEvent(sourceEntity, transferAttempt, broadcast: true); if (transferAttempt.Cancelled) { - sourceEntity.PopupMessage(user, transferAttempt.CancelReason!); + _popupSystem.PopupEntity(transferAttempt.CancelReason!, sourceEntity, user); return FixedPoint2.Zero; } if (source.Volume == 0) { - sourceEntity.PopupMessage(user, - Loc.GetString("comp-solution-transfer-is-empty", ("target", sourceEntity))); + _popupSystem.PopupEntity(Loc.GetString("comp-solution-transfer-is-empty", ("target", sourceEntity)), sourceEntity, user); return FixedPoint2.Zero; } // Check if the target is cancelling the transfer - RaiseLocalEvent(targetEntity, transferAttempt, true); + RaiseLocalEvent(targetEntity, transferAttempt, broadcast: true); if (transferAttempt.Cancelled) { - sourceEntity.PopupMessage(user, transferAttempt.CancelReason!); + _popupSystem.PopupEntity(transferAttempt.CancelReason!, sourceEntity, user); return FixedPoint2.Zero; } if (target.AvailableVolume == 0) { - targetEntity.PopupMessage(user, - Loc.GetString("comp-solution-transfer-is-full", ("target", targetEntity))); + _popupSystem.PopupEntity(Loc.GetString("comp-solution-transfer-is-full", ("target", targetEntity)), targetEntity, user); return FixedPoint2.Zero; } var actualAmount = FixedPoint2.Min(amount, FixedPoint2.Min(source.Volume, target.AvailableVolume)); - var solutionSystem = Get(); - var solution = solutionSystem.Drain(sourceEntity, source, actualAmount); - solutionSystem.Refill(targetEntity, target, solution); + var solution = _solutionContainerSystem.Drain(sourceEntity, source, actualAmount); + _solutionContainerSystem.Refill(targetEntity, target, solution); _adminLogger.Add(LogType.Action, LogImpact.Medium, $"{EntityManager.ToPrettyString(user):player} transferred {string.Join(", ", solution.Contents)} to {EntityManager.ToPrettyString(targetEntity):entity}, which now contains {string.Join(", ", target.Contents)}"); diff --git a/Content.Server/Extinguisher/FireExtinguisherSystem.cs b/Content.Server/Extinguisher/FireExtinguisherSystem.cs index 2e6281a64e..ea0fa7b195 100644 --- a/Content.Server/Extinguisher/FireExtinguisherSystem.cs +++ b/Content.Server/Extinguisher/FireExtinguisherSystem.cs @@ -1,14 +1,13 @@ -using Content.Server.Chemistry.Components; using Content.Server.Chemistry.EntitySystems; using Content.Server.Fluids.EntitySystems; using Content.Server.Popups; using Content.Shared.Audio; +using Content.Shared.Chemistry.Components; using Content.Shared.Extinguisher; using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Interaction.Events; using Content.Shared.Verbs; -using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.Player; diff --git a/Content.Shared/Chemistry/Components/SolutionTransferComponent.cs b/Content.Shared/Chemistry/Components/SolutionTransferComponent.cs new file mode 100644 index 0000000000..826810dcd7 --- /dev/null +++ b/Content.Shared/Chemistry/Components/SolutionTransferComponent.cs @@ -0,0 +1,53 @@ +using Content.Shared.FixedPoint; +using Robust.Shared.GameStates; + +namespace Content.Shared.Chemistry.Components; + +/// +/// Gives click behavior for transferring to/from other reagent containers. +/// +[RegisterComponent, NetworkedComponent] +public sealed class SolutionTransferComponent : Component +{ + /// + /// The amount of solution to be transferred from this solution when clicking on other solutions with it. + /// + [DataField("transferAmount")] + [ViewVariables(VVAccess.ReadWrite)] + public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(5); + + /// + /// The minimum amount of solution that can be transferred at once from this solution. + /// + [DataField("minTransferAmount")] + [ViewVariables(VVAccess.ReadWrite)] + public FixedPoint2 MinimumTransferAmount { get; set; } = FixedPoint2.New(5); + + /// + /// The maximum amount of solution that can be transferred at once from this solution. + /// + [DataField("maxTransferAmount")] + [ViewVariables(VVAccess.ReadWrite)] + public FixedPoint2 MaximumTransferAmount { get; set; } = FixedPoint2.New(50); + + /// + /// Can this entity take reagent from reagent tanks? + /// + [DataField("canReceive")] + [ViewVariables(VVAccess.ReadWrite)] + public bool CanReceive { get; set; } = true; + + /// + /// Can this entity give reagent to other reagent containers? + /// + [DataField("canSend")] + [ViewVariables(VVAccess.ReadWrite)] + public bool CanSend { get; set; } = true; + + /// + /// Whether you're allowed to change the transfer amount. + /// + [DataField("canChangeTransferAmount")] + [ViewVariables(VVAccess.ReadWrite)] + public bool CanChangeTransferAmount { get; set; } = false; +}