Skip to content

Commit

Permalink
MoreCompany compatibility rev 2
Browse files Browse the repository at this point in the history
- Removed Spin Drag code since it was broken for a while already
  • Loading branch information
DaXcess committed Oct 24, 2024
1 parent 7713a36 commit a77b599
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 77 deletions.
14 changes: 11 additions & 3 deletions Source/Compatibility/MoreCompany/MoreCompanyCompatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LCVR.Compatibility.MoreCompany;

internal static class MoreCompanyCompatibility
{
public static void SetupMoreCompanyUI()
public static void SetupMoreCompanyUIMainMenu()
{
var overlay = GameObject.Find("TestOverlay(Clone)");
var menuContainer = GameObject.Find("MenuContainer");
Expand All @@ -19,8 +19,16 @@ public static void SetupMoreCompanyUI()
canvasUi.transform.localScale = Vector3.one;

var activateButton = canvasUi.Find("ActivateButton");
activateButton.transform.localPosition = new Vector3(activateButton.transform.localPosition.x, activateButton.transform.localPosition.y, 90);
activateButton.transform.localPosition = new Vector3(activateButton.transform.localPosition.x,
activateButton.transform.localPosition.y, 90);

overlay.Find("CanvasCam").SetActive(false);
}
}

public static void SetupMoreCompanyUIInGame()
{
var canvasUi = GameObject.Find("Systems/UI/Canvas/GlobalScale");

canvasUi.transform.localPosition = new Vector3(0, 0, -90);
}
}
77 changes: 4 additions & 73 deletions Source/Compatibility/MoreCompany/Patches.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using HarmonyLib;
using LCVR.Patches;
using MoreCompany.Behaviors;
using MoreCompany.Cosmetics;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.XR.Interaction.Toolkit;

namespace LCVR.Compatibility.MoreCompany;

Expand All @@ -13,78 +9,13 @@ namespace LCVR.Compatibility.MoreCompany;
internal static class MoreCompanyUIPatches
{
/// <summary>
/// Not too sure why this was needed, probably had to do with me moving the UI around in the GameObject hierarchy
/// Yeah... I'm completely lost on this one
/// </summary>
[HarmonyPatch(typeof(CosmeticRegistry), nameof(CosmeticRegistry.UpdateCosmeticsOnDisplayGuy))]
[HarmonyPostfix]
private static void AfterUpdateCosmetics()
{
CosmeticRegistry.displayGuyCosmeticApplication.spawnedCosmetics.Do(cosmetic => cosmetic.transform.localScale *= 0.5f);
CosmeticRegistry.displayGuyCosmeticApplication.spawnedCosmetics.Do(cosmetic =>
cosmetic.transform.localScale *= CosmeticRegistry.menuIsInGame ? 2.15f : 0.5f);
}

// Spin dragger patches
private static int pointer = -1;
private static XRRayInteractor leftInteractor;
private static XRRayInteractor rightInteractor;
private static Vector2 lastRayPosition = Vector2.zero;
private static Vector3 rotationalVelocity = Vector3.zero;

[HarmonyPatch(typeof(SpinDragger), nameof(SpinDragger.Update))]
[HarmonyPrefix]
private static bool UpdateSpinDragger(SpinDragger __instance)
{
if (pointer != -1)
{
var position = Vector2.zero;

var interactor = (pointer == 1 ? rightInteractor : leftInteractor);
if (interactor.TryGetCurrentUIRaycastResult(out var res))
position = res.screenPosition;

var delta = position - lastRayPosition;
rotationalVelocity = new Vector3(0, -delta.x, 0) * __instance.dragSpeed;
lastRayPosition = position;
}

rotationalVelocity *= __instance.airDrag;

__instance.target.transform.Rotate(rotationalVelocity * Time.deltaTime * __instance.speed, Space.World);

return false;
}

[HarmonyPatch(typeof(SpinDragger), nameof(SpinDragger.OnPointerDown))]
[HarmonyPrefix]
private static bool OnPointerDown(SpinDragger __instance, PointerEventData eventData)
{
__instance.dragSpeed = 10;

leftInteractor = GameObject.Find("Left Controller").GetComponent<XRRayInteractor>();
rightInteractor = GameObject.Find("Right Controller").GetComponent<XRRayInteractor>();

pointer = eventData.pointerId;

if (pointer != 1 && pointer != 2)
{
pointer = -1;
return false;
}

var interactor = (pointer == 1 ? rightInteractor : leftInteractor);
if (interactor.TryGetCurrentUIRaycastResult(out var res))
lastRayPosition = res.screenPosition;
else
lastRayPosition = Vector2.zero;

return false;
}

[HarmonyPatch(typeof(SpinDragger), nameof(SpinDragger.OnPointerUp))]
[HarmonyPrefix]
private static bool OnPointerUp()
{
pointer = -1;

return false;
}
}
}
2 changes: 1 addition & 1 deletion Source/Patches/UIPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static void OnMainMenuShown(MenuManager __instance)
InitMenuScene(canvas);

if (Compat.IsLoaded(Compat.MoreCompany))
Compatibility.MoreCompany.MoreCompanyCompatibility.SetupMoreCompanyUI();
Compatibility.MoreCompany.MoreCompanyCompatibility.SetupMoreCompanyUIMainMenu();

if (__instance.isInitScene)
return;
Expand Down
4 changes: 4 additions & 0 deletions Source/UI/VRHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ private void Awake()

// Set up belt bag UI
FindObjectOfType<BeltBagInventoryUI>(true).gameObject.AddComponent<BeltBagUI>();

// MoreCompany compatibility
if (Compat.IsLoaded(Compat.MoreCompany))
Compatibility.MoreCompany.MoreCompanyCompatibility.SetupMoreCompanyUIInGame();
}

private static void MoveToFront(Component component)
Expand Down

0 comments on commit a77b599

Please sign in to comment.