diff --git a/src/general/base_stage/EditorComponentBase.cs b/src/general/base_stage/EditorComponentBase.cs index 637363069b7..a3b79114bc7 100644 --- a/src/general/base_stage/EditorComponentBase.cs +++ b/src/general/base_stage/EditorComponentBase.cs @@ -171,6 +171,8 @@ protected virtual void NextOrFinishClicked() { GUICommon.Instance.PlayButtonPressSound(); + ModalManager.Instance.ClearModals(); + if (OnFinish != null) { if (OnFinish!.Invoke(null)) diff --git a/src/gui_common/ModalManager.cs b/src/gui_common/ModalManager.cs index bb76c2fd985..cca910fbe37 100644 --- a/src/gui_common/ModalManager.cs +++ b/src/gui_common/ModalManager.cs @@ -98,17 +98,22 @@ public bool HideTopMostPopup() if (popup.Exclusive && !popup.ExclusiveAllowCloseOnEscape) return false; - // This is emitted before closing to allow window using components to differentiate between "cancel" and - // "any other reason for closing" in case some logic can be simplified by handling just those two situations. - if (popup is CustomWindow dialog) - dialog.EmitSignal(nameof(CustomWindow.Cancelled)); - - popup.Close(); - popup.Notification(Control.NotificationModalClose); + HideModal(popup); return true; } + /// + /// Attempt to clear all open modals. + /// + public void ClearModals() + { + foreach (var modal in modalStack) + { + HideModal(modal); + } + } + /// /// Returns the top-most popup in the modal stack if there's any and it's exclusive, otherwise null. /// @@ -125,6 +130,25 @@ public bool HideTopMostPopup() return null; } + /// + /// Attempts to hide the given modal. + /// This won't hide the modal if it's exclusive and doesn't allow closing on escape. + /// + /// Modal to hide + private static void HideModal(TopLevelContainer popup) + { + if (!popup.Visible) + return; + + // This is emitted before closing to allow window using components to differentiate between "cancel" and + // "any other reason for closing" in case some logic can be simplified by handling just those two situations. + if (popup is CustomWindow dialog) + dialog.EmitSignal(nameof(CustomWindow.Cancelled)); + + popup.Close(); + popup.Notification(Control.NotificationModalClose); + } + private void UpdateModals() { while (demotedModals.Count > 0)