Skip to content

Commit

Permalink
Возможность отключения музыки с бумбоксов. Понижение максимальной гро…
Browse files Browse the repository at this point in the history
…мкости. (#136)

* Ползунок громкости для магнитофонов (булка наныл)

* Фикс обрезания названия в интерфейсе

* Отключение школьников с бумбоксами

* Понижение макс громкости и радиуса слышимости
  • Loading branch information
VigersRay authored Jun 21, 2024
1 parent bb47363 commit a4cbdda
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 12 deletions.
1 change: 1 addition & 0 deletions Content.Client/Options/UI/Tabs/AudioTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<CheckBox Name="EventMusicCheckBox" Text="{Loc 'ui-options-event-music'}" />
<CheckBox Name="AdminSoundsCheckBox" Text="{Loc 'ui-options-admin-sounds'}" />
<CheckBox Name="TtsClientCheckBox" Text="{Loc 'ui-options-tts-enabled'}" />
<CheckBox Name="TapePlayerClientCheckBox" Text="{Loc 'ui-options-tape-player-enabled'}" />
</BoxContainer>
</BoxContainer>
<controls:StripeBack HasBottomEdge="False" HasMargins="False">
Expand Down
12 changes: 11 additions & 1 deletion Content.Client/Options/UI/Tabs/AudioTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public AudioTab()
EventMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.EventMusicEnabled);
AdminSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.AdminSoundsEnabled);
TtsClientCheckBox.Pressed = _cfg.GetCVar(SunriseCCVars.TTSClientEnabled);
TapePlayerClientCheckBox.Pressed = _cfg.GetCVar(SunriseCCVars.TapePlayerClientEnabled);

ApplyButton.OnPressed += OnApplyButtonPressed;
ResetButton.OnPressed += OnResetButtonPressed;
Expand All @@ -47,6 +48,7 @@ public AudioTab()
EventMusicCheckBox.OnToggled += OnEventMusicCheckToggled;
AdminSoundsCheckBox.OnToggled += OnAdminSoundsCheckToggled;
TtsClientCheckBox.OnToggled += OnTtsClientCheckToggled;
TapePlayerClientCheckBox.OnToggled += OnTapePlayerClientCheckToggled;

AmbienceSoundsSlider.MinValue = _cfg.GetCVar(CCVars.MinMaxAmbientSourcesConfigured);
AmbienceSoundsSlider.MaxValue = _cfg.GetCVar(CCVars.MaxMaxAmbientSourcesConfigured);
Expand Down Expand Up @@ -146,6 +148,11 @@ private void OnTtsClientCheckToggled(BaseButton.ButtonEventArgs args)
UpdateChanges();
}

private void OnTapePlayerClientCheckToggled(BaseButton.ButtonEventArgs args)
{
UpdateChanges();
}

private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
{
_cfg.SetCVar(CVars.AudioMasterVolume, MasterVolumeSlider.Value / 100f * ContentAudioSystem.MasterVolumeMultiplier);
Expand All @@ -167,6 +174,7 @@ private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
_cfg.SetCVar(CCVars.EventMusicEnabled, EventMusicCheckBox.Pressed);
_cfg.SetCVar(CCVars.AdminSoundsEnabled, AdminSoundsCheckBox.Pressed);
_cfg.SetCVar(SunriseCCVars.TTSClientEnabled, TtsClientCheckBox.Pressed);
_cfg.SetCVar(SunriseCCVars.TapePlayerClientEnabled, TapePlayerClientCheckBox.Pressed);
_cfg.SaveToFile();
UpdateChanges();
}
Expand Down Expand Up @@ -195,6 +203,7 @@ private void Reset()
EventMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.EventMusicEnabled);
AdminSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.AdminSoundsEnabled);
TtsClientCheckBox.Pressed = _cfg.GetCVar(SunriseCCVars.TTSClientEnabled);
TapePlayerClientCheckBox.Pressed = _cfg.GetCVar(SunriseCCVars.TapePlayerClientEnabled);
UpdateChanges();
}

Expand Down Expand Up @@ -226,8 +235,9 @@ private void UpdateChanges()
var isEventSame = EventMusicCheckBox.Pressed == _cfg.GetCVar(CCVars.EventMusicEnabled);
var isAdminSoundsSame = AdminSoundsCheckBox.Pressed == _cfg.GetCVar(CCVars.AdminSoundsEnabled);
var isTtsClientSame = TtsClientCheckBox.Pressed == _cfg.GetCVar(SunriseCCVars.TTSClientEnabled);
var isTapePlayerClientSame = TapePlayerClientCheckBox.Pressed == _cfg.GetCVar(SunriseCCVars.TapePlayerClientEnabled);
var isEverythingSame = isMasterVolumeSame && isMidiVolumeSame && isAmbientVolumeSame && isAmbientMusicVolumeSame && isAmbientSoundsSame && isLobbySame && isRestartSoundsSame && isEventSame
&& isAdminSoundsSame && isLobbyVolumeSame && isInterfaceVolumeSame && isTtsClientSame;
&& isAdminSoundsSame && isLobbyVolumeSame && isInterfaceVolumeSame && isTtsClientSame && isTapePlayerClientSame;
isEverythingSame = isEverythingSame && isTtsRadioVolumeSame && isTtsVolumeSame && isTtsAnnounceVolumeSame; // Sunrise-TTS
ApplyButton.Disabled = isEverythingSame;
ResetButton.Disabled = isEverythingSame;
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/_Sunrise/TapePlayer/TapePlayerMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<BoxContainer Orientation="Vertical">
<Label Name="InsertedTape" Text="{Loc 'tape-player-menu-inserted-tape'}" />
<BoxContainer Orientation="Horizontal">
<Label Name="SongName" Text="---" MaxWidth="200" ClipText="True"/>
<Label Name="SongName" Text="---" MaxWidth="280" RectClipContent="True"/>
<Label Name="DurationLabel" Text="00:00 / 00:00" HorizontalAlignment="Right" HorizontalExpand="True"/>
</BoxContainer>
<Slider Name="PlaybackSlider" HorizontalExpand="True" />
Expand Down
15 changes: 15 additions & 0 deletions Content.Client/_Sunrise/TapePlayer/TapePlayerSystem.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
using Content.Shared._Sunrise.SunriseCCVars;
using Content.Shared._Sunrise.TapePlayer;
using Robust.Client.GameObjects;
using Robust.Shared.Configuration;

namespace Content.Client._Sunrise.TapePlayer
{
public sealed class TapePlayerSystem : SharedTapePlayerSystem
{
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<TapePlayerComponent, AppearanceChangeEvent>(OnAppearanceChange);
SubscribeLocalEvent<TapePlayerComponent, AnimationCompletedEvent>(OnAnimationCompleted);
SubscribeLocalEvent<TapePlayerComponent, AfterAutoHandleStateEvent>(OnTapePlayerAfterState);
_cfg.OnValueChanged(SunriseCCVars.TapePlayerClientEnabled, OnTapePlayerClientOptionChanged, true);
}

public override void Shutdown()
{
base.Shutdown();
_cfg.UnsubValueChanged(SunriseCCVars.TapePlayerClientEnabled, OnTapePlayerClientOptionChanged);
}

private void OnTapePlayerClientOptionChanged(bool option)
{
RaiseNetworkEvent(new ClientOptionTapePlayerEvent(option));
}

private void OnTapePlayerAfterState(Entity<TapePlayerComponent> ent, ref AfterAutoHandleStateEvent args)
Expand Down
28 changes: 24 additions & 4 deletions Content.Server/_Sunrise/TapePlayer/TapePlayerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public sealed class TapePlayerSystem : SharedTapePlayerSystem
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
[Dependency] private readonly AppearanceSystem _appearanceSystem = default!;

private readonly List<ICommonSession> _ignoredRecipients = [];

public override void Initialize()
{
base.Initialize();
Expand All @@ -31,8 +33,16 @@ public override void Initialize()
SubscribeLocalEvent<TapePlayerComponent, TapePlayerSetTimeMessage>(OnTapePlayerSetTime);
SubscribeLocalEvent<TapePlayerComponent, TapePlayerSetVolumeMessage>(OnTapePlayerSetVolume);


SubscribeLocalEvent<TapePlayerComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeNetworkEvent<ClientOptionTapePlayerEvent>(OnClientOptionTapePlayer);
}

private async void OnClientOptionTapePlayer(ClientOptionTapePlayerEvent ev, EntitySessionEventArgs args)
{
if (ev.Enabled)
_ignoredRecipients.Remove(args.SenderSession);
else
_ignoredRecipients.Add(args.SenderSession);
}

private void OnItemInserted(EntityUid uid, TapePlayerComponent component, EntInsertedIntoContainerMessage args)
Expand Down Expand Up @@ -74,12 +84,21 @@ private void OnTapePlayerPlay(EntityUid uid, TapePlayerComponent component, ref
return;
}

var volume = SharedAudioSystem.GainToVolume(component.Volume) - component.DecreaseVolume;

var audioParams = AudioParams.Default
.WithVolume(SharedAudioSystem.GainToVolume(component.Volume))
.WithVolume(volume)
.WithMaxDistance(component.MaxDistance)
.WithRolloffFactor(component.RolloffFactor)
.WithLoop(component.Loop);
component.AudioStream = Audio.PlayPvs(musicTapeComponent.Sound, uid, audioParams)?.Entity;
var filter = Filter.Pvs(uid).RemovePlayers(_ignoredRecipients);
var audio = Audio.PlayEntity(
musicTapeComponent.Sound,
filter,
uid,
false,
audioParams);
component.AudioStream = audio.Value.Entity;
Dirty(uid, component);
}
}
Expand All @@ -102,7 +121,8 @@ private void OnTapePlayerSetTime(EntityUid uid, TapePlayerComponent component, T
private void OnTapePlayerSetVolume(EntityUid uid, TapePlayerComponent component, TapePlayerSetVolumeMessage args)
{
component.Volume = args.Volume;
Audio.SetVolume(component.AudioStream, SharedAudioSystem.GainToVolume(args.Volume));
var volume = SharedAudioSystem.GainToVolume(component.Volume) - component.DecreaseVolume;
Audio.SetVolume(component.AudioStream, volume);
Dirty(uid, component);
}

Expand Down
10 changes: 10 additions & 0 deletions Content.Shared/_Sunrise/SunriseCCVars/SunriseCCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,14 @@ public sealed class SunriseCCVars
/// </summary>
public static readonly CVarDef<int> ArrivalsMinHours =
CVarDef.Create("transithub.arrivals_min_hours", 10, CVar.SERVER | CVar.ARCHIVE);

/**
* Tape Player
*/

/// <summary>
/// Параметр отключения школьников с колонками у клиента.
/// </summary>
public static readonly CVarDef<bool> TapePlayerClientEnabled =
CVarDef.Create("tape_player.client_enabled", true, CVar.CLIENTONLY | CVar.ARCHIVE);
}
13 changes: 13 additions & 0 deletions Content.Shared/_Sunrise/TapePlayer/ClientOptionTapePlayerEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Robust.Shared.Serialization;

namespace Content.Shared._Sunrise.TapePlayer;

[Serializable, NetSerializable]
public sealed class ClientOptionTapePlayerEvent : EntityEventArgs
{
public bool Enabled { get; }
public ClientOptionTapePlayerEvent(bool enabled)
{
Enabled = enabled;
}
}
4 changes: 4 additions & 0 deletions Content.Shared/_Sunrise/TapePlayer/TapePlayerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public sealed partial class TapePlayerComponent : Component
[ViewVariables]
public float Volume = 0.5f;

[DataField]
[ViewVariables]
public float DecreaseVolume = 0f;

[DataField]
[ViewVariables(VVAccess.ReadWrite)]
public float RolloffFactor = 1f;
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/escape-menu/ui/options-menu.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ui-options-restart-sounds = Звуки перезапуска раунда
ui-options-event-music = Музыка событий
ui-options-admin-sounds = Музыка админов
ui-options-tts-enabled = Включить TTS
ui-options-tape-player-enabled = Школьники с колонками
ui-options-volume-label = Громкость
ui-options-volume-percent = { TOSTRING($volume, "P0") }
Expand Down
5 changes: 3 additions & 2 deletions Resources/Prototypes/Entities/Structures/Machines/jukebox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
anchored: true
# Sunrise-Start
- type: TapePlayer
rolloffFactor: 1
maxDistance: 20
rolloffFactor: 1.5
maxDistance: 15
decreaseVolume: 5
tapeSlot:
insertSound: /Audio/_Sunrise/TapePlayer/insert_tape.ogg
ejectSound: /Audio/_Sunrise/TapePlayer/eject_tape.ogg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
- state: "off"
map: ["enum.TapePlayerVisualLayers.Base"]
- type: TapePlayer
rolloffFactor: 1.2
maxDistance: 15
rolloffFactor: 2
maxDistance: 10
decreaseVolume: 5
- type: MeleeWeapon
attackRate: 0.75
damage:
Expand All @@ -40,6 +41,7 @@
- type: TapePlayer
rolloffFactor: 1
maxDistance: 20
decreaseVolume: 0
- type: MeleeWeapon
attackRate: 0.75
damage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
- state: "off"
map: ["enum.TapePlayerVisualLayers.Base"]
- type: TapePlayer
rolloffFactor: 1.2
maxDistance: 10
rolloffFactor: 3
maxDistance: 5
decreaseVolume: 10
tapeSlot:
insertSound: /Audio/_Sunrise/TapePlayer/insert_tape.ogg
ejectSound: /Audio/_Sunrise/TapePlayer/eject_tape.ogg
Expand Down

0 comments on commit a4cbdda

Please sign in to comment.