From 2caaa48b911d0459f3fe7c5b3e70d0bb898c62d1 Mon Sep 17 00:00:00 2001 From: scrawl <720642+scrawl@users.noreply.github.com> Date: Sun, 14 Jan 2018 00:27:53 +0000 Subject: [PATCH] Workaround to make sure message box remains on top (Fixes #4298) --- apps/openmw/mwgui/messagebox.cpp | 12 +++++++----- apps/openmw/mwgui/messagebox.hpp | 4 ++++ apps/openmw/mwgui/windowmanagerimp.cpp | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 7c89c4979..a79112b9f 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -207,8 +207,6 @@ namespace MWGui , mMessageBoxManager(parMessageBoxManager) , mButtonPressed(-1) { - setVisible(true); - int textPadding = 10; // padding between text-widget and main-widget int textButtonPadding = 10; // padding between the text-widget und the button-widget int buttonLeftPadding = 10; // padding between the buttons if horizontal @@ -358,7 +356,11 @@ namespace MWGui mMessageWidget->setCoord(messageWidgetCoord); } - // Set key focus to "Ok" button + setVisible(true); + } + + MyGUI::Widget* InteractiveMessageBox::getDefaultKeyFocus() + { std::vector keywords { "sOk", "sYes" }; for(std::vector::const_iterator button = mButtons.begin(); button != mButtons.end(); ++button) { @@ -366,11 +368,11 @@ namespace MWGui { if(Misc::StringUtils::ciEqual(MyGUI::LanguageManager::getInstance().replaceTags("#{" + keyword + "}"), (*button)->getCaption())) { - MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(*button); - return; + return *button; } } } + return NULL; } void InteractiveMessageBox::mousePressed (MyGUI::Widget* pressed) diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index 53b277416..e0bcbe667 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -28,6 +28,8 @@ namespace MWGui bool createInteractiveMessageBox (const std::string& message, const std::vector& buttons); bool isInteractiveMessageBox (); + const InteractiveMessageBox* getInteractiveMessageBox() const { return mInterMessageBoxe; } + /// Remove all message boxes void clear(); @@ -77,6 +79,8 @@ namespace MWGui void mousePressed (MyGUI::Widget* _widget); int readPressedButton (); + MyGUI::Widget* getDefaultKeyFocus() override; + virtual bool exit() { return false; } bool mMarkedToDelete; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 2084786b3..300f8e39f 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -874,6 +874,22 @@ namespace MWGui window->onFrame(frameDuration); } + // Make sure message boxes are always in front + // This is an awful workaround for a series of awfully interwoven issues that couldn't be worked around + // in a better way because of an impressive number of even more awfully interwoven issues. + if (mMessageBoxManager && mMessageBoxManager->isInteractiveMessageBox() && mCurrentModals.back() != mMessageBoxManager->getInteractiveMessageBox()) + { + std::vector::iterator found = std::find(mCurrentModals.begin(), mCurrentModals.end(), mMessageBoxManager->getInteractiveMessageBox()); + if (found != mCurrentModals.end()) + { + WindowModal* msgbox = *found; + std::swap(*found, mCurrentModals.back()); + MyGUI::InputManager::getInstance().addWidgetModal(msgbox->mMainWidget); + mKeyboardNavigation->setModalWindow(msgbox->mMainWidget); + mKeyboardNavigation->setDefaultFocus(msgbox->mMainWidget, msgbox->getDefaultKeyFocus()); + } + } + if (!mCurrentModals.empty()) mCurrentModals.back()->onFrame(frameDuration);