mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-10 10:51:14 +03:00
# Conflicts: # Content.Server/GameTicking/Rules/NukeopsRuleSystem.cs # Resources/Prototypes/Catalog/VendingMachines/Inventories/detdrobe.yml # Resources/Prototypes/Entities/Clothing/Masks/specific.yml # Resources/Prototypes/Entities/Mobs/NPCs/slimes.yml # Resources/Prototypes/GameRules/midround.yml # Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml # Resources/Prototypes/Roles/Jobs/Security/warden.yml # Resources/Prototypes/StatusEffects/health.yml # Resources/Prototypes/StatusIcon/antag.yml # Resources/ServerInfo/Guidebook/Antagonist/Antagonists.xml # Resources/ServerInfo/Guidebook/Antagonist/SpaceNinja.xml # Resources/ServerInfo/Guidebook/Engineering/AME.xml # Resources/ServerInfo/Guidebook/Engineering/AccessConfigurator.xml # Resources/ServerInfo/Guidebook/Engineering/AirlockSecurity.xml # Resources/ServerInfo/Guidebook/Engineering/Atmospherics.xml # Resources/ServerInfo/Guidebook/Engineering/Construction.xml # Resources/ServerInfo/Guidebook/Engineering/Engineering.xml # Resources/ServerInfo/Guidebook/Engineering/Fires.xml # Resources/ServerInfo/Guidebook/Engineering/NetworkConfigurator.xml # Resources/ServerInfo/Guidebook/Engineering/Networking.xml # Resources/ServerInfo/Guidebook/Engineering/PortableGenerator.xml # Resources/ServerInfo/Guidebook/Engineering/Power.xml # Resources/ServerInfo/Guidebook/Engineering/Shuttlecraft.xml # Resources/ServerInfo/Guidebook/Engineering/Singularity.xml # Resources/ServerInfo/Guidebook/Engineering/TEG.xml # Resources/ServerInfo/Guidebook/Science/ArtifactReports.xml # Resources/ServerInfo/Guidebook/Science/TraversalDistorter.xml # Resources/ServerInfo/Guidebook/Science/Xenoarchaeology.xml # Resources/ServerInfo/Guidebook/Security/Forensics.xml # Resources/Textures/Objects/Specific/Hydroponics/chili.rsi/produce.png
119 lines
4.5 KiB
C#
119 lines
4.5 KiB
C#
using Content.Server.Administration.Logs;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.Popups;
|
|
using Content.Shared.Clothing;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Preferences;
|
|
using Content.Shared.Speech;
|
|
using Content.Shared.VoiceMask;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
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!;
|
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<VoiceMaskComponent, TransformSpeakerNameEvent>(OnSpeakerNameTransform);
|
|
SubscribeLocalEvent<VoiceMaskComponent, VoiceMaskChangeNameMessage>(OnChangeName);
|
|
SubscribeLocalEvent<VoiceMaskComponent, VoiceMaskChangeVerbMessage>(OnChangeVerb);
|
|
SubscribeLocalEvent<VoiceMaskComponent, WearerMaskToggledEvent>(OnMaskToggled);
|
|
SubscribeLocalEvent<VoiceMaskerComponent, ClothingGotEquippedEvent>(OnEquip);
|
|
SubscribeLocalEvent<VoiceMaskerComponent, ClothingGotUnequippedEvent>(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.PopupEntity(Loc.GetString("voice-mask-popup-failure"), uid, message.Session, PopupType.SmallCaution);
|
|
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.PopupEntity(Loc.GetString("voice-mask-popup-success"), uid, message.Session);
|
|
|
|
TrySetLastKnownName(uid, message.Name);
|
|
|
|
UpdateUI(uid, component);
|
|
}
|
|
|
|
private void OnChangeVerb(Entity<VoiceMaskComponent> ent, ref VoiceMaskChangeVerbMessage msg)
|
|
{
|
|
if (msg.Verb is {} id && !_proto.HasIndex<SpeechVerbPrototype>(id))
|
|
return;
|
|
|
|
ent.Comp.SpeechVerb = msg.Verb;
|
|
// verb is only important to metagamers so no need to log as opposed to name
|
|
|
|
_popupSystem.PopupEntity(Loc.GetString("voice-mask-popup-success"), ent, msg.Session);
|
|
|
|
TrySetLastSpeechVerb(ent, msg.Verb);
|
|
|
|
UpdateUI(ent, ent.Comp);
|
|
}
|
|
|
|
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;
|
|
if (component.SpeechVerb != null)
|
|
args.SpeechVerb = component.SpeechVerb;
|
|
}
|
|
}
|
|
|
|
private void OnMaskToggled(Entity<VoiceMaskComponent> ent, ref WearerMaskToggledEvent args)
|
|
{
|
|
ent.Comp.Enabled = !args.IsToggled;
|
|
}
|
|
|
|
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))
|
|
_uiSystem.SetUiState(bui, new VoiceMaskBuiState(component.VoiceName, component.VoiceId, component.SpeechVerb)); // Corvax-TTS
|
|
}
|
|
}
|