Skip to content

Commit

Permalink
fix saved levels lag
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Dec 17, 2023
1 parent 92db244 commit 24761eb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
14 changes: 13 additions & 1 deletion src/hooks/GameLevelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using namespace geode::prelude;

class $modify(GameLevelManager) {
bool skipSavedFilter = false;
CCArray* filteredLevels = nullptr;

/*
* Helpers
Expand Down Expand Up @@ -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<bool>("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();

Expand Down Expand Up @@ -185,6 +193,10 @@ class $modify(GameLevelManager) {
pRet->addObject(level);
}

Mod::get()->setSavedValue<bool>("user_search_dirty", false);

m_fields->filteredLevels = pRet;
m_fields->filteredLevels->retain();
return pRet;
}

Expand Down
14 changes: 10 additions & 4 deletions src/layers/LevelFiltering/ProfileSearchOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -134,6 +134,11 @@ bool ProfileSearchOptions::init(LevelBrowserLayer* levelBrowserLayer, const std:
return true;
}

void ProfileSearchOptions::reloadBrowser(){
Mod::get()->setSavedValue<bool>("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);
Expand Down Expand Up @@ -203,7 +208,7 @@ void ProfileSearchOptions::drawToggles(){
break;
}

if(m_levelBrowserLayer != nullptr) m_levelBrowserLayer->loadPage(m_levelBrowserLayer->m_searchObject);
reloadBrowser();
}

void ProfileSearchOptions::drawTogglesPrimary(){
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/layers/LevelFiltering/ProfileSearchOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 24761eb

Please sign in to comment.