Skip to content

Commit

Permalink
Fix bag UI destruction bug and publicize setting
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Sep 5, 2024
1 parent d3ca274 commit c827f4e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Source/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public class Config(string assemblyPath, ConfigFile file)
public ConfigEntry<float> LODBias { get; } = file.Bind("Rendering", "LODBias", 2f, new ConfigDescription("The LOD bias is a multiplier that dictates when an LOD must reduce their quality. Higher values means that more detailed LODs will persist for longer.", new AcceptableValueRange<float>(1, 5)));
public ConfigEntry<bool> DisableLensDistortion { get; } = file.Bind("Rendering", "DisableLensDistortion", false, "Disables the warping effects that you experience when you are under water, use the TZP-inhalant and more.");
public ConfigEntry<bool> SpectatorLightRemovesVolumetrics { get; } = file.Bind("Rendering", "SpectatorLightRemovesVolumetrics", false, "When spectating, also disable all volumetrics (fog) while the fullbright lighting is enabled for more visibility.");
public ConfigEntry<float> MirrorXOffset { get; } = file.Bind("Internal", "MirrorXOffset", 0f, "The X offset that is added to the XR Mirror View shader. Do not touch if you don't know what this means.");
public ConfigEntry<float> MirrorYOffset { get; } = file.Bind("Internal", "MirrorYOffset", 0f, "The Y offset that is added to the XR Mirror View shader. Do not touch if you don't know what this means.");
public ConfigEntry<float> MirrorXOffset { get; } = file.Bind("Rendering", "MirrorXOffset", 0f, new ConfigDescription("The X offset that is added to the XR Mirror View shader. Do not touch if you don't know what this means.", new AcceptableValueRange<float>(-1, 1)));
public ConfigEntry<float> MirrorYOffset { get; } = file.Bind("Rendering", "MirrorYOffset", 0f, new ConfigDescription("The Y offset that is added to the XR Mirror View shader. Do not touch if you don't know what this means.", new AcceptableValueRange<float>(-1, 1)));

// Interaction configuration

Expand Down
8 changes: 7 additions & 1 deletion Source/Items/VRBeltBagItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public class VRBeltBagItem : VRItem<BeltBagItem>
protected override void Awake()
{
base.Awake();


if (!IsLocal)
return;

shake = new ShakeDetector(transform, 0.06f, true);
shakeBig = new ShakeDetector(transform, 0.1f, true);
inventoryUI = FindObjectOfType<BeltBagInventoryUI>(true);
Expand Down Expand Up @@ -57,6 +60,9 @@ protected override void Awake()

protected override void OnUpdate()
{
if (!IsLocal)
return;

shake.Update();
shakeBig.Update();
}
Expand Down
36 changes: 16 additions & 20 deletions Source/UI/BeltBagUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ namespace LCVR.UI;

public class BeltBagUI : MonoBehaviour
{
private const float UI_SCALE_GROUNDED = 0.004f;
private const float UI_SCALE_IN_HAND = 0.003f;
private const float UI_SCALE_GROUNDED = 0.002f;
private const float UI_SCALE_IN_HAND = 0.0015f;

private BeltBagInventoryUI inventoryUI;
private BeltBagItem currentBeltBag;
private Canvas canvas;

private void Awake()
Expand All @@ -33,10 +32,10 @@ private void Awake()
beltUI.SetParent(canvas.transform, false);
beltUI.localPosition = Vector3.zero;
beltUI.localRotation = Quaternion.identity;

// Remove X button
beltUI.transform.Find("Buttons/ExitButton").gameObject.SetActive(false);

// Set up interactables
for (var i = 0; i < inventoryUI.inventorySlots.Length; i++)
{
Expand All @@ -54,35 +53,32 @@ private void Update()
if (inventoryUI.currentBeltBag is null)
return;

if (inventoryUI.currentBeltBag != currentBeltBag)
UpdateCanvas();

currentBeltBag = inventoryUI.currentBeltBag;

if (currentBeltBag.playerHeldBy is null)
if (inventoryUI.currentBeltBag.playerHeldBy is null)
UpdateGrounded();
else if (currentBeltBag.playerHeldBy == StartOfRound.Instance.localPlayerController)
else if (inventoryUI.currentBeltBag.playerHeldBy == StartOfRound.Instance.localPlayerController)
UpdateHand();
}

private void UpdateCanvas()
private void LateUpdate()
{
if (inventoryUI.currentBeltBag is null)
return;

var itemTransform = inventoryUI.currentBeltBag.transform;
var canvasTransform = canvas.transform;

canvasTransform.SetParent(itemTransform);
canvasTransform.localEulerAngles = new Vector3(290, 180, 0);
canvasTransform.localPosition = new Vector3(0, 0.2f, 1);
canvasTransform.rotation = itemTransform.rotation * Quaternion.Euler(290, 180, 0);
canvasTransform.position = itemTransform.TransformPoint(new Vector3(0, 0.15f, 1));
}

private void UpdateGrounded()
{
if (currentBeltBag.currentPlayerChecking != StartOfRound.Instance.localPlayerController)
if (inventoryUI.currentBeltBag.currentPlayerChecking != StartOfRound.Instance.localPlayerController)
return;

canvas.transform.localScale = Vector3.one * UI_SCALE_GROUNDED;

var vpPos = VRSession.Instance.MainCamera.WorldToViewportPoint(currentBeltBag.transform.position);
var vpPos = VRSession.Instance.MainCamera.WorldToViewportPoint(inventoryUI.currentBeltBag.transform.position);
if (vpPos.x is >= 0 and <= 1 && vpPos.y is >= 0 and <= 1f && vpPos.z > 0f)
return;

Expand Down

0 comments on commit c827f4e

Please sign in to comment.