fix: теперь в лобби можно прослушать голос

This commit is contained in:
Remuchi
2024-04-20 12:38:13 +07:00
parent 31ad875b2f
commit 28b714a318
7 changed files with 51 additions and 59 deletions

View File

@@ -126,8 +126,8 @@
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'humanoid-profile-editor-species-label'}" />
<Control HorizontalExpand="True"/>
<TextureButton Name="SpeciesInfoButton" Scale="0.3 0.3" VerticalAlignment="Center"></TextureButton>
<OptionButton Name="CSpeciesButton" />
<TextureButton Name="SpeciesInfoButton" Scale="0.5 0.5" VerticalAlignment="Center"></TextureButton>
</BoxContainer>
</prefUi:HighlightedContainer>
<!-- Show clothing -->

View File

@@ -76,7 +76,7 @@ namespace Content.Client.Preferences.UI
private Button _nameRandomButton => CNameRandomize;
private Button _nameClownRandomButton => CClownNameRandomize;
private Button _nameMimeRandomButton => CMimeNameRandomize;
private Button _nameBorgRandomButton => CBorgNameRandomize;
private Button _nameBorgRandomButton => CBorgNameRandomize;
private Button _randomizeEverythingButton => CRandomizeEverything;
private RichTextLabel _warningLabel => CWarningLabel;
private Button _saveButton => CSaveButton;

View File

@@ -5,6 +5,8 @@ using Content.Shared.Preferences;
using Content.Shared._White.TTS;
using Robust.Shared.Random;
// ReSharper disable InconsistentNaming
namespace Content.Client.Preferences.UI;
public sealed partial class HumanoidProfileEditor
@@ -12,6 +14,7 @@ public sealed partial class HumanoidProfileEditor
private TTSManager _ttsMgr = default!;
private TTSSystem _ttsSys = default!;
private List<TTSVoicePrototype> _voiceList = default!;
private readonly List<string> _sampleText = new()
{
"Помогите, клоун насилует в технических тоннелях!",
@@ -35,7 +38,6 @@ public sealed partial class HumanoidProfileEditor
};
_voicePlayButton.OnPressed += _ => { PlayTTS(); };
}
private void UpdateTTSVoicesControls()
@@ -88,4 +90,4 @@ public sealed partial class HumanoidProfileEditor
_ttsSys.StopAllStreams();
_ttsMgr.RequestTTS(_previewDummy.Value, IoCManager.Resolve<IRobustRandom>().Pick(_sampleText), Profile.Voice);
}
}
}

View File

@@ -7,6 +7,7 @@ namespace Content.Client._White.TTS;
public sealed class TTSManager
{
[Dependency] private readonly IClientNetManager _netMgr = default!;
[Dependency] private readonly EntityManager _entityManager = default!;
public void Initialize()
{
@@ -16,7 +17,8 @@ public sealed class TTSManager
// ReSharper disable once InconsistentNaming
public void RequestTTS(EntityUid uid, string text, string voiceId)
{
var msg = new MsgRequestTTS() { Text = text, Uid = uid, VoiceId = voiceId };
var netEntity = _entityManager.GetNetEntity(uid);
var msg = new MsgRequestTTS() { Text = text, Uid = netEntity, VoiceId = voiceId };
_netMgr.ClientSendMessage(msg);
}
}
}

View File

@@ -5,6 +5,7 @@ using Content.Shared.Physics;
using Content.Shared._White;
using Content.Shared._White.TTS;
using Robust.Client.Audio;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Audio.Sources;
using Robust.Shared.Configuration;
@@ -25,16 +26,16 @@ public sealed class TTSSystem : EntitySystem
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly SharedPhysicsSystem _broadPhase = default!;
[Dependency] private readonly TransformSystem _transform = default!;
private ISawmill _sawmill = default!;
private float _volume = 0.0f;
private float _volume;
private const int TTSCollisionMask = (int)CollisionGroup.Impassable;
private readonly HashSet<AudioStream> _currentStreams = new();
private readonly Dictionary<EntityUid, Queue<AudioStream>> _entityQueues = new();
public override void Initialize()
{
_sawmill = Logger.GetSawmill("tts");
_cfg.OnValueChanged(WhiteCVars.TtsVolume, OnTtsVolumeChanged, true);
SubscribeNetworkEvent<PlayTTSEvent>(OnPlayTTS);
}
@@ -64,26 +65,27 @@ public sealed class TTSSystem : EntitySystem
continue;
}
var mapPos = xform.MapPosition;
var mapPos = _transform.GetMapCoordinates(xform);
if (mapPos.MapId != MapId.Nullspace)
{
stream.Source.Position = mapPos.Position;
}
if (mapPos.MapId == _eye.CurrentMap)
if (mapPos.MapId != _eye.CurrentMap)
{
var collisionMask = (int) CollisionGroup.Impassable;
var sourceRelative = ourPos - mapPos.Position;
var occlusion = 0f;
if (sourceRelative.Length() > 0)
{
occlusion = _broadPhase.IntersectRayPenetration(mapPos.MapId,
new CollisionRay(mapPos.Position, sourceRelative.Normalized(), collisionMask),
sourceRelative.Length(), stream.Uid);
}
stream.Source.Occlusion = occlusion;
continue;
}
var sourceRelative = ourPos - mapPos.Position;
var occlusion = 0f;
if (sourceRelative.Length() > 0)
{
occlusion = _broadPhase.IntersectRayPenetration(mapPos.MapId,
new CollisionRay(mapPos.Position, sourceRelative.Normalized(), TTSCollisionMask),
sourceRelative.Length(), stream.Uid);
}
stream.Source.Occlusion = occlusion;
}
foreach (var audioStream in streamToRemove)
@@ -178,7 +180,7 @@ public sealed class TTSSystem : EntitySystem
if (!_entity.TryGetComponent<TransformComponent>(stream.Uid, out var xform))
return;
stream.Source.Position = xform.WorldPosition;
stream.Source.Position = _transform.GetWorldPosition(xform);
stream.Source.StartPlaying();
_currentStreams.Add(stream);
}
@@ -204,16 +206,10 @@ public sealed class TTSSystem : EntitySystem
}
// ReSharper disable once InconsistentNaming
private sealed class AudioStream
private sealed class AudioStream(EntityUid uid, IAudioSource source)
{
public EntityUid Uid { get; }
public EntityUid Uid { get; } = uid;
public IAudioSource Source { get; }
public AudioStream(EntityUid uid, IAudioSource source)
{
Uid = uid;
Source = source;
}
public IAudioSource Source { get; } = source;
}
}
}