Skip to content

Commit

Permalink
No longer forcing minimal UI, showing decent prompts everywhere, incl…
Browse files Browse the repository at this point in the history
…uding tutorials. (#157)

* Decent prompts now

* Hide reticule and examine prompts

* Hide read prompt too

* Tutorials!

* Remove extra spaces from prompts

* Cleanup

* Fix scroll prompts

* Hide map and compass prompts

* Show jogging tutorial instead of zoom.

* Hide one of the settings tab prompts

* Show cancel in inventory prompt

* Scale down UI

* Auto update prompts when connecting controllers. (#161)

* Auto update prompts when connecting controllers.

* Check specific sources

* Revert logs changes
  • Loading branch information
Raicuparta authored Feb 8, 2022
1 parent e4a26be commit 46668f8
Show file tree
Hide file tree
Showing 22 changed files with 338 additions and 114 deletions.
14 changes: 7 additions & 7 deletions TwoForksVr/src/LaserPointer/VrLaser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using TwoForksVr.Helpers;
using TwoForksVr.VrInput;
using TwoForksVr.VrInput.ActionInputs;
using UnityEngine;
using Valve.VR;

Expand All @@ -8,7 +8,7 @@ namespace TwoForksVr.LaserPointer
public class VrLaser : MonoBehaviour
{
private const float laserLength = 1f;
private readonly SteamVR_Action_Boolean inputAction = BindingsManager.ActionSet.Interact;
private readonly IActionInput actionInput = ActionInputDefinitions.Interact;
private bool ignoreNextInput;

private LaserInputModule inputModule;
Expand Down Expand Up @@ -61,7 +61,7 @@ private void Update()

private void UpdateLaserParent(SteamVR_Input_Sources inputSource, Transform hand)
{
if (!inputAction.GetStateDown(inputSource) || transform.parent == hand) return;
if (!actionInput.GetButtonDown(inputSource) || transform.parent == hand) return;
ignoreNextInput = true;
transform.SetParent(hand, false);
}
Expand All @@ -87,13 +87,13 @@ private bool HasCurrentTarget()
private void UpdateLaserVisibility()
{
lineRenderer.enabled =
HasCurrentTarget() || BindingsManager.ActionSet.Interact.state;
HasCurrentTarget() || ActionInputDefinitions.Interact.AxisValue != 0;
}

public bool ClickDown()
{
if (ignoreNextInput) return false;
return inputAction.stateDown;
return actionInput.ButtonDown;
}

public bool ClickUp()
Expand All @@ -104,12 +104,12 @@ public bool ClickUp()
return false;
}

return inputAction.stateUp;
return actionInput.ButtonUp;
}

public bool IsClicking()
{
return inputAction.state;
return actionInput.ButtonValue;
}
}
}
6 changes: 3 additions & 3 deletions TwoForksVr/src/Limbs/VrHand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using TwoForksVr.Assets;
using TwoForksVr.Helpers;
using TwoForksVr.VrInput;
using TwoForksVr.VrInput.ActionInputs;
using UnityEngine;
using Valve.VR;

Expand Down Expand Up @@ -49,12 +49,12 @@ private void SetUpPose()
if (isLeft)
{
pose.inputSource = SteamVR_Input_Sources.LeftHand;
pose.poseAction = BindingsManager.ActionSet.PoseLeftHand;
pose.poseAction = ActionInputDefinitions.ActionSet.PoseLeftHand;
}
else
{
pose.inputSource = SteamVR_Input_Sources.RightHand;
pose.poseAction = BindingsManager.ActionSet.PoseRightHand;
pose.poseAction = ActionInputDefinitions.ActionSet.PoseRightHand;
}
}

Expand Down
10 changes: 5 additions & 5 deletions TwoForksVr/src/Locomotion/TeleportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using TwoForksVr.Limbs;
using TwoForksVr.Settings;
using TwoForksVr.Stage;
using TwoForksVr.VrInput;
using TwoForksVr.VrInput.ActionInputs;
using UnityEngine;
using Valve.VR;

Expand All @@ -11,7 +11,7 @@ namespace TwoForksVr.Locomotion
public class TeleportController : MonoBehaviour
{
private const float triggerTeleportSquareDistance = 0.3f;
private static readonly SteamVR_Action_Boolean teleportInput = BindingsManager.ActionSet.Teleport;
private static readonly IActionInput teleportInput = ActionInputDefinitions.Teleport;
private VrLimbManager limbManager;
private vgPlayerNavigationController navigationController;
private TeleportArc teleportArc;
Expand All @@ -36,8 +36,8 @@ public void SetUp(vgPlayerController playerController)

private void Update()
{
if (teleportInput.GetStateDown(SteamVR_Input_Sources.LeftHand)) SetHand(limbManager.LeftHand);
if (teleportInput.GetStateDown(SteamVR_Input_Sources.RightHand)) SetHand(limbManager.RightHand);
if (teleportInput.GetButtonDown(SteamVR_Input_Sources.LeftHand)) SetHand(limbManager.LeftHand);
if (teleportInput.GetButtonDown(SteamVR_Input_Sources.RightHand)) SetHand(limbManager.RightHand);
UpdateArc();
UpdatePlayerRotation();
}
Expand All @@ -61,7 +61,7 @@ public bool IsNextToTeleportMarker(Transform objectTransform)
public bool IsTeleporting()
{
return VrSettings.Teleport.Value &&
teleportInput.GetState(SteamVR_Input_Sources.Any) && navigationController &&
teleportInput.ButtonValue && navigationController &&
navigationController.enabled && !vgPauseManager.Instance.isPaused;
}

Expand Down
8 changes: 4 additions & 4 deletions TwoForksVr/src/Locomotion/TurningController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using TwoForksVr.Settings;
using TwoForksVr.Stage;
using TwoForksVr.VrCamera;
using TwoForksVr.VrInput;
using TwoForksVr.VrInput.ActionInputs;
using UnityEngine;

namespace TwoForksVr.Locomotion
Expand Down Expand Up @@ -45,13 +45,13 @@ private void Update()

private void UpdateSnapTurning()
{
if (BindingsManager.ActionSet.SnapTurnLeft.stateDown)
if (ActionInputDefinitions.SnapTurnLeft.ButtonDown)
{
stage.FadeToBlack();
Invoke(nameof(SnapTurnLeft), FadeOverlay.Duration);
}

if (BindingsManager.ActionSet.SnapTurnRight.stateDown)
if (ActionInputDefinitions.SnapTurnRight.ButtonDown)
{
stage.FadeToBlack();
Invoke(nameof(SnapTurnRight), FadeOverlay.Duration);
Expand All @@ -62,7 +62,7 @@ private void UpdateSmoothTurning()
{
navigationController.transform.Rotate(
Vector3.up,
BindingsManager.ActionSet.Rotate.axis.x * smoothRotationSpeed * Time.unscaledDeltaTime);
ActionInputDefinitions.RotateX.AxisValue * smoothRotationSpeed * Time.unscaledDeltaTime);
}

private void SnapTurnLeft()
Expand Down
15 changes: 0 additions & 15 deletions TwoForksVr/src/Settings/Patches/SettingsPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ private static void ForceDisableHeadBob(ref bool value)
value = false;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(vgSettingsManager), nameof(vgSettingsManager.minimalInterface), MethodType.Setter)]
private static void ForceEnableMinimalInterface(ref bool value)
{
value = true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(vgSettingsManager), nameof(vgSettingsManager.MotionBlurQuality), MethodType.Setter)]
private static void ForceNoMotionBlur(ref int value)
Expand All @@ -45,13 +38,5 @@ private static bool HideResolutionOptions()
{
return false;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(vgSettingsMenuController), nameof(vgSettingsMenuController.Start))]
private static void RemoveControlsTab(vgSettingsMenuController __instance)
{
__instance.screens.RemoveAt(2);
Object.Destroy(__instance.selectionGroup.buttonElements[2].gameObject);
}
}
}
14 changes: 7 additions & 7 deletions TwoForksVr/src/Tools/ToolPicker.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using TwoForksVr.Assets;
using TwoForksVr.Helpers;
using TwoForksVr.VrInput;
using TwoForksVr.VrInput.ActionInputs;
using UnityEngine;
using Valve.VR;

Expand All @@ -11,7 +11,7 @@ public class ToolPicker : MonoBehaviour
{
private const float minSquareDistance = 0.03f;

private readonly SteamVR_Action_Boolean input = BindingsManager.ActionSet.ToolPicker;
private readonly IActionInput input = ActionInputDefinitions.ToolPicker;
private ToolPickerItem hoveredTool;
private Transform leftHand;
private Transform rightHand;
Expand Down Expand Up @@ -41,11 +41,11 @@ private void Start()

private void Update()
{
if (input.GetState(SteamVR_Input_Sources.RightHand)) UpdateSelectedTool(rightHand);
if (input.GetState(SteamVR_Input_Sources.LeftHand)) UpdateSelectedTool(leftHand);
if (input.GetStateDown(SteamVR_Input_Sources.RightHand)) OpenToolPicker(rightHand);
if (input.GetStateDown(SteamVR_Input_Sources.LeftHand)) OpenToolPicker(leftHand);
if (input.stateUp) CloseToolPicker();
if (input.GetButtonValue(SteamVR_Input_Sources.RightHand)) UpdateSelectedTool(rightHand);
if (input.GetButtonValue(SteamVR_Input_Sources.LeftHand)) UpdateSelectedTool(leftHand);
if (input.GetButtonDown(SteamVR_Input_Sources.RightHand)) OpenToolPicker(rightHand);
if (input.GetButtonDown(SteamVR_Input_Sources.LeftHand)) OpenToolPicker(leftHand);
if (input.ButtonUp) CloseToolPicker();
}

private void SetUpTools()
Expand Down
2 changes: 1 addition & 1 deletion TwoForksVr/src/UI/Patches/CanvasToWorldSpacePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static void MoveCanvasesToWorldSpace(CanvasScaler __instance)
if (canvas.GetComponent<GraphicRaycaster>())
AttachedUi.Create<InteractiveUi>(canvas, StageInstance.GetInteractiveUiTarget(), 0.002f);
else
AttachedUi.Create<StaticUi>(canvas, StageInstance.GetStaticUiTarget(), 0.0005f);
AttachedUi.Create<StaticUi>(canvas, StageInstance.GetStaticUiTarget(), 0.0004f);
}
catch (Exception exception)
{
Expand Down
27 changes: 27 additions & 0 deletions TwoForksVr/src/UI/Patches/SettingsMenuPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using HarmonyLib;
using UnityEngine;

// Some of the available game settings don't go well with VR.
// These patches force some settings to certain values to prevent VR funkyness.
namespace TwoForksVr.UI.Patches
{
[HarmonyPatch]
public class SettingsMenuPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(vgSettingsMenuController), nameof(vgSettingsMenuController.Start))]
private static void RemoveUnusedSettingsElements(vgSettingsMenuController __instance)
{
// Rmove control settings screen.
__instance.screens.RemoveAt(2);

// Remove control settings tab.
Object.Destroy(__instance.selectionGroup.buttonElements[2].gameObject);

// Remove one of the tab input prompts.
// Since the input prompts have been patched to use VR control names, both of these prompts (left and right)
// were saying the same thing (something like "Right Stick"). So we can remove one of them.
__instance.selectionGroup.transform.Find("ButtonContainer").GetChild(0).gameObject.SetActive(false);
}
}
}
70 changes: 70 additions & 0 deletions TwoForksVr/src/UI/Patches/TutorialPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.Collections.Generic;
using HarmonyLib;
using TMPro;
using TwoForksVr.Helpers;
using TwoForksVr.VrInput;
using UnityEngine;

namespace TwoForksVr.UI.Patches
{
[HarmonyPatch]
public static class TutorialPatches
{
private static readonly Dictionary<string, string> tutorialTextMap = new Dictionary<string, string>
{
{"textRadio", $"Hold [{VirtualKey.Radio}] to activate radio."},
{"textRadio_select_dialog", $"[{VirtualKey.ScrollUpDown}] to select dialog."},
{"textUse_radio", $"Release [{VirtualKey.Radio}] to talk to Delilah."},
{"textInspect_object", "Look at hand to inspect objects."},
{"textInspect_object_move", ""},
{"textRadio_object", $"Aim with hand and hold [{VirtualKey.Radio}] to talk about targeted object."},
{"textJournal_examine", "Look at hand to inspect journal."},
{"textJournal_stow", $"[{VirtualKey.StoreObject}] to keep journal."},
{"textCompass", $"Hold [{VirtualKey.ToolPicker}] to select compass from tool picker."},
{"textFlashlight", $"Hold [{VirtualKey.ToolPicker}] to select flashlight from tool picker."},
{"textMap", $"Hold [{VirtualKey.ToolPicker}] to select map from tool picker."},
{"textJog_toggle", $"[{VirtualKey.Jog}] to toggle jogging."},
{"textMantle", $"[{VirtualKey.LocomotionAction}] to climb over obstructions."},
{"textUse_object", $"Aim with hand and press [{VirtualKey.Use}] to use objects."},
{"textInventory_open", $"Hold [{VirtualKey.ToolPicker}] to select notes inventory from the tool picker."},
{"textInventory_browse", "Use hand laser to browse notes."},
{"textInventory_read", $"[{VirtualKey.StoreObject}] to store note"},
{"textCamera", $"Hold [{VirtualKey.ToolPicker}] to select camera from tool picker."},
{"textCamera_picture", $"[{VirtualKey.Use}] to take a picture."},
{"textCamera_lower", $"Press [{VirtualKey.ToolPicker}] to lower camera."},
{"textWaveReceiver", $"Hold [{VirtualKey.ToolPicker}] to select wave receiver from tool picker."},
{"textRadio_concept", $"Hold [{VirtualKey.Radio}] to radio about current subject of interest."},
{"textRadio_heldobject", $"Hold [{VirtualKey.Radio}] to talk about currently held object."},

// There's no zooming in VR. Couldn't figure out an easy way to hide the whole tutorial box,
// so I'm just showing the jogging tutorial instead.
{"textZoom", $"[{VirtualKey.Jog}] to toggle jogging."},

// Unused tutorial text.
{"Text", ""}
};

[HarmonyPrefix]
[HarmonyPatch(typeof(vgHudManager), nameof(vgHudManager.Awake))]
private static void SetUpTutorials(vgHudManager __instance)
{
var tutorialObject =
__instance.transform.Find(
"uGUI Root/HUD/SafeZoner/BottomCenterGroup/TutorialPopup/TutorialPopupParent/TutorialObject");

Logs.LogInfo($"Found {tutorialObject.childCount} tutorials");
foreach (Transform child in tutorialObject)
{
Logs.LogInfo($"{child.name}: {child.GetComponent<TextMeshProUGUI>().text}");
tutorialTextMap.TryGetValue(child.name, out var tutorialString);
if (tutorialString == null)
{
Logs.LogError($"No tutorial text found for {child.name}");
continue;
}

child.GetComponent<TextMeshProUGUI>().text = tutorialString;
}
}
}
}
21 changes: 21 additions & 0 deletions TwoForksVr/src/UI/Patches/UIPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,26 @@ private static void PreventTextFromDrawingOnTop(TextMeshProUGUI __instance)
Logs.LogWarning($"Error in TMPro Patch ({__instance.name}): {exception}");
}
}

[HarmonyPostfix]
[HarmonyPatch(typeof(vgHudManager), nameof(vgHudManager.Awake))]
private static void HideHudElements(vgHudManager __instance)
{
__instance.readObjectButtonGroup.transform.parent.Find("ExamineItem").gameObject.SetActive(false);
__instance.readObjectButtonGroup.SetActive(false);

// Dummy object is just so the hud manager still has a valid reference after we destroy the object.
__instance.readObjectButtonGroup = new GameObject("Dummy");
__instance.readObjectButtonGroup.transform.SetParent(__instance.transform, false);

var safeZoner = __instance.transform.Find("uGUI Root/HUD/SafeZoner");
var reticule = safeZoner.Find("ReticuleGroup/ReticuleParent/ReticuleCanvasGroup/Reticule");
reticule.GetComponent<Image>().enabled = false;
reticule.Find("ReticuleLarge").GetComponent<Image>().enabled = false;

var bottomLeftObjects = safeZoner.Find("BottomLeftObjects");
bottomLeftObjects.Find("CompassOnScreenTooltip").gameObject.SetActive(false);
bottomLeftObjects.Find("MapOnScreenTooltip").gameObject.SetActive(false);
}
}
}
4 changes: 2 additions & 2 deletions TwoForksVr/src/VrCamera/VrCameraManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using TwoForksVr.Helpers;
using TwoForksVr.Stage;
using TwoForksVr.VrInput;
using TwoForksVr.VrInput.ActionInputs;
using UnityEngine;
using UnityEngine.XR;
using UnityStandardAssets.ImageEffects;
Expand Down Expand Up @@ -42,7 +42,7 @@ private void Start()

private void Update()
{
if (BindingsManager.ActionSet.Recenter.stateDown) RecenterPosition(true);
if (ActionInputDefinitions.Recenter.ButtonDown) RecenterPosition(true);
UpdateCulling();
}

Expand Down
Loading

0 comments on commit 46668f8

Please sign in to comment.