Skip to content

Commit

Permalink
fix collab and high obj icons not getting offset on username load
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Dec 9, 2023
1 parent 91f3136 commit 32de836
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,21 +420,32 @@ void BetterInfo::reloadUsernames(LevelBrowserLayer* levelBrowserLayer) {
auto playerName = static_cast<CCMenuItemSpriteExtra*>(menu->getChildren()->objectAtIndex(1));
auto textNode = static_cast<CCLabelBMFont*>(playerName->getChildren()->objectAtIndex(0));

float oldXSize = textNode->getScaledContentSize().width;

auto userName = GameLevelManager::sharedState()->userNameForUserID(levelCell->m_level->m_userID);

auto oldString = std::string(textNode->getString());
auto newString = fmt::format("By {}", std::string(userName));

size_t difference = newString.length() - oldString.length();

textNode->setString(newString.c_str());
playerName->setContentSize(textNode->getContentSize() * textNode->getScale());
//playerName->setPositionX(playerName->getContentSize().width / 2);
auto winSize = CCDirector::sharedDirector()->getWinSize();
//playerName->setPositionX((-(winSize.width / 2) + 23.5) + (playerName->getContentSize().width / 2));
playerName->setPositionX((-285.5 + 23.5) + (playerName->getContentSize().width / 2));
textNode->setPositionX(playerName->getContentSize().width / 2);

float difference = textNode->getScaledContentSize().width - oldXSize;

for(unsigned int i = 0; i < layer->getChildrenCount(); i++){
CCSprite* node = typeinfo_cast<CCSprite*>(layer->getChildren()->objectAtIndex(i));
if(node == nullptr) continue;

if(isSprite(node, "collaborationIcon_001.png") || isSprite(node, "highObjectIcon_001.png")) {

node->setPositionX(node->getPositionX() + difference);

}
}

levelCell->m_level->m_creatorName = userName;

}
Expand Down Expand Up @@ -623,4 +634,11 @@ bool BetterInfo::isHoveringNode(CCNode* target) {
);

return bounds.containsPoint(touchPos);
}

bool BetterInfo::isSprite(CCSprite* sprite, const char* name) {
auto cache = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name);
if(!cache) return false;

return cache->getTexture() == sprite->getTexture() && cache->getRect() == sprite->getTextureRect();
}
2 changes: 2 additions & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ namespace BetterInfo {

void loadImportantNotices(CCLayer* layer);
bool isHoveringNode(CCNode* target);

bool isSprite(CCSprite* sprite, const char* name);
}

0 comments on commit 32de836

Please sign in to comment.