Skip to content

Commit

Permalink
Change tool hiding logic in the dream (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
artumino authored Jan 23, 2023
1 parent 4af0a10 commit 9a617e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 0 additions & 1 deletion NomaiVR/Tools/HoldTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ public override void ApplyPatches()
{
Postfix<ToolModeSwapper>(nameof(ToolModeSwapper.IsTranslatorEquipPromptAllowed), nameof(IsPromptAllowed));
Postfix<ToolModeSwapper>(nameof(ToolModeSwapper.GetAutoEquipTranslator), nameof(IsPromptAllowed));
Postfix<ToolModeSwapper>(nameof(ToolModeSwapper.IsNomaiTextInFocus), nameof(IsPromptAllowed));
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Unusued parameter is needed for return value passthrough.")]
Expand Down
14 changes: 12 additions & 2 deletions NomaiVR/Tools/HolsterTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
12 changes: 12 additions & 0 deletions NomaiVR/Tools/VRToolSwapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ internal class VRToolSwapper : NomaiVRModule<NomaiVRModule.EmptyBehaviour, VRToo
public static event Action Equipped;
public static event Action UnEquipped;

public static bool NomaiTextFocused = false;

private static readonly Dictionary<ToolMode, bool> toolsAllowedToEquip = new Dictionary<ToolMode, bool>() {
{ ToolMode.Item, true }
};
Expand Down Expand Up @@ -72,6 +74,7 @@ public override void ApplyPatches()
{
Prefix<ToolModeSwapper>(nameof(ToolModeSwapper.EquipToolMode), nameof(PreEquipTool));
Prefix<ShipCockpitController>(nameof(ShipCockpitController.OnPressInteract), nameof(PreShipCockpitController));
Postfix<ToolModeSwapper>(nameof(ToolModeSwapper.IsNomaiTextInFocus), nameof(PreIsNomaiTextInFocus));
}

private static void PreShipCockpitController()
Expand All @@ -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;
}
}
}
}

0 comments on commit 9a617e9

Please sign in to comment.