From d610f2a56c387bfcac3b76fc47757c5af9293cc1 Mon Sep 17 00:00:00 2001 From: Marat Gadzhiev <15rinkashikachi15@gmail.com> Date: Sat, 9 Jul 2022 16:48:57 +0300 Subject: [PATCH] Order manifests for shuttle orders. Now with item names and approver info. (#9464) Co-authored-by: Kara --- .../CargoOrderConsoleBoundUserInterface.cs | 4 +- .../Cargo/UI/CargoConsoleMenu.xaml.cs | 3 -- .../Cargo/Systems/CargoSystem.Orders.cs | 5 +- .../Cargo/Systems/CargoSystem.Shuttle.cs | 49 ++++++++++++++++--- .../Cargo/Systems/CargoSystem.Telepad.cs | 6 +-- Content.Shared/Cargo/CargoOrderData.cs | 35 ++++++++++--- .../en-US/cargo/cargo-console-component.ftl | 1 + 7 files changed, 77 insertions(+), 26 deletions(-) diff --git a/Content.Client/Cargo/BUI/CargoOrderConsoleBoundUserInterface.cs b/Content.Client/Cargo/BUI/CargoOrderConsoleBoundUserInterface.cs index 1d9f4a4cf5..756a7e5b62 100644 --- a/Content.Client/Cargo/BUI/CargoOrderConsoleBoundUserInterface.cs +++ b/Content.Client/Cargo/BUI/CargoOrderConsoleBoundUserInterface.cs @@ -1,8 +1,6 @@ -using Content.Client.Cargo.UI; -using Content.Shared.Access.Systems; using Content.Shared.Cargo; +using Content.Client.Cargo.UI; using Content.Shared.Cargo.BUI; -using Content.Shared.Cargo.Components; using Content.Shared.Cargo.Events; using Content.Shared.Cargo.Prototypes; using Robust.Client.GameObjects; diff --git a/Content.Client/Cargo/UI/CargoConsoleMenu.xaml.cs b/Content.Client/Cargo/UI/CargoConsoleMenu.xaml.cs index 18bd9276a5..c62da36b6a 100644 --- a/Content.Client/Cargo/UI/CargoConsoleMenu.xaml.cs +++ b/Content.Client/Cargo/UI/CargoConsoleMenu.xaml.cs @@ -5,11 +5,8 @@ using Content.Shared.Cargo.Prototypes; using Robust.Client.AutoGenerated; using Robust.Client.GameObjects; using Robust.Client.UserInterface.Controls; -using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; -using Robust.Client.Utility; using Robust.Shared.Prototypes; -using Robust.Shared.Utility; using static Robust.Client.UserInterface.Controls.BaseButton; namespace Content.Client.Cargo.UI diff --git a/Content.Server/Cargo/Systems/CargoSystem.Orders.cs b/Content.Server/Cargo/Systems/CargoSystem.Orders.cs index ccee28f087..15e157ca1a 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Orders.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Orders.cs @@ -154,9 +154,8 @@ namespace Content.Server.Cargo.Systems return; } - order.Approved = true; _idCardSystem.TryFindIdCard(player, out var idCard); - order.Approver = idCard?.FullName ?? string.Empty; + order.SetApproverData(idCard); SoundSystem.Play(component.ConfirmSound.GetSound(), Filter.Pvs(uid, entityManager: EntityManager), uid); @@ -227,7 +226,7 @@ namespace Content.Server.Cargo.Systems private CargoOrderData GetOrderData(CargoConsoleAddOrderMessage args, int index) { - return new CargoOrderData(index, args.Requester, args.Reason, args.ProductId, args.Amount); + return new CargoOrderData(index, args.ProductId, args.Amount, args.Requester, args.Reason); } private int GetOrderCount(StationCargoOrderDatabaseComponent component) diff --git a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs index e7789a107a..caa9cecc87 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs @@ -1,10 +1,11 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Server.Cargo.Components; -using Content.Server.GameTicking.Events; +using Content.Server.Labels.Components; using Content.Server.Shuttles.Components; using Content.Server.Shuttles.Events; using Content.Server.UserInterface; +using Content.Server.Paper; using Content.Shared.Cargo; using Content.Shared.Cargo.BUI; using Content.Shared.Cargo.Components; @@ -14,7 +15,7 @@ using Content.Shared.CCVar; using Content.Shared.Dataset; using Content.Shared.GameTicking; using Content.Shared.MobState.Components; -using Robust.Server.GameObjects; + using Robust.Server.Maps; using Robust.Shared.Audio; using Robust.Shared.Configuration; @@ -232,8 +233,7 @@ public sealed partial class CargoSystem if (cappedAmount < order.Amount) { - var reducedOrder = new CargoOrderData(order.OrderNumber, order.Requester, order.Reason, order.ProductId, - cappedAmount); + var reducedOrder = new CargoOrderData(order.OrderNumber, order.ProductId, cappedAmount, order.Requester, order.Reason); orders.Add(reducedOrder); break; @@ -415,8 +415,10 @@ public sealed partial class CargoSystem { var order = orders[i]; - Spawn(_protoMan.Index(order.ProductId).Product, - new EntityCoordinates(component.Owner, xformQuery.GetComponent(_random.PickAndTake(pads).Owner).LocalPosition)); + var coordinates = new EntityCoordinates(component.Owner, xformQuery.GetComponent(_random.PickAndTake(pads).Owner).LocalPosition); + + var item = Spawn(_protoMan.Index(order.ProductId).Product, coordinates); + SpawnAndAttachOrderManifest(item, order, coordinates, component); order.Amount--; if (order.Amount == 0) @@ -432,6 +434,41 @@ public sealed partial class CargoSystem } } + /// + /// In this method we are printing and attaching order manifests to the orders. + /// + private void SpawnAndAttachOrderManifest(EntityUid item, CargoOrderData order, EntityCoordinates coordinates, CargoShuttleComponent component) + { + if (!_protoMan.TryIndex(order.ProductId, out CargoProductPrototype? prototype)) + return; + + // spawn a piece of paper. + var printed = EntityManager.SpawnEntity("Paper", coordinates); + + if (!TryComp(printed, out var paper)) + return; + + // fill in the order data + var val = Loc.GetString("cargo-console-paper-print-name", ("orderNumber", order.OrderNumber)); + + MetaData(printed).EntityName = val; + + _paperSystem.SetContent(printed, Loc.GetString( + "cargo-console-paper-print-text", + ("orderNumber", order.OrderNumber), + ("itemName", prototype.Name), + ("requester", order.Requester), + ("reason", order.Reason), + ("approver", order.Approver ?? string.Empty)), + paper); + + // attempt to attach the label + if (TryComp(item, out var label)) + { + _slots.TryInsert(item, label.LabelSlot, printed, null); + } + } + public bool CanRecallShuttle(EntityUid? uid, [NotNullWhen(false)] out string? reason, TransformComponent? xform = null) { reason = null; diff --git a/Content.Server/Cargo/Systems/CargoSystem.Telepad.cs b/Content.Server/Cargo/Systems/CargoSystem.Telepad.cs index 1316ec4531..ba99b1f4bd 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Telepad.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Telepad.cs @@ -1,4 +1,3 @@ -using System.Linq; using Content.Server.Cargo.Components; using Content.Server.Labels.Components; using Content.Server.Paper; @@ -149,15 +148,16 @@ public sealed partial class CargoSystem _paperSystem.SetContent(printed, Loc.GetString( "cargo-console-paper-print-text", ("orderNumber", data.OrderNumber), + ("itemName", prototype.Name), ("requester", data.Requester), ("reason", data.Reason), - ("approver", data.Approver)), + ("approver", data.Approver ?? string.Empty)), paper); // attempt to attach the label if (TryComp(product, out var label)) { - _slots.TryInsert(component.Owner, label.LabelSlot, printed, null); + _slots.TryInsert(product, label.LabelSlot, printed, null); } } } diff --git a/Content.Shared/Cargo/CargoOrderData.cs b/Content.Shared/Cargo/CargoOrderData.cs index 38ebe195fa..3d0d98f623 100644 --- a/Content.Shared/Cargo/CargoOrderData.cs +++ b/Content.Shared/Cargo/CargoOrderData.cs @@ -1,27 +1,46 @@ using Robust.Shared.Serialization; - +using Content.Shared.Access.Components; +using System.Text; namespace Content.Shared.Cargo { [NetSerializable, Serializable] public sealed class CargoOrderData { public int OrderNumber; + public string ProductId; + public int Amount; public string Requester; // public String RequesterRank; // TODO Figure out how to get Character ID card data // public int RequesterId; public string Reason; - public string ProductId; - public int Amount; - public bool Approved; - public string Approver = string.Empty; + public bool Approved => Approver is not null; + public string? Approver; - public CargoOrderData(int orderNumber, string requester, string reason, string productId, int amount) + public CargoOrderData(int orderNumber, string productId, int amount, string requester, string reason) { OrderNumber = orderNumber; - Requester = requester; - Reason = reason; ProductId = productId; Amount = amount; + Requester = requester; + Reason = reason; + } + + public void SetApproverData(IdCardComponent? idCard) + { + var sb = new StringBuilder(); + if (!string.IsNullOrWhiteSpace(idCard?.FullName)) + { + sb.Append($"{idCard.FullName} "); + } + if (!string.IsNullOrWhiteSpace(idCard?.JobTitle)) + { + sb.Append($"({idCard.JobTitle})"); + } + + if (sb.Length > 0) + { + Approver = sb.ToString(); + } } } } diff --git a/Resources/Locale/en-US/cargo/cargo-console-component.ftl b/Resources/Locale/en-US/cargo/cargo-console-component.ftl index 62045cac34..b684a62ad9 100644 --- a/Resources/Locale/en-US/cargo/cargo-console-component.ftl +++ b/Resources/Locale/en-US/cargo/cargo-console-component.ftl @@ -32,6 +32,7 @@ cargo-console-insufficient-funds = Insufficient funds (require {$cost}) cargo-console-paper-print-name = Order #{$orderNumber} cargo-console-paper-print-text = Order #{$orderNumber} + Item: {$itemName} Requested by: {$requester} Reason: {$reason} Approved by: {$approver}