2023-02-11 13:26:44 -06:00
using Content.Server.Administration.Logs ;
2022-09-28 19:22:27 -07:00
using Content.Server.Chat.Systems ;
using Content.Server.Popups ;
using Content.Shared.Actions ;
2023-02-11 13:26:44 -06:00
using Content.Shared.Database ;
2022-09-28 19:22:27 -07:00
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 ! ;
2023-02-11 13:26:44 -06:00
[Dependency] private readonly IAdminLogManager _adminLogger = default ! ;
2022-09-28 19:22:27 -07:00
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 )
{
2022-12-19 10:41:47 +13:00
_popupSystem . PopupCursor ( Loc . GetString ( "voice-mask-popup-failure" ) , message . Session ) ;
2022-09-28 19:22:27 -07:00
return ;
}
component . VoiceName = message . Name ;
2023-02-11 13:26:44 -06:00
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}" ) ;
2022-09-28 19:22:27 -07:00
2022-12-19 10:41:47 +13:00
_popupSystem . PopupCursor ( Loc . GetString ( "voice-mask-popup-success" ) , message . Session ) ;
2022-09-28 19:22:27 -07:00
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 ;
2023-07-08 09:02:17 -07:00
if ( ! _uiSystem . TryGetUi ( player , VoiceMaskUIKey . Key , out var bui ) )
return ;
2022-09-28 19:22:27 -07:00
2023-07-08 09:02:17 -07:00
_uiSystem . OpenUi ( bui , actor . PlayerSession ) ;
2022-09-28 19:22:27 -07:00
UpdateUI ( player ) ;
}
private void UpdateUI ( EntityUid owner , VoiceMaskComponent ? component = null )
{
if ( ! Resolve ( owner , ref component ) )
{
return ;
}
2023-07-08 09:02:17 -07:00
if ( _uiSystem . TryGetUi ( owner , VoiceMaskUIKey . Key , out var bui ) )
UserInterfaceSystem . SetUiState ( bui , new VoiceMaskBuiState ( component . VoiceName ) ) ;
2022-09-28 19:22:27 -07:00
}
}
2023-08-22 18:14:33 -07:00
public sealed partial class VoiceMaskSetNameEvent : InstantActionEvent
2022-09-28 19:22:27 -07:00
{
}