From 329a18c915f16d9a46e2b0b078e46498bc8240ab Mon Sep 17 00:00:00 2001 From: DaXcess Date: Tue, 3 Sep 2024 17:59:29 +0200 Subject: [PATCH] Add toggle sprint indicator --- Source/Assets/AssetManager.cs | 2 ++ Source/Player/VRPlayer.cs | 2 ++ Source/UI/VRHUD.cs | 30 +++++++++++++++++++++++++----- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Source/Assets/AssetManager.cs b/Source/Assets/AssetManager.cs index b22b28c4..e6b11665 100644 --- a/Source/Assets/AssetManager.cs +++ b/Source/Assets/AssetManager.cs @@ -34,6 +34,7 @@ internal static class AssetManager public static Sprite KofiImage; public static Sprite DiscordImage; public static Sprite WarningImage; + public static Sprite SprintImage; public static AudioClip DoorLocked; @@ -75,6 +76,7 @@ public static bool LoadAssets() KofiImage = assetBundle.LoadAsset("Ko-Fi"); DiscordImage = assetBundle.LoadAsset("Discord"); WarningImage = assetBundle.LoadAsset("Warning"); + SprintImage = assetBundle.LoadAsset("Aguy"); DoorLocked = assetBundle.LoadAsset("doorlocked"); diff --git a/Source/Player/VRPlayer.cs b/Source/Player/VRPlayer.cs index ffcd8a86..1d0f1799 100644 --- a/Source/Player/VRPlayer.cs +++ b/Source/Player/VRPlayer.cs @@ -630,6 +630,8 @@ PlayerController.currentTriggerInAnimationWith is not null && PlayerControllerB_Sprint_Patch.sprint = !IsRoomCrouching && !PlayerController.isCrouching && isSprinting ? 1 : 0; + VRSession.Instance.HUD.SprintIcon.enabled = + !IsRoomCrouching && !PlayerController.isCrouching && isSprinting; } else PlayerControllerB_Sprint_Patch.sprint = !IsRoomCrouching && Actions.Instance["Sprint"].IsPressed() ? 1 : 0; diff --git a/Source/UI/VRHUD.cs b/Source/UI/VRHUD.cs index 745d47de..2927adcd 100644 --- a/Source/UI/VRHUD.cs +++ b/Source/UI/VRHUD.cs @@ -24,6 +24,7 @@ public class VRHUD : MonoBehaviour private GameObject redGlowBodyParts; private GameObject weightUi; private GameObject pttIcon; + private GameObject sprintIcon; private GameObject clock; private GameObject battery; private GameObject inventory; @@ -73,6 +74,11 @@ public class VRHUD : MonoBehaviour /// public NonNativeKeyboard TerminalKeyboard { get; internal set; } + /// + /// The sprint icon used for toggle sprint + /// + public Image SprintIcon { get; private set; } + private void Awake() { // Create canvasses @@ -168,7 +174,13 @@ private void Awake() redGlowBodyParts = GameObject.Find("RedGlowBodyParts"); weightUi = GameObject.Find("WeightUI"); pttIcon = GameObject.Find("PTTIcon"); + + sprintIcon = Instantiate(pttIcon, pttIcon.transform.parent); + sprintIcon.name = "SprintIcon"; + sprintIcon.GetComponent().sprite = AssetManager.SprintImage; + SprintIcon = sprintIcon.GetComponent(); + if (Plugin.Config.DisableArmHUD.Value) { selfRed.transform.SetParent(FaceCanvas.transform, false); @@ -177,6 +189,7 @@ private void Awake() redGlowBodyParts.transform.SetParent(FaceCanvas.transform, false); weightUi.transform.SetParent(FaceCanvas.transform, false); pttIcon.transform.SetParent(FaceCanvas.transform, false); + sprintIcon.transform.SetParent(FaceCanvas.transform, false); selfRed.transform.localPosition = self.transform.localPosition = @@ -184,19 +197,22 @@ private void Awake() sprintMeter.transform.localPosition = new Vector3(-284 + xOffset, 80 + yOffset, 0); weightUi.transform.localPosition = new Vector3(-195 + xOffset, 25 + yOffset, 0); pttIcon.transform.localPosition = new Vector3(-195 + xOffset, 165 + yOffset, 0); + sprintIcon.transform.localPosition = new Vector3(-175 + xOffset, 115 + yOffset, 0); selfRed.transform.localRotation = self.transform.localRotation = sprintMeter.transform.localRotation = redGlowBodyParts.transform.localRotation = weightUi.transform.localRotation = - pttIcon.transform.localRotation = Quaternion.identity; + pttIcon.transform.localRotation = + sprintIcon.transform.localRotation = Quaternion.identity; selfRed.transform.localScale = self.transform.localScale = sprintMeter.transform.localScale = redGlowBodyParts.transform.localScale = - pttIcon.transform.localScale = Vector3.one * 2; + pttIcon.transform.localScale = + sprintIcon.transform.localScale = Vector3.one * 2; weightUi.transform.localScale = Vector3.one; weightUi.transform.Find("Weight").localScale = Vector3.one * 1.4f; @@ -213,6 +229,7 @@ private void Awake() redGlowBodyParts.transform.SetParent(LeftHandCanvas.transform, false); weightUi.transform.SetParent(LeftHandCanvas.transform, false); pttIcon.transform.SetParent(LeftHandCanvas.transform, false); + sprintIcon.transform.SetParent(LeftHandCanvas.transform, false); selfRed.transform.localPosition = self.transform.localPosition = @@ -220,21 +237,23 @@ private void Awake() sprintMeter.transform.localPosition = new Vector3(-50, 100, 72); weightUi.transform.localPosition = new Vector3(-50, 80, 65); pttIcon.transform.localPosition = new Vector3(-50, 145, 35); + sprintIcon.transform.localPosition = new Vector3(-50, 124, 22); - // idk what the official formatting rule is for this kind of code but I guess this looks fine selfRed.transform.localRotation = self.transform.localRotation = sprintMeter.transform.localRotation = redGlowBodyParts.transform.localRotation = weightUi.transform.localRotation = - pttIcon.transform.localRotation = Quaternion.Euler(0, 90, 0); + pttIcon.transform.localRotation = + sprintIcon.transform.localRotation = Quaternion.Euler(0, 90, 0); selfRed.transform.localScale = self.transform.localScale = sprintMeter.transform.localScale = redGlowBodyParts.transform.localScale = weightUi.transform.localScale = - pttIcon.transform.localScale = Vector3.one; + pttIcon.transform.localScale = + sprintIcon.transform.localScale = Vector3.one; weightUi.transform.Find("Weight").localScale = Vector3.one * 0.7f; } @@ -518,6 +537,7 @@ public void HideHUD(bool hide) redGlowBodyParts.SetActive(!hide); weightUi.SetActive(!hide); pttIcon.SetActive(!hide); + sprintIcon.SetActive(!hide); // Keep clock UI for spectators to be able to see the time