Voice mask (#10458)
This commit is contained in:
46
Content.Client/VoiceMask/VoiceMaskBoundUserInterface.cs
Normal file
46
Content.Client/VoiceMask/VoiceMaskBoundUserInterface.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Content.Shared.VoiceMask;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.VoiceMask;
|
||||
|
||||
public sealed class VoiceMaskBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
public VoiceMaskBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
private VoiceMaskNameChangeWindow? _window;
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_window = new();
|
||||
|
||||
_window.OpenCentered();
|
||||
_window.OnNameChange += OnNameSelected;
|
||||
_window.OnClose += Close;
|
||||
}
|
||||
|
||||
private void OnNameSelected(string name)
|
||||
{
|
||||
SendMessage(new VoiceMaskChangeNameMessage(name));
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
if (state is not VoiceMaskBuiState cast || _window == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_window.UpdateState(cast.Name);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
_window?.Close();
|
||||
}
|
||||
}
|
||||
11
Content.Client/VoiceMask/VoiceMaskNameChangeWindow.xaml
Normal file
11
Content.Client/VoiceMask/VoiceMaskNameChangeWindow.xaml
Normal file
@@ -0,0 +1,11 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
Title="{Loc 'voice-mask-name-change-window'}"
|
||||
MinSize="5 20">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<Label Text="{Loc 'voice-mask-name-change-info'}" />
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<LineEdit Name="NameSelector" HorizontalExpand="True" />
|
||||
<Button Name="NameSelectorSet" Text="{Loc 'voice-mask-name-change-set'}" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</DefaultWindow>
|
||||
26
Content.Client/VoiceMask/VoiceMaskNameChangeWindow.xaml.cs
Normal file
26
Content.Client/VoiceMask/VoiceMaskNameChangeWindow.xaml.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.VoiceMask;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class VoiceMaskNameChangeWindow : DefaultWindow
|
||||
{
|
||||
public Action<string>? OnNameChange;
|
||||
|
||||
public VoiceMaskNameChangeWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
NameSelectorSet.OnPressed += _ =>
|
||||
{
|
||||
OnNameChange!(NameSelector.Text);
|
||||
};
|
||||
}
|
||||
|
||||
public void UpdateState(string name)
|
||||
{
|
||||
NameSelector.Text = name;
|
||||
}
|
||||
}
|
||||
@@ -259,12 +259,15 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
return;
|
||||
}
|
||||
|
||||
var nameEv = new TransformSpeakerNameEvent(source, Name(source));
|
||||
RaiseLocalEvent(source, nameEv);
|
||||
|
||||
message = TransformSpeech(source, message);
|
||||
if (message.Length == 0)
|
||||
return;
|
||||
|
||||
var messageWrap = Loc.GetString("chat-manager-entity-say-wrap-message",
|
||||
("entityName", Name(source)));
|
||||
("entityName", nameEv.Name));
|
||||
|
||||
SendInVoiceRange(ChatChannel.Local, message, messageWrap, source, hideChat);
|
||||
_listener.PingListeners(source, message, null);
|
||||
@@ -295,8 +298,12 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
|
||||
var transformSource = Transform(source);
|
||||
var sourceCoords = transformSource.Coordinates;
|
||||
|
||||
var nameEv = new TransformSpeakerNameEvent(source, Name(source));
|
||||
RaiseLocalEvent(source, nameEv);
|
||||
|
||||
var messageWrap = Loc.GetString("chat-manager-entity-whisper-wrap-message",
|
||||
("entityName", Name(source)));
|
||||
("entityName", nameEv.Name));
|
||||
|
||||
var xforms = GetEntityQuery<TransformComponent>();
|
||||
var ghosts = GetEntityQuery<GhostComponent>();
|
||||
@@ -530,6 +537,18 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
#endregion
|
||||
}
|
||||
|
||||
public sealed class TransformSpeakerNameEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Sender;
|
||||
public string Name;
|
||||
|
||||
public TransformSpeakerNameEvent(EntityUid sender, string name)
|
||||
{
|
||||
Sender = sender;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised broadcast in order to transform speech.
|
||||
/// </summary>
|
||||
|
||||
@@ -13,6 +13,7 @@ using Content.Server.Disease.Components;
|
||||
using Content.Server.IdentityManagement;
|
||||
using Content.Server.Nutrition.EntitySystems;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.VoiceMask;
|
||||
using Content.Shared.Clothing.EntitySystems;
|
||||
using Content.Shared.IdentityManagement.Components;
|
||||
using Robust.Shared.Player;
|
||||
@@ -87,6 +88,8 @@ namespace Content.Server.Clothing
|
||||
_clothing.SetEquippedPrefix(uid, mask.IsToggled ? "toggled" : null, clothing);
|
||||
}
|
||||
|
||||
// shouldn't this be an event?
|
||||
|
||||
// toggle ingestion blocking
|
||||
if (TryComp<IngestionBlockerComponent>(uid, out var blocker))
|
||||
blocker.Enabled = !mask.IsToggled;
|
||||
@@ -99,6 +102,10 @@ namespace Content.Server.Clothing
|
||||
if (TryComp<IdentityBlockerComponent>(uid, out var identity))
|
||||
identity.Enabled = !mask.IsToggled;
|
||||
|
||||
// toggle voice masking
|
||||
if (TryComp<VoiceMaskComponent>(uid, out var voiceMask))
|
||||
voiceMask.Enabled = !mask.IsToggled;
|
||||
|
||||
// toggle breath tool connection (skip during equip since that is handled in LungSystem)
|
||||
if (isEquip || !TryComp<BreathToolComponent>(uid, out var breathTool))
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Content.Server.Radio.Components;
|
||||
using Content.Server.VoiceMask;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Radio;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Network;
|
||||
@@ -28,12 +30,19 @@ namespace Content.Server.Ghost.Components
|
||||
|
||||
var playerChannel = actor.PlayerSession.ConnectedClient;
|
||||
|
||||
var name = _entMan.GetComponent<MetaDataComponent>(speaker).EntityName;
|
||||
|
||||
if (_entMan.TryGetComponent(speaker, out VoiceMaskComponent? mask) && mask.Enabled)
|
||||
{
|
||||
name = Identity.Name(speaker, _entMan);
|
||||
}
|
||||
|
||||
var msg = new MsgChatMessage
|
||||
{
|
||||
Channel = ChatChannel.Radio,
|
||||
Message = message,
|
||||
//Square brackets are added here to avoid issues with escaping
|
||||
MessageWrap = Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", _entMan.GetComponent<MetaDataComponent>(speaker).EntityName))
|
||||
MessageWrap = Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", name))
|
||||
};
|
||||
|
||||
_netManager.ServerSendMessage(msg, playerChannel);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.Radio.Components;
|
||||
using Content.Server.Radio.EntitySystems;
|
||||
using Content.Server.VoiceMask;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Radio;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -58,6 +60,13 @@ namespace Content.Server.Headset
|
||||
|
||||
var playerChannel = actor.PlayerSession.ConnectedClient;
|
||||
|
||||
var name = _entMan.GetComponent<MetaDataComponent>(source).EntityName;
|
||||
|
||||
if (_entMan.TryGetComponent(source, out VoiceMaskComponent? mask) && mask.Enabled)
|
||||
{
|
||||
name = Identity.Name(source, _entMan);
|
||||
}
|
||||
|
||||
message = _chatSystem.TransformSpeech(source, message);
|
||||
if (message.Length == 0)
|
||||
return;
|
||||
@@ -67,7 +76,7 @@ namespace Content.Server.Headset
|
||||
Channel = ChatChannel.Radio,
|
||||
Message = message,
|
||||
//Square brackets are added here to avoid issues with escaping
|
||||
MessageWrap = Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", _entMan.GetComponent<MetaDataComponent>(source).EntityName))
|
||||
MessageWrap = Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", name))
|
||||
};
|
||||
|
||||
_netManager.ServerSendMessage(msg, playerChannel);
|
||||
|
||||
@@ -43,7 +43,6 @@ namespace Content.Server.Radio.EntitySystems
|
||||
|
||||
foreach (var radio in EntityManager.EntityQuery<IRadio>(true))
|
||||
{
|
||||
//TODO: once voice identity gets added, pass into receiver via source.GetSpeakerVoice()
|
||||
radio.Receive(message, channel, speaker);
|
||||
}
|
||||
|
||||
|
||||
9
Content.Server/VoiceMask/VoiceMaskComponent.cs
Normal file
9
Content.Server/VoiceMask/VoiceMaskComponent.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Content.Server.VoiceMask;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class VoiceMaskComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)] public bool Enabled = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] public string VoiceName = "Unknown";
|
||||
}
|
||||
48
Content.Server/VoiceMask/VoiceMaskSystem.Equip.cs
Normal file
48
Content.Server/VoiceMask/VoiceMaskSystem.Equip.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Content.Server.Actions;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.Speech;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.VoiceMask;
|
||||
|
||||
// This partial deals with equipment, i.e., the syndicate voice mask.
|
||||
public sealed partial class VoiceMaskSystem
|
||||
{
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
[Dependency] private readonly ActionsSystem _actions = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
private const string MaskSlot = "mask";
|
||||
|
||||
private void OnEquip(EntityUid uid, VoiceMaskerComponent component, GotEquippedEvent args)
|
||||
{
|
||||
var comp = EnsureComp<VoiceMaskComponent>(args.Equipee);
|
||||
comp.VoiceName = component.LastSetName;
|
||||
|
||||
if (!_prototypeManager.TryIndex<InstantActionPrototype>(component.Action, out var action))
|
||||
{
|
||||
throw new ArgumentException("Could not get voice masking prototype.");
|
||||
}
|
||||
|
||||
_actions.AddAction(args.Equipee, (InstantAction) action.Clone(), uid);
|
||||
}
|
||||
|
||||
private void OnUnequip(EntityUid uid, VoiceMaskerComponent compnent, GotUnequippedEvent args)
|
||||
{
|
||||
RemComp<VoiceMaskComponent>(args.Equipee);
|
||||
}
|
||||
|
||||
private void TrySetLastKnownName(EntityUid maskWearer, string lastName)
|
||||
{
|
||||
if (!HasComp<VoiceMaskComponent>(maskWearer)
|
||||
|| !_inventory.TryGetSlotEntity(maskWearer, MaskSlot, out var maskEntity)
|
||||
|| !TryComp<VoiceMaskerComponent>(maskEntity, out var maskComp))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
maskComp.LastSetName = lastName;
|
||||
}
|
||||
}
|
||||
88
Content.Server/VoiceMask/VoiceMaskSystem.cs
Normal file
88
Content.Server/VoiceMask/VoiceMaskSystem.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.Preferences;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.VoiceMask;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.VoiceMask;
|
||||
|
||||
public sealed partial class VoiceMaskSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<VoiceMaskComponent, TransformSpeakerNameEvent>(OnSpeakerNameTransform);
|
||||
SubscribeLocalEvent<VoiceMaskComponent, VoiceMaskChangeNameMessage>(OnChangeName);
|
||||
SubscribeLocalEvent<VoiceMaskerComponent, GotEquippedEvent>(OnEquip);
|
||||
SubscribeLocalEvent<VoiceMaskerComponent, GotUnequippedEvent>(OnUnequip);
|
||||
SubscribeLocalEvent<VoiceMaskSetNameEvent>(OnSetName);
|
||||
// SubscribeLocalEvent<VoiceMaskerComponent, GetVerbsEvent<AlternativeVerb>>(GetVerbs);
|
||||
}
|
||||
|
||||
private void OnSetName(VoiceMaskSetNameEvent ev)
|
||||
{
|
||||
OpenUI(ev.Performer);
|
||||
}
|
||||
|
||||
private void OnChangeName(EntityUid uid, VoiceMaskComponent component, VoiceMaskChangeNameMessage message)
|
||||
{
|
||||
if (message.Name.Length > HumanoidCharacterProfile.MaxNameLength || message.Name.Length <= 0)
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("voice-mask-popup-failure"), Filter.SinglePlayer(message.Session));
|
||||
return;
|
||||
}
|
||||
|
||||
component.VoiceName = message.Name;
|
||||
|
||||
_popupSystem.PopupCursor(Loc.GetString("voice-mask-popup-success"), Filter.SinglePlayer(message.Session));
|
||||
|
||||
TrySetLastKnownName(uid, message.Name);
|
||||
|
||||
UpdateUI(uid, component);
|
||||
}
|
||||
|
||||
private void OnSpeakerNameTransform(EntityUid uid, VoiceMaskComponent component, TransformSpeakerNameEvent args)
|
||||
{
|
||||
if (component.Enabled)
|
||||
{
|
||||
/*
|
||||
args.Name = _idCard.TryGetIdCard(uid, out var card) && !string.IsNullOrEmpty(card.FullName)
|
||||
? card.FullName
|
||||
: Loc.GetString("voice-mask-unknown");
|
||||
*/
|
||||
|
||||
args.Name = component.VoiceName;
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenUI(EntityUid player, ActorComponent? actor = null)
|
||||
{
|
||||
if (!Resolve(player, ref actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_uiSystem.GetUiOrNull(player, VoiceMaskUIKey.Key)?.Open(actor.PlayerSession);
|
||||
UpdateUI(player);
|
||||
}
|
||||
|
||||
private void UpdateUI(EntityUid owner, VoiceMaskComponent? component = null)
|
||||
{
|
||||
if (!Resolve(owner, ref component))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_uiSystem.GetUiOrNull(owner, VoiceMaskUIKey.Key)?.SetState(new VoiceMaskBuiState(component.VoiceName));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class VoiceMaskSetNameEvent : InstantActionEvent
|
||||
{
|
||||
}
|
||||
13
Content.Server/VoiceMask/VoiceMaskerComponent.cs
Normal file
13
Content.Server/VoiceMask/VoiceMaskerComponent.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.VoiceMask;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class VoiceMaskerComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)] public string LastSetName = "Unknown";
|
||||
|
||||
[DataField("action", customTypeSerializer: typeof(PrototypeIdSerializer<InstantActionPrototype>))]
|
||||
public string Action = "ChangeVoiceMask";
|
||||
}
|
||||
31
Content.Shared/VoiceMask/SharedVoiceMaskSystem.cs
Normal file
31
Content.Shared/VoiceMask/SharedVoiceMaskSystem.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.VoiceMask;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum VoiceMaskUIKey : byte
|
||||
{
|
||||
Key
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class VoiceMaskBuiState : BoundUserInterfaceState
|
||||
{
|
||||
public string Name { get; }
|
||||
|
||||
public VoiceMaskBuiState(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class VoiceMaskChangeNameMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public string Name { get; }
|
||||
|
||||
public VoiceMaskChangeNameMessage(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
7
Resources/Locale/en-US/voice-mask.ftl
Normal file
7
Resources/Locale/en-US/voice-mask.ftl
Normal file
@@ -0,0 +1,7 @@
|
||||
voice-mask-name-change-window = Voice Mask Name Change
|
||||
voice-mask-name-change-info = Type in the name you want to mimic.
|
||||
voice-mask-name-change-set = Set name
|
||||
voice-mask-name-change-set-description = Change the name others hear to something else.
|
||||
|
||||
voice-mask-popup-success = Name set successfully.
|
||||
voice-mask-popup-failure = Name could not be set.
|
||||
@@ -56,6 +56,13 @@
|
||||
popupToggleSuffix: -enabled
|
||||
event: !type:ToggleCombatActionEvent
|
||||
|
||||
- type: instantAction
|
||||
id: ChangeVoiceMask
|
||||
name: voice-mask-name-change-set
|
||||
icon: Interface/Actions/scream.png # somebody else can figure out a better icon for this
|
||||
description: voice-mask-name-change-set-description
|
||||
serverEvent: !type:VoiceMaskSetNameEvent
|
||||
|
||||
- type: instantAction
|
||||
id: VendingThrow
|
||||
name: vending-machine-action-name
|
||||
|
||||
@@ -260,6 +260,16 @@
|
||||
categories:
|
||||
- UplinkUtility
|
||||
|
||||
- type: listing
|
||||
id: UplinkVoiceMask
|
||||
name: Voice Mask
|
||||
description: A gas mask that lets you adjust your voice to whoever you can think of.
|
||||
productEntity: ClothingMaskGasVoiceMasker
|
||||
cost:
|
||||
Telecrystal: 5
|
||||
categories:
|
||||
- UplinkUtility
|
||||
|
||||
# Bundles
|
||||
|
||||
- type: listing
|
||||
|
||||
@@ -102,6 +102,15 @@
|
||||
Piercing: 0.95
|
||||
Heat: 0.95
|
||||
|
||||
- type: entity
|
||||
parent: ClothingMaskGas
|
||||
id: ClothingMaskGasVoiceMasker
|
||||
name: gas mask
|
||||
suffix: Voice Mask
|
||||
description: A face-covering mask that can be connected to an air supply. There are switches and knobs underneath the mask.
|
||||
components:
|
||||
- type: VoiceMasker
|
||||
|
||||
- type: entity
|
||||
parent: ClothingMaskPullableBase
|
||||
id: ClothingMaskBreathMedical
|
||||
|
||||
@@ -258,6 +258,8 @@
|
||||
- type: Strippable
|
||||
- type: UserInterface
|
||||
interfaces:
|
||||
- key: enum.VoiceMaskUIKey.Key
|
||||
type: VoiceMaskBoundUserInterface
|
||||
- key: enum.HumanoidMarkingModifierKey.Key
|
||||
type: HumanoidMarkingModifierBoundUserInterface
|
||||
- key: enum.StrippingUiKey.Key
|
||||
|
||||
Reference in New Issue
Block a user