From ba0ca39a7ad5ceef2ae0582e13be5044e6f0a5f7 Mon Sep 17 00:00:00 2001 From: Psychpsyo <60073468+Psychpsyo@users.noreply.github.com> Date: Fri, 2 Feb 2024 13:39:12 +0100 Subject: [PATCH] Screen Shake Intensity Slider in Accessibility Settings (#24749) * Reduced motion toggle disables screen shake * Actually, screen shake is its own slider instead * Cache screen shake intensity cvar --- Content.Client/Camera/CameraRecoilSystem.cs | 25 +++++++++++++++++++ Content.Client/Options/UI/Tabs/MiscTab.xaml | 9 +++++++ .../Options/UI/Tabs/MiscTab.xaml.cs | 13 ++++++++++ Content.Shared/CCVar/CCVars.cs | 7 ++++++ .../en-US/escape-menu/ui/options-menu.ftl | 2 ++ 5 files changed, 56 insertions(+) diff --git a/Content.Client/Camera/CameraRecoilSystem.cs b/Content.Client/Camera/CameraRecoilSystem.cs index 65a3fc71c7..bb419b465d 100644 --- a/Content.Client/Camera/CameraRecoilSystem.cs +++ b/Content.Client/Camera/CameraRecoilSystem.cs @@ -1,14 +1,34 @@ using System.Numerics; using Content.Shared.Camera; +using Content.Shared.CCVar; +using Robust.Shared.Configuration; namespace Content.Client.Camera; public sealed class CameraRecoilSystem : SharedCameraRecoilSystem { + [Dependency] private readonly IConfigurationManager _configManager = default!; + + protected float Intensity; + public override void Initialize() { base.Initialize(); SubscribeNetworkEvent(OnCameraKick); + + _configManager.OnValueChanged(CCVars.ScreenShakeIntensity, OnCvarChanged, true); + } + + public override void Shutdown() + { + base.Shutdown(); + + _configManager.UnsubValueChanged(CCVars.ScreenShakeIntensity, OnCvarChanged); + } + + private void OnCvarChanged(float value) + { + Intensity = value; } private void OnCameraKick(CameraKickEvent ev) @@ -18,9 +38,14 @@ public sealed class CameraRecoilSystem : SharedCameraRecoilSystem public override void KickCamera(EntityUid uid, Vector2 recoil, CameraRecoilComponent? component = null) { + if (Intensity == 0) + return; + if (!Resolve(uid, ref component, false)) return; + recoil *= Intensity; + // Use really bad math to "dampen" kicks when we're already kicked. var existing = component.CurrentKick.Length(); var dampen = existing / KickMagnitudeMax; diff --git a/Content.Client/Options/UI/Tabs/MiscTab.xaml b/Content.Client/Options/UI/Tabs/MiscTab.xaml index e37333b0e4..db176db456 100644 --- a/Content.Client/Options/UI/Tabs/MiscTab.xaml +++ b/Content.Client/Options/UI/Tabs/MiscTab.xaml @@ -22,6 +22,15 @@ FontColorOverride="{xNamespace:Static s:StyleNano.NanoGold}" StyleClasses="LabelKeyText"/> + +