Skip to content

Commit

Permalink
add platformer length support
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Jan 17, 2024
1 parent a609fb5 commit 69a2a1d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/hooks/GameLevelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class $modify(GameLevelManager) {

//getting config
std::vector<unsigned int> len;
for(unsigned int i = 0; i <= 4; i++){
for(unsigned int i = 0; i <= 5; i++){
if(
Mod::get()->getSavedValue<bool>(
CCString::createWithFormat("user_search_len_%02u", i)->getCString()
Expand Down
27 changes: 20 additions & 7 deletions src/layers/LevelFiltering/ProfileSearchOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ bool ProfileSearchOptions::init(LevelBrowserLayer* levelBrowserLayer, const std:
m_nextBtn->setID("next-button"_spr);
m_buttonMenu->addChild(m_nextBtn);

m_lenMenu = CCMenu::create();
m_lenMenu->setZOrder(10);
m_lenMenu->setContentSize({330, 30});
m_lenMenu->setPosition({(winSize.width / 2) , (winSize.height / 2) - 120});
m_lenMenu->setLayout(
RowLayout::create()
->setGap(20.f)
);
m_mainLayer->addChild(m_lenMenu);

drawToggles();

return true;
Expand Down Expand Up @@ -179,13 +189,16 @@ void ProfileSearchOptions::drawTogglesPrimary(){
m_buttonMenu->addChild(timeIcon);
m_toggles.push_back(timeIcon);

createButtonToggle("len_00", CCLabelBMFont::create("Tiny", "bigFont.fnt"), -142, -119, 0.6f);
createButtonToggle("len_01", CCLabelBMFont::create("Short", "bigFont.fnt"), -69, -119, 0.6f);
createButtonToggle("len_02", CCLabelBMFont::create("Medium", "bigFont.fnt"), 16, -119, 0.6f);
createButtonToggle("len_03", CCLabelBMFont::create("Long", "bigFont.fnt"), 93.5f, -119, 0.6f);
createButtonToggle("len_04", CCLabelBMFont::create("XL", "bigFont.fnt"), 150, -119, 0.6f);
createButtonToggle("len_00", CCLabelBMFont::create("Tiny", "bigFont.fnt"), -142, -119, 0.6f, m_lenMenu);
createButtonToggle("len_01", CCLabelBMFont::create("Short", "bigFont.fnt"), -69, -119, 0.6f, m_lenMenu);
createButtonToggle("len_02", CCLabelBMFont::create("Medium", "bigFont.fnt"), 16, -119, 0.6f, m_lenMenu);
createButtonToggle("len_03", CCLabelBMFont::create("Long", "bigFont.fnt"), 93.5f, -119, 0.6f, m_lenMenu);
createButtonToggle("len_04", CCLabelBMFont::create("XL", "bigFont.fnt"), 150, -119, 0.6f, m_lenMenu);
createButtonToggle("len_05", CCLabelBMFont::create("Plat.", "bigFont.fnt"), 150, -119, 0.6f, m_lenMenu);
createButtonToggle("star", CCSprite::createWithSpriteFrameName("GJ_starsIcon_001.png"), 193, -120);

m_lenMenu->updateLayout();

for(unsigned int i = 0; i <= 6; i++){
createButtonToggle(
CCString::createWithFormat("diff_%02u", i)->getCString(),
Expand Down Expand Up @@ -347,7 +360,7 @@ BISearchObject ProfileSearchOptions::getSearchObject() {
if(getOption(diff)) searchObj.difficulty.insert(i);
}

for(int i = 0; i <= 4; i++) {
for(int i = 0; i <= 5; i++) {
auto len = CCString::createWithFormat("len_%02i", i)->getCString();
if(getOption(len)) searchObj.length.insert(i);
}
Expand Down Expand Up @@ -408,7 +421,7 @@ void ProfileSearchOptions::setSearchObject(const BISearchObject& searchObj) {
);
}

for(int i = 0; i <= 4; i++) {
for(int i = 0; i <= 5; i++) {
setOption(
CCString::createWithFormat("len_%02i", i)->getCString(),
searchObj.length.find(i) != searchObj.length.end()
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 @@ -19,6 +19,7 @@ class ProfileSearchOptions : public CvoltonOptionsLayer, public SongDialogCloseD
cocos2d::extension::CCScale9Sprite* m_diffBg = nullptr;
cocos2d::extension::CCScale9Sprite* m_demonDiffBg = nullptr;
BISearchObjectDelegate* m_searchObjDelegate = nullptr;
cocos2d::CCMenu* m_lenMenu = nullptr;
std::string m_prefix;
int m_page = 0;
public:
Expand Down
17 changes: 10 additions & 7 deletions src/layers/_bases/CvoltonOptionsLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,20 @@ void CvoltonOptionsLayer::onToggle(cocos2d::CCObject* sender)
sender->release();
}

void CvoltonOptionsLayer::createToggle(const char* option, const char* name, SEL_MenuHandler additional){
void CvoltonOptionsLayer::createToggle(const char* option, const char* name, SEL_MenuHandler additional, CCNode* parent){
float width = m_alertSize.x - 50;

float x = -170 + floor(width / m_columns) * floor(m_toggleCount % m_columns);
float y = m_top - m_gap * floor(m_toggleCount / m_columns);

createToggle(option, name, x, y, additional);
createToggle(option, name, x, y, additional, parent);

m_toggleCount++;
}

void CvoltonOptionsLayer::createToggle(const char* option, const char* name, float x, float y, SEL_MenuHandler additional){
void CvoltonOptionsLayer::createToggle(const char* option, const char* name, float x, float y, SEL_MenuHandler additional, CCNode* parent){
if(!parent) parent = m_buttonMenu;

auto buttonSprite = CCSprite::createWithSpriteFrameName(getOption(option) ? "GJ_checkOn_001.png" : "GJ_checkOff_001.png");
buttonSprite->setScale(0.8f);
auto button = CCMenuItemSpriteExtra::create(
Expand All @@ -71,13 +73,13 @@ void CvoltonOptionsLayer::createToggle(const char* option, const char* name, flo
);
button->setID(Mod::get()->expandSpriteName(fmt::format("{}-toggle", option).c_str()));
button->setPosition({x, y});
m_buttonMenu->addChild(button);
parent->addChild(button);
m_toggles.push_back(button);

auto optionString = CCString::create(option);
button->setUserObject(optionString);

auto label = createTextLabel(name, {x + 20, y}, 0.5f, m_buttonMenu);
auto label = createTextLabel(name, {x + 20, y}, 0.5f, parent);
label->setAnchorPoint({0,0.5f});
label->limitLabelWidth(80, 0.35f, 0);
label->setID(Mod::get()->expandSpriteName(fmt::format("{}-label", option).c_str()));
Expand All @@ -90,7 +92,8 @@ void CvoltonOptionsLayer::createToggle(const char* option, const char* name, flo
}
}

void CvoltonOptionsLayer::createButtonToggle(const char* option, CCNode* sprite, float x, float y, float scale){
void CvoltonOptionsLayer::createButtonToggle(const char* option, CCNode* sprite, float x, float y, float scale, CCNode* parent){
if(!parent) parent = m_buttonMenu;

sprite->setScale(scale);
auto button = CCMenuItemSpriteExtra::create(
Expand All @@ -101,7 +104,7 @@ void CvoltonOptionsLayer::createButtonToggle(const char* option, CCNode* sprite,
button->setID(Mod::get()->expandSpriteName(fmt::format("{}-toggle", option).c_str()));
button->setPosition({x, y});
if(!getOption(option)) button->setColor({125,125,125});
m_buttonMenu->addChild(button);
parent->addChild(button);
m_toggles.push_back(button);

auto optionString = CCString::create(option);
Expand Down
6 changes: 3 additions & 3 deletions src/layers/_bases/CvoltonOptionsLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class CvoltonOptionsLayer : public CvoltonAlertLayerStub {
virtual void destroyToggles();
virtual void drawToggles();
static cocos2d::CCLabelBMFont* createTextLabel(const std::string text, const cocos2d::CCPoint& position, const float scale, cocos2d::CCNode* menu, const char* font = "bigFont.fnt");
void createToggle(const char* option, const char* name, cocos2d::SEL_MenuHandler additional = nullptr);
void createToggle(const char* option, const char* name, float x, float y, cocos2d::SEL_MenuHandler additional = nullptr);
void createButtonToggle(const char* option, cocos2d::CCNode* sprite, float x, float y, float scale = 1.f);
void createToggle(const char* option, const char* name, cocos2d::SEL_MenuHandler additional = nullptr, CCNode* parent = nullptr);
void createToggle(const char* option, const char* name, float x, float y, cocos2d::SEL_MenuHandler additional = nullptr, CCNode* parent = nullptr);
void createButtonToggle(const char* option, cocos2d::CCNode* sprite, float x, float y, float scale = 1.f, CCNode* parent = nullptr);

virtual bool getOption(const std::string& option) const;
virtual int getOptionInt(const std::string& option) const;
Expand Down
4 changes: 2 additions & 2 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ bool BetterInfo::isAdvancedEnabled(GJSearchObject* searchObject) {
}

bool BetterInfo::isSavedFiltered() {
for(unsigned int i = 0; i <= 4; i++){
for(unsigned int i = 0; i <= 5; i++){
if(
Mod::get()->getSavedValue<bool>(
CCString::createWithFormat("user_search_len_%02u", i)->getCString()
Expand Down Expand Up @@ -173,7 +173,7 @@ bool BetterInfo::isSavedFiltered() {
"user_search_completedorbs", "user_search_completedleaderboard", "user_search_uncompletedorbs",
"user_search_uncompletedleaderboard", "user_search_percentage", "user_search_percentageorbs",
"user_search_percentageleaderboard", "user_search_starrange", "user_search_completedcoins",
"user_search_uncompletedcoins"
"user_search_uncompletedcoins", "user_search_legendary", "user_search_mythic"
};

for(auto option : options) {
Expand Down

0 comments on commit 69a2a1d

Please sign in to comment.