1+ #include " RandomAdPopup.hpp"
2+
3+ #include < Geode/Geode.hpp>
4+
5+ using namespace geode ::prelude;
6+
7+ bool RandomAdPopup::setup () {
8+ setID (" ad" _spr);
9+ setTitle (" Sponsored" );
10+
11+ auto textLabel = CCLabelBMFont::create (" Check out this cool level we found!" , " chatFont.fnt" );
12+ textLabel->setID (" message" );
13+ textLabel->ignoreAnchorPointForPosition (false );
14+ textLabel->setPosition ({ m_mainLayer->getScaledContentWidth () / 2 .f , m_mainLayer->getScaledContentHeight () - 12 .5f });
15+ textLabel->setAlignment (CCTextAlignment::kCCTextAlignmentCenter );
16+ textLabel->setAnchorPoint ({ 0.5 , 0.5 });
17+
18+ m_mainLayer->addChild (textLabel);
19+
20+ // featured project thumbnail
21+ auto projThumb = LazySprite::create ({ 192 .f , 108 .f }, true );
22+ projThumb->setID (" thumbnail" );
23+ projThumb->setPosition ({ m_mainLayer->getContentWidth () / 2 .f , m_mainLayer->getContentHeight () * 0 .375f });
24+
25+ projThumb->setLoadCallback ([this , projThumb](Result<> res) {
26+ if (res.isOk ()) {
27+ log::info (" Sprite loaded successfully" );
28+
29+ projThumb->setScale (0.25 );
30+ } else {
31+ log::error (" Sprite failed to load: {}" , res.unwrapErr ());
32+ projThumb->removeMeAndCleanup ();
33+ };
34+ });
35+
36+ projThumb->loadFromUrl (" https://api.cubicstudios.xyz/avalanche/v1/fetch/random-thumbnail" );
37+ if (projThumb) m_mainLayer->addChild (projThumb);
38+
39+ return true ;
40+ };
41+
42+ RandomAdPopup* RandomAdPopup::create () {
43+ auto ret = new RandomAdPopup ();
44+
45+ if (ret && ret->initAnchored (375 .f , 250 .f )) {
46+ ret->autorelease ();
47+ return ret;
48+ };
49+
50+ CC_SAFE_DELETE (ret);
51+ return nullptr ;
52+ };
0 commit comments