Skip to content

Commit b165bfb

Browse files
committed
PurchaseItemPopup support
1 parent 5587fda commit b165bfb

File tree

9 files changed

+170
-83
lines changed

9 files changed

+170
-83
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_library(${PROJECT_NAME} SHARED
1111
src/DialogLayer.cpp
1212
src/CCKeyboardDispatcher.cpp
1313
src/changeDesign.cpp
14+
src/PurchaseItemPopup.cpp
1415
# Add any extra C++ source files here
1516
)
1617

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### v1.4.0
2+
- Made purchase popups look Deltarune as well!
3+
14
### v1.3.0
25
- Added Custom Keybinds support to MacOS!
36

mod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "4.2.0",
2+
"geode": "4.2.1",
33
"gd": {
44
"win": "2.2074",
55
"android": "2.2074",
@@ -8,7 +8,7 @@
88
},
99
"id": "timestepyt.deltarune_textboxes",
1010
"name": "Deltarune Textboxes",
11-
"version": "v1.3.0",
11+
"version": "v1.4.0-alpha.1",
1212
"developer": "TimeStepYT",
1313
"description": "Makes Popups look like Deltarune",
1414
"links": {

src/FLAlertLayer.cpp

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ float randomNumberInAGivenRangeThatGetsAddedOrRemovedFromADifferentNumber(float
88
}
99

1010
void DeltaruneAlertLayer::initMaps() {
11-
auto& nameToFile{ m_fields->nameToFile };
12-
auto& nameToSound{ m_fields->nameToSound };
11+
auto& nameToFile = m_fields->nameToFile;
12+
auto& nameToSound = m_fields->nameToSound;
1313

1414
nameToFile["Default"] = "SND_TXT1";
1515
nameToFile["Typewriter"] = "SND_TXT2";
@@ -50,14 +50,14 @@ bool DeltaruneAlertLayer::init(FLAlertLayerProtocol* delegate, char const* title
5050
if (!FLAlertLayer::init(delegate, title, desc, btn1, btn2, width, scroll, height, textScale)) return false;
5151

5252
NodeIDs::provideFor(this);
53-
setID("FLAlertLayer");
53+
this->setID("FLAlertLayer");
5454

5555
std::string_view descString = desc;
5656
bool const isEmpty = std::ranges::all_of(descString, [](unsigned char c) {
5757
return std::isspace(c);
5858
});
5959
bool const prismLoaded = Loader::get()->isModLoaded("firee.prism");
60-
std::string_view prismString{ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" }; // probably the easiest way to detect a Prism Menu alert :3
60+
std::string_view prismString = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; // probably the easiest way to detect a Prism Menu alert :3
6161
if ((prismLoaded && desc == prismString) || isEmpty) {
6262
m_fields->incompatible = true;
6363
return true;
@@ -148,18 +148,18 @@ void DeltaruneAlertLayer::onBtn1(CCObject* sender) {
148148
}
149149

150150
int DeltaruneAlertLayer::getLinesLeft() {
151-
auto& textArea{ m_fields->textArea };
151+
auto& textArea = m_fields->textArea;
152152
if (!m_fields->textAreaClippingNode) return 0;
153153
if (!textArea) return 0;
154154

155-
auto bitmapFont{ textArea->getChildByType<MultilineBitmapFont>(0) };
156-
CCArrayExt<CCLabelBMFont*> content{ bitmapFont->getChildren() };
155+
auto bitmapFont = textArea->getChildByType<MultilineBitmapFont>(0);
156+
CCArrayExt<CCLabelBMFont*> content = bitmapFont->getChildren();
157157
return content.size() - m_fields->linesProgressed;
158158
}
159159
void DeltaruneAlertLayer::show() {
160-
bool& showing{ m_fields->showing };
161-
bool& incompatible{ m_fields->incompatible };
162-
auto& titleNode{ m_fields->title };
160+
bool& showing = m_fields->showing;
161+
bool& incompatible = m_fields->incompatible;
162+
auto& titleNode = m_fields->title;
163163

164164
FLAlertLayer::show();
165165

@@ -173,9 +173,9 @@ void DeltaruneAlertLayer::show() {
173173
if (!m_mainLayer) return;
174174

175175

176-
auto title{ std::string_view(titleNode->getString()) };
176+
auto title = titleNode->getString();
177177

178-
if (Loader::get()->isModLoaded("user95401.geode-mod-comments") && (title == "Create Comment" || this->getID() == "finish")) {
178+
if (Loader::get()->isModLoaded("user95401.geode-mod-comments") && (strcmp(title, "Create Comment") == 0 || this->getID() == "finish")) {
179179
this->setVisible(false);
180180
Loader::get()->queueInMainThread([this] {
181181
this->setVisible(true);
@@ -192,16 +192,18 @@ void DeltaruneAlertLayer::show() {
192192
changeLook();
193193
}
194194
void DeltaruneAlertLayer::setHeartPosition(CCMenuItemSpriteExtra* button) {
195-
auto& heart{ m_fields->heart };
196-
auto text{ button->getChildByType<ButtonSprite>(0)->getChildByType<CCLabelBMFont>(0) };
195+
auto& heart = m_fields->heart;
196+
auto text = button->getChildByType<ButtonSprite>(0)->getChildByType<CCLabelBMFont>(0);
197197

198198
if (!text) return;
199199

200-
heart->setPositionX(m_buttonMenu->getPositionX() + button->getPositionX() - text->getContentWidth() / 2 - heart->getContentWidth() / 2 - 5);
200+
auto xPos = m_buttonMenu->getPositionX() + button->getPositionX() - text->getContentWidth() / 2 - heart->getContentWidth() / 2 - 5;
201+
202+
heart->setPositionX(xPos);
201203
}
202204

203205
void DeltaruneAlertLayer::clickedOnButton(CCMenuItemSpriteExtra* btn, ButtonSprite* buttonSprite, int btnSelected) {
204-
auto label{ buttonSprite->getChildByType<CCLabelBMFont>(0) };
206+
auto label = buttonSprite->getChildByType<CCLabelBMFont>(0);
205207
if (!label) return;
206208
if (btn->isSelected()) {
207209
label->setColor(ccColor3B{ 255, 255, 0 });
@@ -226,7 +228,7 @@ bool DeltaruneAlertLayer::ccTouchBegan(CCTouch* touch, CCEvent* event) {
226228

227229
if (!btn1 || !btn2) return ret;
228230
if (!btn1->isSelected() && !btn2->isSelected()) return ret;
229-
231+
230232
clickedOnButton(btn1, m_button1, 1);
231233
clickedOnButton(btn2, m_button2, 2);
232234
return ret;
@@ -360,14 +362,14 @@ void DeltaruneAlertLayer::skipText() {
360362
}
361363

362364
int DeltaruneAlertLayer::emptyLinesAmount(int offset) {
363-
auto& textArea{ m_fields->textArea };
364-
auto& linesProgressed{ m_fields->linesProgressed };
365-
auto fontNode{ textArea->getChildByType<MultilineBitmapFont>(0) };
366-
int lines{ 0 };
365+
auto& textArea = m_fields->textArea;
366+
auto& linesProgressed = m_fields->linesProgressed;
367+
auto fontNode = textArea->getChildByType<MultilineBitmapFont>(0);
368+
int lines = 0;
367369
while (true) {
368370
if (linesProgressed + lines + offset >= fontNode->getChildrenCount()) break;
369371

370-
auto topLine{ fontNode->getChildByType<CCLabelBMFont>(linesProgressed + lines + offset) };
372+
auto topLine = fontNode->getChildByType<CCLabelBMFont>(linesProgressed + lines + offset);
371373
if (!topLine) break;
372374

373375
std::string_view topLineString = topLine->getString();
@@ -378,8 +380,8 @@ int DeltaruneAlertLayer::emptyLinesAmount(int offset) {
378380

379381
lines++;
380382

381-
auto star{ m_mainLayer->getChildByID("star"_spr) };
382-
auto starShadow{ m_mainLayer->getChildByID("starShadow"_spr) };
383+
auto star = m_mainLayer->getChildByID("star"_spr);
384+
auto starShadow = m_mainLayer->getChildByID("starShadow"_spr);
383385

384386
if (star) star->setVisible(true);
385387
if (starShadow) starShadow->setVisible(true);
@@ -392,21 +394,21 @@ void DeltaruneAlertLayer::progressText() {
392394
if (!m_buttonMenu) return;
393395
if (!m_fields->textAreaClippingNode) return;
394396

395-
auto& textArea{ m_fields->textArea };
396-
auto& btn1{ m_fields->btn1 };
397-
auto& btn2{ m_fields->btn2 };
398-
auto& shadow{ m_fields->shadow };
399-
auto& gradientOverlay{ m_fields->gradientOverlay };
400-
int& btnSelected{ m_fields->btnSelected };
401-
int& linesProgressed{ m_fields->linesProgressed };
402-
bool& done{ m_fields->done };
403-
bool& noShadow{ m_fields->noShadow };
397+
auto& textArea = m_fields->textArea;
398+
auto& btn1 = m_fields->btn1;
399+
auto& btn2 = m_fields->btn2;
400+
auto& shadow = m_fields->shadow;
401+
auto& gradientOverlay = m_fields->gradientOverlay;
402+
int& btnSelected = m_fields->btnSelected;
403+
int& linesProgressed = m_fields->linesProgressed;
404+
bool& done = m_fields->done;
405+
bool& noShadow = m_fields->noShadow;
404406

405407
if (!textArea) return;
406408

407409
if (getLinesLeft() - emptyLinesAmount(3) <= 3) {
408410
if (!m_button2) {
409-
auto dialogLayer{ m_fields->dialogLayer };
411+
auto& dialogLayer = m_fields->dialogLayer;
410412
done = true;
411413
if (m_fields->dialog && dialogLayer) {
412414
dialogLayer->keyBackClicked();
@@ -490,15 +492,15 @@ void DeltaruneAlertLayer::progressText() {
490492
}
491493

492494
void DeltaruneAlertLayer::rollText(float dt) {
493-
int& waitQueue{ m_fields->waitQueue };
494-
int& linesProgressed{ m_fields->linesProgressed };
495-
int& characterCount{ m_fields->characterCount };
496-
int& rollingLine{ m_fields->rollingLine };
497-
bool& playedSound{ m_fields->playedSound };
498-
bool& doneRolling{ m_fields->doneRolling };
499-
bool& rolledPage{ m_fields->rolledPage };
500-
float& lostTime{ m_fields->lostTime };
501-
double const pause{ Mod::get()->getSettingValue<double>("textRollingPause") / 30 };
495+
int& waitQueue = m_fields->waitQueue;
496+
int& linesProgressed = m_fields->linesProgressed;
497+
int& characterCount = m_fields->characterCount;
498+
int& rollingLine = m_fields->rollingLine;
499+
bool& playedSound = m_fields->playedSound;
500+
bool& doneRolling = m_fields->doneRolling;
501+
bool& rolledPage = m_fields->rolledPage;
502+
float& lostTime = m_fields->lostTime;
503+
double const pause = Mod::get()->getSettingValue<double>("textRollingPause") / 30;
502504

503505
if (dt - pause > pause)
504506
lostTime += dt - pause;
@@ -528,9 +530,9 @@ void DeltaruneAlertLayer::rollText(float dt) {
528530
CCArrayExt<CCLabelBMFont*> lines = textArea->getChildByType<MultilineBitmapFont>(0)->getChildren();
529531
int currentLine = linesProgressed + rollingLine;
530532
if (currentLine < lines.size() && currentLine < linesProgressed + 3) {
531-
auto line{ lines[currentLine] };
532-
CCArrayExt<CCNode*> letters{ line->getChildren() };
533-
auto letter{ letters[characterCount] };
533+
auto line = lines[currentLine];
534+
CCArrayExt<CCNode*> letters = line->getChildren();
535+
auto letter = letters[characterCount];
534536
if (letter->isVisible()) {
535537
unschedule(schedule_selector(DeltaruneAlertLayer::rollText));
536538
doneRolling = true;
@@ -577,26 +579,26 @@ void DeltaruneAlertLayer::rollText(float dt) {
577579
}
578580
auto& nameToFile = m_fields->nameToFile;
579581
auto const textSound = m_fields->textSound;
580-
auto const resFolder = Mod::get()->getResourcesDir().string();
581-
auto path = fmt::format("{}/{}.wav", resFolder, nameToFile[textSound]);
582+
auto const resFolder = Mod::get()->getResourcesDir();
583+
auto path = resFolder / fmt::format("{}.wav", nameToFile[textSound]);
582584

583585
if (nameToFile.find(textSound) == nameToFile.end()) return;
584586

585587
if (!playSound || playedSound) {
586588
playedSound = false;
587589
return;
588590
}
589-
float pitch{ 1.f };
591+
float pitch = 1.f;
590592
playedSound = true;
591593

592-
auto& system{ m_fields->system };
593-
auto& channel{ m_fields->channel };
594-
auto& sound{ m_fields->sound };
594+
auto& system = m_fields->system;
595+
auto& channel = m_fields->channel;
596+
auto& sound = m_fields->sound;
595597

596598
if (textSound == "Queen")
597599
pitch = 1 + randomNumberInAGivenRangeThatGetsAddedOrRemovedFromADifferentNumber(0.2f);
598600

599-
system->createSound(path.c_str(), FMOD_DEFAULT, nullptr, &sound);
601+
system->createSound(path.string().c_str(), FMOD_DEFAULT, nullptr, &sound);
600602
system->playSound(sound, nullptr, false, &channel);
601603
channel->setPitch(pitch);
602604
channel->setVolume(FMODAudioEngine::sharedEngine()->m_sfxVolume);

src/FLAlertLayer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class $modify(DeltaruneAlertLayer, FLAlertLayer) {
4242
std::vector<std::string> titles;
4343
std::string text = "";
4444
std::string textSound = Mod::get()->getSettingValue<std::string>("textSound");
45-
std::unordered_map<std::string_view, std::string_view> nameToFile;
46-
std::unordered_map<std::string_view, std::string_view> nameToSound;
45+
std::unordered_map<std::string, std::string_view> nameToFile;
46+
std::unordered_map<std::string, std::string_view> nameToSound;
4747
};
4848
void animateBG(float);
4949
void changeBG();

src/PurchaseItemPopup.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include "PurchaseItemPopup.h"
2+
3+
void DeltarunePurchaseItemPopup::handlePurchasePopup() {
4+
auto& quickPopup = m_fields->quickPopup;
5+
6+
this->setVisible(false);
7+
quickPopup->setTouchPriority(this->getTouchPriority() + 1);
8+
quickPopup->setVisible(true);
9+
}
10+
11+
void DeltarunePurchaseItemPopup::onBuy() {
12+
this->onPurchase(nullptr);
13+
}
14+
15+
void DeltarunePurchaseItemPopup::onCancel() {
16+
this->onClose(nullptr);
17+
}
18+
19+
bool DeltarunePurchaseItemPopup::init(GJStoreItem* p0) {
20+
if (!PurchaseItemPopup::init(p0)) return false;
21+
22+
auto title = this->m_mainLayer->getChildByType<CCLabelBMFont>(0)->getString();
23+
std::string content = "";
24+
25+
auto textArea = this->m_mainLayer->getChildByType<TextArea>(0);
26+
27+
CCArrayExt<CCLabelBMFont*> contentParent = textArea->getChildByType<MultilineBitmapFont>(0)->getChildren();
28+
for (auto label : contentParent) {
29+
content.append(label->getString());
30+
}
31+
32+
auto menu = this->m_mainLayer->getChildByType<CCMenu>(0);
33+
34+
if (!menu) return true;
35+
36+
auto button1 = menu->getChildByType<CCMenuItemSpriteExtra>(0)->getChildByType<ButtonSprite>(0);
37+
auto button2 = menu->getChildByType<CCMenuItemSpriteExtra>(1)->getChildByType<ButtonSprite>(0);
38+
39+
if (!button1 || !button2) return true;
40+
41+
auto button1String = button1->getChildByType<CCLabelBMFont>(0)->getString();
42+
auto button2String = button2->getChildByType<CCLabelBMFont>(0)->getString();
43+
44+
auto quickPopup = geode::createQuickPopup(
45+
title,
46+
content,
47+
button1String, button2String,
48+
[this](auto, bool btn2) {
49+
if (btn2) {
50+
onBuy();
51+
return;
52+
}
53+
onCancel();
54+
}
55+
);
56+
57+
this->setKeyboardEnabled(false);
58+
this->setKeypadEnabled(false);
59+
this->setTouchEnabled(false);
60+
this->setMouseEnabled(false);
61+
62+
quickPopup->setVisible(false);
63+
m_fields->quickPopup = quickPopup;
64+
Loader::get()->queueInMainThread([this] { // for some reason, making it invisible immediately doesn't work
65+
this->handlePurchasePopup();
66+
});
67+
68+
return true;
69+
}

src/PurchaseItemPopup.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "include.h"
2+
3+
class $modify(DeltarunePurchaseItemPopup, PurchaseItemPopup) {
4+
struct Fields {
5+
FLAlertLayer* quickPopup = nullptr;
6+
};
7+
void handlePurchasePopup();
8+
void onCancel();
9+
void onBuy();
10+
bool init(GJStoreItem* p0);
11+
};

0 commit comments

Comments
 (0)