HUD Themes (#3774)

* HUD Themes

* Prototypes

* field

* oops

* ugh

* Fixes

* Update Content.Client/UserInterface/GameHud.cs

Co-authored-by: ike709 <sparebytes@protonmail.com>
This commit is contained in:
ike709
2021-04-11 17:43:53 -05:00
committed by GitHub
parent 98c158d2b7
commit 69dbb9f654
93 changed files with 210 additions and 28 deletions

View File

@@ -1,4 +1,8 @@
using Robust.Client.Graphics;
using System;
using Content.Client.GameObjects.Components.HUD.Inventory;
using Content.Shared;
using Content.Shared.Prototypes.HUD;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
@@ -7,6 +11,7 @@ using Robust.Shared.Configuration;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
namespace Content.Client.UserInterface
{
@@ -26,16 +31,19 @@ namespace Content.Client.UserInterface
};
private readonly IConfigurationManager _cfg;
private readonly IPrototypeManager _prototypeManager;
private readonly Button ApplyButton;
private readonly CheckBox VSyncCheckBox;
private readonly CheckBox FullscreenCheckBox;
private readonly OptionButton LightingPresetOption;
private readonly OptionButton _uiScaleOption;
private readonly OptionButton _hudThemeOption;
public GraphicsControl(IConfigurationManager cfg)
public GraphicsControl(IConfigurationManager cfg, IPrototypeManager proMan)
{
_cfg = cfg;
_prototypeManager = proMan;
var vBox = new VBoxContainer();
var contents = new VBoxContainer
@@ -75,10 +83,9 @@ namespace Content.Client.UserInterface
HorizontalAlignment = HAlignment.Right
};
var resourceCache = IoCManager.Resolve<IResourceCache>();
_uiScaleOption = new OptionButton();
_uiScaleOption.AddItem(Loc.GetString("ui-options-scale-auto", ("scale", UserInterfaceManager.DefaultUIScale)));
_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"));
@@ -97,6 +104,23 @@ namespace Content.Client.UserInterface
}
});
_hudThemeOption = new OptionButton();
foreach (var gear in _prototypeManager.EnumeratePrototypes<HudThemePrototype>())
{
_hudThemeOption.AddItem(Loc.GetString(gear.Name));
}
_hudThemeOption.OnItemSelected += OnHudThemeChanged;
contents.AddChild(new HBoxContainer
{
Children =
{
new Label {Text = Loc.GetString("ui-options-hud-theme")},
new Control {MinSize = (4, 0)},
_hudThemeOption
}
});
contents.AddChild(new Placeholder()
{
VerticalExpand = true,
@@ -120,6 +144,7 @@ namespace Content.Client.UserInterface
FullscreenCheckBox.Pressed = ConfigIsFullscreen;
LightingPresetOption.SelectId(GetConfigLightingQuality());
_uiScaleOption.SelectId(GetConfigUIScalePreset(ConfigUIScale));
_hudThemeOption.SelectId(_cfg.GetCVar(CCVars.HudTheme));
AddChild(vBox);
}
@@ -130,10 +155,21 @@ namespace Content.Client.UserInterface
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);
if (_hudThemeOption.SelectedId != _cfg.GetCVar(CCVars.HudTheme)) // Don't unnecessarily redraw the HUD
{
_cfg.SetCVar(CCVars.HudTheme, _hudThemeOption.SelectedId);
}
_cfg.SetCVar(CVars.DisplayWindowMode,
(int) (FullscreenCheckBox.Pressed ? WindowMode.Fullscreen : WindowMode.Windowed));
_cfg.SetCVar(CVars.DisplayUIScale, UIScaleOptions[_uiScaleOption.SelectedId]);
@@ -157,8 +193,10 @@ namespace Content.Client.UserInterface
var isVSyncSame = VSyncCheckBox.Pressed == _cfg.GetCVar(CVars.DisplayVSync);
var isFullscreenSame = FullscreenCheckBox.Pressed == ConfigIsFullscreen;
var isLightingQualitySame = LightingPresetOption.SelectedId == GetConfigLightingQuality();
var isHudThemeSame = _hudThemeOption.SelectedId == _cfg.GetCVar(CCVars.HudTheme);
var isUIScaleSame = MathHelper.CloseTo(UIScaleOptions[_uiScaleOption.SelectedId], ConfigUIScale);
ApplyButton.Disabled = isVSyncSame && isFullscreenSame && isLightingQualitySame && isUIScaleSame;
ApplyButton.Disabled = isVSyncSame && isFullscreenSame && isLightingQualitySame && isHudThemeSame &&
isUIScaleSame;
}
private bool ConfigIsFullscreen =>