Files
OldThink/Content.Client/_White/TTS/HumanoidProfileEditor.TTS.cs

100 lines
3.1 KiB
C#
Raw Permalink Normal View History

using System.Linq;
using Content.Client._White.Sponsors;
using Content.Client._White.TTS;
using Content.Client.Lobby;
using Content.Shared.Preferences;
using Content.Shared._White.TTS;
2023-05-04 17:51:53 +03:00
using Robust.Shared.Random;
// ReSharper disable InconsistentNaming
namespace Content.Client.Preferences.UI;
public sealed partial class HumanoidProfileEditor
{
2023-05-04 17:51:53 +03:00
private TTSManager _ttsMgr = default!;
private TTSSystem _ttsSys = default!;
private List<TTSVoicePrototype> _voiceList = default!;
2023-05-04 17:51:53 +03:00
private readonly List<string> _sampleText = new()
{
2023-05-07 20:24:36 +03:00
"Помогите, клоун насилует в технических тоннелях!",
"ХоС, ваши сотрудники украли у меня собаку и засунули ее в стиральную машину!",
"Агент синдиката украл пиво из бара и взорвался!",
"Врача! Позовите врача!"
2023-05-04 17:51:53 +03:00
};
2023-09-02 16:00:02 +03:00
private const string AnySexVoiceProto = "SponsorAnySexVoices";
private void InitializeVoice()
{
2023-05-04 17:51:53 +03:00
_ttsMgr = IoCManager.Resolve<TTSManager>();
_ttsSys = _entMan.System<TTSSystem>();
_voiceList = _prototypeManager.EnumeratePrototypes<TTSVoicePrototype>().Where(o => o.RoundStart).ToList();
_voiceButton.OnItemSelected += args =>
{
_voiceButton.SelectId(args.Id);
SetVoice(_voiceList[args.Id].ID);
};
2023-05-04 17:51:53 +03:00
_voicePlayButton.OnPressed += _ => { PlayTTS(); };
}
private void UpdateTTSVoicesControls()
{
if (Profile is null)
return;
var sponsorsManager = IoCManager.Resolve<SponsorsManager>();
_voiceButton.Clear();
var firstVoiceChoiceId = 1;
for (var i = 0; i < _voiceList.Count; i++)
{
var voice = _voiceList[i];
if (!HumanoidCharacterProfile.CanHaveVoice(voice, Profile.Sex))
2023-09-02 16:00:02 +03:00
{
if (!sponsorsManager.TryGetInfo(out var sponsorInfo)
|| !sponsorInfo.AllowedMarkings.Contains(AnySexVoiceProto))
continue;
}
var name = Loc.GetString(voice.Name);
_voiceButton.AddItem(name, i);
if (firstVoiceChoiceId == 1)
firstVoiceChoiceId = i;
if (voice.SponsorOnly &&
sponsorsManager.TryGetInfo(out var sponsor) &&
!sponsor.AllowedMarkings.Contains(voice.ID))
{
_voiceButton.SetItemDisabled(i, true);
}
}
var voiceChoiceId = _voiceList.FindIndex(x => x.ID == Profile.Voice);
if (!_voiceButton.TrySelectId(voiceChoiceId) &&
_voiceButton.TrySelectId(firstVoiceChoiceId))
{
SetVoice(_voiceList[firstVoiceChoiceId].ID);
}
}
2023-05-04 17:51:53 +03:00
private void PlayTTS()
{
var dummy = _controller?.GetPreviewDummy();
if (!dummy.HasValue)
return;
if (Profile == null)
2023-05-04 17:51:53 +03:00
return;
_ttsSys.StopCurrentTTS(dummy.Value);
_ttsMgr.RequestTTS(dummy.Value, IoCManager.Resolve<IRobustRandom>().Pick(_sampleText), Profile.Voice);
2023-05-04 17:51:53 +03:00
}
}