forked from space-wizards/space-station-14
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
voicemask can select speech verb (space-wizards#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>
- Loading branch information
1 parent
df7f2a1
commit d13da28
Showing
11 changed files
with
200 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
67 changes: 63 additions & 4 deletions
67
Content.Client/VoiceMask/VoiceMaskNameChangeWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
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)); | ||
} | ||
|
||
public void UpdateState(string name) | ||
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
using Content.Shared.Speech; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; | ||
|
||
namespace Content.Server.VoiceMask; | ||
|
||
[RegisterComponent] | ||
public sealed partial class VoiceMaskerComponent : Component | ||
{ | ||
[ViewVariables(VVAccess.ReadWrite)] public string LastSetName = "Unknown"; | ||
[DataField] | ||
public string LastSetName = "Unknown"; | ||
|
||
[DataField("action", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))] | ||
public string Action = "ActionChangeVoiceMask"; | ||
[DataField] | ||
public ProtoId<SpeechVerbPrototype>? LastSpeechVerb; | ||
|
||
[DataField("actionEntity")] public EntityUid? ActionEntity; | ||
[DataField] | ||
public EntProtoId Action = "ActionChangeVoiceMask"; | ||
|
||
[DataField] | ||
public EntityUid? ActionEntity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.