ARFlightController: Changed the control mask to ALL_SHIP_CONTROLS. Added event listeners to make sure we return control when leaving flight or changing vessels.
ARFlightController: Changed the control mask to ALL_SHIP_CONTROLS. Added event listeners to make sure we return control when leaving flight or changing vessels.

--- a/ARFlightController.cs
+++ b/ARFlightController.cs
@@ -64,7 +64,7 @@
 		{
 			get
 			{
-				return ControlTypes.GROUPS_ALL | ControlTypes.STAGING | ControlTypes.SAS | ControlTypes.RCS;
+				return ControlTypes.ALL_SHIP_CONTROLS;
 			}
 		}
 
@@ -86,37 +86,63 @@
 		protected void Awake()
 		{
 			this.lockID = "ARConnectionRequired";
+
+			GameEvents.onGameSceneLoadRequested.Add(this.onSceneChangeRequested);
+			GameEvents.onVesselChange.Add(this.onVesselChange);
 		}
 
 		protected void FixedUpdate()
 		{
+			// Do nothing if the vessel reference is invalid.
+			if (this.vessel == null)
+			{
+				return;
+			}
+
+			// If we are requiring a connection for control, the vessel does not have any adequately staffed pods,
+			// and the vessel does not have any connected relays...
 			if (
+				HighLogic.LoadedSceneIsFlight &&
 				requireConnectionForControl &&
-				this.vessel != null &&
 				!this.vessel.hasCrewCommand() &&
-				this.vessel.IsControllable
-			)
+				!this.vessel.HasConnectedRelay())
 			{
-				if (this.vessel.HasConnectedRelay())
+				// ...and if the controls are not currently locked...
+				if (currentControlLock == ControlTypes.None)
 				{
-					if (currentControlLock != ControlTypes.None)
-					{
-						InputLockManager.RemoveControlLock(this.lockID);
-					}
+					// ...lock the controls.
+					InputLockManager.SetControlLock(this.lockSet, this.lockID);
 				}
-				else
-				{
-					if (currentControlLock == ControlTypes.None)
-					{
-						InputLockManager.SetControlLock(this.lockSet, this.lockID);
-					}
-				}
+			}
+			// ...otherwise, if the controls are locked...
+			else if (currentControlLock != ControlTypes.None)
+			{
+				// ...unlock the controls.
+				InputLockManager.RemoveControlLock(this.lockID);
 			}
 		}
 
 		protected void Destroy()
 		{
+			InputLockManager.RemoveControlLock(this.lockID);
 
+			GameEvents.onGameSceneLoadRequested.Remove(this.onSceneChangeRequested);
+			GameEvents.onVesselChange.Remove(this.onVesselChange);
+		}
+		#endregion
+
+		#region Event Handlers
+		protected void onSceneChangeRequested(GameScenes scene)
+		{
+			if (scene != GameScenes.FLIGHT)
+			{
+				InputLockManager.RemoveControlLock(this.lockID);
+			}
+		}
+
+		protected void onVesselChange(Vessel vessel)
+		{
+			InputLockManager.RemoveControlLock(this.lockID);
 		}
 		#endregion
 	}