Skip to content

Commit

Permalink
Add TTS name examine
Browse files Browse the repository at this point in the history
  • Loading branch information
lzk228 committed Aug 29, 2024
1 parent a47ba31 commit d2f933d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
68 changes: 68 additions & 0 deletions Content.Server/Corvax/TTS/TTSExamineSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Content.Server.VoiceMask;
using Content.Shared.Corvax.CCCVars;
using Content.Shared.Corvax.TTS;
using Content.Shared.Examine;
using Content.Shared.IdentityManagement;
using Content.Shared.Verbs;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Server.Corvax.TTS
{
public sealed class DetailExaminableSystem : EntitySystem
{
[Dependency] private readonly ExamineSystemShared _examineSystem = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] protected readonly IConfigurationManager _configManager = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<TTSComponent, GetVerbsEvent<ExamineVerb>>(OnGetExamineVerbs);
}

private void OnGetExamineVerbs(EntityUid uid, TTSComponent component, GetVerbsEvent<ExamineVerb> args)
{
// Don't show verb if no TTS enabled OR if user's name is hidden
if (!_configManager.GetCVar(CCCVars.TTSEnabled) ||
Identity.Name(args.Target, EntityManager) != MetaData(args.Target).EntityName)
return;

string? voiceId = string.Empty;

// If user is wearing a voice mask, we will take its voice
if (TryComp<VoiceMaskComponent>(uid, out var voiceMask))
voiceId = voiceMask.VoiceId;
else
voiceId = component.VoicePrototypeId;

// Get the voice name
string voiceName = string.Empty;
if (_prototypeManager.TryIndex<TTSVoicePrototype>(voiceId ?? string.Empty, out var protoVoice))
{
voiceName = Loc.GetString(protoVoice.Name);
}

var detailsRange = _examineSystem.IsInDetailsRange(args.User, uid);

var verb = new ExamineVerb()
{
Act = () =>
{
var markup = new FormattedMessage();
markup.AddMarkup(Loc.GetString("tts-examine-voice", ("name", voiceName)));
_examineSystem.SendExamineTooltip(args.User, uid, markup, false, false);
},
Text = Loc.GetString("tts-examine"),
Category = VerbCategory.Examine,
Disabled = !detailsRange,
Message = detailsRange ? null : Loc.GetString("tts-examine-disabled"),
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/Emotes/vocal.png"))
};

args.Verbs.Add(verb);
}
}
}
3 changes: 3 additions & 0 deletions Resources/Locale/ru-RU/corvax/tts/tts-examine.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tts-examine = Узнать голос TTS
tts-examine-voice = Голос TTS: [color=yellow]{$name}[/color].
tts-examine-disabled = Осмотрите ближе

0 comments on commit d2f933d

Please sign in to comment.