Фичи для педалей (#202)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Content.Shared.CCVar;
|
||||
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;
|
||||
@@ -18,28 +18,72 @@ public sealed partial class AdminSettingsTab : Control
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
LoadData();
|
||||
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 LoadData()
|
||||
private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
var bwoinkVolume = _cfg.GetCVar(WhiteCVars.BwoinkVolume);
|
||||
AhelpSoundVolume.Value = bwoinkVolume;
|
||||
AhelpSoundVolumeLabel.Text = ((int) bwoinkVolume).ToString();
|
||||
_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)
|
||||
{
|
||||
_cfg.SetCVar(WhiteCVars.BwoinkVolume, LV100ToDB(newValue.Value));
|
||||
AhelpSoundVolumeLabel.Text = ((int)newValue.Value).ToString();
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user