Fix hud theme selection (#19106)

* Fix hud theme selection

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Remove iterator indexing in the theme configuration

Signed-off-by: c4llv07e <kseandi@gmail.com>

---------

Signed-off-by: c4llv07e <kseandi@gmail.com>
This commit is contained in:
c4llv07e
2023-09-15 02:05:55 +00:00
committed by GitHub
parent 89337f33bc
commit 649cd34edc
3 changed files with 15 additions and 7 deletions

View File

@@ -158,6 +158,7 @@ namespace Content.Client.Entry
_euiManager.Initialize(); _euiManager.Initialize();
_voteManager.Initialize(); _voteManager.Initialize();
_userInterfaceManager.SetDefaultTheme("SS14DefaultTheme"); _userInterfaceManager.SetDefaultTheme("SS14DefaultTheme");
_userInterfaceManager.SetActiveTheme(_configManager.GetCVar(CVars.InterfaceTheme));
_documentParsingManager.Initialize(); _documentParsingManager.Initialize();
_baseClient.RunLevelChanged += (_, args) => _baseClient.RunLevelChanged += (_, args) =>

View File

@@ -26,6 +26,8 @@ namespace Content.Client.Options.UI.Tabs
2f 2f
}; };
private Dictionary<string, int> hudThemeIdToIndex = new();
[Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
@@ -56,6 +58,7 @@ namespace Content.Client.Options.UI.Tabs
foreach (var gear in _prototypeManager.EnumeratePrototypes<HudThemePrototype>()) foreach (var gear in _prototypeManager.EnumeratePrototypes<HudThemePrototype>())
{ {
HudThemeOption.AddItem(Loc.GetString(gear.Name)); HudThemeOption.AddItem(Loc.GetString(gear.Name));
hudThemeIdToIndex.Add(gear.ID, HudThemeOption.GetItemId(HudThemeOption.ItemCount - 1));
} }
HudThemeOption.OnItemSelected += OnHudThemeChanged; HudThemeOption.OnItemSelected += OnHudThemeChanged;
@@ -109,7 +112,7 @@ namespace Content.Client.Options.UI.Tabs
FullscreenCheckBox.Pressed = ConfigIsFullscreen; FullscreenCheckBox.Pressed = ConfigIsFullscreen;
LightingPresetOption.SelectId(GetConfigLightingQuality()); LightingPresetOption.SelectId(GetConfigLightingQuality());
UIScaleOption.SelectId(GetConfigUIScalePreset(ConfigUIScale)); UIScaleOption.SelectId(GetConfigUIScalePreset(ConfigUIScale));
HudThemeOption.SelectId(_cfg.GetCVar(CCVars.HudTheme)); HudThemeOption.SelectId(hudThemeIdToIndex.GetValueOrDefault(_cfg.GetCVar(CVars.InterfaceTheme), 0));
ViewportScaleSlider.Value = _cfg.GetCVar(CCVars.ViewportFixedScaleFactor); ViewportScaleSlider.Value = _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);
ViewportStretchCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportStretch); ViewportStretchCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportStretch);
IntegerScalingCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0; IntegerScalingCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0;
@@ -145,9 +148,13 @@ namespace Content.Client.Options.UI.Tabs
{ {
_cfg.SetCVar(CVars.DisplayVSync, VSyncCheckBox.Pressed); _cfg.SetCVar(CVars.DisplayVSync, VSyncCheckBox.Pressed);
SetConfigLightingQuality(LightingPresetOption.SelectedId); SetConfigLightingQuality(LightingPresetOption.SelectedId);
if (HudThemeOption.SelectedId != _cfg.GetCVar(CCVars.HudTheme)) // Don't unnecessarily redraw the HUD
foreach (var theme in _prototypeManager.EnumeratePrototypes<HudThemePrototype>())
{ {
_cfg.SetCVar(CCVars.HudTheme, HudThemeOption.SelectedId); if (hudThemeIdToIndex[theme.ID] != HudThemeOption.SelectedId)
continue;
_cfg.SetCVar(CVars.InterfaceTheme, theme.ID);
break;
} }
_cfg.SetCVar(CVars.DisplayWindowMode, _cfg.SetCVar(CVars.DisplayWindowMode,
@@ -189,7 +196,7 @@ namespace Content.Client.Options.UI.Tabs
var isVSyncSame = VSyncCheckBox.Pressed == _cfg.GetCVar(CVars.DisplayVSync); var isVSyncSame = VSyncCheckBox.Pressed == _cfg.GetCVar(CVars.DisplayVSync);
var isFullscreenSame = FullscreenCheckBox.Pressed == ConfigIsFullscreen; var isFullscreenSame = FullscreenCheckBox.Pressed == ConfigIsFullscreen;
var isLightingQualitySame = LightingPresetOption.SelectedId == GetConfigLightingQuality(); var isLightingQualitySame = LightingPresetOption.SelectedId == GetConfigLightingQuality();
var isHudThemeSame = HudThemeOption.SelectedId == _cfg.GetCVar(CCVars.HudTheme); var isHudThemeSame = HudThemeOption.SelectedId == hudThemeIdToIndex.GetValueOrDefault(_cfg.GetCVar(CVars.InterfaceTheme), 0);
var isUIScaleSame = MathHelper.CloseToPercent(UIScaleOptions[UIScaleOption.SelectedId], ConfigUIScale); var isUIScaleSame = MathHelper.CloseToPercent(UIScaleOptions[UIScaleOption.SelectedId], ConfigUIScale);
var isVPStretchSame = ViewportStretchCheckBox.Pressed == _cfg.GetCVar(CCVars.ViewportStretch); var isVPStretchSame = ViewportStretchCheckBox.Pressed == _cfg.GetCVar(CCVars.ViewportStretch);
var isVPScaleSame = (int) ViewportScaleSlider.Value == _cfg.GetCVar(CCVars.ViewportFixedScaleFactor); var isVPScaleSame = (int) ViewportScaleSlider.Value == _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);

View File

@@ -1,14 +1,14 @@
- type: hudTheme - type: hudTheme
id: 0 id: SS14DefaultTheme
name: ui-options-hud-theme-default name: ui-options-hud-theme-default
path: Default path: Default
- type: hudTheme - type: hudTheme
id: 1 id: SS14ModernizedTheme
name: ui-options-hud-theme-modernized name: ui-options-hud-theme-modernized
path: Modernized path: Modernized
- type: hudTheme - type: hudTheme
id: 2 id: SS14ClassicTheme
name: ui-options-hud-theme-classic name: ui-options-hud-theme-classic
path: Classic path: Classic