Skip to content

Commit

Permalink
Fix layout crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Jan 19, 2024
1 parent 408d50b commit 00773ba
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 60 deletions.
1 change: 1 addition & 0 deletions src/hooks/ProfilePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class $modify(BIProfilePage, ProfilePage) {
} else {
if(auto playerStats = m_mainLayer->getChildByID("stats-menu")) {
if(auto starsIcon = playerStats->getChildByID("stars-icon")) {
m_buttons->removeObject(starsIcon);
m_buttons->addObject(BetterInfo::replaceWithButton(starsIcon, this, menu_selector(BIProfilePage::onProfilePageStar)));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/layers/StarsInfoPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ bool StarsInfoPopup::init(){
cornerMenu->addChild(cornerFont1);

auto cornerFont2 = CCLabelBMFont::create(fmt::format("Gauntlet: {}", BetterInfo::completedLevelsInStarRange(0, 10, false, GLM->m_gauntletLevels).size() + BetterInfo::completedLevelsInStarRange(0, 10, true, GLM->m_gauntletLevels).size()).c_str(), "goldFont.fnt");
cornerFont2->setLayoutOptions(cornerFont1->getLayoutOptions());
cornerFont2->setLayoutOptions(BetterInfo::copyLayoutOptions(cornerFont1));
cornerFont2->setAnchorPoint(cornerFont1->getAnchorPoint());
cornerFont2->setID("gauntlet-text"_spr);
cornerMenu->addChild(cornerFont2);
Expand Down
134 changes: 75 additions & 59 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,77 +615,93 @@ CCMenuItemSpriteExtra* BetterInfo::replaceWithButton(CCNode* node, CCNode* self,
auto idx = parent->getChildren()->indexOfObject(node);
node->removeFromParent();

for(auto i = idx; i < parent->getChildrenCount(); i++) {
auto child = static_cast<CCNode*>(parent->getChildren()->objectAtIndex(i));
child->setZOrder(child->getZOrder() + 1);
}

auto button = CCMenuItemSpriteExtra::create(
node,
self,
handler
);
button->setLayoutOptions(node->getLayoutOptions());
button->setLayoutOptions(copyLayoutOptions(node));
button->setZOrder(node->getZOrder());
button->setID(node->getID());

parent->getChildren()->insertObject(button, idx);
parent->addChild(button);
parent->updateLayout();

button->setParent(parent);
return button;
}

UnlockType BetterInfo::iconTypeToUnlockType(IconType type) {
//the actual func doesnt work for an unknown reason
int result = 0;

if(parent->isRunning()) {
button->onEnter();
button->onEnterTransitionDidFinish();
switch ((int) type)
{
case 0:
result = 1;
break;
case 1:
result = 4;
break;
case 2:
result = 5;
break;
case 3:
result = 6;
break;
case 4:
result = 7;
break;
case 5:
result = 8;
break;
case 6:
result = 9;
break;
case 7:
result = 13;
break;
case 8:
result = 14;
break;
case 9:
result = 11;
break;
case 0xA:
result = 10;
break;
case 0xB:
result = 12;
break;
case 0xC:
result = 15;
break;
default:
result = 0;
break;
}
return (UnlockType) result;
}

return button;
AxisLayoutOptions* BetterInfo::copyLayoutOptions(CCNode* a) {
return copyLayoutOptions(typeinfo_cast<AxisLayoutOptions*>(a->getLayoutOptions()));
}

UnlockType BetterInfo::iconTypeToUnlockType(IconType type)
{
//the actual func doesnt work for an unknown reason
int result = 0;

switch ((int) type)
{
case 0:
result = 1;
break;
case 1:
result = 4;
break;
case 2:
result = 5;
break;
case 3:
result = 6;
break;
case 4:
result = 7;
break;
case 5:
result = 8;
break;
case 6:
result = 9;
break;
case 7:
result = 13;
break;
case 8:
result = 14;
break;
case 9:
result = 11;
break;
case 0xA:
result = 10;
break;
case 0xB:
result = 12;
break;
case 0xC:
result = 15;
break;
default:
result = 0;
break;
}
return (UnlockType) result;
}
AxisLayoutOptions* BetterInfo::copyLayoutOptions(AxisLayoutOptions* a) {
if(!a) return nullptr;

return AxisLayoutOptions::create()
->setMaxScale(a->getMaxScale())
->setMinScale(a->getMinScale())
->setRelativeScale(a->getRelativeScale())
->setLength(a->getLength())
->setPrevGap(a->getPrevGap())
->setNextGap(a->getNextGap())
->setBreakLine(a->getBreakLine())
->setSameLine(a->getSameLine())
->setScalePriority(a->getScalePriority());
}
3 changes: 3 additions & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ namespace BetterInfo {
CCMenuItemSpriteExtra* replaceWithButton(CCNode* node, CCNode* self, cocos2d::SEL_MenuHandler handler);

UnlockType iconTypeToUnlockType(IconType type);

AxisLayoutOptions* copyLayoutOptions(CCNode* a);
AxisLayoutOptions* copyLayoutOptions(AxisLayoutOptions* a);
}

0 comments on commit 00773ba

Please sign in to comment.