Add settings to change opacity of hud markers and the look arrow (#511)

* Add settings to change opacity of hud markers and the look arrow

* Avoid unecessary confusion in comments and naming

* Merge look arrow setting with opacity

* Version bump
This commit is contained in:
artum 2022-07-03 20:11:31 +02:00 committed by GitHub
parent 0c7207c34c
commit be68ea5d66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 99 additions and 22 deletions

View File

@ -68,5 +68,20 @@ namespace NomaiVR.Helpers
}
}
}
public static void SetCanvasAlpha(Canvas canvas, float alpha)
{
CanvasGroup opacityGroup = canvas.GetComponent<CanvasGroup>();
if (opacityGroup == null)
opacityGroup = canvas.gameObject.AddComponent<CanvasGroup>();
opacityGroup.alpha = alpha;
foreach (Renderer renderer in canvas.GetComponentsInChildren<Renderer>(true))
{
var uiColor = renderer.material.color;
uiColor.a = alpha;
renderer.material.SetColor("_Color", uiColor);
}
}
}
}

View File

@ -47,6 +47,12 @@ namespace NomaiVR.ModConfig
private ConfigEntry<float> hudOpacity;
public float HudOpacity => hudOpacity.Value;
private ConfigEntry<float> markersOpacity;
public float MarkersOpacity => markersOpacity.Value;
private ConfigEntry<float> lookArrowOpacity;
public float LookArrowOpacity => lookArrowOpacity.Value;
private ConfigEntry<bool> hudSmoothFollow;
public bool HudSmoothFollow => hudSmoothFollow.value;
@ -66,6 +72,8 @@ namespace NomaiVR.ModConfig
showHelmet = config.Bind(section, "helmetVisibility", true, "");
hudScale = config.Bind(section, "hudScale", 1f, new ConfigDescription("", new AcceptableValueRange<float>(0.2f, 1.8f)));
hudOpacity = config.Bind(section, "hudOpacity", 1f, new ConfigDescription("", new AcceptableValueRange<float>(0f, 1f)));
markersOpacity = config.Bind(section, "markersOpacity", 1f, new ConfigDescription("", new AcceptableValueRange<float>(0f, 1f)));
lookArrowOpacity = config.Bind(section, "lookArrowOpacity", 1f, new ConfigDescription("", new AcceptableValueRange<float>(0f, 1f)));
hudSmoothFollow = config.Bind(section, "hudSmoothFollow", true, "");
controllerOrientedMovement = config.Bind(section, "movementControllerOriented", false, "");
enableGesturePrompts = config.Bind(section, "showGesturePrompts", true, "");

View File

@ -14,7 +14,6 @@ namespace NomaiVR.ModConfig
bool EnableGesturePrompts { get; }
bool EnableHandLaser { get; }
bool EnableFeetMarker { get; }
bool EnableLookArrow { get; }
bool PreventClipping { get; }
bool FlashlightGesture { get; }
bool ControllerOrientedMovement { get; }
@ -22,6 +21,8 @@ namespace NomaiVR.ModConfig
float ToolbeltHeight { get; }
float HudScale { get; }
float HudOpacity { get; }
float MarkersOpacity { get; }
float LookArrowOpacity { get; }
bool HudSmoothFollow { get; }
void Configure();

View File

@ -16,7 +16,6 @@ namespace NomaiVR.ModConfig
public static bool EnableGesturePrompts => settingsProvider.EnableGesturePrompts;
public static bool EnableHandLaser => settingsProvider.EnableHandLaser;
public static bool EnableFeetMarker => settingsProvider.EnableFeetMarker;
public static bool EnableLookArrow => settingsProvider.EnableLookArrow;
public static bool PreventClipping => settingsProvider.PreventClipping;
public static bool FlashlightGesture => settingsProvider.FlashlightGesture;
public static bool ControllerOrientedMovement => settingsProvider.ControllerOrientedMovement;
@ -24,6 +23,8 @@ namespace NomaiVR.ModConfig
public static float ToolbeltHeight => settingsProvider.ToolbeltHeight;
public static float HudScale => settingsProvider.HudScale;
public static float HudOpacity => settingsProvider.HudOpacity;
public static float MarkersOpacity => settingsProvider.MarkersOpacity;
public static float LookArrowOpacity => settingsProvider.LookArrowOpacity;
public static bool HudSmoothFollow => settingsProvider.HudSmoothFollow;
public static void SetProvider(IModSettingProvider provider)

View File

@ -15,7 +15,6 @@ namespace NomaiVR.ModConfig
public bool EnableGesturePrompts { get; private set; }
public bool EnableHandLaser { get; private set; }
public bool EnableFeetMarker { get; private set; }
public bool EnableLookArrow { get; private set; }
public bool PreventClipping { get; private set; }
public bool FlashlightGesture { get; private set; }
public bool ControllerOrientedMovement { get; private set; }
@ -23,6 +22,8 @@ namespace NomaiVR.ModConfig
public float ToolbeltHeight { get; private set; }
public float HudScale { get; private set; }
public float HudOpacity { get; private set; }
public float MarkersOpacity { get; private set; }
public float LookArrowOpacity { get; private set; }
public bool HudSmoothFollow { get; private set; } = true;
private readonly IModConfig config;
@ -40,20 +41,20 @@ namespace NomaiVR.ModConfig
EnableGesturePrompts = config.GetSettingsValue<bool>("showGesturePrompts");
EnableHandLaser = config.GetSettingsValue<bool>("showHandLaser");
EnableFeetMarker = config.GetSettingsValue<bool>("showFeetMarker");
EnableLookArrow = config.GetSettingsValue<bool>("showLookArrow");
FlashlightGesture = config.GetSettingsValue<bool>("flashlightGesture");
PreventClipping = config.GetSettingsValue<bool>("preventClipping");
DebugMode = config.GetSettingsValue<bool>("debug");
AutoHideToolbelt = config.GetSettingsValue<bool>("autoHideToolbelt");
HudScale = config.GetSettingsValue<float>("hudScale");
HudSmoothFollow = config.GetSettingsValue<bool>("hudSmoothFollow");
PreventCursorLock = config.GetSettingsValue<bool>("disableCursorLock");
HudOpacity = config.GetSettingsValue<float>("hudOpacity");
MarkersOpacity = config.GetSettingsValue<float>("markersOpacity");
LookArrowOpacity = config.GetSettingsValue<float>("lookArrowOpacity");
// OWML doesn't support negative slider values so I subtract it here.
ToolbeltHeight = config.GetSettingsValue<float>("toolbeltHeight") - 1f;
// Disabled these until we can fix scrolling in mod config menu.
PreventCursorLock = config.GetSettingsValue<bool>("disableCursorLock");
HudOpacity = config.GetSettingsValue<float>("hudOpacity");
OnConfigChange?.Invoke();
}

View File

@ -50,6 +50,20 @@
"max": 1,
"title": "Helmet HUD Opacity"
},
"markersOpacity": {
"type": "slider",
"value": 1,
"min": 0,
"max": 1,
"title": "Markers Opacity"
},
"lookArrowOpacity": {
"type": "slider",
"value": 1,
"min": 0,
"max": 1,
"title": "Look Arrow Opacity"
},
"hudSmoothFollow": {
"type": "toggle",
"value": true,
@ -85,13 +99,6 @@
"yes": "Show",
"no": "Hide"
},
"showLookArrow": {
"type": "toggle",
"value": true,
"title": "Look arrow",
"yes": "Show",
"no": "Hide"
},
"preventClipping": {
"type": "toggle",
"value": true,

View File

@ -1,4 +1,5 @@

using Harmony;
using NomaiVR.Assets;
using NomaiVR.Helpers;
using NomaiVR.ModConfig;
@ -149,6 +150,7 @@ namespace NomaiVR.UI
Postfix<ThrustAndAttitudeIndicator>(nameof(ThrustAndAttitudeIndicator.LateUpdate), nameof(FixThrusterHudRotation));
Postfix<HUDCamera>(nameof(HUDCamera.Awake), nameof(FixHudDistortion));
Postfix<HUDCamera>(nameof(HUDCamera.OnGraphicSettingsUpdated), nameof(FixHudDistortion));
Postfix<ReferenceFrameGUI>(nameof(ReferenceFrameGUI.OnEnable), nameof(ApplyReferenceFrameGUIOpacity));
}
private static void FixHudDistortion(Camera ____camera)
@ -161,6 +163,14 @@ namespace NomaiVR.UI
var rotation = instance.helmet.InverseTransformRotation(Locator.GetPlayerTransform().rotation);
thrusterHUD.transform.rotation = rotation;
}
private static void ApplyReferenceFrameGUIOpacity(ReferenceFrameGUI __instance)
{
if (__instance._offScreenIndicator != null)
{
MaterialHelper.SetCanvasAlpha(__instance._canvas, ModSettings.MarkersOpacity * ModSettings.MarkersOpacity);
}
}
}
}
}

View File

@ -17,12 +17,14 @@ namespace NomaiVR.UI
private Transform leftArrow;
private Transform wrapper;
private Canvas canvas;
private static Transform target;
private static bool pauseNextFrame;
internal void Start()
{
var canvas = Instantiate(AssetLoader.LookArrowPrefab).GetComponent<Canvas>();
canvas = Instantiate(AssetLoader.LookArrowPrefab).GetComponent<Canvas>();
wrapper = canvas.transform;
wrapper.parent = Locator.GetPlayerCamera().transform;
wrapper.localPosition = new Vector3(0, 0, 4);
@ -34,6 +36,19 @@ namespace NomaiVR.UI
leftArrow = canvas.transform.Find("look-left");
leftArrow.GetComponent<SpriteRenderer>().material = MaterialHelper.GetOverlayMaterial();
leftArrow.gameObject.SetActive(false);
SetArrowOpacity();
ModSettings.OnConfigChange += SetArrowOpacity;
}
internal void OnDestroy()
{
ModSettings.OnConfigChange -= SetArrowOpacity;
}
internal void SetArrowOpacity()
{
MaterialHelper.SetCanvasAlpha(canvas, ModSettings.LookArrowOpacity * ModSettings.LookArrowOpacity);
}
internal void Update()
@ -65,12 +80,7 @@ namespace NomaiVR.UI
private void UpdateArrow()
{
if (target == null || !ModSettings.EnableLookArrow)
{
HideArrow();
return;
}
if (CameraHelper.IsOnScreen(target.position))
if (target == null || CameraHelper.IsOnScreen(target.position))
{
HideArrow();
return;

View File

@ -2,6 +2,7 @@
using System.Linq;
using NomaiVR.Assets;
using NomaiVR.Helpers;
using NomaiVR.ModConfig;
using NomaiVR.ReusableBehaviours;
using UnityEngine;
using UnityEngine.UI;
@ -51,6 +52,24 @@ namespace NomaiVR.UI
}
ScreenCanvasesToWorld();
ModSettings.OnConfigChange += ModSettings_OnConfigChange;
}
internal void OnDestroy()
{
ModSettings.OnConfigChange -= ModSettings_OnConfigChange;
}
private void ModSettings_OnConfigChange()
{
if (Locator.GetMarkerManager() != null)
{
foreach (CanvasMarker marker in Locator.GetMarkerManager()._nonFogMarkers)
{
MaterialHelper.SetCanvasAlpha(marker._canvas, ModSettings.MarkersOpacity * ModSettings.MarkersOpacity);
}
}
}
internal void Update()
@ -333,6 +352,11 @@ namespace NomaiVR.UI
private static void PostMarkerManagerStart(CanvasMarkerManager __instance)
{
__instance.GetComponent<Canvas>().planeDistance = 5;
foreach (CanvasMarker marker in __instance._nonFogMarkers)
{
MaterialHelper.SetCanvasAlpha(marker._canvas, ModSettings.MarkersOpacity * ModSettings.MarkersOpacity);
}
}
}
}

View File

@ -8,7 +8,7 @@
"title": "Before playing NomaiVR, some information:",
"body": "- Click the NomaiVR readme button in the Mod Manager for information about troubleshooting, requirements, performance, how to uninstall, etc.\n\n- Some VR controllers will have missing icons. Message us if you want to help us add icons for these devices.\n\n- If you have the game on Steam:\n--- Right-click Outer Wilds on your Steam library\n--- Select 'Properties...'\n--- Disable 'Use Desktop Game Theatre.'"
},
"version": "2.6.0",
"version": "2.7.0",
"owmlVersion": "2.3.0",
"requireVR": true
}