voicemask can select speech verb (#25768)
* add Name field to SpeechVerbPrototype * extra locale for voice mask ui * SpeechVerb ui and handling * raaaaaaaaa * reeeeeeeeal Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * fix sort * did you hear john syndicate died of ligma * Update Content.Client/VoiceMask/VoiceMaskNameChangeWindow.xaml --------- Co-authored-by: deltanedas <@deltanedas:kde.org> Co-authored-by: Tayrtahn <tayrtahn@gmail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using Content.Shared.VoiceMask;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.VoiceMask;
|
||||
|
||||
public sealed class VoiceMaskBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private VoiceMaskNameChangeWindow? _window;
|
||||
|
||||
@@ -16,10 +19,11 @@ public sealed class VoiceMaskBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_window = new();
|
||||
_window = new(_proto);
|
||||
|
||||
_window.OpenCentered();
|
||||
_window.OnNameChange += OnNameSelected;
|
||||
_window.OnVerbChange += verb => SendMessage(new VoiceMaskChangeVerbMessage(verb));
|
||||
_window.OnClose += Close;
|
||||
}
|
||||
|
||||
@@ -35,7 +39,7 @@ public sealed class VoiceMaskBoundUserInterface : BoundUserInterface
|
||||
return;
|
||||
}
|
||||
|
||||
_window.UpdateState(cast.Name);
|
||||
_window.UpdateState(cast.Name, cast.Verb);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
<controls:FancyWindow xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
Title="{Loc 'voice-mask-name-change-window'}"
|
||||
MinSize="5 20">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
MinSize="5 30">
|
||||
<BoxContainer Orientation="Vertical" Margin="5">
|
||||
<Label Text="{Loc 'voice-mask-name-change-info'}" />
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<BoxContainer Orientation="Horizontal" Margin="5">
|
||||
<LineEdit Name="NameSelector" HorizontalExpand="True" />
|
||||
<Button Name="NameSelectorSet" Text="{Loc 'voice-mask-name-change-set'}" />
|
||||
</BoxContainer>
|
||||
<BoxContainer Orientation="Horizontal" Margin="5">
|
||||
<Label Text="{Loc 'voice-mask-name-change-speech-style'}" />
|
||||
<OptionButton Name="SpeechVerbSelector" /> <!-- Populated in LoadVerbs -->
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</DefaultWindow>
|
||||
</controls:FancyWindow>
|
||||
|
||||
@@ -1,26 +1,85 @@
|
||||
using Content.Client.UserInterface.Controls;
|
||||
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 : DefaultWindow
|
||||
public sealed partial class VoiceMaskNameChangeWindow : FancyWindow
|
||||
{
|
||||
public Action<string>? OnNameChange;
|
||||
public Action<string?>? OnVerbChange;
|
||||
|
||||
public VoiceMaskNameChangeWindow()
|
||||
private List<(string, string)> _verbs = new();
|
||||
|
||||
private string? _verb;
|
||||
|
||||
public VoiceMaskNameChangeWindow(IPrototypeManager proto)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
NameSelectorSet.OnPressed += _ =>
|
||||
{
|
||||
OnNameChange!(NameSelector.Text);
|
||||
OnNameChange?.Invoke(NameSelector.Text);
|
||||
};
|
||||
|
||||
SpeechVerbSelector.OnItemSelected += args =>
|
||||
{
|
||||
OnVerbChange?.Invoke((string?) args.Button.GetItemMetadata(args.Id));
|
||||
SpeechVerbSelector.SelectId(args.Id);
|
||||
};
|
||||
|
||||
ReloadVerbs(proto);
|
||||
|
||||
AddVerbs();
|
||||
}
|
||||
|
||||
public void UpdateState(string name)
|
||||
private 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));
|
||||
}
|
||||
|
||||
private 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? verb)
|
||||
{
|
||||
NameSelector.Text = name;
|
||||
_verb = verb;
|
||||
|
||||
for (int id = 0; id < SpeechVerbSelector.ItemCount; id++)
|
||||
{
|
||||
if (string.Equals(verb, SpeechVerbSelector.GetItemMetadata(id)))
|
||||
{
|
||||
SpeechVerbSelector.SelectId(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user