From 93e7550e8b8c378129578419efba78b9287f7fd3 Mon Sep 17 00:00:00 2001 From: Droog71 <71droog71@gmail.com> Date: Fri, 25 Sep 2020 18:54:42 -0400 Subject: [PATCH] Fixed GUI not closing properly based on distance from objects leaving mouse cursor enabled. --- BlockInteraction.cs | 6 ++++++ InteractionController.cs | 11 ++++++----- MachineInteraction.cs | 16 ++++++++-------- PlayerController.cs | 2 ++ StorageInteraction.cs | 2 ++ 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/BlockInteraction.cs b/BlockInteraction.cs index 5b33971..56b3d79 100644 --- a/BlockInteraction.cs +++ b/BlockInteraction.cs @@ -16,6 +16,7 @@ public class BlockInteraction //! Called once per frame when the player is looking at an iron block. public void InteractWithIronBlock() { + playerController.machineGUIopen = false; if (cInput.GetKeyDown("Collect Object")) { string objectName = ""; @@ -36,6 +37,7 @@ public class BlockInteraction //! Called once per frame when the player is looking at a steel block. public void InteractWithSteelBlock() { + playerController.machineGUIopen = false; if (cInput.GetKeyDown("Collect Object")) { string objectName = ""; @@ -55,6 +57,7 @@ public class BlockInteraction //! Called once per frame when the player is looking at a glass block. public void InteractWithGlass() { + playerController.machineGUIopen = false; if (cInput.GetKeyDown("Collect Object")) { interactionController.CollectObject("Glass Block"); @@ -64,6 +67,7 @@ public class BlockInteraction //! Called once per frame when the player is looking at a brick block. public void InteractWithBricks() { + playerController.machineGUIopen = false; if (cInput.GetKeyDown("Collect Object")) { interactionController.CollectObject("Brick"); @@ -73,6 +77,7 @@ public class BlockInteraction //! Called once per frame when the player is looking at a combined mesh object. public void InteractWithCombinedMesh() { + playerController.machineGUIopen = false; playerController.lookingAtCombinedMesh = true; if (cInput.GetKeyDown("Collect Object") && playerController.paintGunActive == false) { @@ -119,6 +124,7 @@ public class BlockInteraction private IEnumerator PaintMesh(GameObject[] holders, string name) { + playerController.machineGUIopen = false; BlockDictionary blockDictionary = new BlockDictionary(playerController); Color color = new Color(playerController.paintRed, playerController.paintGreen, playerController.paintBlue); foreach (GameObject holder in holders) diff --git a/InteractionController.cs b/InteractionController.cs index 21fa0b7..879e914 100644 --- a/InteractionController.cs +++ b/InteractionController.cs @@ -154,6 +154,10 @@ public class InteractionController : MonoBehaviour { playerController.objectInSight = obj; } + else + { + EndInteraction(); + } } else { @@ -217,7 +221,7 @@ public class InteractionController : MonoBehaviour } //! Opens the machine GUI. - public void OpenMachineGUI() + public void ToggleMachineGUI() { if (playerController.machineGUIopen == false) { @@ -260,10 +264,7 @@ public class InteractionController : MonoBehaviour //! Called when the player is no longer looking at any interactive objects. private void EndInteraction() { - if (playerController.machineGUIopen == true) - { - playerController.machineGUIopen = false; - } + playerController.machineGUIopen = false; playerController.lookingAtCombinedMesh = false; playerController.objectInSight = null; playerController.machineInSight = null; diff --git a/MachineInteraction.cs b/MachineInteraction.cs index 57d534f..1604402 100644 --- a/MachineInteraction.cs +++ b/MachineInteraction.cs @@ -100,7 +100,7 @@ public class MachineInteraction } if (cInput.GetKeyDown("Interact")) { - interactionController.OpenMachineGUI(); + interactionController.ToggleMachineGUI(); } } @@ -137,7 +137,7 @@ public class MachineInteraction } if (cInput.GetKeyDown("Interact")) { - interactionController.OpenMachineGUI(); + interactionController.ToggleMachineGUI(); } } @@ -158,7 +158,7 @@ public class MachineInteraction } if (cInput.GetKeyDown("Interact")) { - interactionController.OpenMachineGUI(); + interactionController.ToggleMachineGUI(); } } @@ -181,7 +181,7 @@ public class MachineInteraction } if (cInput.GetKeyDown("Interact")) { - interactionController.OpenMachineGUI(); + interactionController.ToggleMachineGUI(); } } @@ -203,7 +203,7 @@ public class MachineInteraction } if (cInput.GetKeyDown("Interact")) { - interactionController.OpenMachineGUI(); + interactionController.ToggleMachineGUI(); } } @@ -421,7 +421,7 @@ public class MachineInteraction } if (cInput.GetKeyDown("Interact")) { - interactionController.OpenMachineGUI(); + interactionController.ToggleMachineGUI(); } } @@ -499,7 +499,7 @@ public class MachineInteraction } if (cInput.GetKeyDown("Interact")) { - interactionController.OpenMachineGUI(); + interactionController.ToggleMachineGUI(); } } @@ -737,7 +737,7 @@ public class MachineInteraction } if (cInput.GetKeyDown("Interact")) { - interactionController.OpenMachineGUI(); + interactionController.ToggleMachineGUI(); } } diff --git a/PlayerController.cs b/PlayerController.cs index 360dcc7..8f0ab06 100644 --- a/PlayerController.cs +++ b/PlayerController.cs @@ -751,6 +751,7 @@ public class PlayerController : MonoBehaviour if (distance > 40) { storageGUIopen = false; + inventoryOpen = false; } } else @@ -759,6 +760,7 @@ public class PlayerController : MonoBehaviour if (distance > 40) { storageGUIopen = false; + inventoryOpen = false; } } } diff --git a/StorageInteraction.cs b/StorageInteraction.cs index 14a6d97..cca9233 100644 --- a/StorageInteraction.cs +++ b/StorageInteraction.cs @@ -15,6 +15,7 @@ public class StorageInteraction //! Called when the player is looking at a storage container. public void InteractWithStorageContainer() { + playerController.machineGUIopen = false; InventoryManager inventory = playerController.objectInSight.GetComponent(); if (cInput.GetKeyDown("Interact")) { @@ -100,6 +101,7 @@ public class StorageInteraction //! Called when the player is looking at a storage computer. public void InteractWithStorageComputer() { + playerController.machineGUIopen = false; playerController.machineInSight = playerController.objectInSight; StorageComputer computer = playerController.objectInSight.GetComponent(); playerController.machineID = computer.ID;