@@ -38,6 +38,9 @@ public class ProbeControlRoom : MonoBehaviour
3838 float savedrot = 0f ;
3939 float savedzoom = 0f ;
4040
41+ // portrait nonsense
42+ static FieldInfo x_Kerbal_running_FieldInfo ;
43+
4144 //Current PCR module
4245 private ProbeControlRoomPart aModule ;
4346 private Part aPart => aModule ? . part ;
@@ -75,26 +78,27 @@ public class ProbeControlRoom : MonoBehaviour
7578 string enabledTexture = "ProbeControlRoom/Icons/ProbeControlRoomToolbarEnabled" ;
7679 string disabledTexture = "ProbeControlRoom/Icons/ProbeControlRoomToolbarDisabled" ;
7780
78- static void GetFields ( )
81+ static ProbeControlRoom ( )
7982 {
80- if ( field_get_internalcamera_currentPitch == null )
83+ try
84+ {
8185 field_get_internalcamera_currentPitch = VirindiHelpers . DynamicEmitFields . CreateDynamicInstanceFieldGet < float , InternalCamera > ( "currentPitch" ) ;
82- if ( field_get_internalcamera_currentRot == null )
8386 field_get_internalcamera_currentRot = VirindiHelpers . DynamicEmitFields . CreateDynamicInstanceFieldGet < float , InternalCamera > ( "currentRot" ) ;
84- if ( field_get_internalcamera_currentZoom == null )
8587 field_get_internalcamera_currentZoom = VirindiHelpers . DynamicEmitFields . CreateDynamicInstanceFieldGet < float , InternalCamera > ( "currentZoom" ) ;
8688
87- if ( field_set_internalcamera_currentPitch == null )
8889 field_set_internalcamera_currentPitch = VirindiHelpers . DynamicEmitFields . CreateDynamicInstanceFieldSet < float , InternalCamera > ( "currentPitch" ) ;
89- if ( field_set_internalcamera_currentRot == null )
9090 field_set_internalcamera_currentRot = VirindiHelpers . DynamicEmitFields . CreateDynamicInstanceFieldSet < float , InternalCamera > ( "currentRot" ) ;
91- if ( field_set_internalcamera_currentZoom == null )
9291 field_set_internalcamera_currentZoom = VirindiHelpers . DynamicEmitFields . CreateDynamicInstanceFieldSet < float , InternalCamera > ( "currentZoom" ) ;
9392
94- if ( method_vessellabels_enablealllabels == null )
9593 method_vessellabels_enablealllabels = typeof ( VesselLabels ) . GetMethod ( "EnableAllLabels" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Public | System . Reflection . BindingFlags . InvokeMethod | System . Reflection . BindingFlags . Instance ) ;
96- if ( method_vessellabels_disablealllabels == null )
9794 method_vessellabels_disablealllabels = typeof ( VesselLabels ) . GetMethod ( "DisableAllLabels" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Public | System . Reflection . BindingFlags . InvokeMethod | System . Reflection . BindingFlags . Instance ) ;
95+
96+ x_Kerbal_running_FieldInfo = typeof ( Kerbal ) . GetField ( "running" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
97+ }
98+ catch ( Exception ex )
99+ {
100+ ProbeControlRoomUtils . Logger . debug ( "Exception finding fields: " + ex . ToString ( ) ) ;
101+ }
98102 }
99103
100104 /// <summary>
@@ -105,17 +109,6 @@ public void Start()
105109 ProbeControlRoomUtils . Logger . debug ( "Start()" ) ;
106110 Instance = this ;
107111
108-
109- try
110- {
111- GetFields ( ) ;
112- }
113- catch ( Exception ex )
114- {
115- ProbeControlRoomUtils . Logger . debug ( "Exception finding fields: " + ex . ToString ( ) ) ;
116- }
117-
118-
119112 refreshVesselRooms ( ) ;
120113
121114 //Register game events
@@ -348,20 +341,14 @@ public bool startIVA()
348341 return false ;
349342 }
350343
351- // this prevents the portrait gallery from responding to VesselWasModified callbacks
352- KerbalPortraitGallery . Instance . enabled = false ;
353-
354344 // spawn the internal model
355345 if ( aPart . internalModel == null )
356346 {
347+ aPart . CreateInternalModel ( ) ;
357348 if ( aPart . internalModel == null )
358349 {
359- aPart . CreateInternalModel ( ) ;
360- if ( aPart . internalModel == null )
361- {
362- ProbeControlRoomUtils . Logger . message ( "startIVA() failed to spawn the internal model. DIE." ) ;
363- return false ;
364- }
350+ ProbeControlRoomUtils . Logger . message ( "startIVA() failed to spawn the internal model. DIE." ) ;
351+ return false ;
365352 }
366353
367354 aPart . internalModel . Initialize ( aPart ) ;
@@ -445,8 +432,11 @@ public bool startIVA()
445432 if ( UIPartActionController . Instance != null )
446433 UIPartActionController . Instance . Deactivate ( ) ;
447434
435+ // this prevents the portrait gallery from responding to VesselWasModified callbacks
436+ KerbalPortraitGallery . Instance . gameObject . SetActive ( false ) ;
437+ KerbalPortraitGallery . Instance . StopAllCoroutines ( ) ;
438+
448439 //Activate internal camera
449- //CameraManager.Instance.SetCameraInternal(aPart.internalModel, actualTransform);
450440 StartCoroutine ( DelayedIVACameraSwitch ( ) ) ;
451441
452442 ProbeControlRoomUtils . Logger . debug ( "startIVA() - DONE" ) ;
@@ -477,13 +467,6 @@ public bool startIVA()
477467
478468 }
479469
480- static FieldInfo x_Kerbal_running_FieldInfo ;
481-
482- static ProbeControlRoom ( )
483- {
484- x_Kerbal_running_FieldInfo = typeof ( Kerbal ) . GetField ( "running" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
485- }
486-
487470 IEnumerator DelayedIVACameraSwitch ( )
488471 {
489472 // we have to wait a frame after spawning the kerbals to switch to IVA camera, because they need to have their Start() functions called for everything to work properly
@@ -527,8 +510,8 @@ public void stopIVA()
527510 }
528511
529512 // re-enable the portrait gallery
530- KerbalPortraitGallery . Instance . enabled = true ;
531- KerbalPortraitGallery . Instance . StartRefresh ( aPart ? . vessel ) ;
513+ KerbalPortraitGallery . Instance . gameObject . SetActive ( true ) ;
514+ KerbalPortraitGallery . Instance . StartReset ( aPart ? . vessel ) ;
532515
533516 //Restore settings to levels prior to entering IVA
534517 if ( ProbeControlRoomSettings . Instance . DisableSounds )
@@ -642,11 +625,9 @@ public void LateUpdate()
642625 // if pressing the camera mode (C) button and we either failed to enter IVA mode or just left it, then try to start PCR mode
643626 if ( ! GameSettings . MODIFIER_KEY . GetKey ( ) && GameSettings . CAMERA_MODE . GetKeyDown ( ) && CameraManager . Instance . currentCameraMode == CameraManager . CameraMode . Flight )
644627 {
645- // If we were previously in IVA mode and pressing C switched to Flight, the portrait gallery will have spun up a coroutine to refresh itself
646- // which interferes with which internal spaces are shown or hidden. Stop it from doing that.
647- if ( startIVA ( ) )
628+ //if (FlightGlobals.ActiveVessel?.GetCrewCount() == 0)
648629 {
649- KerbalPortraitGallery . Instance . StopAllCoroutines ( ) ;
630+ startIVA ( ) ;
650631 }
651632 }
652633 }
0 commit comments