Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radio agora vai ter um som de alerta configuravel #30

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Content.Client/Audio/ContentAudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public sealed partial class ContentAudioSystem : SharedContentAudioSystem
public const float LobbyMultiplier = 3f;
public const float InterfaceMultiplier = 2f;
public const float AnnouncerMultiplier = 3f;
public const float RadioMultiplier = 3f;

public override void Initialize()
{
Expand Down
21 changes: 20 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:s="clr-namespace:Content.Client.Stylesheets"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls">
Expand Down Expand Up @@ -87,6 +87,19 @@
<Label Name="InterfaceVolumeLabel" MinSize="48 0" Align="Right" />
<Control MinSize="4 0"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal" Margin="5 0 0 0">
<Label Text="Radio Volume" HorizontalExpand="True" />
<Control MinSize="8 0" />
<Slider Name="RadioVolumeSlider"
MinValue="0"
MaxValue="100"
HorizontalExpand="True"
MinSize="80 0"
Rounded="True" />
<Control MinSize="8 0" />
<Label Name="RadioVolumeLabel" MinSize="48 0" Align="Right" />
<Control MinSize="4 0"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal" Margin="5 0 0 0">
<Label Text="{Loc 'ui-options-ambience-max-sounds'}" HorizontalExpand="True" />
<Control MinSize="8 0" />
Expand Down Expand Up @@ -121,6 +134,12 @@
Text="{Loc 'ui-options-announcer-disable-multiple-sounds'}"
ToolTip="{Loc 'ui-options-announcer-disable-multiple-sounds-tooltip'}" />
<CheckBox Name="AdminSoundsCheckBox" Text="{Loc 'ui-options-admin-sounds'}" />
<CheckBox Name="RadioChatterCheckbox" Text="Radio Chatter" />
<BoxContainer Orientation="Horizontal">
<Label Text="Radio Spam" />
<Control MinSize="4 0" />
<OptionButton Name="RadioCooldown" MinSize="100 0" />
</BoxContainer>
</BoxContainer>
</BoxContainer>
<controls:StripeBack HasBottomEdge="False" HasMargins="False">
Expand Down
77 changes: 73 additions & 4 deletions Content.Client/Options/UI/Tabs/AudioTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public AudioTab()
RestartSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.RestartSoundsEnabled);
EventMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.EventMusicEnabled);
AdminSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.AdminSoundsEnabled);
RadioChatterCheckbox.Pressed = _cfg.GetCVar(CCVars.RadioSoundsEnabled);

RadioCooldown.AddItem(Loc.GetString("ui-options-lighting-very-low"));
RadioCooldown.AddItem(Loc.GetString("ui-options-lighting-low"));
RadioCooldown.AddItem(Loc.GetString("ui-options-lighting-medium"));
RadioCooldown.AddItem(Loc.GetString("ui-options-lighting-high"));
RadioCooldown.OnItemSelected += OnRadioSpanChanged;

ApplyButton.OnPressed += OnApplyButtonPressed;
ResetButton.OnPressed += OnResetButtonPressed;
Expand All @@ -40,12 +47,14 @@ public AudioTab()
LobbyVolumeSlider,
InterfaceVolumeSlider,
AnnouncerVolumeSlider,
RadioVolumeSlider,

LobbyMusicCheckBox,
RestartSoundsCheckBox,
EventMusicCheckBox,
AnnouncerDisableMultipleSoundsCheckBox,
AdminSoundsCheckBox
AdminSoundsCheckBox,
RadioChatterCheckbox
);

AmbienceSoundsSlider.MinValue = _cfg.GetCVar(CCVars.MinMaxAmbientSourcesConfigured);
Expand Down Expand Up @@ -85,12 +94,14 @@ protected override void Dispose(bool disposing)
LobbyVolumeSlider,
InterfaceVolumeSlider,
AnnouncerVolumeSlider,
RadioVolumeSlider,

LobbyMusicCheckBox,
RestartSoundsCheckBox,
EventMusicCheckBox,
AnnouncerDisableMultipleSoundsCheckBox,
AdminSoundsCheckBox
AdminSoundsCheckBox,
RadioChatterCheckbox
);

base.Dispose(disposing);
Expand Down Expand Up @@ -125,6 +136,7 @@ private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
_cfg.SetCVar(CCVars.LobbyMusicVolume, LobbyVolumeSlider.Value / 100f * ContentAudioSystem.LobbyMultiplier);
_cfg.SetCVar(CCVars.InterfaceVolume, InterfaceVolumeSlider.Value / 100f * ContentAudioSystem.InterfaceMultiplier);
_cfg.SetCVar(CCVars.AnnouncerVolume, AnnouncerVolumeSlider.Value / 100f * ContentAudioSystem.AnnouncerMultiplier);
_cfg.SetCVar(CCVars.RadioVolume, RadioVolumeSlider.Value / 100f * ContentAudioSystem.RadioMultiplier);

_cfg.SetCVar(CCVars.MaxAmbientSources, (int)AmbienceSoundsSlider.Value);

Expand All @@ -133,6 +145,10 @@ private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
_cfg.SetCVar(CCVars.EventMusicEnabled, EventMusicCheckBox.Pressed);
_cfg.SetCVar(CCVars.AnnouncerDisableMultipleSounds, AnnouncerDisableMultipleSoundsCheckBox.Pressed);
_cfg.SetCVar(CCVars.AdminSoundsEnabled, AdminSoundsCheckBox.Pressed);
_cfg.SetCVar(CCVars.RadioSoundsEnabled, RadioChatterCheckbox.Pressed);
_cfg.SetCVar(CCVars.RadioSoundsEnabled, RadioChatterCheckbox.Pressed);
var value = RadioCooldown.SelectedId;
SetConfigRadioSpam(value);
_cfg.SaveToFile();
UpdateChanges();
}
Expand All @@ -151,8 +167,8 @@ private void Reset()
LobbyVolumeSlider.Value = _cfg.GetCVar(CCVars.LobbyMusicVolume) * 100f / ContentAudioSystem.LobbyMultiplier;
InterfaceVolumeSlider.Value = _cfg.GetCVar(CCVars.InterfaceVolume) * 100f / ContentAudioSystem.InterfaceMultiplier;
AnnouncerVolumeSlider.Value = _cfg.GetCVar(CCVars.AnnouncerVolume) * 100f / ContentAudioSystem.AnnouncerMultiplier;

AmbienceSoundsSlider.Value = _cfg.GetCVar(CCVars.MaxAmbientSources);
RadioVolumeSlider.Value = _cfg.GetCVar(CCVars.RadioVolume) * 100f / ContentAudioSystem.RadioMultiplier;

LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
RestartSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.RestartSoundsEnabled);
Expand All @@ -179,17 +195,22 @@ private void UpdateChanges()
Math.Abs(InterfaceVolumeSlider.Value - _cfg.GetCVar(CCVars.InterfaceVolume) * 100f / ContentAudioSystem.InterfaceMultiplier) < 0.01f;
var isAnnouncerVolumeSame =
Math.Abs(AnnouncerVolumeSlider.Value - _cfg.GetCVar(CCVars.AnnouncerVolume) * 100f / ContentAudioSystem.AnnouncerMultiplier) < 0.01f;
var isRadioVolumeSame =
Math.Abs(RadioVolumeSlider.Value - _cfg.GetCVar(CCVars.RadioVolume) * 100f / ContentAudioSystem.RadioMultiplier) < 0.01f;

var isAmbientSoundsSame = (int)AmbienceSoundsSlider.Value == _cfg.GetCVar(CCVars.MaxAmbientSources);
var isLobbySame = LobbyMusicCheckBox.Pressed == _cfg.GetCVar(CCVars.LobbyMusicEnabled);
var isRestartSoundsSame = RestartSoundsCheckBox.Pressed == _cfg.GetCVar(CCVars.RestartSoundsEnabled);
var isEventSame = EventMusicCheckBox.Pressed == _cfg.GetCVar(CCVars.EventMusicEnabled);
var isAnnouncerDisableMultipleSoundsSame = AnnouncerDisableMultipleSoundsCheckBox.Pressed == _cfg.GetCVar(CCVars.AnnouncerDisableMultipleSounds);
var isAdminSoundsSame = AdminSoundsCheckBox.Pressed == _cfg.GetCVar(CCVars.AdminSoundsEnabled);
var isRadioSoundsSame = RadioChatterCheckbox.Pressed == _cfg.GetCVar(CCVars.RadioSoundsEnabled);
var isRadioSpamSame = RadioCooldown.SelectedId == GetConfigRadioSpam();
var isEverythingSame = isMasterVolumeSame && isMidiVolumeSame && isAmbientVolumeSame
&& isAmbientMusicVolumeSame && isAmbientSoundsSame && isLobbySame && isRestartSoundsSame && isEventSame
&& isAnnouncerDisableMultipleSoundsSame && isAdminSoundsSame && isLobbyVolumeSame
&& isInterfaceVolumeSame && isAnnouncerVolumeSame;
&& isInterfaceVolumeSame && isAnnouncerVolumeSame
&& isRadioVolumeSame && isRadioSoundsSame && isRadioSpamSame;
ApplyButton.Disabled = isEverythingSame;
ResetButton.Disabled = isEverythingSame;
MasterVolumeLabel.Text =
Expand All @@ -207,6 +228,54 @@ private void UpdateChanges()
AnnouncerVolumeLabel.Text =
Loc.GetString("ui-options-volume-percent", ("volume", AnnouncerVolumeSlider.Value / 100));
AmbienceSoundsLabel.Text = ((int)AmbienceSoundsSlider.Value).ToString();
RadioVolumeLabel.Text =
Loc.GetString("ui-options-volume-percent", ("volume", RadioVolumeSlider.Value / 100));


}
private void OnRadioSpanChanged(OptionButton.ItemSelectedEventArgs args)
{
RadioCooldown.SelectId(args.Id);
UpdateChanges();
}
private int GetConfigRadioSpam()
{
var val = _cfg.GetCVar(CCVars.RadioCooldown);
if (val == 10f)
return 0;

if (val >= 5f)
return 1;

if (val >= 2f)
return 2;

if (val >= 0f)
return 3;

return 2;
}
public void SetConfigRadioSpam(int value)
{
switch (value)
{
case 0:
_cfg.SetCVar(CCVars.RadioCooldown, 10f);
break;
case 1:
_cfg.SetCVar(CCVars.RadioCooldown, 5f);
break;
case 2:
_cfg.SetCVar(CCVars.RadioCooldown, 2f);
break;
case 3:
_cfg.SetCVar(CCVars.RadioCooldown, 0f);
break;
default: // = QualityMedium
_cfg.SetCVar(CCVars.RadioCooldown, 2f);
break;
}
}
}

}
33 changes: 33 additions & 0 deletions Content.Client/UserInterface/Systems/Chat/ChatUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
using Robust.Shared.Replays;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Robust.Shared.Player;
using Robust.Client.Audio;
using Robust.Shared.Audio;

namespace Content.Client.UserInterface.Systems.Chat;

Expand Down Expand Up @@ -72,6 +75,7 @@ public sealed class ChatUIController : UIController
private const string ChatNamePalette = "ChatNames";
private string[] _chatNameColors = default!;
private bool _chatNameColorsEnabled;
private TimeSpan _lastRadioPlayTime = TimeSpan.Zero;

private ISawmill _sawmill = default!;

Expand Down Expand Up @@ -598,6 +602,7 @@ public void ClearUnfilteredUnreads(ChatChannel channels)
}
}


public override void FrameUpdate(FrameEventArgs delta)
{
UpdateQueuedSpeechBubbles(delta);
Expand Down Expand Up @@ -868,6 +873,10 @@ public void ProcessChatMessage(ChatMessage msg, bool speechBubble = true)
UnreadMessageCountsUpdated?.Invoke(msg.Channel, count);
}
}
if (msg.Channel == ChatChannel.Radio && msg.SenderEntity == default && _ghost is not { IsGhost: true })
{
PlayChatSound();
}

// Local messages that have an entity attached get a speech bubble.
if (!speechBubble || msg.SenderEntity == default)
Expand Down Expand Up @@ -939,6 +948,30 @@ public void Repopulate()
}
}

public void PlayChatSound()
{
var radioChatterEnabled = _config.GetCVar(CCVars.RadioSoundsEnabled);
if (radioChatterEnabled)
{
// Check if enough time has passed since the last sound played
if (_timing.CurTime < _lastRadioPlayTime)
return;
var sound = _config.GetCVar(CCVars.RadioSoundPath);
var audioParams = new AudioParams
{
//Volume não faz o impacto desejado
Volume = _config.GetCVar(CCVars.RadioVolume) - 5f,
Variation = 0.125f
};
if (IoCManager.Resolve<IEntityManager>().TrySystem<AudioSystem>(out var audio))
{
audio.PlayGlobal(sound, Filter.Local(), false, audioParams);
var radioCooldown = _config.GetCVar(CCVars.RadioCooldown);
_lastRadioPlayTime = _timing.CurTime + TimeSpan.FromSeconds(radioCooldown);
}
}
}

/// <summary>
/// Returns the chat name color for a mob
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions Content.Shared/CCVar/CCVars.Radio.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Robust.Shared.Configuration;
namespace Content.Shared.CCVar;
public sealed partial class CCVars
{
/*
* Radio sounds
*/
public static readonly CVarDef<bool> RadioSoundsEnabled =
CVarDef.Create("audio.radio_sounds_enabled", true, CVar.ARCHIVE | CVar.CLIENT | CVar.REPLICATED);
public static readonly CVarDef<string> RadioSoundPath =
CVarDef.Create("audio.radio_sound_path", "/Audio/_Andromeda/Effects/Radio/sound_items_radio_radio_receive.ogg", CVar.ARCHIVE | CVar.CLIENT | CVar.REPLICATED);
public static readonly CVarDef<float> RadioVolume =
CVarDef.Create("audio.radio_volume", -5f, CVar.ARCHIVE | CVar.CLIENT | CVar.REPLICATED);
public static readonly CVarDef<float> RadioCooldown =
CVarDef.Create("audio.radio_cooldown", 2f, CVar.ARCHIVE | CVar.CLIENT | CVar.REPLICATED);
}
Binary file not shown.
Loading