From 9a617e9c1680997698a326e75ca274bad7dafa0e Mon Sep 17 00:00:00 2001 From: artum Date: Mon, 23 Jan 2023 23:03:59 +0100 Subject: [PATCH] Change tool hiding logic in the dream (#531) --- NomaiVR/Tools/HoldTranslator.cs | 1 - NomaiVR/Tools/HolsterTool.cs | 14 ++++++++++++-- NomaiVR/Tools/VRToolSwapper.cs | 12 ++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/NomaiVR/Tools/HoldTranslator.cs b/NomaiVR/Tools/HoldTranslator.cs index f2d7da80..2c8ca2bc 100644 --- a/NomaiVR/Tools/HoldTranslator.cs +++ b/NomaiVR/Tools/HoldTranslator.cs @@ -177,7 +177,6 @@ public override void ApplyPatches() { Postfix(nameof(ToolModeSwapper.IsTranslatorEquipPromptAllowed), nameof(IsPromptAllowed)); Postfix(nameof(ToolModeSwapper.GetAutoEquipTranslator), nameof(IsPromptAllowed)); - Postfix(nameof(ToolModeSwapper.IsNomaiTextInFocus), nameof(IsPromptAllowed)); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Unusued parameter is needed for return value passthrough.")] diff --git a/NomaiVR/Tools/HolsterTool.cs b/NomaiVR/Tools/HolsterTool.cs index 4bf6a05c..6701bcd6 100644 --- a/NomaiVR/Tools/HolsterTool.cs +++ b/NomaiVR/Tools/HolsterTool.cs @@ -16,6 +16,7 @@ internal class HolsterTool : MonoBehaviour public float scale; private MeshRenderer[] renderers; private bool visible = true; + private bool showInDream = false; private int equippedIndex = -1; private Transform hand; public Action ONUnequip; @@ -100,13 +101,22 @@ private void OnGripUpdated(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sour private bool IsHandNear(Transform hand) => (hand.position - cachedTransform.position).sqrMagnitude < minHandDistance; + private void UpdateDreamVisibility(bool isInDream) + { + if (!isInDream) showInDream = false; + else showInDream |= (mode == ToolMode.Translator && VRToolSwapper.NomaiTextFocused); + } + private void UpdateVisibility() { var isCharacterMode = OWInput.IsInputMode(InputMode.Character); - var isInDream = Locator.GetDreamWorldController() != null && Locator.GetDreamWorldController().IsInDream(); var isHoldingVisionTorch = Locator.GetToolModeSwapper()?.GetItemCarryTool()?.GetHeldItemType() == ItemType.VisionTorch; var isHandClose = !ModSettings.AutoHideToolbelt || IsHandNear(HandsController.Behaviour.RightHand) || IsHandNear(HandsController.Behaviour.LeftHand); - var shouldBeVisible = !ToolHelper.IsUsingAnyTool() && isCharacterMode && !isInDream && !isHoldingVisionTorch && isHandClose; + var isInDream = Locator.GetDreamWorldController() != null && Locator.GetDreamWorldController().IsInDream(); + + UpdateDreamVisibility(isInDream); + + var shouldBeVisible = !ToolHelper.IsUsingAnyTool() && isCharacterMode && (!isInDream || showInDream) && !isHoldingVisionTorch && isHandClose; if (!visible && shouldBeVisible) { diff --git a/NomaiVR/Tools/VRToolSwapper.cs b/NomaiVR/Tools/VRToolSwapper.cs index c4d3a9d5..91a32486 100644 --- a/NomaiVR/Tools/VRToolSwapper.cs +++ b/NomaiVR/Tools/VRToolSwapper.cs @@ -19,6 +19,8 @@ internal class VRToolSwapper : NomaiVRModule toolsAllowedToEquip = new Dictionary() { { ToolMode.Item, true } }; @@ -72,6 +74,7 @@ public override void ApplyPatches() { Prefix(nameof(ToolModeSwapper.EquipToolMode), nameof(PreEquipTool)); Prefix(nameof(ShipCockpitController.OnPressInteract), nameof(PreShipCockpitController)); + Postfix(nameof(ToolModeSwapper.IsNomaiTextInFocus), nameof(PreIsNomaiTextInFocus)); } private static void PreShipCockpitController() @@ -83,6 +86,15 @@ private static bool PreEquipTool(ToolMode mode) { return IsAllowedToEquip(mode); } + + + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Unusued parameter is needed for return value passthrough.")] + private static bool PreIsNomaiTextInFocus(bool __result) + { + NomaiTextFocused = __result; + return false; + } } } } \ No newline at end of file