mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
* First commit * Added base.Initialize() * Voice wire fix (Electricty name) * Various minor cleanups * Localized default voice mask name * Added VoiceOverride stuff * Removed unused stuff * Typo * Better localized stuff * Typo / spelling stuff / comments * Blessed
122 lines
3.4 KiB
C#
122 lines
3.4 KiB
C#
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared._White.TTS;
|
|
using Content.Shared.Speech;
|
|
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 : FancyWindow
|
|
{
|
|
public Action<string>? OnNameChange;
|
|
public Action<string>? OnVoiceChange; // WD EDIT
|
|
public Action<string?>? OnVerbChange;
|
|
|
|
private readonly List<TTSVoicePrototype> _voices = new(); // WD EDIT
|
|
private List<(string, string)> _verbs = new();
|
|
|
|
private string? _verb;
|
|
|
|
public VoiceMaskNameChangeWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
|
|
NameSelectorSet.OnPressed += _ =>
|
|
{
|
|
OnNameChange?.Invoke(NameSelector.Text);
|
|
};
|
|
|
|
// WD EDIT START
|
|
VoiceSelector.OnItemSelected += args =>
|
|
{
|
|
VoiceSelector.SelectId(args.Id);
|
|
if (VoiceSelector.SelectedMetadata != null)
|
|
OnVoiceChange?.Invoke((string) VoiceSelector.SelectedMetadata);
|
|
};
|
|
// WD EDIT END
|
|
|
|
SpeechVerbSelector.OnItemSelected += args =>
|
|
{
|
|
OnVerbChange?.Invoke((string?) args.Button.GetItemMetadata(args.Id));
|
|
SpeechVerbSelector.SelectId(args.Id);
|
|
};
|
|
}
|
|
|
|
// WD EDIT START
|
|
public void ReloadVoices(IPrototypeManager proto)
|
|
{
|
|
foreach (var voice in proto.EnumeratePrototypes<TTSVoicePrototype>())
|
|
if (voice.RoundStart)
|
|
_voices.Add(voice);
|
|
|
|
_voices.Sort((a, b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal));
|
|
}
|
|
|
|
public void AddVoices()
|
|
{
|
|
VoiceSelector.Clear();
|
|
for (var i = 0; i < _voices.Count; i++)
|
|
{
|
|
var name = Loc.GetString(_voices[i].Name);
|
|
VoiceSelector.AddItem(name);
|
|
VoiceSelector.SetItemMetadata(i, _voices[i].ID);
|
|
}
|
|
}
|
|
// WD EDIT END
|
|
|
|
public void ReloadVerbs(IPrototypeManager proto)
|
|
{
|
|
foreach (var verb in proto.EnumeratePrototypes<SpeechVerbPrototype>())
|
|
{
|
|
_verbs.Add((Loc.GetString(verb.Name), verb.ID));
|
|
}
|
|
_verbs.Sort((a, b) => a.Item1.CompareTo(b.Item1));
|
|
}
|
|
|
|
public void AddVerbs()
|
|
{
|
|
SpeechVerbSelector.Clear();
|
|
|
|
AddVerb(Loc.GetString("chat-speech-verb-name-none"), null);
|
|
foreach (var (name, id) in _verbs)
|
|
{
|
|
AddVerb(name, id);
|
|
}
|
|
}
|
|
|
|
private void AddVerb(string name, string? verb)
|
|
{
|
|
var id = SpeechVerbSelector.ItemCount;
|
|
SpeechVerbSelector.AddItem(name);
|
|
if (verb is {} metadata)
|
|
SpeechVerbSelector.SetItemMetadata(id, metadata);
|
|
|
|
if (verb == _verb)
|
|
SpeechVerbSelector.SelectId(id);
|
|
}
|
|
|
|
public void UpdateState(string name, string voice, string? verb) // WD EDIT
|
|
{
|
|
NameSelector.Text = name;
|
|
_verb = verb;
|
|
|
|
// WD EDIT START
|
|
var voiceIdx = _voices.FindIndex(v => v.ID == voice);
|
|
if (voiceIdx != -1)
|
|
VoiceSelector.Select(voiceIdx);
|
|
// WD EDIT END
|
|
|
|
for (int id = 0; id < SpeechVerbSelector.ItemCount; id++)
|
|
{
|
|
if (string.Equals(verb, SpeechVerbSelector.GetItemMetadata(id)))
|
|
{
|
|
SpeechVerbSelector.SelectId(id);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|