Skip to content

Commit

Permalink
Fix ship positioning in ProfilePage (#4)
Browse files Browse the repository at this point in the history
* Fix ship positioning in ProfilePage

* Fix remaining ProfilePage issues
  • Loading branch information
Cvolton authored Jan 19, 2024
1 parent 4590cb8 commit 56c305d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/ProfilePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ void wrapSimplePlayer(CCNode* player, CCArray* buttons, CCSize size = {42.6f, 42
container->setZOrder(player->getZOrder());
container->setID(player->getID());

player->removeFromParent();
player->setPosition((container->getContentSize() / 2) - CCPoint((size.width - 42.6f) / 2, 0));
container->addChild(player);

parent->removeChild(player);
parent->addChild(container);
}

Expand Down Expand Up @@ -164,6 +164,7 @@ struct ProfilePageIDs : Modify<ProfilePageIDs, ProfilePage> {

bmFont->setID(fmt::format("{}-label", label));
bmFont->setZOrder(0);
bmFont->removeFromParent();

auto bmFontContainer = CCNode::create();
bmFontContainer->setContentSize({bmFont->getScaledContentSize().width, bmFont->getScaledContentSize().height});
Expand All @@ -176,6 +177,7 @@ struct ProfilePageIDs : Modify<ProfilePageIDs, ProfilePage> {

bmFont->setPosition({0, bmFontContainer->getContentSize().height / 2});

icon->removeFromParent();
icon->setID(fmt::format("{}-icon", label));
icon->setZOrder(0);
icon->setLayoutOptions(
Expand All @@ -188,9 +190,6 @@ struct ProfilePageIDs : Modify<ProfilePageIDs, ProfilePage> {
static_cast<CCNode*>(icon->getChildren()->objectAtIndex(0))->setScale(1.f);
}

fontParentNode->removeChild(bmFont);
iconParentNode->removeChild(icon);

if(auto statsMenu = m_mainLayer->getChildByID("stats-menu")) {
statsMenu->addChild(bmFontContainer);
statsMenu->addChild(icon);
Expand All @@ -210,27 +209,32 @@ struct ProfilePageIDs : Modify<ProfilePageIDs, ProfilePage> {
static_cast<CCNode*>(m_buttons->objectAtIndex(idx++))->setID("player-swing");

wrapSimplePlayer(m_mainLayer->getChildByID("player-icon"), m_buttons);

#ifndef GEODE_IS_WINDOWS
wrapSimplePlayer(m_buttonMenu->getChildByID("player-ship"), m_buttons);
wrapSimplePlayer(m_mainLayer->getChildByID("player-ship"), m_buttons);
#endif

wrapSimplePlayer(m_mainLayer->getChildByID("player-ball"), m_buttons);
wrapSimplePlayer(m_mainLayer->getChildByID("player-ufo"), m_buttons);
wrapSimplePlayer(m_mainLayer->getChildByID("player-wave"), m_buttons, {36.6f, 42.6f});
wrapSimplePlayer(m_mainLayer->getChildByID("player-robot"), m_buttons);
wrapSimplePlayer(m_mainLayer->getChildByID("player-spider"), m_buttons);
wrapSimplePlayer(m_mainLayer->getChildByID("player-swing"), m_buttons, {44.6f, 42.6f});

#ifdef GEODE_IS_WINDOWS
if(auto ship = m_buttonMenu->getChildByID("player-ship")) {
ship->setContentSize({42.6f, 42.6f});
static_cast<CCNode*>(ship->getChildren()->objectAtIndex(0))->setPosition(ship->getContentSize() / 2);
}
#endif

auto playerMenu = detachAndCreateMenu(
m_mainLayer, "player-menu",
RowLayout::create()
->setGap(0.f)
->setAxisAlignment(AxisAlignment::Center),
m_mainLayer->getChildByID("player-icon"),
m_mainLayer->getChildByID("player-ship"),
m_buttonMenu->getChildByID("player-ship"),
m_mainLayer->getChildByID("player-ball"),
m_mainLayer->getChildByID("player-ufo"),
Expand Down Expand Up @@ -338,16 +342,16 @@ struct ProfilePageIDs : Modify<ProfilePageIDs, ProfilePage> {

if(auto socialsMenu = m_mainLayer->getChildByID("socials-menu")) {
if(auto youtubeButton = m_buttonMenu->getChildByID("youtube-button")) {
youtubeButton->removeFromParent();
socialsMenu->addChild(youtubeButton);
m_buttonMenu->removeChild(youtubeButton, false);
}
if(auto twitterButton = m_buttonMenu->getChildByID("twitter-button")) {
twitterButton->removeFromParent();
socialsMenu->addChild(twitterButton);
m_buttonMenu->removeChild(twitterButton, false);
}
if(auto twitchButton = m_buttonMenu->getChildByID("twitch-button")) {
twitchButton->removeFromParent();
socialsMenu->addChild(twitchButton);
m_buttonMenu->removeChild(twitchButton, false);
}
socialsMenu->updateLayout();
}
Expand Down

0 comments on commit 56c305d

Please sign in to comment.