@@ -24,7 +24,7 @@ namespace mle {
2424 auto path = CCFileUtils::get ()->fullPathForFilename (levelFileName.c_str (), 0 );
2525 level = level::importLevelFile (path.c_str ()).unwrapOr (level);
2626 }
27- else log::debug (" don't exists in search paths: {}" , levelFileName.c_str ());
27+ else log::info (" don't exists in search paths: {}" , levelFileName.c_str ());
2828
2929 if (!appendSubDir) return tryLoadFromFiles (level, customLvlID, true );
3030 return level;
@@ -243,10 +243,45 @@ class MainLevelsEditorMenu : public geode::Popup<> {
243243
244244 CCMenuItemSpriteExtra* reload_levels_cache = CCMenuItemExt::createSpriteExtra (
245245 btnspr (" Reload levels cache!" ),
246- [__this = Ref (this )](auto ) {
246+ [__this = Ref (this )](CCMenuItemSpriteExtra*) {
247+ // Reload the level cache
247248 LocalLevelManager::get ()->init ();
248- // (LevelSelectLayer::create(__this = Ref(this)->m_scrollLayer->m_page));
249- Notification::create (" local level manager was reinitialized" , NotificationIcon::Info)->show ();
249+
250+ // Try to refresh the UI if we're currently in a level select layer
251+ auto scene = CCScene::get ();
252+ if (auto levelSelectLayer = scene->getChildByType <LevelSelectLayer>(0 )) {
253+ // Get the current page to preserve user's position
254+ int currentPage = 0 ;
255+ if (auto scrollLayer = typeinfo_cast<BoomScrollLayer*>(levelSelectLayer->m_scrollLayer )) {
256+ currentPage = scrollLayer->m_page ;
257+ }
258+
259+ // Close the popup first
260+ __this->keyBackClicked ();
261+
262+ // Schedule a refresh after a brief delay to let the popup close
263+ levelSelectLayer->runAction (CCSequence::create (
264+ CCDelayTime::create (0 .2f ),
265+ CallFuncExt::create ([levelSelectLayer, currentPage]() {
266+ // Refresh the level select layer by reinitializing it
267+ // This will trigger the BoomScrollLayer hook to reload levels with new cache data
268+ if (levelSelectLayer && levelSelectLayer->getParent ()) {
269+ auto parent = levelSelectLayer->getParent ();
270+ levelSelectLayer->removeFromParent ();
271+
272+ // Create a new level select layer
273+ auto newLevelSelect = LevelSelectLayer::create (currentPage);
274+ parent->addChild (newLevelSelect);
275+ }
276+ }),
277+ nullptr
278+ ));
279+
280+ Notification::create (" Levels cache reloaded and UI refreshed!" , NotificationIcon::Success)->show ();
281+ } else {
282+ // Not in level select, just show the standard notification
283+ Notification::create (" Levels cache reloaded!\n Navigate to level select to see changes." , NotificationIcon::Info)->show ();
284+ }
250285 }
251286 );
252287 reload_levels_cache->setLayoutOptions (lopts);
@@ -426,7 +461,10 @@ class MainLevelsEditorMenu : public geode::Popup<> {
426461 Mod::get ()->setSettingValue <std::string>(" LEVELS_LISTING" , new_listing);
427462 Mod::get ()->saveData ().isOk ();
428463
429- Notification::create (" Level inserted to list!" , NotificationIcon::Success)->show ();
464+ Notification::create (
465+ " Level inserted successfully!\n Use 'Reload levels cache!' to see changes." ,
466+ NotificationIcon::Success
467+ )->show ();
430468 }
431469 );
432470 insert_to_level_list->setLayoutOptions (lopts);
@@ -791,34 +829,34 @@ class $modify(MLE_LocalLevelManager, LocalLevelManager) {
791829 }
792830 else {
793831 log::info (" Custom settings file not found, checking for backup..." );
794- if ( std::filesystem::exists (backupPath, fucku)) {
795- // replace
796- std::filesystem::remove ( getMod ()-> getSaveDir () / " settings.json" , fucku);
797- std::filesystem::rename (backupPath, getMod ()-> getSaveDir () / " settings.json " , fucku);
798- // reload
832+ auto savePath = getMod ()-> getSaveDir () / " settings.json " ;
833+ if (! std::filesystem::exists (savePath, fucku) && std::filesystem::exists (backupPath, fucku)) {
834+ // restore only if settings.json is missing
835+ std::filesystem::rename (backupPath, savePath , fucku);
836+ // reload
799837 auto loadResult = getMod ()->loadData ();
800838 if (loadResult.isErr ()) log::error (" Failed to reload mod data: {}" , loadResult.unwrapErr ());
801839 else log::info (" Settings successfully restored from backup!" );
802840 }
803- else log::info (" No backup file found, using current settings " );
841+ else log::info (" Settings present or no backup found; not restoring from backup " );
804842 }
805843
806- log::debug (" Loading .level files for list: {}" , mle::getListingIDs ());
844+ log::info (" Loading .level files for list: {}" , mle::getListingIDs ());
807845 for (auto id : mle::getListingIDs ()) {
808- log::debug (" Loading level {}" , id);
846+ log::info (" Loading level {}" , id);
809847 auto level = GJGameLevel::create ();
810848 level->m_levelName = " ___level_was_not_loaded" ;
811849 level = mle::tryLoadFromFiles (level, id);
812- log::debug ( " {} " , level->m_levelName .c_str ());
850+ log::info ( " Level {} name: {} " , id , level->m_levelName .c_str ());
813851 if (std::string (level->m_levelName .c_str ()) != " ___level_was_not_loaded" ) { // level name was changed if it was loaded
814852 log::info (" Loaded level {}" , id);
815853 if (std::string (level->m_levelString .c_str ()).empty ()) void ();
816854 else m_mainLevels[id] = level->m_levelString ;
817- log::debug (" Level {} string size is {}" , id, std::string (level->m_levelString .c_str ()).size ());
855+ log::info (" Level {} string size is {}" , id, std::string (level->m_levelString .c_str ()).size ());
818856 MLE_LevelsInJSON::get ()->insert_or_assign (id, level::jsonFromLevel (level));
819- log::debug (" Level {} json dump size is {}" , id, MLE_LevelsInJSON::get ()->at (id).dump ().size ());
857+ log::info (" Level {} json dump size is {}" , id, MLE_LevelsInJSON::get ()->at (id).dump ().size ());
820858 }
821- else log::debug (" The .level file for {} was not founded " , id);
859+ else log::info (" The .level file for {} was not found " , id);
822860 }
823861
824862 return true ;
0 commit comments