diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index a86c77524..3690e8648 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1296,7 +1296,11 @@ extern "C" void Graph_StartFrame() { switch (dwScancode) { case KbScancode::LUS_KB_F1: { std::shared_ptr modal = static_pointer_cast(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Modal Window")); - modal->RegisterPopup("Menu Moved", "The menubar, accessed by hitting F1, no longer exists.\nThe new menu can be accessed by hitting the Esc button instead.", "OK"); + if (modal->IsPopupOpen("Menu Moved")) { + modal->DismissPopup(); + } else { + modal->RegisterPopup("Menu Moved", "The menubar, accessed by hitting F1, no longer exists.\nThe new menu can be accessed by hitting the Esc button instead.", "OK"); + } break; } case KbScancode::LUS_KB_F5: { diff --git a/soh/soh/SohGui/SohModals.cpp b/soh/soh/SohGui/SohModals.cpp index b1fe0b43b..e2025437f 100644 --- a/soh/soh/SohGui/SohModals.cpp +++ b/soh/soh/SohGui/SohModals.cpp @@ -20,6 +20,8 @@ struct SohModal { }; std::vector modals; +bool closePopup = false; + void SohModalWindow::Draw() { if (!IsVisible()) { return; @@ -35,6 +37,11 @@ void SohModalWindow::DrawElement() { if (!ImGui::IsPopupOpen(curModal.title_.c_str())) { ImGui::OpenPopup(curModal.title_.c_str()); } + if (closePopup) { + ImGui::CloseCurrentPopup(); + modals.erase(modals.begin()); + closePopup = false; + } if (ImGui::BeginPopupModal(curModal.title_.c_str(), NULL, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings)) { ImGui::Text("%s", curModal.message_.c_str()); UIWidgets::PushStyleButton(THEME_COLOR); @@ -66,3 +73,11 @@ void SohModalWindow::DrawElement() { void SohModalWindow::RegisterPopup(std::string title, std::string message, std::string button1, std::string button2, std::function button1callback, std::function button2callback) { modals.push_back({ title, message, button1, button2, button1callback, button2callback }); } + +bool SohModalWindow::IsPopupOpen(std::string title) { + return !modals.empty() && modals.at(0).title_ == title; +} + +void SohModalWindow::DismissPopup() { + closePopup = true; +} diff --git a/soh/soh/SohGui/SohModals.h b/soh/soh/SohGui/SohModals.h index f584b9540..9a1fed80c 100644 --- a/soh/soh/SohGui/SohModals.h +++ b/soh/soh/SohGui/SohModals.h @@ -13,4 +13,6 @@ class SohModalWindow : public Ship::GuiWindow { void DrawElement() override; void UpdateElement() override {}; void RegisterPopup(std::string title, std::string message, std::string button1 = "OK", std::string button2 = "", std::function button1callback = nullptr, std::function button2callback = nullptr); + bool IsPopupOpen(std::string title); + void DismissPopup(); }; \ No newline at end of file