Skip to content

Commit

Permalink
Система... Готова?
Browse files Browse the repository at this point in the history
  • Loading branch information
FaDeOkno committed Aug 10, 2024
1 parent 0b346ee commit 374dc8d
Show file tree
Hide file tree
Showing 55 changed files with 4,849 additions and 13 deletions.
106 changes: 106 additions & 0 deletions Content.Client/ADT/Bark/Systems/HumanoidProfileEditor.Barks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System.Linq;
using Content.Client.ADT.SpeechBarks;
using Content.Client.Lobby;
using Content.Corvax.Interfaces.Shared;

Check failure on line 4 in Content.Client/ADT/Bark/Systems/HumanoidProfileEditor.Barks.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Corvax' does not exist in the namespace 'Content' (are you missing an assembly reference?)

Check failure on line 4 in Content.Client/ADT/Bark/Systems/HumanoidProfileEditor.Barks.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Corvax' does not exist in the namespace 'Content' (are you missing an assembly reference?)

Check failure on line 4 in Content.Client/ADT/Bark/Systems/HumanoidProfileEditor.Barks.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Corvax' does not exist in the namespace 'Content' (are you missing an assembly reference?)

Check failure on line 4 in Content.Client/ADT/Bark/Systems/HumanoidProfileEditor.Barks.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Corvax' does not exist in the namespace 'Content' (are you missing an assembly reference?)

Check failure on line 4 in Content.Client/ADT/Bark/Systems/HumanoidProfileEditor.Barks.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'Corvax' does not exist in the namespace 'Content' (are you missing an assembly reference?)

Check failure on line 4 in Content.Client/ADT/Bark/Systems/HumanoidProfileEditor.Barks.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'Corvax' does not exist in the namespace 'Content' (are you missing an assembly reference?)

Check failure on line 4 in Content.Client/ADT/Bark/Systems/HumanoidProfileEditor.Barks.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'Corvax' does not exist in the namespace 'Content' (are you missing an assembly reference?)

Check failure on line 4 in Content.Client/ADT/Bark/Systems/HumanoidProfileEditor.Barks.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'Corvax' does not exist in the namespace 'Content' (are you missing an assembly reference?)
using Content.Shared.Corvax.TTS;
using Content.Shared.Preferences;
using Content.Shared.ADT.SpeechBarks;

namespace Content.Client.Lobby.UI;

public sealed partial class HumanoidProfileEditor
{
private List<BarkPrototype> _barkList = new();

private void InitializeBarks()
{
_barkList = _prototypeManager
.EnumeratePrototypes<BarkPrototype>()
.Where(o => o.RoundStart)
.OrderBy(o => Loc.GetString(o.Name))
.ToList();

BarkProtoButton.OnItemSelected += args =>
{
BarkProtoButton.SelectId(args.Id);
SetBarkProto(_barkList[args.Id].ID);
};

PitchEdit.OnTextChanged += args =>
{
if (!float.TryParse(args.Text, out var newPitch))
return;

SetBarkPitch(newPitch);
};

DelayVariationMinEdit.OnTextChanged += args =>
{
if (!float.TryParse(args.Text, out var newVar))
return;

SetBarkMinVariation(newVar);
};

DelayVariationMaxEdit.OnTextChanged += args =>
{
if (!float.TryParse(args.Text, out var newVar))
return;

SetBarkMaxVariation(newVar);
};

BarkPlayButton.OnPressed += _ => PlayPreviewBark();

IoCManager.Instance!.TryResolveType(out _sponsorsMgr);
}

private void UpdateBarkVoicesControls()
{
if (Profile is null)
return;

BarkProtoButton.Clear();

PitchEdit.Text = Profile.BarkPitch.ToString();
DelayVariationMinEdit.Text = Profile.BarkLowVar.ToString();
DelayVariationMaxEdit.Text = Profile.BarkHighVar.ToString();

var firstVoiceChoiceId = 1;
for (var i = 0; i < _barkList.Count; i++)
{
var voice = _barkList[i];
//if (!HumanoidCharacterProfile.CanHaveVoice(voice, Profile.Sex))
// continue;

var name = Loc.GetString(voice.Name);
BarkProtoButton.AddItem(name, i);

if (firstVoiceChoiceId == 1)
firstVoiceChoiceId = i;

if (_sponsorsMgr is null)
continue;
if (voice.SponsorOnly && _sponsorsMgr != null &&
!_sponsorsMgr.GetClientPrototypes().Contains(voice.ID))
{
BarkProtoButton.SetItemDisabled(VoiceButton.GetIdx(i), true);
}
}

var voiceChoiceId = _barkList.FindIndex(x => x.ID == Profile.BarkProto);
if (!BarkProtoButton.TrySelectId(voiceChoiceId) &&
BarkProtoButton.TrySelectId(firstVoiceChoiceId))
{
SetBarkProto(_barkList[firstVoiceChoiceId].ID);
}
}

private void PlayPreviewBark()
{
if (Profile is null)
return;

_entManager.System<SpeechBarksSystem>().PlayDataPrewiew(Profile.BarkProto, Profile.BarkPitch, Profile.BarkLowVar, Profile.BarkHighVar);
}
}
142 changes: 142 additions & 0 deletions Content.Client/ADT/Bark/Systems/SpeechBarksSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Content.Shared.ADT.SpeechBarks;
using Content.Shared.Chat;
using Content.Shared.Corvax.CCCVars;
using Robust.Client.Audio;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
using System.Threading.Tasks;
using Robust.Client.ResourceManagement;
using Robust.Shared.Utility;
using Robust.Client.Player;
using Content.Shared.ADT.CCVar;

namespace Content.Client.ADT.SpeechBarks;

public sealed class SpeechBarksSystem : SharedSpeechBarksSystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly SharedChatSystem _chat = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IPlayerManager _player = default!;

public override void Initialize()
{
base.Initialize();

_cfg.OnValueChanged(CCCVars.TTSVolume, OnVolumeChanged, true);

SubscribeNetworkEvent<PlaySpeechBarksEvent>(OnEntitySpoke);
}

private readonly List<string> _sampleText =
new()
{
"Тест мессЭдж 1.",
"Тест мессЭдж 2!",
"Тест мессЭдж 3?",
"Здесь был котя."
};

private const float MinimalVolume = -10f;
private float _volume = 0.0f;
private const float WhisperFade = 4f;

private void OnVolumeChanged(float volume)
{
_volume = volume;
}

private float AdjustVolume(bool isWhisper)
{
var volume = MinimalVolume + SharedAudioSystem.GainToVolume(_volume);

if (isWhisper)
{
volume -= SharedAudioSystem.GainToVolume(WhisperFade);
}

return volume;
}

private float AdjustDistance(bool isWhisper)
{
return isWhisper ? SharedChatSystem.WhisperMuffledRange : SharedChatSystem.VoiceRange;
}

private async void OnEntitySpoke(PlaySpeechBarksEvent ev)
{
if (_cfg.GetCVar(ADTCCVars.ReplaceTTSWithBarks) == false)
return;

if (ev.Message == null)
return;

if (ev.Source != null)
{
var audioParams = AudioParams.Default
.WithMaxDistance(AdjustDistance(ev.IsWhisper))
.WithPitchScale(ev.Pitch)
.WithVolume(AdjustVolume(ev.IsWhisper));

if (ev.Message.EndsWith('!'))
audioParams = audioParams.WithRolloffFactor(1.4f);
//audioParams = audioParams.WithVolume(audioParams.Volume * 2.5f);

var count = Math.Clamp((int)ev.Message.Length / 3f, 1, 15);
var message = ev.Message;
var audioResource = new AudioResource();
string str = ev.Sound;

var path = new ResPath(str);
audioResource.Load(IoCManager.Instance!, path);

for (var i = 0; i < count; i++)
{
if (_player.LocalSession == null)
break;

_audio.PlayEntity(audioResource.AudioStream, GetEntity(ev.Source.Value), audioParams.WithPitchScale(_random.NextFloat(ev.Pitch - 0.1f, ev.Pitch + 0.1f)));

await Task.Delay(TimeSpan.FromSeconds(_random.NextFloat(ev.LowVar, ev.HighVar)));
}
}
}

public async void PlayDataPrewiew(string protoId, float pitch, float lowVar, float highVar)
{
if (!_proto.TryIndex<BarkPrototype>(protoId, out var proto))
return;

var message = _random.Pick(_sampleText);

var audioParams = AudioParams.Default
.WithVolume(AdjustVolume(false));

var count = (int)message.Length / 3f;
var audioResource = new AudioResource();
string str = proto.Sound;

if (message.EndsWith('!'))
audioParams = audioParams.WithRolloffFactor(1.4f);

var path = new ResPath(str);
audioResource.Load(IoCManager.Instance!, path);

for (var i = 0; i < count; i++)
{
if (_player.LocalSession == null)
break;

_audio.PlayGlobal(str, _player.LocalSession, audioParams.WithPitchScale(_random.NextFloat(pitch - 0.1f, pitch + 0.1f)));

await Task.Delay(TimeSpan.FromSeconds(_random.NextFloat(lowVar, highVar)));
}
}


}
4 changes: 4 additions & 0 deletions Content.Client/Corvax/TTS/TTSSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Robust.Shared.Utility;
using Content.Shared.ADT.Language; // ADT Languages
using Robust.Shared.Player;
using Content.Shared.ADT.CCVar;

namespace Content.Client.Corvax.TTS;

Expand Down Expand Up @@ -73,6 +74,9 @@ private void OnPlayTTS(PlayTTSEvent ev)

var filePath = new ResPath($"{_fileIdx++}.ogg");

if (_cfg.GetCVar(ADTCCVars.ReplaceTTSWithBarks) == true)
return;

// Languages TTS support start
var player = _playerManager.LocalSession?.AttachedEntity;
if (player != null)
Expand Down
20 changes: 20 additions & 0 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@
<Control HorizontalExpand="True"/>
<OptionButton Name="SpawnPriorityButton" HorizontalAlignment="Right" />
</BoxContainer>
<!-- ADT-Barks-Start -->
<BoxContainer HorizontalExpand="True" Visible="False" Name="BarksContainer">
<Label Text="{Loc 'humanoid-profile-editor-bark-label'}" />
<Control HorizontalExpand="True"/>
<OptionButton Name="BarkProtoButton" HorizontalAlignment="Right" />
<Button Name="BarkPlayButton" Text="{Loc 'humanoid-profile-editor-voice-play'}" MaxWidth="80" />
</BoxContainer>
<BoxContainer HorizontalExpand="True" Visible="False" Name="BarksPitchContainer">
<Label Text="{Loc 'humanoid-profile-editor-bark-pitch-label'}" />
<Control HorizontalExpand="True"/>
<LineEdit Name="PitchEdit" MinSize="40 0" HorizontalAlignment="Right" Margin="2 0 2 0" />
</BoxContainer>
<BoxContainer HorizontalExpand="True" Visible="False" Name="BarksDelayContainer">
<Label Text="{Loc 'humanoid-profile-editor-bark-delay-label'}" />
<Control HorizontalExpand="True"/>
<LineEdit Name="DelayVariationMinEdit" MinSize="40 0" HorizontalAlignment="Right" Margin="2 0 2 0" />
<LineEdit Name="DelayVariationMaxEdit" MinSize="40 0" HorizontalAlignment="Right" Margin="2 0 2 0" />
</BoxContainer>
<!-- ADT-Barks-End -->

<!-- Corvax-TTS-Start -->
<BoxContainer HorizontalExpand="True" Visible="False" Name="TTSContainer">
<Label Text="{Loc 'humanoid-profile-editor-voice-label'}" />
Expand Down
46 changes: 46 additions & 0 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Content.Client.Sprite;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Systems.Guidebook;
using Content.Shared.ADT.CCVar;
using Content.Shared.ADT.SpeechBarks;
using Content.Shared.CCVar;
using Content.Shared.Clothing;
using Content.Shared.Corvax.CCCVars;
Expand Down Expand Up @@ -223,6 +225,20 @@ public HumanoidProfileEditor(
#endregion
// Corvax-TTS-End

// ADT Barks Start
#region Voice

if (configurationManager.GetCVar(ADTCCVars.BarksEnabled))
{
BarksContainer.Visible = true;
BarksPitchContainer.Visible = true;
BarksDelayContainer.Visible = true;
InitializeBarks();
}

#endregion
// ADT Barks End

RefreshSpecies();

SpeciesButton.OnItemSelected += args =>
Expand Down Expand Up @@ -453,6 +469,7 @@ public HumanoidProfileEditor(
SpeciesInfoButton.OnPressed += OnSpeciesInfoButtonPressed;

UpdateSpeciesGuidebookIcon();
ReloadPreview();
IsDirty = false;
}

Expand Down Expand Up @@ -764,6 +781,7 @@ public void SetProfile(HumanoidCharacterProfile? profile, int? slot)
UpdateSaveButton();
UpdateMarkings();
UpdateTTSVoicesControls(); // Corvax-TTS
UpdateBarkVoicesControls(); // ADT Barks
UpdateHairPickers();
UpdateCMarkingsHair();
UpdateCMarkingsFacialHair();
Expand Down Expand Up @@ -1213,6 +1231,34 @@ private void SetVoice(string newVoice)
}
// Corvax-TTS-End

private void SetBarkProto(string prototype)
{
Profile = Profile?.WithBarkProto(prototype);
ReloadPreview();
SetDirty();
}

private void SetBarkPitch(float pitch)
{
Profile = Profile?.WithBarkPitch(Math.Clamp(pitch, _cfgManager.GetCVar(ADTCCVars.BarksMinPitch), _cfgManager.GetCVar(ADTCCVars.BarksMaxPitch)));
ReloadPreview();
SetDirty();
}

private void SetBarkMinVariation(float variation)
{
Profile = Profile?.WithBarkMinVariation(Math.Clamp(variation, _cfgManager.GetCVar(ADTCCVars.BarksMinDelay), Profile.BarkHighVar));
ReloadPreview();
SetDirty();
}

private void SetBarkMaxVariation(float variation)
{
Profile = Profile?.WithBarkMaxVariation(Math.Clamp(variation, Profile.BarkLowVar, _cfgManager.GetCVar(ADTCCVars.BarksMaxDelay)));
ReloadPreview();
SetDirty();
}

private void SetSpecies(string newSpecies)
{
Profile = Profile?.WithSpecies(newSpecies);
Expand Down
5 changes: 4 additions & 1 deletion Content.Client/Options/UI/Tabs/AudioTab.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Control xmlns="https://spacestation14.io"
<Control xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:Content.Client.Options.UI">
<BoxContainer Orientation="Vertical">
Expand All @@ -9,6 +9,9 @@
<ui:OptionSlider Name="SliderVolumeMaster" Title="{Loc 'ui-options-master-volume'}"
Margin="0 0 0 8" />
<!-- Corvax-TTS-Start --><ui:OptionSlider Name="SliderVolumeTts" Title="{Loc 'ui-options-tts-volume'}" /><!-- Corvax-TTS-End -->
<!-- Corvax-TTS-Start -->
<ui:OptionDropDown Name="DropDownBarksOrTTS" Title="{Loc 'ui-options-barks-or-tts'}" />
<!-- Corvax-TTS-End -->
<ui:OptionSlider Name="SliderVolumeMidi" Title="{Loc 'ui-options-midi-volume'}" />
<ui:OptionSlider Name="SliderVolumeAmbientMusic" Title="{Loc 'ui-options-ambient-music-volume'}" />
<ui:OptionSlider Name="SliderVolumeAmbience" Title="{Loc 'ui-options-ambience-volume'}" />
Expand Down
Loading

0 comments on commit 374dc8d

Please sign in to comment.