CatStation/Content.Server/VoiceMask/VoiceMaskSystem.cs
faint 076d2e339b Merge remote-tracking branch 'wizards/master' into upstream-sync
# Conflicts:
#	Content.Client/Administration/UI/AdminMenuWindow.xaml.cs
#	Content.Client/LateJoin/LateJoinGui.cs
#	Content.Client/Power/PowerMonitoringWindow.xaml.cs
#	Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs
#	Content.Server/VoiceMask/VoiceMaskSystem.cs
#	Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml
#	Resources/Prototypes/Entities/Objects/Misc/paper.yml
#	Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml
#	Resources/Prototypes/Roles/Jobs/Security/security_officer.yml
#	Resources/Prototypes/secret_weights.yml
#	Resources/Textures/Clothing/Back/Backpacks/security.rsi/equipped-BACKPACK.png
#	Resources/Textures/Clothing/Back/Backpacks/security.rsi/meta.json
#	Resources/Textures/Clothing/OuterClothing/Vests/kevlar.rsi/equipped-OUTERCLOTHING.png
#	Resources/Textures/Clothing/OuterClothing/Vests/kevlar.rsi/icon.png
#	Resources/Textures/Clothing/OuterClothing/Vests/kevlar.rsi/inhand-left.png
#	Resources/Textures/Clothing/OuterClothing/Vests/kevlar.rsi/inhand-right.png
#	RobustToolbox
2023-07-10 07:03:24 +03:00

95 lines
3.4 KiB
C#

using Content.Server.Administration.Logs;
using Content.Server.Chat.Systems;
using Content.Server.Popups;
using Content.Shared.Actions;
using Content.Shared.Database;
using Content.Shared.Inventory.Events;
using Content.Shared.Preferences;
using Content.Shared.VoiceMask;
using Robust.Server.GameObjects;
namespace Content.Server.VoiceMask;
public sealed partial class VoiceMaskSystem : EntitySystem
{
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = 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);
InitializeTTS(); // Corvax-TTS
}
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"), message.Session);
return;
}
component.VoiceName = message.Name;
if (message.Session.AttachedEntity != null)
_adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(message.Session.AttachedEntity.Value):player} set voice of {ToPrettyString(uid):mask}: {component.VoiceName}");
else
_adminLogger.Add(LogType.Action, LogImpact.Medium, $"Voice of {ToPrettyString(uid):mask} set: {component.VoiceName}");
_popupSystem.PopupCursor(Loc.GetString("voice-mask-popup-success"), 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;
if (!_uiSystem.TryGetUi(player, VoiceMaskUIKey.Key, out var bui))
return;
_uiSystem.OpenUi(bui, actor.PlayerSession);
UpdateUI(player);
}
private void UpdateUI(EntityUid owner, VoiceMaskComponent? component = null)
{
if (!Resolve(owner, ref component))
{
return;
}
if (_uiSystem.TryGetUi(owner, VoiceMaskUIKey.Key, out var bui))
UserInterfaceSystem.SetUiState(bui, new VoiceMaskBuiState(component.VoiceName, component.VoiceId)); // Corvax-TTS
}
}
public sealed class VoiceMaskSetNameEvent : InstantActionEvent
{
}