Move HUD options to general options tab (#22884)

This commit is contained in:
Nemanja
2023-12-23 01:32:56 -05:00
committed by GitHub
parent 9b18357a88
commit 06a663d3ab
7 changed files with 101 additions and 78 deletions

View File

@@ -1,6 +1,4 @@
using Content.Client.UserInterface.Screens;
using Content.Shared.CCVar;
using Content.Shared.HUD;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
@@ -8,7 +6,6 @@ using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
namespace Content.Client.Options.UI.Tabs
{
@@ -26,10 +23,7 @@ namespace Content.Client.Options.UI.Tabs
2f
};
private Dictionary<string, int> hudThemeIdToIndex = new();
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public GraphicsTab()
{
@@ -55,34 +49,6 @@ namespace Content.Client.Options.UI.Tabs
UIScaleOption.AddItem(Loc.GetString("ui-options-scale-200"));
UIScaleOption.OnItemSelected += OnUIScaleChanged;
foreach (var gear in _prototypeManager.EnumeratePrototypes<HudThemePrototype>())
{
HudThemeOption.AddItem(Loc.GetString(gear.Name));
hudThemeIdToIndex.Add(gear.ID, HudThemeOption.GetItemId(HudThemeOption.ItemCount - 1));
}
HudThemeOption.OnItemSelected += OnHudThemeChanged;
var hudLayout = _cfg.GetCVar(CCVars.UILayout);
var id = 0;
foreach (var layout in Enum.GetValues(typeof(ScreenType)))
{
var name = layout.ToString()!;
HudLayoutOption.AddItem(name, id);
if (name == hudLayout)
{
HudLayoutOption.SelectId(id);
}
HudLayoutOption.SetItemMetadata(id, name);
id++;
}
HudLayoutOption.OnItemSelected += args =>
{
HudLayoutOption.SelectId(args.Id);
UpdateApplyButton();
};
ViewportStretchCheckBox.OnToggled += _ =>
{
UpdateViewportScale();
@@ -110,7 +76,6 @@ namespace Content.Client.Options.UI.Tabs
FullscreenCheckBox.Pressed = ConfigIsFullscreen;
LightingPresetOption.SelectId(GetConfigLightingQuality());
UIScaleOption.SelectId(GetConfigUIScalePreset(ConfigUIScale));
HudThemeOption.SelectId(hudThemeIdToIndex.GetValueOrDefault(_cfg.GetCVar(CVars.InterfaceTheme), 0));
ViewportScaleSlider.Value = _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);
ViewportStretchCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportStretch);
IntegerScalingCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0;
@@ -134,25 +99,11 @@ namespace Content.Client.Options.UI.Tabs
UpdateApplyButton();
}
private void OnHudThemeChanged(OptionButton.ItemSelectedEventArgs args)
{
HudThemeOption.SelectId(args.Id);
UpdateApplyButton();
}
private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
{
_cfg.SetCVar(CVars.DisplayVSync, VSyncCheckBox.Pressed);
SetConfigLightingQuality(LightingPresetOption.SelectedId);
foreach (var theme in _prototypeManager.EnumeratePrototypes<HudThemePrototype>())
{
if (hudThemeIdToIndex[theme.ID] != HudThemeOption.SelectedId)
continue;
_cfg.SetCVar(CVars.InterfaceTheme, theme.ID);
break;
}
_cfg.SetCVar(CVars.DisplayWindowMode,
(int) (FullscreenCheckBox.Pressed ? WindowMode.Fullscreen : WindowMode.Windowed));
_cfg.SetCVar(CVars.DisplayUIScale, UIScaleOptions[UIScaleOption.SelectedId]);
@@ -165,11 +116,6 @@ namespace Content.Client.Options.UI.Tabs
_cfg.SetCVar(CCVars.HudFpsCounterVisible, FpsCounterCheckBox.Pressed);
_cfg.SetCVar(CCVars.ViewportWidth, (int) ViewportWidthSlider.Value);
if (HudLayoutOption.SelectedMetadata is string opt)
{
_cfg.SetCVar(CCVars.UILayout, opt);
}
_cfg.SaveToFile();
UpdateApplyButton();
}
@@ -190,7 +136,6 @@ namespace Content.Client.Options.UI.Tabs
var isVSyncSame = VSyncCheckBox.Pressed == _cfg.GetCVar(CVars.DisplayVSync);
var isFullscreenSame = FullscreenCheckBox.Pressed == ConfigIsFullscreen;
var isLightingQualitySame = LightingPresetOption.SelectedId == GetConfigLightingQuality();
var isHudThemeSame = HudThemeOption.SelectedId == hudThemeIdToIndex.GetValueOrDefault(_cfg.GetCVar(CVars.InterfaceTheme), 0);
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);
@@ -199,7 +144,6 @@ namespace Content.Client.Options.UI.Tabs
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);
var isLayoutSame = HudLayoutOption.SelectedMetadata is string opt && opt == _cfg.GetCVar(CCVars.UILayout);
ApplyButton.Disabled = isVSyncSame &&
isFullscreenSame &&
@@ -210,10 +154,8 @@ namespace Content.Client.Options.UI.Tabs
isIntegerScalingSame &&
isVPResSame &&
isPLQSame &&
isHudThemeSame &&
isFpsCounterVisibleSame &&
isWidthSame &&
isLayoutSame;
isWidthSame;
}
private bool ConfigIsFullscreen =>