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:
@@ -1,18 +1,24 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Client.UserInterface.Stylesheets;
|
||||
using Content.Client.Utility;
|
||||
using Content.Shared;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Prototypes.HUD;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using static Robust.Client.Input.Keyboard.Key;
|
||||
using Control = Robust.Client.UserInterface.Control;
|
||||
@@ -74,6 +80,10 @@ namespace Content.Client.UserInterface
|
||||
|
||||
void AddTopNotification(TopNotification notification);
|
||||
|
||||
Texture GetHudTexture(string path);
|
||||
|
||||
bool ValidateHudTheme(int idx);
|
||||
|
||||
// Init logic.
|
||||
void Initialize();
|
||||
}
|
||||
@@ -95,7 +105,9 @@ namespace Content.Client.UserInterface
|
||||
private VBoxContainer _topNotificationContainer = default!;
|
||||
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
[Dependency] private readonly INetConfigurationManager _configManager = default!;
|
||||
|
||||
public Control HandsContainer { get; private set; } = default!;
|
||||
public Control SuspicionContainer { get; private set; } = default!;
|
||||
@@ -121,6 +133,38 @@ namespace Content.Client.UserInterface
|
||||
_topNotificationContainer.AddChild(notification);
|
||||
}
|
||||
|
||||
public bool ValidateHudTheme(int idx)
|
||||
{
|
||||
if (!_prototypeManager.TryIndex(idx.ToString(), out HudThemePrototype? _))
|
||||
{
|
||||
Logger.ErrorS("hud", "invalid HUD theme id {0}, using different theme",
|
||||
idx);
|
||||
var proto = _prototypeManager.EnumeratePrototypes<HudThemePrototype>().FirstOrDefault();
|
||||
if (proto == null)
|
||||
{
|
||||
throw new NullReferenceException("No valid HUD prototypes!");
|
||||
}
|
||||
var id = int.Parse(proto.ID);
|
||||
_configManager.SetCVar(CCVars.HudTheme, id);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Texture GetHudTexture(string path)
|
||||
{
|
||||
var id = _configManager.GetCVar<int>("hud.theme");
|
||||
var dir = string.Empty;
|
||||
if (!_prototypeManager.TryIndex(id.ToString(), out HudThemePrototype? proto))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
dir = proto.Path;
|
||||
|
||||
var resourcePath = (new ResourcePath("/Textures/Interface/Inventory") / dir) / path;
|
||||
return _resourceCache.GetTexture(resourcePath);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
RootControl = new LC { Name = "AAAAAAAAAAAAAAAAAAAAAA"};
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Content.Client.UserInterface
|
||||
private bool _activeHand;
|
||||
private bool _highlighted;
|
||||
|
||||
public HandButton(Texture texture, Texture storageTexture, Texture blockedTexture, HandLocation location) : base(texture, storageTexture)
|
||||
public HandButton(Texture texture, Texture storageTexture, string textureName, Texture blockedTexture, HandLocation location) : base(texture, storageTexture, textureName)
|
||||
{
|
||||
Location = location;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Client.GameObjects.Components.Items;
|
||||
using Content.Client.Utility;
|
||||
using Content.Shared;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.Input;
|
||||
using Robust.Client.Graphics;
|
||||
@@ -10,6 +11,7 @@ using Robust.Client.Player;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -21,10 +23,12 @@ namespace Content.Client.UserInterface
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[Dependency] private readonly IItemSlotManager _itemSlotManager = default!;
|
||||
[Dependency] private readonly IGameHud _gameHud = default!;
|
||||
[Dependency] private readonly INetConfigurationManager _configManager = default!;
|
||||
|
||||
private readonly Texture _leftHandTexture;
|
||||
private readonly Texture _middleHandTexture;
|
||||
private readonly Texture _rightHandTexture;
|
||||
private Texture _leftHandTexture;
|
||||
private Texture _middleHandTexture;
|
||||
private Texture _rightHandTexture;
|
||||
|
||||
private readonly ItemStatusPanel _topPanel;
|
||||
|
||||
@@ -36,6 +40,8 @@ namespace Content.Client.UserInterface
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_configManager.OnValueChanged(CCVars.HudTheme, UpdateHudTheme, invokeImmediately: true);
|
||||
|
||||
AddChild(_guiContainer = new HBoxContainer
|
||||
{
|
||||
SeparationOverride = 0,
|
||||
@@ -52,9 +58,21 @@ namespace Content.Client.UserInterface
|
||||
}),
|
||||
}
|
||||
});
|
||||
_leftHandTexture = _resourceCache.GetTexture("/Textures/Interface/Inventory/hand_l.png");
|
||||
_middleHandTexture = _resourceCache.GetTexture("/Textures/Interface/Inventory/hand_l.png");
|
||||
_rightHandTexture = _resourceCache.GetTexture("/Textures/Interface/Inventory/hand_r.png");
|
||||
_leftHandTexture = _gameHud.GetHudTexture("hand_l.png");
|
||||
_middleHandTexture = _gameHud.GetHudTexture("hand_l.png");
|
||||
_rightHandTexture = _gameHud.GetHudTexture("hand_r.png");
|
||||
}
|
||||
|
||||
private void UpdateHudTheme(int idx)
|
||||
{
|
||||
if (!_gameHud.ValidateHudTheme(idx))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_leftHandTexture = _gameHud.GetHudTexture("hand_l.png");
|
||||
_middleHandTexture = _gameHud.GetHudTexture("hand_l.png");
|
||||
_rightHandTexture = _gameHud.GetHudTexture("hand_r.png");
|
||||
UpdateHandIcons();
|
||||
}
|
||||
|
||||
private Texture HandTexture(HandLocation location)
|
||||
@@ -82,10 +100,15 @@ namespace Content.Client.UserInterface
|
||||
/// </param>
|
||||
private void AddHand(Hand hand, HandLocation buttonLocation)
|
||||
{
|
||||
var textureName = "hand_l.png";
|
||||
if(buttonLocation == HandLocation.Right)
|
||||
{
|
||||
textureName = "hand_r.png";
|
||||
}
|
||||
var buttonTexture = HandTexture(buttonLocation);
|
||||
var storageTexture = _resourceCache.GetTexture("/Textures/Interface/Inventory/back.png");
|
||||
var storageTexture = _gameHud.GetHudTexture("back.png");
|
||||
var blockedTexture = _resourceCache.GetTexture("/Textures/Interface/Inventory/blocked.png");
|
||||
var button = new HandButton(buttonTexture, storageTexture, blockedTexture, buttonLocation);
|
||||
var button = new HandButton(buttonTexture, storageTexture, textureName, blockedTexture, buttonLocation);
|
||||
var slot = hand.Name;
|
||||
|
||||
button.OnPressed += args => HandKeyBindDown(args, slot);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Client.UserInterface
|
||||
public TextureRect Button { get; }
|
||||
public SpriteView SpriteView { get; }
|
||||
public SpriteView HoverSpriteView { get; }
|
||||
public BaseButton StorageButton { get; }
|
||||
public TextureButton StorageButton { get; }
|
||||
public CooldownGraphic CooldownDisplay { get; }
|
||||
|
||||
public Action<GUIBoundKeyEventArgs>? OnPressed { get; set; }
|
||||
@@ -27,10 +27,14 @@ namespace Content.Client.UserInterface
|
||||
|
||||
private readonly PanelContainer _highlightRect;
|
||||
|
||||
public ItemSlotButton(Texture texture, Texture storageTexture)
|
||||
public string TextureName { get; set; }
|
||||
|
||||
public ItemSlotButton(Texture texture, Texture storageTexture, string textureName)
|
||||
{
|
||||
MinSize = (64, 64);
|
||||
|
||||
TextureName = textureName;
|
||||
|
||||
AddChild(Button = new TextureRect
|
||||
{
|
||||
Texture = texture,
|
||||
|
||||
@@ -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 =>
|
||||
|
||||
@@ -5,12 +5,14 @@ using Robust.Shared.Configuration;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.UserInterface
|
||||
{
|
||||
public sealed partial class OptionsMenu : SS14Window
|
||||
{
|
||||
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IClydeAudio _clydeAudio = default!;
|
||||
|
||||
public OptionsMenu()
|
||||
@@ -28,7 +30,7 @@ namespace Content.Client.UserInterface
|
||||
{
|
||||
Children =
|
||||
{
|
||||
(graphicsControl = new GraphicsControl(_configManager)),
|
||||
(graphicsControl = new GraphicsControl(_configManager, _prototypeManager)),
|
||||
(rebindControl = new KeyRebindControl()),
|
||||
(audioControl = new AudioControl(_configManager, _clydeAudio)),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user