Files
ss14-wl/Content.Client/Corvax/TTS/HumanoidProfileEditor.TTS.cs
Litogin 899526f0d9 Custom preview TTS (#256)
* Custom preview TTS

* Update TTSSystem.cs

* mini fix
2025-10-04 22:34:11 +03:00

79 lines
2.2 KiB
C#

using System.Linq;
using Content.Client.Corvax.TTS;
using Content.Client.Lobby;
using Content.Corvax.Interfaces.Shared;
using Content.Shared.Corvax.TTS;
using Content.Shared.Preferences;
namespace Content.Client.Lobby.UI;
public sealed partial class HumanoidProfileEditor
{
private ISharedSponsorsManager? _sponsorsMgr;
private List<TTSVoicePrototype> _voiceList = new();
private void InitializeVoice()
{
_voiceList = _prototypeManager
.EnumeratePrototypes<TTSVoicePrototype>()
.Where(o => o.RoundStart)
.OrderBy(o => Loc.GetString(o.Name))
.ToList();
VoiceButton.OnItemSelected += args =>
{
VoiceButton.SelectId(args.Id);
SetVoice(_voiceList[args.Id].ID);
};
VoicePlayButton.OnPressed += _ => PlayPreviewTTS();
IoCManager.Instance!.TryResolveType(out _sponsorsMgr);
}
private void UpdateTTSVoicesControls()
{
if (Profile is null)
return;
VoiceButton.Clear();
var firstVoiceChoiceId = 1;
for (var i = 0; i < _voiceList.Count; i++)
{
var voice = _voiceList[i];
if (!HumanoidCharacterProfile.CanHaveVoice(voice, Profile.Sex))
continue;
var name = Loc.GetString(voice.Name);
VoiceButton.AddItem(name, i);
if (firstVoiceChoiceId == 1)
firstVoiceChoiceId = i;
if (_sponsorsMgr is null)
continue;
if (voice.SponsorOnly && _sponsorsMgr != null &&
!_sponsorsMgr.GetClientPrototypes().Contains(voice.ID))
{
VoiceButton.SetItemDisabled(VoiceButton.GetIdx(i), true);
}
}
var voiceChoiceId = _voiceList.FindIndex(x => x.ID == Profile.Voice);
if (!VoiceButton.TrySelectId(voiceChoiceId) &&
VoiceButton.TrySelectId(firstVoiceChoiceId))
{
SetVoice(_voiceList[firstVoiceChoiceId].ID);
}
}
private void PlayPreviewTTS()
{
if (Profile is null)
return;
_entManager.System<TTSSystem>().RequestPreviewTTS(Profile.Voice, CTTSPreview?.Text ?? String.Empty); //WL-PreviewTTSEdit
}
}