From 24761eb5eadd3215181a5efa7f38fdafaa9422cb Mon Sep 17 00:00:00 2001 From: Cvolton Date: Sun, 17 Dec 2023 16:50:28 +0100 Subject: [PATCH] fix saved levels lag --- src/hooks/GameLevelManager.cpp | 14 +++++++++++++- src/layers/LevelFiltering/ProfileSearchOptions.cpp | 14 ++++++++++---- src/layers/LevelFiltering/ProfileSearchOptions.h | 1 + src/utils.cpp | 1 - 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/hooks/GameLevelManager.cpp b/src/hooks/GameLevelManager.cpp index 3869398..ed8e65d 100644 --- a/src/hooks/GameLevelManager.cpp +++ b/src/hooks/GameLevelManager.cpp @@ -9,6 +9,7 @@ using namespace geode::prelude; class $modify(GameLevelManager) { bool skipSavedFilter = false; + CCArray* filteredLevels = nullptr; /* * Helpers @@ -93,7 +94,14 @@ class $modify(GameLevelManager) { CCArray* getSavedLevels(bool filter, int folderID){ CCArray* original = GameLevelManager::getSavedLevels(filter, folderID); - if(m_fields->skipSavedFilter) return original; + if(m_fields->skipSavedFilter || !BetterInfo::isSavedFiltered()) return original; + + if(m_fields->filteredLevels != nullptr && Mod::get()->getSavedValue("user_search_dirty", true)) { + m_fields->filteredLevels->release(); + m_fields->filteredLevels = nullptr; + } + + if(m_fields->filteredLevels != nullptr) return m_fields->filteredLevels; CCArray* pRet = CCArray::create(); @@ -185,6 +193,10 @@ class $modify(GameLevelManager) { pRet->addObject(level); } + Mod::get()->setSavedValue("user_search_dirty", false); + + m_fields->filteredLevels = pRet; + m_fields->filteredLevels->retain(); return pRet; } diff --git a/src/layers/LevelFiltering/ProfileSearchOptions.cpp b/src/layers/LevelFiltering/ProfileSearchOptions.cpp index 1872755..af80854 100644 --- a/src/layers/LevelFiltering/ProfileSearchOptions.cpp +++ b/src/layers/LevelFiltering/ProfileSearchOptions.cpp @@ -21,7 +21,7 @@ void ProfileSearchOptions::onClose(cocos2d::CCObject* sender) { destroyToggles(); if(m_searchObjDelegate != nullptr) m_searchObjDelegate->onSearchObjectFinished(getSearchObject()); - if(m_levelBrowserLayer != nullptr) m_levelBrowserLayer->loadPage(m_levelBrowserLayer->m_searchObject); + reloadBrowser(); if(m_levelBrowserLayer != nullptr) m_levelBrowserLayer->release(); setKeypadEnabled(false); removeFromParentAndCleanup(true); @@ -134,6 +134,11 @@ bool ProfileSearchOptions::init(LevelBrowserLayer* levelBrowserLayer, const std: return true; } +void ProfileSearchOptions::reloadBrowser(){ + Mod::get()->setSavedValue("user_search_dirty", true); + if(m_levelBrowserLayer != nullptr) m_levelBrowserLayer->loadPage(m_levelBrowserLayer->m_searchObject); +} + void ProfileSearchOptions::createToggle(const char* option, const char* name, float x, float y){ auto buttonSprite = CCSprite::createWithSpriteFrameName(getOption(option) ? "GJ_checkOn_001.png" : "GJ_checkOff_001.png"); buttonSprite->setScale(0.8f); @@ -203,7 +208,7 @@ void ProfileSearchOptions::drawToggles(){ break; } - if(m_levelBrowserLayer != nullptr) m_levelBrowserLayer->loadPage(m_levelBrowserLayer->m_searchObject); + reloadBrowser(); } void ProfileSearchOptions::drawTogglesPrimary(){ @@ -308,7 +313,7 @@ void ProfileSearchOptions::drawTogglesTerciary(){ } void ProfileSearchOptions::onDialogClosed(){ - if(m_levelBrowserLayer != nullptr) m_levelBrowserLayer->loadPage(m_levelBrowserLayer->m_searchObject); + reloadBrowser(); } void ProfileSearchOptions::onIDRangeFinished(int min, int max, int additional) { @@ -330,7 +335,8 @@ void ProfileSearchOptions::onIDRangeFinished(int min, int max, int additional) { setOptionInt(fmt::format("{}_min", option), min); setOptionInt(fmt::format("{}_max", option), max); - if(m_levelBrowserLayer != nullptr) m_levelBrowserLayer->loadPage(m_levelBrowserLayer->m_searchObject); + + reloadBrowser(); } bool ProfileSearchOptions::getOption(const std::string& option) const { diff --git a/src/layers/LevelFiltering/ProfileSearchOptions.h b/src/layers/LevelFiltering/ProfileSearchOptions.h index 0d883af..fc19a87 100644 --- a/src/layers/LevelFiltering/ProfileSearchOptions.h +++ b/src/layers/LevelFiltering/ProfileSearchOptions.h @@ -34,6 +34,7 @@ class ProfileSearchOptions : public CvoltonOptionsLayer, public DialogCloseDeleg void onNext(cocos2d::CCObject* sender); void onSecondaryInfo(cocos2d::CCObject* sender); bool init(LevelBrowserLayer* levelBrowserLayer = nullptr, const std::string& prefix = "", BISearchObjectDelegate* searchObjDelegate = nullptr); + void reloadBrowser(); void destroyToggles(); void drawToggles(); void drawTogglesPrimary(); diff --git a/src/utils.cpp b/src/utils.cpp index 6b185c8..7c49643 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -135,7 +135,6 @@ bool BetterInfo::isAdvancedEnabled(GJSearchObject* searchObject) { || searchObject->m_searchType == SearchType::Friends; } - bool BetterInfo::isSavedFiltered() { for(unsigned int i = 0; i <= 4; i++){ if(