Фичи для педалей (#202)
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
x:Class="Content.Client.Options.UI.Tabs.AdminSettingsTab">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<BoxContainer Orientation="Vertical" Margin="5 0 0 0" VerticalExpand="True">
|
||||
<BoxContainer Orientation="Horizontal" Margin="4 10 4 0">
|
||||
<CheckBox Name="DeadChatAdminCheckbox" Text="Отображать сообщения в гост чате как админские" />
|
||||
</BoxContainer>
|
||||
<BoxContainer Orientation="Horizontal" Margin="0 3 0 0">
|
||||
<Label Text="Громкость звука ахелпа" HorizontalExpand="True"/>
|
||||
<Control MinSize="8 0" />
|
||||
@@ -28,10 +31,6 @@
|
||||
StyleClasses="Caution"
|
||||
HorizontalExpand="True"
|
||||
HorizontalAlignment="Right" />
|
||||
<Button Name="DefaultButton"
|
||||
Text="{Loc 'ui-options-default'}"
|
||||
TextAlign="Center"
|
||||
HorizontalAlignment="Right" />
|
||||
<Control MinSize="2 0" />
|
||||
<Button Name="ApplyButton"
|
||||
Text="{Loc 'ui-options-apply'}"
|
||||
|
||||
@@ -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