MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / init

Method init

Source/SongInfoLayer.cpp:61–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61bool SongInfoLayer::init(std::string_view songName, std::string_view artistName, std::string_view urlLink,
62 std::string_view ngArtistLink, std::string_view ytArtistLink, std::string_view fbArtistLink)
63{
64 if (!PopupLayer::init())
65 return false;
66
67 const auto& winSize = Director::getInstance()->getWinSize();
68
69 _downloadLink = urlLink;
70 _ngArtistLink = ngArtistLink;
71 _ytArtistLink = ytArtistLink;
72 _fbArtistLink = fbArtistLink;
73
74 auto bg = ax::ui::Scale9Sprite::create(GameToolbox::getTextureString("GJ_square01.png"), {0, 0, 80, 80});
75 bg->setContentSize({ 420.0, 260.0 });
76 bg->setPosition(winSize / 2);
77
78 this->_mainLayer->addChild(bg);
79
80
81 auto songLabel = Label::createWithBMFont(GameToolbox::getTextureString("bigFont.fnt"), songName);
82 songLabel->setPosition({ winSize.width / 2, (winSize.height / 2) + 90 });
83
84 if (songLabel->getContentSize().width > 300.0f)
85 songLabel->setScale(300 / songLabel->getContentSize().width);
86
87 this->_mainLayer->addChild(songLabel);
88
89 auto artistLabel = Label::createWithBMFont(GameToolbox::getTextureString("goldFont.fnt"), fmt::format("By {}", artistName));
90 artistLabel->setPosition({ winSize.width / 2, (songLabel->getPosition().height + 4) - 30});
91
92 if (artistLabel->getContentSize().width > 300.0f)
93 artistLabel->setScale(300 / artistLabel->getContentSize().width);
94
95 if (artistLabel->getScale() >= 0.8)
96 artistLabel->setScale(0.8);
97
98 this->_mainLayer->addChild(artistLabel);
99
100
101 auto closeBtn = MenuItemSpriteExtra::create(Sprite::createWithSpriteFrameName("GJ_closeBtn_001.png"), [&](Node*)
102 {
103 this->close();
104 });
105 auto closeBtnMenu = Menu::create();
106 closeBtnMenu->addChild(closeBtn);
107
108 closeBtnMenu->setPosition({ (winSize.width / 2) - 210 + 10, (winSize.height / 2) + 130 - 10 });
109
110 this->_mainLayer->addChild(closeBtnMenu);
111
112 auto dls = MenuItemSpriteExtra::create(ButtonSprite::create("Download Soundtrack", 0xDC, 0, 0.6, false, GameToolbox::getTextureString("bigFont.fnt"), GameToolbox::getTextureString("GJ_button_01.png"), 30), [&](Node*)
113 {
114 Application::getInstance()->openURL(_downloadLink);
115 });
116 dls->setPosition(closeBtnMenu->convertToNodeSpace(artistLabel->getPosition()) + Vec2(0, -50));
117 closeBtnMenu->addChild(dls);
118

Callers 1

createMethod · 0.45

Calls 6

createFunction · 0.85
setPositionMethod · 0.80
setScaleMethod · 0.80
emptyMethod · 0.80
Vec2Class · 0.70
closeMethod · 0.45

Tested by

no test coverage detected