]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add description of tool qualities to entity (#32436)
authorlzk <124214523+lzk228@users.noreply.github.com>
Fri, 20 Dec 2024 22:15:40 +0000 (23:15 +0100)
committerGitHub <noreply@github.com>
Fri, 20 Dec 2024 22:15:40 +0000 (23:15 +0100)
* Add description of tool qualities to entity

* LMAO I FORGOT FUCKING FTL FILE

* minor cleanup

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Shared/Tools/Systems/SharedToolSystem.cs
Resources/Locale/en-US/tools/components/tool-component.ftl [new file with mode: 0644]

index 4c7383a38c435a5de77b2c49e883f84524658cc3..95377d913a9c9779b1178ee42b81dca64cbdf0a9 100644 (file)
@@ -1,6 +1,7 @@
 using Content.Shared.Administration.Logs;
 using Content.Shared.Chemistry.EntitySystems;
 using Content.Shared.DoAfter;
+using Content.Shared.Examine;
 using Content.Shared.Interaction;
 using Content.Shared.Item.ItemToggle;
 using Content.Shared.Maps;
@@ -41,6 +42,7 @@ public abstract partial class SharedToolSystem : EntitySystem
         InitializeTile();
         InitializeWelder();
         SubscribeLocalEvent<ToolComponent, ToolDoAfterEvent>(OnDoAfter);
+        SubscribeLocalEvent<ToolComponent, ExaminedEvent>(OnExamine);
     }
 
     private void OnDoAfter(EntityUid uid, ToolComponent tool, ToolDoAfterEvent args)
@@ -57,6 +59,34 @@ public abstract partial class SharedToolSystem : EntitySystem
             RaiseLocalEvent((object) ev);
     }
 
+    private void OnExamine(Entity<ToolComponent> ent, ref ExaminedEvent args)
+    {
+        // If the tool has no qualities, exit early
+        if (ent.Comp.Qualities.Count == 0)
+            return;
+
+        var message = new FormattedMessage();
+
+        // Create a list to store tool quality names
+        var toolQualities = new List<string>();
+
+        // Loop through tool qualities and add localized names to the list
+        foreach (var toolQuality in ent.Comp.Qualities)
+        {
+            if (_protoMan.TryIndex<ToolQualityPrototype>(toolQuality ?? string.Empty, out var protoToolQuality))
+            {
+                toolQualities.Add(Loc.GetString(protoToolQuality.Name));
+            }
+        }
+
+        // Combine the qualities into a single string and localize the final message
+        var qualitiesString = string.Join(", ", toolQualities);
+
+        // Add the localized message to the FormattedMessage object
+        message.AddMarkupPermissive(Loc.GetString("tool-component-qualities", ("qualities", qualitiesString)));
+        args.PushMessage(message);
+    }
+
     public void PlayToolSound(EntityUid uid, ToolComponent tool, EntityUid? user)
     {
         if (tool.UseSound == null)
diff --git a/Resources/Locale/en-US/tools/components/tool-component.ftl b/Resources/Locale/en-US/tools/components/tool-component.ftl
new file mode 100644 (file)
index 0000000..0c9e60c
--- /dev/null
@@ -0,0 +1 @@
+tool-component-qualities = This item can be used for [color=yellow]{ $qualities }[/color].