Files
OldThink/Content.Client/Options/UI/Tabs/AdminSettingsTab.xaml.cs

95 lines
2.9 KiB
C#

using Content.Shared._White;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
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);
Reset();
ApplyButton.OnPressed += OnApplyButtonPressed;
ResetButton.OnPressed += OnResetButtonPressed;
DeadChatAdminCheckbox.OnToggled += OnDeadChatAdminToggled;
AhelpSoundVolume.OnValueChanged += OnAhelpVolumeChanged;
}
protected override void Dispose(bool disposing)
{
ApplyButton.OnPressed -= OnApplyButtonPressed;
ResetButton.OnPressed -= OnResetButtonPressed;
DeadChatAdminCheckbox.OnToggled -= OnDeadChatAdminToggled;
AhelpSoundVolume.OnValueChanged -= OnAhelpVolumeChanged;
base.Dispose(disposing);
}
private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
{
_cfg.SetCVar(WhiteCVars.BwoinkVolume, LV100ToDB(AhelpSoundVolume.Value));
_cfg.SetCVar(WhiteCVars.DeadChatAdmin, DeadChatAdminCheckbox.Pressed);
_cfg.SaveToFile();
UpdateChanges();
}
private void OnResetButtonPressed(BaseButton.ButtonEventArgs args)
{
Reset();
}
private void Reset()
{
DeadChatAdminCheckbox.Pressed = _cfg.GetCVar(WhiteCVars.DeadChatAdmin);
AhelpSoundVolume.Value = DBToLV100(_cfg.GetCVar(WhiteCVars.BwoinkVolume));
UpdateChanges();
}
private void UpdateChanges()
{
var isAhelpSoundVolumeSame =
Math.Abs(AhelpSoundVolume.Value - DBToLV100(_cfg.GetCVar(WhiteCVars.BwoinkVolume))) < 0.01f;
var isDeadChatAdminSame = DeadChatAdminCheckbox.Pressed == _cfg.GetCVar(WhiteCVars.DeadChatAdmin);
var isEverythingSame = isAhelpSoundVolumeSame && isDeadChatAdminSame;
ApplyButton.Disabled = isEverythingSame;
ResetButton.Disabled = isEverythingSame;
AhelpSoundVolumeLabel.Text =
Loc.GetString("ui-options-volume-percent", ("volume", AhelpSoundVolume.Value / 100));
}
private void OnAhelpVolumeChanged(Range newValue)
{
UpdateChanges();
}
private void OnDeadChatAdminToggled(BaseButton.ButtonToggledEventArgs obj)
{
UpdateChanges();
}
private float DBToLV100(float db)
{
return MathF.Pow(10, db / 10) * 100;
}
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);
}
}