Rewrite the options menu (#28389)
* Basic attempt at rewriting how the options menu works, move accessibility settings into their own tab. * Audio tab uses the new options system. * Rewrite Misc tab * Clean up heading styling * Rewrite options tab and other minor cleanup all over the place. * Documentation comments and minor cleanup. --------- Co-authored-by: AJCM <AJCM@tutanota.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
committed by
GitHub
parent
e0a6604d06
commit
07fe1a6b5a
@@ -7,220 +7,141 @@ using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Configuration;
|
||||
|
||||
namespace Content.Client.Options.UI.Tabs
|
||||
namespace Content.Client.Options.UI.Tabs;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class GraphicsTab : Control
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class GraphicsTab : Control
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
|
||||
public GraphicsTab()
|
||||
{
|
||||
private static readonly float[] UIScaleOptions =
|
||||
IoCManager.InjectDependencies(this);
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
Control.AddOptionCheckBox(CVars.DisplayVSync, VSyncCheckBox);
|
||||
Control.AddOption(new OptionFullscreen(Control, _cfg, FullscreenCheckBox));
|
||||
Control.AddOption(new OptionLightingQuality(Control, _cfg, DropDownLightingQuality));
|
||||
|
||||
Control.AddOptionDropDown(
|
||||
CVars.DisplayUIScale,
|
||||
DropDownUIScale,
|
||||
[
|
||||
new OptionDropDownCVar<float>.ValueOption(
|
||||
0f,
|
||||
Loc.GetString("ui-options-scale-auto", ("scale", UserInterfaceManager.DefaultUIScale))),
|
||||
new OptionDropDownCVar<float>.ValueOption(0.75f, Loc.GetString("ui-options-scale-75")),
|
||||
new OptionDropDownCVar<float>.ValueOption(1.00f, Loc.GetString("ui-options-scale-100")),
|
||||
new OptionDropDownCVar<float>.ValueOption(1.25f, Loc.GetString("ui-options-scale-125")),
|
||||
new OptionDropDownCVar<float>.ValueOption(1.50f, Loc.GetString("ui-options-scale-150")),
|
||||
new OptionDropDownCVar<float>.ValueOption(1.75f, Loc.GetString("ui-options-scale-175")),
|
||||
new OptionDropDownCVar<float>.ValueOption(2.00f, Loc.GetString("ui-options-scale-200")),
|
||||
]);
|
||||
|
||||
var vpStretch = Control.AddOptionCheckBox(CCVars.ViewportStretch, ViewportStretchCheckBox);
|
||||
var vpVertFit = Control.AddOptionCheckBox(CCVars.ViewportVerticalFit, ViewportVerticalFitCheckBox);
|
||||
Control.AddOptionSlider(
|
||||
CCVars.ViewportFixedScaleFactor,
|
||||
ViewportScaleSlider,
|
||||
1,
|
||||
5,
|
||||
(_, value) => Loc.GetString("ui-options-vp-scale-value", ("scale", value)));
|
||||
|
||||
vpStretch.ImmediateValueChanged += _ => UpdateViewportSettingsVisibility();
|
||||
vpVertFit.ImmediateValueChanged += _ => UpdateViewportSettingsVisibility();
|
||||
|
||||
Control.AddOptionSlider(
|
||||
CCVars.ViewportWidth,
|
||||
ViewportWidthSlider,
|
||||
(int)ViewportWidthSlider.Slider.MinValue,
|
||||
(int)ViewportWidthSlider.Slider.MaxValue);
|
||||
|
||||
Control.AddOption(new OptionIntegerScaling(Control, _cfg, IntegerScalingCheckBox));
|
||||
Control.AddOptionCheckBox(CCVars.ViewportScaleRender, ViewportLowResCheckBox, invert: true);
|
||||
Control.AddOptionCheckBox(CCVars.ParallaxLowQuality, ParallaxLowQualityCheckBox);
|
||||
Control.AddOptionCheckBox(CCVars.HudFpsCounterVisible, FpsCounterCheckBox);
|
||||
|
||||
Control.Initialize();
|
||||
|
||||
_cfg.OnValueChanged(CCVars.ViewportMinimumWidth, _ => UpdateViewportWidthRange());
|
||||
_cfg.OnValueChanged(CCVars.ViewportMaximumWidth, _ => UpdateViewportWidthRange());
|
||||
|
||||
UpdateViewportWidthRange();
|
||||
UpdateViewportSettingsVisibility();
|
||||
}
|
||||
|
||||
private void UpdateViewportSettingsVisibility()
|
||||
{
|
||||
ViewportScaleSlider.Visible = !ViewportStretchCheckBox.Pressed;
|
||||
IntegerScalingCheckBox.Visible = ViewportStretchCheckBox.Pressed;
|
||||
ViewportVerticalFitCheckBox.Visible = ViewportStretchCheckBox.Pressed;
|
||||
ViewportWidthSlider.Visible = !ViewportStretchCheckBox.Pressed || !ViewportVerticalFitCheckBox.Pressed;
|
||||
}
|
||||
|
||||
private void UpdateViewportWidthRange()
|
||||
{
|
||||
var min = _cfg.GetCVar(CCVars.ViewportMinimumWidth);
|
||||
var max = _cfg.GetCVar(CCVars.ViewportMaximumWidth);
|
||||
|
||||
ViewportWidthSlider.Slider.MinValue = min;
|
||||
ViewportWidthSlider.Slider.MaxValue = max;
|
||||
}
|
||||
|
||||
private sealed class OptionLightingQuality : BaseOption
|
||||
{
|
||||
private readonly IConfigurationManager _cfg;
|
||||
private readonly OptionDropDown _dropDown;
|
||||
|
||||
private const int QualityVeryLow = 0;
|
||||
private const int QualityLow = 1;
|
||||
private const int QualityMedium = 2;
|
||||
private const int QualityHigh = 3;
|
||||
|
||||
private const int QualityDefault = QualityMedium;
|
||||
|
||||
public OptionLightingQuality(OptionsTabControlRow controller, IConfigurationManager cfg, OptionDropDown dropDown) : base(controller)
|
||||
{
|
||||
0f,
|
||||
0.75f,
|
||||
1f,
|
||||
1.25f,
|
||||
1.50f,
|
||||
1.75f,
|
||||
2f
|
||||
};
|
||||
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
|
||||
public GraphicsTab()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
VSyncCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
FullscreenCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
|
||||
LightingPresetOption.AddItem(Loc.GetString("ui-options-lighting-very-low"));
|
||||
LightingPresetOption.AddItem(Loc.GetString("ui-options-lighting-low"));
|
||||
LightingPresetOption.AddItem(Loc.GetString("ui-options-lighting-medium"));
|
||||
LightingPresetOption.AddItem(Loc.GetString("ui-options-lighting-high"));
|
||||
LightingPresetOption.OnItemSelected += OnLightingQualityChanged;
|
||||
|
||||
UIScaleOption.AddItem(Loc.GetString("ui-options-scale-auto",
|
||||
("scale", UserInterfaceManager.DefaultUIScale)));
|
||||
UIScaleOption.AddItem(Loc.GetString("ui-options-scale-75"));
|
||||
UIScaleOption.AddItem(Loc.GetString("ui-options-scale-100"));
|
||||
UIScaleOption.AddItem(Loc.GetString("ui-options-scale-125"));
|
||||
UIScaleOption.AddItem(Loc.GetString("ui-options-scale-150"));
|
||||
UIScaleOption.AddItem(Loc.GetString("ui-options-scale-175"));
|
||||
UIScaleOption.AddItem(Loc.GetString("ui-options-scale-200"));
|
||||
UIScaleOption.OnItemSelected += OnUIScaleChanged;
|
||||
|
||||
ViewportStretchCheckBox.OnToggled += _ =>
|
||||
{
|
||||
UpdateViewportScale();
|
||||
UpdateApplyButton();
|
||||
};
|
||||
|
||||
ViewportScaleSlider.OnValueChanged += _ =>
|
||||
{
|
||||
UpdateApplyButton();
|
||||
UpdateViewportScale();
|
||||
};
|
||||
|
||||
ViewportWidthSlider.OnValueChanged += _ =>
|
||||
{
|
||||
UpdateViewportWidthDisplay();
|
||||
UpdateApplyButton();
|
||||
};
|
||||
|
||||
ViewportVerticalFitCheckBox.OnToggled += _ =>
|
||||
{
|
||||
UpdateViewportScale();
|
||||
UpdateApplyButton();
|
||||
};
|
||||
|
||||
IntegerScalingCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
ViewportLowResCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
ParallaxLowQualityCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
FpsCounterCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
ApplyButton.OnPressed += OnApplyButtonPressed;
|
||||
VSyncCheckBox.Pressed = _cfg.GetCVar(CVars.DisplayVSync);
|
||||
FullscreenCheckBox.Pressed = ConfigIsFullscreen;
|
||||
LightingPresetOption.SelectId(GetConfigLightingQuality());
|
||||
UIScaleOption.SelectId(GetConfigUIScalePreset(ConfigUIScale));
|
||||
ViewportScaleSlider.Value = _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);
|
||||
ViewportStretchCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportStretch);
|
||||
IntegerScalingCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0;
|
||||
ViewportVerticalFitCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportVerticalFit);
|
||||
ViewportLowResCheckBox.Pressed = !_cfg.GetCVar(CCVars.ViewportScaleRender);
|
||||
ParallaxLowQualityCheckBox.Pressed = _cfg.GetCVar(CCVars.ParallaxLowQuality);
|
||||
FpsCounterCheckBox.Pressed = _cfg.GetCVar(CCVars.HudFpsCounterVisible);
|
||||
ViewportWidthSlider.Value = _cfg.GetCVar(CCVars.ViewportWidth);
|
||||
|
||||
_cfg.OnValueChanged(CCVars.ViewportMinimumWidth, _ => UpdateViewportWidthRange());
|
||||
_cfg.OnValueChanged(CCVars.ViewportMaximumWidth, _ => UpdateViewportWidthRange());
|
||||
|
||||
UpdateViewportWidthRange();
|
||||
UpdateViewportWidthDisplay();
|
||||
UpdateViewportScale();
|
||||
UpdateApplyButton();
|
||||
_cfg = cfg;
|
||||
_dropDown = dropDown;
|
||||
var button = dropDown.Button;
|
||||
button.AddItem(Loc.GetString("ui-options-lighting-very-low"), QualityVeryLow);
|
||||
button.AddItem(Loc.GetString("ui-options-lighting-low"), QualityLow);
|
||||
button.AddItem(Loc.GetString("ui-options-lighting-medium"), QualityMedium);
|
||||
button.AddItem(Loc.GetString("ui-options-lighting-high"), QualityHigh);
|
||||
button.OnItemSelected += OnOptionSelected;
|
||||
}
|
||||
|
||||
private void OnUIScaleChanged(OptionButton.ItemSelectedEventArgs args)
|
||||
private void OnOptionSelected(OptionButton.ItemSelectedEventArgs obj)
|
||||
{
|
||||
UIScaleOption.SelectId(args.Id);
|
||||
UpdateApplyButton();
|
||||
_dropDown.Button.SelectId(obj.Id);
|
||||
ValueChanged();
|
||||
}
|
||||
|
||||
private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
|
||||
public override void LoadValue()
|
||||
{
|
||||
_cfg.SetCVar(CVars.DisplayVSync, VSyncCheckBox.Pressed);
|
||||
SetConfigLightingQuality(LightingPresetOption.SelectedId);
|
||||
|
||||
_cfg.SetCVar(CVars.DisplayWindowMode,
|
||||
(int) (FullscreenCheckBox.Pressed ? WindowMode.Fullscreen : WindowMode.Windowed));
|
||||
_cfg.SetCVar(CVars.DisplayUIScale, UIScaleOptions[UIScaleOption.SelectedId]);
|
||||
_cfg.SetCVar(CCVars.ViewportStretch, ViewportStretchCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.ViewportFixedScaleFactor, (int) ViewportScaleSlider.Value);
|
||||
_cfg.SetCVar(CCVars.ViewportSnapToleranceMargin,
|
||||
IntegerScalingCheckBox.Pressed ? CCVars.ViewportSnapToleranceMargin.DefaultValue : 0);
|
||||
_cfg.SetCVar(CCVars.ViewportVerticalFit, ViewportVerticalFitCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.ViewportScaleRender, !ViewportLowResCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.ParallaxLowQuality, ParallaxLowQualityCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.HudFpsCounterVisible, FpsCounterCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.ViewportWidth, (int) ViewportWidthSlider.Value);
|
||||
|
||||
_cfg.SaveToFile();
|
||||
UpdateApplyButton();
|
||||
_dropDown.Button.SelectId(GetConfigLightingQuality());
|
||||
}
|
||||
|
||||
private void OnCheckBoxToggled(BaseButton.ButtonToggledEventArgs args)
|
||||
public override void SaveValue()
|
||||
{
|
||||
UpdateApplyButton();
|
||||
}
|
||||
|
||||
private void OnLightingQualityChanged(OptionButton.ItemSelectedEventArgs args)
|
||||
{
|
||||
LightingPresetOption.SelectId(args.Id);
|
||||
UpdateApplyButton();
|
||||
}
|
||||
|
||||
private void UpdateApplyButton()
|
||||
{
|
||||
var isVSyncSame = VSyncCheckBox.Pressed == _cfg.GetCVar(CVars.DisplayVSync);
|
||||
var isFullscreenSame = FullscreenCheckBox.Pressed == ConfigIsFullscreen;
|
||||
var isLightingQualitySame = LightingPresetOption.SelectedId == GetConfigLightingQuality();
|
||||
var isUIScaleSame = MathHelper.CloseToPercent(UIScaleOptions[UIScaleOption.SelectedId], ConfigUIScale);
|
||||
var isVPStretchSame = ViewportStretchCheckBox.Pressed == _cfg.GetCVar(CCVars.ViewportStretch);
|
||||
var isVPScaleSame = (int) ViewportScaleSlider.Value == _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);
|
||||
var isIntegerScalingSame = IntegerScalingCheckBox.Pressed == (_cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0);
|
||||
var isVPVerticalFitSame = ViewportVerticalFitCheckBox.Pressed == _cfg.GetCVar(CCVars.ViewportVerticalFit);
|
||||
var isVPResSame = ViewportLowResCheckBox.Pressed == !_cfg.GetCVar(CCVars.ViewportScaleRender);
|
||||
var isPLQSame = ParallaxLowQualityCheckBox.Pressed == _cfg.GetCVar(CCVars.ParallaxLowQuality);
|
||||
var isFpsCounterVisibleSame = FpsCounterCheckBox.Pressed == _cfg.GetCVar(CCVars.HudFpsCounterVisible);
|
||||
var isWidthSame = (int) ViewportWidthSlider.Value == _cfg.GetCVar(CCVars.ViewportWidth);
|
||||
|
||||
ApplyButton.Disabled = isVSyncSame &&
|
||||
isFullscreenSame &&
|
||||
isLightingQualitySame &&
|
||||
isUIScaleSame &&
|
||||
isVPStretchSame &&
|
||||
isVPScaleSame &&
|
||||
isIntegerScalingSame &&
|
||||
isVPVerticalFitSame &&
|
||||
isVPResSame &&
|
||||
isPLQSame &&
|
||||
isFpsCounterVisibleSame &&
|
||||
isWidthSame;
|
||||
}
|
||||
|
||||
private bool ConfigIsFullscreen =>
|
||||
_cfg.GetCVar(CVars.DisplayWindowMode) == (int) WindowMode.Fullscreen;
|
||||
|
||||
public void UpdateProperties()
|
||||
{
|
||||
FullscreenCheckBox.Pressed = ConfigIsFullscreen;
|
||||
}
|
||||
|
||||
|
||||
private float ConfigUIScale => _cfg.GetCVar(CVars.DisplayUIScale);
|
||||
|
||||
private int GetConfigLightingQuality()
|
||||
{
|
||||
var val = _cfg.GetCVar(CVars.LightResolutionScale);
|
||||
var soft = _cfg.GetCVar(CVars.LightSoftShadows);
|
||||
if (val <= 0.125)
|
||||
switch (_dropDown.Button.SelectedId)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if ((val <= 0.5) && !soft)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (val <= 0.5)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetConfigLightingQuality(int value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case 0:
|
||||
case QualityVeryLow:
|
||||
_cfg.SetCVar(CVars.LightResolutionScale, 0.125f);
|
||||
_cfg.SetCVar(CVars.LightSoftShadows, false);
|
||||
_cfg.SetCVar(CVars.LightBlur, false);
|
||||
break;
|
||||
case 1:
|
||||
case QualityLow:
|
||||
_cfg.SetCVar(CVars.LightResolutionScale, 0.5f);
|
||||
_cfg.SetCVar(CVars.LightSoftShadows, false);
|
||||
_cfg.SetCVar(CVars.LightBlur, true);
|
||||
break;
|
||||
case 2:
|
||||
default: // = QualityMedium
|
||||
_cfg.SetCVar(CVars.LightResolutionScale, 0.5f);
|
||||
_cfg.SetCVar(CVars.LightSoftShadows, true);
|
||||
_cfg.SetCVar(CVars.LightBlur, true);
|
||||
break;
|
||||
case 3:
|
||||
case QualityHigh:
|
||||
_cfg.SetCVar(CVars.LightResolutionScale, 1);
|
||||
_cfg.SetCVar(CVars.LightSoftShadows, true);
|
||||
_cfg.SetCVar(CVars.LightBlur, true);
|
||||
@@ -228,40 +149,83 @@ namespace Content.Client.Options.UI.Tabs
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetConfigUIScalePreset(float value)
|
||||
public override void ResetToDefault()
|
||||
{
|
||||
for (var i = 0; i < UIScaleOptions.Length; i++)
|
||||
_dropDown.Button.SelectId(QualityDefault);
|
||||
}
|
||||
|
||||
public override bool IsModified()
|
||||
{
|
||||
return _dropDown.Button.SelectedId != GetConfigLightingQuality();
|
||||
}
|
||||
|
||||
public override bool IsModifiedFromDefault()
|
||||
{
|
||||
return _dropDown.Button.SelectedId != QualityDefault;
|
||||
}
|
||||
|
||||
private int GetConfigLightingQuality()
|
||||
{
|
||||
var val = _cfg.GetCVar(CVars.LightResolutionScale);
|
||||
var soft = _cfg.GetCVar(CVars.LightSoftShadows);
|
||||
if (val <= 0.125)
|
||||
return QualityVeryLow;
|
||||
|
||||
if ((val <= 0.5) && !soft)
|
||||
return QualityLow;
|
||||
|
||||
if (val <= 0.5)
|
||||
return QualityMedium;
|
||||
|
||||
return QualityHigh;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class OptionFullscreen : BaseOptionCVar<int>
|
||||
{
|
||||
private readonly CheckBox _checkBox;
|
||||
|
||||
protected override int Value
|
||||
{
|
||||
get => _checkBox.Pressed ? (int) WindowMode.Fullscreen : (int) WindowMode.Windowed;
|
||||
set => _checkBox.Pressed = (value == (int) WindowMode.Fullscreen);
|
||||
}
|
||||
|
||||
public OptionFullscreen(
|
||||
OptionsTabControlRow controller,
|
||||
IConfigurationManager cfg,
|
||||
CheckBox checkBox)
|
||||
: base(controller, cfg, CVars.DisplayWindowMode)
|
||||
{
|
||||
_checkBox = checkBox;
|
||||
_checkBox.OnToggled += _ =>
|
||||
{
|
||||
if (MathHelper.CloseToPercent(UIScaleOptions[i], value))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
ValueChanged();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
private sealed class OptionIntegerScaling : BaseOptionCVar<int>
|
||||
{
|
||||
private readonly CheckBox _checkBox;
|
||||
|
||||
protected override int Value
|
||||
{
|
||||
get => _checkBox.Pressed ? CCVars.ViewportSnapToleranceMargin.DefaultValue : 0;
|
||||
set => _checkBox.Pressed = (value != 0);
|
||||
}
|
||||
|
||||
private void UpdateViewportScale()
|
||||
public OptionIntegerScaling(
|
||||
OptionsTabControlRow controller,
|
||||
IConfigurationManager cfg,
|
||||
CheckBox checkBox)
|
||||
: base(controller, cfg, CCVars.ViewportSnapToleranceMargin)
|
||||
{
|
||||
ViewportScaleBox.Visible = !ViewportStretchCheckBox.Pressed;
|
||||
IntegerScalingCheckBox.Visible = ViewportStretchCheckBox.Pressed;
|
||||
ViewportVerticalFitCheckBox.Visible = ViewportStretchCheckBox.Pressed;
|
||||
ViewportWidthSlider.Visible = ViewportWidthSliderDisplay.Visible = !ViewportStretchCheckBox.Pressed || ViewportStretchCheckBox.Pressed && !ViewportVerticalFitCheckBox.Pressed;
|
||||
ViewportScaleText.Text = Loc.GetString("ui-options-vp-scale", ("scale", ViewportScaleSlider.Value));
|
||||
}
|
||||
|
||||
private void UpdateViewportWidthRange()
|
||||
{
|
||||
var min = _cfg.GetCVar(CCVars.ViewportMinimumWidth);
|
||||
var max = _cfg.GetCVar(CCVars.ViewportMaximumWidth);
|
||||
|
||||
ViewportWidthSlider.MinValue = min;
|
||||
ViewportWidthSlider.MaxValue = max;
|
||||
}
|
||||
|
||||
private void UpdateViewportWidthDisplay()
|
||||
{
|
||||
ViewportWidthSliderDisplay.Text = Loc.GetString("ui-options-vp-width", ("width", (int) ViewportWidthSlider.Value));
|
||||
_checkBox = checkBox;
|
||||
_checkBox.OnToggled += _ =>
|
||||
{
|
||||
ValueChanged();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user