Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description of tool qualities to entity #32436

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Content.Shared/Tools/Systems/SharedToolSystem.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -42,6 +43,7 @@ public override void Initialize()
InitializeTile();
InitializeWelder();
SubscribeLocalEvent<ToolComponent, ToolDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<ToolComponent, ExaminedEvent>(OnExamine);
}

private void OnDoAfter(EntityUid uid, ToolComponent tool, ToolDoAfterEvent args)
Expand All @@ -58,6 +60,34 @@ private void OnDoAfter(EntityUid uid, ToolComponent tool, ToolDoAfterEvent args)
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)
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/tools/components/tool-component.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tool-component-qualities = This item can be used for [color=yellow]{ $qualities }[/color].
Loading