Skip to content

Commit

Permalink
Fixed stuck in menu if trying to change setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Raicuparta committed Aug 20, 2020
1 parent 89a1334 commit 7d01dbb
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions NomaiVR/UI/Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class Behaviour : MonoBehaviour
private static bool _shouldRenderStarLogos;
private static readonly List<Canvas> patchedCanvases = new List<Canvas>();
private static readonly string[] _ignoredCanvases = { "LoadManagerFadeCanvas", "PauseBackdropCanvas" };
private readonly List<GameObject> _canvasObjectsToHide = new List<GameObject>();
private Camera _flashbackCamera;
private Transform _flashbackCameraParent;
private GameObject _canvasParent;
private bool _isCanvasObjectsActive;

internal void Start()
{
SetUpCanvasParent();
if (SceneHelper.IsInGame())
{
SetUpFlashbackCameraParent();
Expand All @@ -43,26 +43,32 @@ internal void Start()

internal void Update()
{
if (_canvasParent.activeSelf && !IsMenuInteractionAllowed())
UpdateCanvasObjectsActive();
}

private void UpdateCanvasObjectsActive()
{
if (_isCanvasObjectsActive && !IsMenuInteractionAllowed())
{
_canvasParent.SetActive(false);
SetCanvasObjectsActive(false);
return;
}
if (!_canvasParent.activeSelf && IsMenuInteractionAllowed())
if (!_isCanvasObjectsActive && IsMenuInteractionAllowed())
{
_canvasParent.SetActive(true);
SetCanvasObjectsActive(true);
return;
}
}

private bool IsMenuInteractionAllowed()
private void SetCanvasObjectsActive(bool active)
{
return OWTime.IsPaused() || !SceneHelper.IsInGame() || PlayerState.IsSleepingAtCampfire();
_canvasObjectsToHide.ForEach(canvasObject => canvasObject.SetActive(active));
_isCanvasObjectsActive = active;
}

private void SetUpCanvasParent()
private bool IsMenuInteractionAllowed()
{
_canvasParent = new GameObject();
return OWTime.IsPaused() || !SceneHelper.IsInGame() || PlayerState.IsSleepingAtCampfire();
}

private void SetUpFlashbackCameraParent()
Expand Down Expand Up @@ -125,7 +131,7 @@ private static void FixTitleMenuCanvases()

private void AddFollowTarget(Canvas canvas)
{
canvas.transform.parent = _canvasParent.transform;
_canvasObjectsToHide.Add(canvas.gameObject);
var followTarget = canvas.gameObject.AddComponent<FollowTarget>();
if (SceneHelper.IsInGame())
{
Expand Down

0 comments on commit 7d01dbb

Please sign in to comment.