[add] Ahelp volume change

This commit is contained in:
rhailrake
2023-04-28 07:55:20 +06:00
committed by Aviu00
parent e458ec9fcd
commit a6f88c6608
6 changed files with 133 additions and 3 deletions

View File

@@ -0,0 +1,50 @@
using Content.Shared.CCVar;
using Content.Shared.White;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Range = Robust.Client.UserInterface.Controls.Range;
namespace Content.Client.Options.UI.Tabs;
[GenerateTypedNameReferences]
public sealed partial class AdminSettingsTab : Control
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
public AdminSettingsTab()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
LoadData();
AhelpSoundVolume.OnValueChanged += OnAhelpVolumeChanged;
}
protected override void Dispose(bool disposing)
{
AhelpSoundVolume.OnValueChanged -= OnAhelpVolumeChanged;
base.Dispose(disposing);
}
private void LoadData()
{
var bwoinkVolume = _cfg.GetCVar(WhiteCVars.BwoinkVolume);
AhelpSoundVolume.Value = bwoinkVolume;
AhelpSoundVolumeLabel.Text = ((int) bwoinkVolume).ToString();
}
private void OnAhelpVolumeChanged(Range newValue)
{
_cfg.SetCVar(WhiteCVars.BwoinkVolume, LV100ToDB(newValue.Value));
AhelpSoundVolumeLabel.Text = ((int)newValue.Value).ToString();
}
private float LV100ToDB(float lv100)
{
// Saving negative infinity doesn't work, so use -10000000 instead (MidiManager does it)
return MathF.Max(-10000000, MathF.Log(lv100 / 100, 10) * 10);
}
}