diff --git a/Source/RP0/Crew/CrewHandler.cs b/Source/RP0/Crew/CrewHandler.cs index a7725407dea..f9378b9833b 100644 --- a/Source/RP0/Crew/CrewHandler.cs +++ b/Source/RP0/Crew/CrewHandler.cs @@ -626,8 +626,9 @@ private void VesselRecoveryProcessing(ProtoVessel v, MissionRecoveryDialog mrDia sb.ToString(), KSP.Localization.Localizer.GetStringByTag("#autoLOC_190905"), true, - HighLogic.UISkin) - .PrePostActions(ControlTypes.KSC_ALL | ControlTypes.UI_MAIN, "RP0CrewUpdate", OnDialogSpawn, OnDialogDismiss); + HighLogic.UISkin, + !HighLogic.LoadedSceneIsFlight) + .PrePostActionsNonFlight(ControlTypes.KSC_ALL | ControlTypes.UI_MAIN, "RP0CrewUpdate", OnDialogSpawn, OnDialogDismiss); } } diff --git a/Source/RP0/Crew/TrainingCourse.cs b/Source/RP0/Crew/TrainingCourse.cs index c4290fe703a..3d8c37e272c 100644 --- a/Source/RP0/Crew/TrainingCourse.cs +++ b/Source/RP0/Crew/TrainingCourse.cs @@ -213,7 +213,7 @@ public void CompleteCourse() KSP.Localization.Localizer.GetStringByTag("#autoLOC_190905"), true, HighLogic.UISkin, - !HighLogic.LoadedSceneIsFlight).HideGUIsWhilePopup(); + !HighLogic.LoadedSceneIsFlight).HideGUIsWhilePopupNonFlight(); } } diff --git a/Source/RP0/Utilities/KSPUtils.cs b/Source/RP0/Utilities/KSPUtils.cs index b029b9f700e..241534948c3 100644 --- a/Source/RP0/Utilities/KSPUtils.cs +++ b/Source/RP0/Utilities/KSPUtils.cs @@ -46,6 +46,22 @@ public static List GetAllLoadedTypes(bool instantiableOnly = true) return list; } + /// + /// Like PrePostActions, but does nothing in the Flight scene + /// + /// + /// + /// + /// + /// + public static PopupDialog PrePostActionsNonFlight(this PopupDialog dialog, ControlTypes lockType = ControlTypes.None, string lockName = null, Callback onCreateAction = null, Callback onDestroyAction = null) + { + if (HighLogic.LoadedSceneIsFlight) + return dialog; + + return PrePostActions(dialog, lockType, lockName, onCreateAction, onDestroyAction); + } + /// /// Adds a way for a PopupDialog to perform actions on spawn/despawn, like locking input for a true modal. /// @@ -54,10 +70,10 @@ public static List GetAllLoadedTypes(bool instantiableOnly = true) /// optional (will use default if not specified and locking controls) /// optional: runs on dialog spawn /// optional: runs when dialog is destroyed - public static void PrePostActions(this PopupDialog dialog, ControlTypes lockType = ControlTypes.None, string lockName = null, Callback onCreateAction = null, Callback onDestroyAction = null) + public static PopupDialog PrePostActions(this PopupDialog dialog, ControlTypes lockType = ControlTypes.None, string lockName = null, Callback onCreateAction = null, Callback onDestroyAction = null) { if (dialog == null) - return; + return null; if (onCreateAction != null) onCreateAction(); @@ -69,6 +85,8 @@ public static void PrePostActions(this PopupDialog dialog, ControlTypes lockType InputLockManager.SetControlLock(lockType, lockName); } dialog.gameObject.AddComponent().Setup(lockName, onDestroyAction); + + return dialog; } public class LockRemover : MonoBehaviour @@ -130,9 +148,17 @@ public void OnDestroy() } } - public static void HideGUIsWhilePopup(this PopupDialog dialog) + public static PopupDialog HideGUIsWhilePopupNonFlight(this PopupDialog dialog) + { + if (HighLogic.LoadedSceneIsFlight) + return dialog; + + return HideGUIsWhilePopup(dialog); + } + + public static PopupDialog HideGUIsWhilePopup(this PopupDialog dialog) { - PrePostActions(dialog, ControlTypes.KSC_ALL | ControlTypes.UI_MAIN | ControlTypes.EDITOR_SOFT_LOCK, "RP0GenericPopupDialogLock", OnDialogSpawn, OnDialogDismiss); + return PrePostActions(dialog, ControlTypes.KSC_ALL | ControlTypes.UI_MAIN | ControlTypes.EDITOR_SOFT_LOCK, "RP0GenericPopupDialogLock", OnDialogSpawn, OnDialogDismiss); } private static void OnDialogSpawn()