diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 6b6db20b9..61fda3b47 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -62,6 +62,7 @@ #include "windows/CTutorialWindow.h" #include "windows/GUIClasses.h" #include "windows/InfoWindows.h" +#include "windows/settings/SettingsMainWindow.h" #include "../CCallback.h" @@ -187,6 +188,7 @@ void CPlayerInterface::closeAllDialogs() while(true) { auto adventureWindow = GH.windows().topWindow(); + auto settingsWindow = GH.windows().topWindow(); auto infoWindow = GH.windows().topWindow(); auto topWindow = GH.windows().topWindow(); @@ -196,10 +198,16 @@ void CPlayerInterface::closeAllDialogs() if(infoWindow && infoWindow->ID != QueryID::NONE) break; - if (topWindow == nullptr) - throw std::runtime_error("Invalid or non-existing top window! Total windows: " + std::to_string(GH.windows().count())); + if (settingsWindow) + { + settingsWindow->close(); + continue; + } - topWindow->close(); + if (topWindow) + topWindow->close(); + else + GH.windows().popWindows(1); // does not inherits from WindowBase, e.g. settings dialog } } diff --git a/client/gui/CIntObject.cpp b/client/gui/CIntObject.cpp index 14e3d09a1..d38238ce6 100644 --- a/client/gui/CIntObject.cpp +++ b/client/gui/CIntObject.cpp @@ -345,7 +345,7 @@ void WindowBase::close() if(!GH.windows().isTopWindow(this)) { auto topWindow = GH.windows().topWindow().get(); - throw std::runtime_error(std::string("Only top interface can be closed! Top window is ") + typeid(*this).name() + " but attempted to close " + typeid(*topWindow).name()); + throw std::runtime_error(std::string("Only top interface can be closed! Top window is ") + typeid(*topWindow).name() + " but attempted to close " + typeid(*this).name()); } GH.windows().popWindows(1); } diff --git a/client/windows/settings/SettingsMainWindow.h b/client/windows/settings/SettingsMainWindow.h index 7b26921df..5e59695d0 100644 --- a/client/windows/settings/SettingsMainWindow.h +++ b/client/windows/settings/SettingsMainWindow.h @@ -29,7 +29,6 @@ private: std::shared_ptr createTab(size_t index); void openTab(size_t index); - void close(); //TODO: copypaste of WindowBase::close(), consider changing Windowbase to IWindowbase with default close() implementation and changing WindowBase inheritance to CIntObject + IWindowBase void loadGameButtonCallback(); void saveGameButtonCallback(); @@ -40,6 +39,7 @@ private: public: SettingsMainWindow(BattleInterface * parentBattleInterface = nullptr); + void close(); //TODO: copypaste of WindowBase::close(), consider changing Windowbase to IWindowbase with default close() implementation and changing WindowBase inheritance to CIntObject + IWindowBase void showAll(Canvas & to) override; void onScreenResize() override; };