Skip to content

Commit 4f4bce1

Browse files
committed
ads lol
1 parent 0d9a4de commit 4f4bce1

3 files changed

Lines changed: 76 additions & 1 deletion

File tree

src/modified/PlayLayer.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "../utils/LevelManager.hpp"
2+
#include "../popups/RandomAdPopup.hpp"
23

34
#include <fmt/core.h>
45

@@ -18,6 +19,8 @@ class $modify(HorriblePlayLayer, PlayLayer) {
1819
struct Fields {
1920
GameObject* m_destroyingObject;
2021

22+
RandomAdPopup* m_currentAd = nullptr;
23+
2124
CCLabelBMFont* m_oxygenLabel = nullptr;
2225

2326
float m_oxygenLevel = 100.f;
@@ -96,13 +99,20 @@ class $modify(HorriblePlayLayer, PlayLayer) {
9699

97100
if (horribleMod->getSavedValue<bool>("math-quiz", false)) {
98101
if ((rand() % 10) == 0) {
99-
log::warn("richard was here");
102+
if (m_isPracticeMode) log::warn("richard was here");
100103
};
101104
};
102105

103106
if (horribleMod->getSavedValue<bool>("ads", false)) {
104107
if ((rand() % 5) == 0) {
105108
log::warn("ad time!");
109+
110+
if (!m_fields->m_currentAd) {
111+
if (auto popup = RandomAdPopup::create()) {
112+
m_fields->m_currentAd = popup;
113+
m_fields->m_currentAd->show();
114+
};
115+
};
106116
};
107117
};
108118

src/popups/RandomAdPopup.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
};

src/popups/RandomAdPopup.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include <Geode/Geode.hpp>
4+
5+
using namespace geode::prelude;
6+
7+
class RandomAdPopup : public Popup<> {
8+
protected:
9+
bool setup() override;
10+
11+
public:
12+
static RandomAdPopup* create();
13+
};

0 commit comments

Comments
 (0)