From 5b80660cd0c5bc37fd8d16aaa566372ada0b6dd0 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Sun, 26 Sep 2021 13:26:45 +0600 Subject: [PATCH] Fix crash with import menu --- src/interface.cpp | 76 ++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/src/interface.cpp b/src/interface.cpp index 7b709ea..e973d02 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -53,49 +53,57 @@ void Interface::ProcessContextMenu() void Interface::ImportMenu() { - ImGui::Spacing(); - ImGui::Text("Notes,"); - ImGui::TextWrapped("Files are imported from '(game dir)/MapEditor' directory"); - ImGui::TextWrapped("Imported objects will be merged with current ones!"); - ImGui::TextWrapped("Use a limit adjuster if you're going to load a lot of objects!"); - ImGui::TextWrapped("You game may freeze while loading!"); - ImGui::Dummy(ImVec2(0, 20)); - static std::string selectedFileName = ""; - - if (ImGui::Button("Import IPL", Utils::GetSize(2))) - { - FileMgr::ImportIPL(selectedFileName.c_str()); - m_bShowPopup = false; - } - ImGui::SameLine(); - if (ImGui::Button("Clear objects", Utils::GetSize(2))) + std::filesystem::path path = PLUGIN_PATH((char*)"/MapEditor/"); + if (std::filesystem::exists(path)) { - for (auto &pObj : ObjManager::m_pVecEntities) + ImGui::Spacing(); + ImGui::Text("Notes,"); + ImGui::TextWrapped("Files are imported from '(game dir)/MapEditor' directory"); + ImGui::TextWrapped("Imported objects will be merged with current ones!"); + ImGui::TextWrapped("Use a limit adjuster if you're going to load a lot of objects!"); + ImGui::TextWrapped("You game may freeze while loading!"); + ImGui::Dummy(ImVec2(0, 20)); + static std::string selectedFileName = ""; + + if (ImGui::Button("Import IPL", Utils::GetSize(2))) { - pObj->Remove(); + FileMgr::ImportIPL(selectedFileName.c_str()); + m_bShowPopup = false; } - ObjManager::m_pSelected = nullptr; - ObjManager::m_pVecEntities.clear(); - CHud::SetHelpMessage("Current objects cleared", false, false, false); - } - ImGui::Spacing(); - // gen file list - std::filesystem::path path = PLUGIN_PATH((char*)"/MapEditor/"); - if(ImGui::BeginChild("ImportMenu")) - { - for (const auto & entry : std::filesystem::directory_iterator(path)) + ImGui::SameLine(); + if (ImGui::Button("Clear objects", Utils::GetSize(2))) { - if (entry.path().filename().string().ends_with(".ipl")) + for (auto &pObj : ObjManager::m_pVecEntities) { - std::string fileName = entry.path().filename().string(); - - if (ImGui::MenuItem(fileName.c_str(), NULL, selectedFileName == fileName)) + pObj->Remove(); + } + ObjManager::m_pSelected = nullptr; + ObjManager::m_pVecEntities.clear(); + CHud::SetHelpMessage("Current objects cleared", false, false, false); + } + ImGui::Spacing(); + + if(ImGui::BeginChild("ImportMenu")) + { + for (const auto & entry : std::filesystem::directory_iterator(path)) + { + if (entry.path().filename().string().ends_with(".ipl")) { - selectedFileName = fileName; + std::string fileName = entry.path().filename().string(); + + if (ImGui::MenuItem(fileName.c_str(), NULL, selectedFileName == fileName)) + { + selectedFileName = fileName; + } } } + + ImGui::EndChild(); } - ImGui::EndChild(); + } + else + { + ImGui::Text("Map Editor folder not found!"); } }