diff --git a/Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYCommonMenu.cpp b/Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYCommonMenu.cpp index 8e3e2663d5..5107a02835 100644 --- a/Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYCommonMenu.cpp +++ b/Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYCommonMenu.cpp @@ -15,6 +15,7 @@ #ifdef IMGUI_ENABLED #include +#include #include #include #include @@ -251,15 +252,37 @@ namespace ImGui if (usePrefabSystemForLevels) { - char levelName[256]; + // Run through all the assets in the asset catalog and gather up the list of level assets + + AZ::Data::AssetType levelAssetType = lvlSystem->GetLevelAssetType(); + AZStd::vector levelNames; + auto enumerateCB = + [levelAssetType, &levelNames]([[maybe_unused]] const AZ::Data::AssetId id, const AZ::Data::AssetInfo& assetInfo) + { + if (assetInfo.m_assetType == levelAssetType) + { + levelNames.emplace_back(assetInfo.m_relativePath); + } + }; + + AZ::Data::AssetCatalogRequestBus::Broadcast( + &AZ::Data::AssetCatalogRequestBus::Events::EnumerateAssets, nullptr, enumerateCB, nullptr); + + AZStd::sort(levelNames.begin(), levelNames.end()); + + // Create a menu item for each level asset, with an action to load it if selected. + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "Load Level: "); - bool result = ImGui::InputText("", levelName, sizeof(levelName), ImGuiInputTextFlags_EnterReturnsTrue); - if (result) + for (int i = 0; i < levelNames.size(); i++) { - AZ_TracePrintf("Imgui", "Attempting to load level '%s'\n", levelName); - AZ::TickBus::QueueFunction([lvlSystem, levelName]() { - lvlSystem->LoadLevel(levelName); - }); + if (ImGui::MenuItem(AZStd::string::format("%d- %s", i, levelNames[i].c_str()).c_str())) + { + AZ::TickBus::QueueFunction( + [lvlSystem, levelNames, i]() + { + lvlSystem->LoadLevel(levelNames[i].c_str()); + }); + } } } else @@ -269,9 +292,8 @@ namespace ImGui { if (ImGui::MenuItem(AZStd::string::format("%d- %s", i, lvlSystem->GetLevelInfo(i)->GetName()).c_str())) { - AZStd::string mapCommandString = AZStd::string::format("map %s", lvlSystem->GetLevelInfo(i)->GetName()); - AZ::TickBus::QueueFunction([mapCommandString]() { - gEnv->pConsole->ExecuteString(mapCommandString.c_str()); + AZ::TickBus::QueueFunction([lvlSystem, i]() { + lvlSystem->LoadLevel(lvlSystem->GetLevelInfo(i)->GetName()); }); } }