From 3634955f7981a0dab1a1edc72e0fc2bcbcc32228 Mon Sep 17 00:00:00 2001 From: LivingFray Date: Sun, 15 Jan 2023 17:12:44 +0000 Subject: [PATCH] Added reticle scaling --- HellsingerVR/HellsingerVR.cs | 4 +++ HellsingerVR/UI/RhythmIndicator.cs | 49 ++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/HellsingerVR/HellsingerVR.cs b/HellsingerVR/HellsingerVR.cs index 763ec4c..db97c06 100644 --- a/HellsingerVR/HellsingerVR.cs +++ b/HellsingerVR/HellsingerVR.cs @@ -42,6 +42,8 @@ public class HellsingerVR : BasePlugin public ConfigEntry SnapTurningAngle; public ConfigEntry MovementType; // UI + public ConfigEntry ReticleFacesCamera; + public ConfigEntry ReticleScaling; public ConfigEntry MenuUIDistance; public ConfigEntry GameUIDistance; public ConfigEntry ReticleLocation; @@ -162,6 +164,8 @@ private void SetupConfig() MenuUIDistance = Config.Bind("UI", "MenuUIDistance", 2.5f, "Distance between the HMD and the menu UIs in meters"); GameUIDistance = Config.Bind("UI", "GameUIDistance", 2.5f, "Distance between the HMD and the game UIs in meters"); ReticleLocation = Config.Bind("UI", "ReticleLocation", "target", "Location of the reticle/beat indicator in the world, valid options are \"target\" (location in world the dominant hand is pointing to), \"head\" (floats a fixed distance in front of the camera), \"sights\" (placed above the weapon in the dominant hand akin to ironsights"); + ReticleFacesCamera = Config.Bind("UI", "ReticleFacesCamera", false, "When reticle location is set to target should the reticle always face the camera, or be flat against the surface it hits"); + ReticleScaling = Config.Bind("UI", "ReticleScaling", "partial", "How should the reticle's scale change with distance. Options are \"none\" (reticle will always be the same scale) \"partial\" (reticle will grow with distance but still appear smaller at a distance) or \"full\" (reticle will grow with distance such that it always occupies the same percentage of the screen)"); ShowHealthOnHand = Config.Bind("UI", "ShowHealthOnHand", true, "Set to false to show the health bar floating in front of the camera instead of attached to the non dominant hand"); ShowUltimateOnHand = Config.Bind("UI", "ShowUltimateOnHand", true, "Set to false to show the ultimate bar floating in front of the camera instead of attached to the non dominant hand"); ShowFuryOnHand = Config.Bind("UI", "ShowFuryOnHand", true, "Set to false to show the fury meter floating in front of the camera instead of attached to the non dominant hand"); diff --git a/HellsingerVR/UI/RhythmIndicator.cs b/HellsingerVR/UI/RhythmIndicator.cs index 285dae6..6b5d0d0 100644 --- a/HellsingerVR/UI/RhythmIndicator.cs +++ b/HellsingerVR/UI/RhythmIndicator.cs @@ -10,11 +10,17 @@ public class RhythmIndicator public enum Position { Head, Sights, Target }; + public enum Scaling { None, Partial, Full }; + public Position position = Position.Target; + public Scaling scaling = Scaling.Partial; + + public bool FaceCamera = false; + public float head_distance = 2.5f; - public float target_distance = 10.0f; + public float target_distance = 25.0f; public float target_offset = 0.25f; public float head_scale = 1.0f; @@ -55,6 +61,23 @@ public void Init() position = Position.Target; break; } + + string scalingCfg = HellsingerVR._instance.ReticleScaling.Value.ToLower(); + + switch (scalingCfg) + { + case "none": + scaling = Scaling.None; + break; + case "full": + scaling = Scaling.Full; + break; + default: + scaling = Scaling.Partial; + break; + } + + FaceCamera = HellsingerVR._instance.ReticleFacesCamera.Value; } public void Update() @@ -142,13 +165,35 @@ private void Update_Target() OutNormal = rotation * Vector3.back; } + if (FaceCamera) + { + OutNormal = rotation * Vector3.back; + } + Vector3 direction = (OutPoint - location).normalized; RhythmIndicatorTrans.position = OutPoint - (direction * target_offset); RhythmIndicatorTrans.LookAt(OutPoint - OutNormal); - FixOtherUIElements(target_scale); + float Distance = (OutPoint - location).magnitude / head_distance; + + float scaleModifier = 1.0f; + + switch (scaling) + { + case Scaling.None: + scaleModifier = 1.0f; + break; + case Scaling.Partial: + scaleModifier = Mathf.Sqrt(Distance); + break; + case Scaling.Full: + scaleModifier = Distance; + break; + } + + FixOtherUIElements(target_scale * scaleModifier); } private void FixOtherUIElements(float scale)