tweaks to head turn

This commit is contained in:
NotAKidoS 2023-03-03 17:57:22 -06:00
parent a8cd7122a8
commit ff70ae9652
6 changed files with 39 additions and 32 deletions

View file

@ -62,6 +62,7 @@ internal class HarmonyPatches
[HarmonyPatch(typeof(CVR_MenuManager), "UpdateMenuPosition")]
private static bool Prefix_CVR_MenuManager_UpdateMenuPosition()
{
if (QuickMenuHelper.Instance == null) return true;
return !QuickMenuHelper.Instance.MenuIsOpen;
}
@ -69,6 +70,7 @@ internal class HarmonyPatches
[HarmonyPatch(typeof(ViewManager), "UpdateMenuPosition")]
private static bool Prefix_ViewManager_UpdateMenuPosition(ref float ___cachedScreenAspectRatio)
{
if (MainMenuHelper.Instance == null) return true;
//this is called once a second, so ill fix their dumb aspect ratio shit
float ratio = (float)Screen.width / (float)Screen.height;
float clamp = Mathf.Clamp(ratio, 0f, 1.8f);

View file

@ -30,14 +30,16 @@ public class MainMenuHelper : MonoBehaviour
void LateUpdate()
{
if (MenuIsOpen)
if (!MenuIsOpen) return;
if (MSP_MenuInfo.PlayerAnchorMenus || NeedsPositionUpdate)
{
UpdateMenuPosition();
}
if (MSP_MenuInfo.UseIndependentHeadTurn)
{
MSP_MenuInfo.HandleIndependentLookInput();
if (MSP_MenuInfo.PlayerAnchorMenus)
UpdateMenuPosition();
if (NeedsPositionUpdate)
UpdateMenuPosition();
}
}
@ -64,13 +66,13 @@ public class MainMenuHelper : MonoBehaviour
}
else
{
worldAnchor.eulerAngles = MSP_MenuInfo.CameraTransform.eulerAngles;
worldAnchor.rotation = MSP_MenuInfo.CameraTransform.rotation;
}
worldAnchor.position = MSP_MenuInfo.CameraTransform.position + MSP_MenuInfo.CameraTransform.forward * 2f * MSP_MenuInfo.ScaleFactor;
}
else
{
worldAnchor.eulerAngles = MSP_MenuInfo.CameraTransform.eulerAngles;
worldAnchor.rotation = MSP_MenuInfo.CameraTransform.rotation;
worldAnchor.position = MSP_MenuInfo.CameraTransform.position;
}
if (updateMenuPos) UpdateMenuPosition();
@ -93,8 +95,8 @@ public class MainMenuHelper : MonoBehaviour
if (MSP_MenuInfo.CameraTransform == null || MSP_MenuInfo.DisableMMHelper) return;
Transform activeAnchor = MSP_MenuInfo.independentHeadTurn ? worldAnchor : MSP_MenuInfo.CameraTransform;
transform.localScale = new Vector3(1.6f * MSP_MenuInfo.ScaleFactor, 0.9f * MSP_MenuInfo.ScaleFactor, 1f);
transform.eulerAngles = activeAnchor.eulerAngles;
transform.position = activeAnchor.position + activeAnchor.forward * 1f * MSP_MenuInfo.ScaleFactor * MSP_MenuInfo.AspectRatio;
transform.rotation = activeAnchor.rotation;
}
//VR Main Menu
@ -103,6 +105,6 @@ public class MainMenuHelper : MonoBehaviour
if (worldAnchor == null || MSP_MenuInfo.DisableMMHelper_VR) return;
transform.localScale = new Vector3(1.6f * MSP_MenuInfo.ScaleFactor * 1.8f, 0.9f * MSP_MenuInfo.ScaleFactor * 1.8f, 1f);
transform.position = worldAnchor.position;
transform.eulerAngles = worldAnchor.eulerAngles;
transform.rotation = worldAnchor.rotation;
}
}

View file

@ -28,14 +28,16 @@ public class QuickMenuHelper : MonoBehaviour
void LateUpdate()
{
if (MenuIsOpen)
if (!MenuIsOpen) return;
if (MSP_MenuInfo.PlayerAnchorMenus || NeedsPositionUpdate || MetaPort.Instance.isUsingVr)
{
UpdateMenuPosition();
}
if (MSP_MenuInfo.UseIndependentHeadTurn)
{
MSP_MenuInfo.HandleIndependentLookInput();
if (MSP_MenuInfo.PlayerAnchorMenus || MetaPort.Instance.isUsingVr)
UpdateMenuPosition();
if (NeedsPositionUpdate)
UpdateMenuPosition();
}
}
@ -51,7 +53,8 @@ public class QuickMenuHelper : MonoBehaviour
public void UpdateWorldAnchors(bool updateMenuPos = false)
{
if (worldAnchor == null || MSP_MenuInfo.CameraTransform == null) return;
worldAnchor.eulerAngles = MSP_MenuInfo.CameraTransform.eulerAngles;
worldAnchor.rotation = MSP_MenuInfo.CameraTransform.rotation;
worldAnchor.position = MSP_MenuInfo.CameraTransform.position;
if (updateMenuPos) UpdateMenuPosition();
}
@ -74,7 +77,7 @@ public class QuickMenuHelper : MonoBehaviour
Transform activeAnchor = MSP_MenuInfo.independentHeadTurn ? worldAnchor : MSP_MenuInfo.CameraTransform;
transform.localScale = new Vector3(1f * MSP_MenuInfo.ScaleFactor, 1f * MSP_MenuInfo.ScaleFactor, 1f);
transform.eulerAngles = activeAnchor.eulerAngles;
transform.rotation = activeAnchor.rotation;
transform.position = activeAnchor.position + activeAnchor.transform.forward * 1f * MSP_MenuInfo.ScaleFactor;
}
@ -86,8 +89,8 @@ public class QuickMenuHelper : MonoBehaviour
if (MSP_MenuInfo.WorldAnchorQM)
{
transform.localScale = new Vector3(1f * MSP_MenuInfo.ScaleFactor, 1f * MSP_MenuInfo.ScaleFactor, 1f);
transform.eulerAngles = worldAnchor.eulerAngles;
transform.position = worldAnchor.position + worldAnchor.transform.forward * 1f * MSP_MenuInfo.ScaleFactor;
transform.rotation = worldAnchor.rotation;
return;
}
transform.localScale = new Vector3(1f * MSP_MenuInfo.ScaleFactor, 1f * MSP_MenuInfo.ScaleFactor, 1f);

View file

@ -1,6 +1,5 @@
using ABI_RC.Core;
using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using ABI_RC.Systems.MovementSystem;
using System.Reflection;
@ -31,7 +30,7 @@ public class MSP_MenuInfo
internal static readonly FieldInfo _desktopMouseModeMM = typeof(CVR_MenuManager).GetField("_desktopMouseMode", BindingFlags.NonPublic | BindingFlags.Instance);
internal static readonly FieldInfo ms_followAngleY = typeof(MovementSystem).GetField("_followAngleY", BindingFlags.NonPublic | BindingFlags.Instance);
internal static bool independentHeadTurn = false;
internal static bool isIndependentHeadTurn = false;
internal static void ToggleDesktopInputMethod(bool flag)
{
@ -42,7 +41,6 @@ public class MSP_MenuInfo
RootLogic.Instance.ToggleMouse(flag);
CVRInputManager.Instance.inputEnabled = !flag;
PlayerSetup.Instance._movementSystem.disableCameraControl = flag;
CVR_MenuManager.Instance.desktopControllerRay.enabled = !flag;
}
@ -50,20 +48,22 @@ public class MSP_MenuInfo
{
//angle of independent look axis
bool isPressed = CVRInputManager.Instance.independentHeadTurn || CVRInputManager.Instance.independentHeadToggle;
if (isPressed && !independentHeadTurn)
if (isPressed && !isIndependentHeadTurn)
{
independentHeadTurn = true;
isIndependentHeadTurn = true;
MSP_MenuInfo.ToggleDesktopInputMethod(false);
QuickMenuHelper.Instance.UpdateWorldAnchors();
MainMenuHelper.Instance.UpdateWorldAnchors();
}
else if (!isPressed && independentHeadTurn)
else if (!isPressed && isIndependentHeadTurn)
{
float angle = (float)ms_followAngleY.GetValue(MovementSystem.Instance);
if (angle == 0f)
{
independentHeadTurn = false;
isIndependentHeadTurn = false;
MSP_MenuInfo.ToggleDesktopInputMethod(true);
QuickMenuHelper.Instance.NeedsPositionUpdate = true;
MainMenuHelper.Instance.NeedsPositionUpdate = true;
}
}
}

View file

@ -25,6 +25,6 @@ using System.Reflection;
namespace NAK.Melons.MenuScalePatch.Properties;
internal static class AssemblyInfoParams
{
public const string Version = "4.2.3";
public const string Version = "4.2.5";
public const string Author = "NotAKidoS";
}

View file

@ -1,7 +1,7 @@
{
"_id": 95,
"name": "MenuScalePatch",
"modversion": "4.2.2",
"modversion": "4.2.5",
"gameversion": "2022r170",
"loaderversion": "0.5.7",
"modtype": "Mod",
@ -16,8 +16,8 @@
"requirements": [
"None"
],
"downloadlink": "https://github.com/NotAKidOnSteam/MenuScalePatch/releases/download/v4.2.2/MenuScalePatch.dll",
"downloadlink": "https://github.com/NotAKidOnSteam/MenuScalePatch/releases/download/v4.2.4/MenuScalePatch.dll",
"sourcelink": "https://github.com/NotAKidOnSteam/MenuScalePatch/",
"changelog": "- Fixed hitching & potential crash when opening menu after a long time of it being closed. Don't disable CohtmlView, only enable it.",
"changelog": "- Tweaked independent head turn implementation. Menu will now recenter after head has returned to target angle.",
"embedcolor": "804221"
}