From 08dcc3b6e679a90ac8cc8ef05b4669ffb13c7a29 Mon Sep 17 00:00:00 2001 From: Ignaz Kraft Date: Wed, 15 Jan 2025 13:25:12 +0100 Subject: [PATCH] job and department restricted chemicals --- .../Controls/GuideReagentEmbed.xaml.cs | 28 ++++++++++++++++++- .../Guidebook/Richtext/ContrabandColors.cs | 5 ++-- .../Forensics/Systems/ForensicPadSystem.cs | 5 ++-- .../Chemistry/Reagent/ReagentPrototype.cs | 11 ++++++++ Resources/Locale/en-US/generic.ftl | 2 ++ 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml.cs b/Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml.cs index 86f2a4b2deb1..73cfaa4db78f 100644 --- a/Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml.cs +++ b/Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml.cs @@ -7,6 +7,8 @@ using Content.Shared.Body.Prototypes; using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; +using Content.Shared.Localizations; +using Content.Shared.Roles; using JetBrains.Annotations; using Robust.Client.AutoGenerated; using Robust.Client.Graphics; @@ -195,7 +197,31 @@ private void GenerateControl(ReagentPrototype reagent) FormattedMessage description = new(); if (_prototype.TryIndex(reagent.Contraband, out var severity)) { - description.AddMarkupOrThrow(Loc.GetString(severity.ExamineText, ("color", severity.ExamineColor))); + if (severity.ShowDepartments && (reagent is { AllowedDepartments: not null } || reagent is { AllowedJobs: not null })) + { + var departments = reagent.AllowedDepartments?.Select(x => + { + if (_prototype.TryIndex(x, out var department)) + { + return Loc.GetString(department.Name); + } + return x.Id; + }) ?? []; + var jobs = reagent.AllowedJobs?.Select(x => + { + if (_prototype.TryIndex(x, out var job)) + { + return Loc.GetString("generic-multiple", ("thing", Loc.GetString(job.Name))); + } + return x.Id; + }) ?? []; + var list = ContentLocalizationManager.FormatList([.. departments, .. jobs]); + description.AddMarkupOrThrow(Loc.GetString("contraband-examine-text-Restricted-department", ("color", severity.ExamineColor), ("departments", list))); + } + else + { + description.AddMarkupOrThrow(Loc.GetString(severity.ExamineText, ("color", severity.ExamineColor))); + } description.PushNewline(); } description.AddText(reagent.LocalizedDescription); diff --git a/Content.Client/Guidebook/Richtext/ContrabandColors.cs b/Content.Client/Guidebook/Richtext/ContrabandColors.cs index 218a26d855b0..63c7e619dd47 100644 --- a/Content.Client/Guidebook/Richtext/ContrabandColors.cs +++ b/Content.Client/Guidebook/Richtext/ContrabandColors.cs @@ -7,6 +7,7 @@ using Robust.Client.UserInterface.RichText; using Robust.Shared.Prototypes; using Robust.Shared.Utility; +using Content.Shared.Localizations; namespace Content.Client.Guidebook.RichText; @@ -22,10 +23,10 @@ public sealed class ContrabandColors : IMarkupTag /// public bool TryGetControl(MarkupNode node, [NotNullWhen(true)] out Control? control) { - var text = _prototypeManager.EnumeratePrototypes().Select(x => + var text = ContentLocalizationManager.FormatList([.. _prototypeManager.EnumeratePrototypes().Select(x => { return $"[color={x.ExamineColor}]{x.ID}[/color]"; - }).Aggregate((x, y) => x + ", " + y); + })]); var label = new RichTextLabel() { diff --git a/Content.Server/Forensics/Systems/ForensicPadSystem.cs b/Content.Server/Forensics/Systems/ForensicPadSystem.cs index 16751214cf9f..47fd23b551c4 100644 --- a/Content.Server/Forensics/Systems/ForensicPadSystem.cs +++ b/Content.Server/Forensics/Systems/ForensicPadSystem.cs @@ -9,6 +9,7 @@ using Content.Shared.IdentityManagement; using Content.Shared.Interaction; using Content.Shared.Inventory; +using Content.Shared.Localizations; using Robust.Shared.Prototypes; namespace Content.Server.Forensics @@ -96,7 +97,7 @@ private void OnAfterInteract(EntityUid uid, ForensicPadComponent component, Afte return; } - var sample = solution.Contents.Select(x => + var sample = ContentLocalizationManager.FormatList([.. solution.Contents.Select(x => { if (_prototypeManager.TryIndex(x.Reagent.Prototype, out ReagentPrototype? reagent)) { @@ -108,7 +109,7 @@ private void OnAfterInteract(EntityUid uid, ForensicPadComponent component, Afte return localizedName; } return "???"; - }).Aggregate((x, y) => x + ", " + y); + })]); StartScan(uid, args.User, args.Target.Value, component, sample); return; } diff --git a/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs b/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs index d067786255d9..2712f44b4932 100644 --- a/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs +++ b/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs @@ -18,6 +18,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array; using Robust.Shared.Utility; +using Content.Shared.Roles; namespace Content.Shared.Chemistry.Reagent { @@ -149,6 +150,16 @@ public sealed partial class ReagentPrototype : IPrototype, IInheritingPrototype /// [DataField] public ProtoId? Contraband = null; + /// + /// Which departments is this reagent restricted to? + /// + [DataField] + public HashSet>? AllowedDepartments = null; + /// + /// Which jobs is this reagent restricted to? + /// + [DataField] + public HashSet>? AllowedJobs = null; public FixedPoint2 ReactionTile(TileRef tile, FixedPoint2 reactVolume, IEntityManager entityManager, List? data) { diff --git a/Resources/Locale/en-US/generic.ftl b/Resources/Locale/en-US/generic.ftl index 350409788521..7e758eadadaa 100644 --- a/Resources/Locale/en-US/generic.ftl +++ b/Resources/Locale/en-US/generic.ftl @@ -15,3 +15,5 @@ generic-minutes = minutes generic-playtime-title = Playtime generic-confirm = Confirm + +generic-multiple = {MAKEPLURAL($thing)}