| 57 | } |
| 58 | |
| 59 | bool SongCell::init(SongObject* songInfo) |
| 60 | { |
| 61 | this->setContentSize({ 356, 60 }); |
| 62 | |
| 63 | _layer = ax::Layer::create(); |
| 64 | _layer->setContentSize(this->getContentSize()); |
| 65 | this->addChild(_layer); |
| 66 | |
| 67 | const auto& contentSize = this->getContentSize(); |
| 68 | auto sID = songInfo->_songID; |
| 69 | |
| 70 | |
| 71 | // Song info |
| 72 | auto songName = Label::createWithBMFont(GameToolbox::getTextureString("bigFont.fnt"), fmt::format("{}", LevelTools::getAudioTitle(sID))); |
| 73 | songName->setAnchorPoint({ 0.0, 0.5 }); |
| 74 | songName->setScale(0.7); |
| 75 | songName->setPosition({ 10, (contentSize.height / 2) + 10 }); |
| 76 | |
| 77 | if (songName->getContentSize().width > 240) |
| 78 | songName->setScale(240 / songName->getContentSize().width); |
| 79 | |
| 80 | if (songName->getScale() >= 0.7) |
| 81 | songName->setScale(0.7); |
| 82 | |
| 83 | auto artistName = Label::createWithBMFont(GameToolbox::getTextureString("goldFont.fnt"), fmt::format("By {}", LevelTools::getNameForArtist(LevelTools::getArtistForAudio(sID)))); |
| 84 | artistName->setAnchorPoint({ 0.0, 0.5 }); |
| 85 | artistName->setScale(0.7); |
| 86 | artistName->setPosition(songName->getPosition() + Vec2(2, -21)); |
| 87 | |
| 88 | if (artistName->getContentSize().width > 140) |
| 89 | artistName->setScale(140 / artistName->getContentSize().width); |
| 90 | |
| 91 | if (artistName->getScale() >= 0.7) |
| 92 | artistName->setScale(0.7); |
| 93 | |
| 94 | _layer->addChild(artistName); |
| 95 | _layer->addChild(songName); |
| 96 | |
| 97 | |
| 98 | // View button |
| 99 | auto buttonSprite = ButtonSprite::create("View", 0x32, 0, 0.6, false, GameToolbox::getTextureString("bigFont.fnt"), GameToolbox::getTextureString("GJ_button_01.png"), 30); |
| 100 | |
| 101 | auto button = MenuItemSpriteExtra::create(buttonSprite, [sID](Node* btn) |
| 102 | { |
| 103 | SongInfoLayer::create(sID)->show(); |
| 104 | }); |
| 105 | |
| 106 | auto viewBtnMenu = Menu::create(); |
| 107 | viewBtnMenu->setPosition({ (this->getContentSize().width - ((buttonSprite->getContentSize().width) / 2.f) - 9.f), this->getContentSize().height / 2 }); |
| 108 | viewBtnMenu->addChild(button); |
| 109 | _layer->addChild(viewBtnMenu); |
| 110 | |
| 111 | |
| 112 | // Outlines for the cell |
| 113 | auto color = Color4B(0, 0, 0, 50); |
| 114 | |
| 115 | auto topLine = DrawNode::create(); |
| 116 | topLine->drawRect(Vec2(0, 0), Vec2(contentSize.width, 0), color); |