CatStation/Content.Client/VoiceMask/VoiceMaskNameChangeWindow.xaml.cs
2023-03-18 12:29:30 -07:00

58 lines
1.7 KiB
C#

using System.Linq;
using Content.Shared.Corvax.TTS;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client.VoiceMask;
[GenerateTypedNameReferences]
public sealed partial class VoiceMaskNameChangeWindow : DefaultWindow
{
private readonly List<TTSVoicePrototype> _voices; // Corvax-TTS
public Action<string>? OnNameChange;
public Action<string>? OnVoiceChange; // Corvax-TTS
public VoiceMaskNameChangeWindow()
{
RobustXamlLoader.Load(this);
NameSelectorSet.OnPressed += _ =>
{
OnNameChange!(NameSelector.Text);
};
// Corvax-TTS-Start
VoiceSelector.OnItemSelected += args =>
{
VoiceSelector.SelectId(args.Id);
if (VoiceSelector.SelectedMetadata != null)
OnVoiceChange!((string)VoiceSelector.SelectedMetadata);
};
_voices = IoCManager
.Resolve<IPrototypeManager>()
.EnumeratePrototypes<TTSVoicePrototype>()
.Where(o => o.RoundStart)
.OrderBy(o => Loc.GetString(o.Name))
.ToList();
for (var i = 0; i < _voices.Count; i++)
{
var name = Loc.GetString(_voices[i].Name);
VoiceSelector.AddItem(name);
VoiceSelector.SetItemMetadata(i, _voices[i].ID);
}
// Corvax-TTS-End
}
public void UpdateState(string name, string voice) // Corvax-TTS
{
NameSelector.Text = name;
// Corvax-TTS-Start
var voiceIdx = _voices.FindIndex(v => v.ID == voice);
if (voiceIdx != -1)
VoiceSelector.Select(voiceIdx);
// Corvax-TTS-End
}
}