mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-04-28 21:27:58 +03:00
Allow F1 to close the menubar modal via new IsPopupOpen()
and DismissPopup
functions in SohModalWindow
. (#5166)
This commit is contained in:
parent
1bcab06fed
commit
04458f2274
3 changed files with 22 additions and 1 deletions
|
@ -1296,7 +1296,11 @@ extern "C" void Graph_StartFrame() {
|
|||
switch (dwScancode) {
|
||||
case KbScancode::LUS_KB_F1: {
|
||||
std::shared_ptr<SohModalWindow> modal = static_pointer_cast<SohModalWindow>(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: {
|
||||
|
|
|
@ -20,6 +20,8 @@ struct SohModal {
|
|||
};
|
||||
std::vector<SohModal> 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<void()> button1callback, std::function<void()> 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;
|
||||
}
|
||||
|
|
|
@ -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<void()> button1callback = nullptr, std::function<void()> button2callback = nullptr);
|
||||
bool IsPopupOpen(std::string title);
|
||||
void DismissPopup();
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue