Skip to content

Commit

Permalink
Add toggle sprint indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Sep 3, 2024
1 parent b93fc3e commit 329a18c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Source/Assets/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -75,6 +76,7 @@ public static bool LoadAssets()
KofiImage = assetBundle.LoadAsset<Sprite>("Ko-Fi");
DiscordImage = assetBundle.LoadAsset<Sprite>("Discord");
WarningImage = assetBundle.LoadAsset<Sprite>("Warning");
SprintImage = assetBundle.LoadAsset<Sprite>("Aguy");

DoorLocked = assetBundle.LoadAsset<AudioClip>("doorlocked");

Expand Down
2 changes: 2 additions & 0 deletions Source/Player/VRPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 25 additions & 5 deletions Source/UI/VRHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,6 +74,11 @@ public class VRHUD : MonoBehaviour
/// </summary>
public NonNativeKeyboard TerminalKeyboard { get; internal set; }

/// <summary>
/// The sprint icon used for toggle sprint
/// </summary>
public Image SprintIcon { get; private set; }

private void Awake()
{
// Create canvasses
Expand Down Expand Up @@ -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<Image>().sprite = AssetManager.SprintImage;

SprintIcon = sprintIcon.GetComponent<Image>();

if (Plugin.Config.DisableArmHUD.Value)
{
selfRed.transform.SetParent(FaceCanvas.transform, false);
Expand All @@ -177,26 +189,30 @@ 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 =
redGlowBodyParts.transform.localPosition = new Vector3(-284 + xOffset, 114 + yOffset, 0);
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;
Expand All @@ -213,28 +229,31 @@ 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 =
redGlowBodyParts.transform.localPosition = new Vector3(-50, 114, 75);
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;
}
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 329a18c

Please sign in to comment.