Skip to content

Commit 8d596f9

Browse files
committed
a lot of smaller changes to the code
1 parent fa475f6 commit 8d596f9

File tree

4 files changed

+64
-67
lines changed

4 files changed

+64
-67
lines changed

src/DialogLayer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class $modify(DeltaruneDialogLayer, DialogLayer) {
44
struct Fields {
55
DialogObject* dialogObject;
66
FLAlertLayer* alert;
7+
CCLayer* dialogMainLayer;
78
};
89
bool init(DialogObject*, CCArray*, int);
910
void displayNextObject();

src/FLAlertLayer.cpp

Lines changed: 31 additions & 35 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";
@@ -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 = static_cast<CCNode*>(textArea->getChildren()->objectAtIndex(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,7 +173,7 @@ void DeltaruneAlertLayer::show() {
173173
if (!m_mainLayer) return;
174174

175175

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

178178
if (Loader::get()->isModLoaded("user95401.geode-mod-comments") && (title == "Create Comment" || this->getID() == "finish")) {
179179
this->setVisible(false);
@@ -191,16 +191,12 @@ void DeltaruneAlertLayer::show() {
191191
decideToBlockKeys();
192192
changeLook();
193193
}
194-
void DeltaruneAlertLayer::setHeartPosition(CCNode* button) {
194+
void DeltaruneAlertLayer::setHeartPosition(CCMenuItemSpriteExtra* button) {
195195
auto& heart = m_fields->heart;
196-
CCNode* text = nullptr;
197-
for (auto node : (CCArrayExt<CCNode*>) static_cast<CCNode*>(button->getChildren()->objectAtIndex(0))->getChildren()) {
198-
if (auto label = typeinfo_cast<CCLabelBMFont*>(node)) {
199-
text = label;
200-
break;
201-
}
202-
}
196+
CCNode* text = button->getChildByType<ButtonSprite>(0)->getChildByType<CCLabelBMFont>(0);
197+
203198
if (!text) return;
199+
204200
heart->setPositionX(m_buttonMenu->getPositionX() + button->getPositionX() - text->getContentWidth() / 2 - heart->getContentWidth() / 2 - 5);
205201
}
206202

@@ -510,22 +506,22 @@ void DeltaruneAlertLayer::progressText() {
510506
}
511507

512508
void DeltaruneAlertLayer::rollText(float dt) {
513-
int& waitQueue = m_fields->waitQueue;
514-
int& linesProgressed = m_fields->linesProgressed;
515-
int& characterCount = m_fields->characterCount;
516-
int& rollingLine = m_fields->rollingLine;
517-
bool& playedSound = m_fields->playedSound;
518-
bool& doneRolling = m_fields->doneRolling;
519-
bool& rolledPage = m_fields->rolledPage;
520-
float& lostTime = m_fields->lostTime;
521-
float const pause = Mod::get()->getSettingValue<double>("textRollingPause") / 30;
509+
int& waitQueue{ m_fields->waitQueue };
510+
int& linesProgressed{ m_fields->linesProgressed };
511+
int& characterCount{ m_fields->characterCount };
512+
int& rollingLine{ m_fields->rollingLine };
513+
bool& playedSound{ m_fields->playedSound };
514+
bool& doneRolling{ m_fields->doneRolling };
515+
bool& rolledPage{ m_fields->rolledPage };
516+
float& lostTime{ m_fields->lostTime };
517+
double const pause{ Mod::get()->getSettingValue<double>("textRollingPause") / 30 };
522518

523519
if (dt - pause > pause)
524520
lostTime += dt - pause;
525521

526522
bool playSound = true;
527523

528-
for (bool firstRun = true; lostTime >= pause || firstRun;) {
524+
for (bool firstRun{ true }; lostTime >= pause || firstRun;) {
529525
bool newLine = false;
530526
firstRun = false;
531527
if (waitQueue != 0) {
@@ -595,23 +591,23 @@ void DeltaruneAlertLayer::rollText(float dt) {
595591
lostTime -= pause;
596592
}
597593
}
598-
auto nameToFile = m_fields->nameToFile;
599-
std::string const textSound = m_fields->textSound;
600-
std::string const resFolder = Mod::get()->getResourcesDir().string();
601-
std::string path = fmt::format("{}/{}.wav", resFolder, nameToFile[textSound]);
594+
auto& nameToFile = m_fields->nameToFile;
595+
auto const textSound = m_fields->textSound;
596+
auto const resFolder = Mod::get()->getResourcesDir().string();
597+
auto path = fmt::format("{}/{}.wav", resFolder, nameToFile[textSound]);
602598

603599
if (nameToFile.find(textSound) == nameToFile.end()) return;
604600

605601
if (!playSound || playedSound) {
606602
playedSound = false;
607603
return;
608604
}
609-
float pitch = 1;
605+
float pitch{ 1.f };
610606
playedSound = true;
611607

612-
auto& system = m_fields->system;
613-
auto& channel = m_fields->channel;
614-
auto& sound = m_fields->sound;
608+
auto& system{ m_fields->system };
609+
auto& channel{ m_fields->channel };
610+
auto& sound{ m_fields->sound };
615611

616612
if (textSound == "Queen")
617613
pitch = 1 + randomNumberInAGivenRangeThatGetsAddedOrRemovedFromADifferentNumber(0.2f);

src/FLAlertLayer.h

Lines changed: 3 additions & 3 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, std::string> nameToFile;
46-
std::unordered_map<std::string, std::string> nameToSound;
45+
std::unordered_map<std::string_view, std::string_view> nameToFile;
46+
std::unordered_map<std::string_view, std::string_view> nameToSound;
4747
};
4848
void animateBG(float);
4949
void changeBG();
@@ -59,7 +59,7 @@ class $modify(DeltaruneAlertLayer, FLAlertLayer) {
5959
void handleLetters(TextArea*, bool&, bool&);
6060
void rollText(float);
6161
void showButtons();
62-
void setHeartPosition(CCNode*);
62+
void setHeartPosition(CCMenuItemSpriteExtra*);
6363
int getLinesLeft();
6464
void skipText();
6565
int emptyLinesAmount(int = 0);

src/changeDesign.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ void DeltaruneAlertLayer::changeButtons() {
9191
m_buttonMenu->setVisible(false);
9292

9393
if (!m_button2) return;
94-
auto& bg = m_fields->bg;
95-
float const positionStart = bg->getPositionX() - m_buttonMenu->getPositionX() - m_fields->screenSize / 2;
94+
auto& bg{ m_fields->bg };
95+
float const positionStart{ bg->getPositionX() - m_buttonMenu->getPositionX() - m_fields->screenSize / 2 };
9696
m_fields->btn1->setPositionX(positionStart + m_fields->screenSize / 4);
9797
m_fields->btn2->setPositionX(positionStart + (m_fields->screenSize / 4) * 3);
9898

99-
CCArrayExt<CCNode*> buttons = m_buttonMenu->getChildren();
99+
CCArrayExt<CCNode*> buttons{ m_buttonMenu->getChildren() };
100100

101-
auto heart = CCSprite::create("heart.png"_spr);
101+
auto heart{ CCSprite::create("heart.png"_spr) };
102102
heart->setVisible(false);
103103
heart->setPositionY(m_buttonMenu->getPositionY());
104104
heart->setPositionX(m_buttonMenu->getPositionX());
@@ -111,38 +111,38 @@ void DeltaruneAlertLayer::changeButtons() {
111111
}
112112

113113
void DeltaruneAlertLayer::changeTitle() {
114-
CCLabelBMFont* &title = m_fields->title;
115-
auto& bg = m_fields->bg;
114+
auto& title{ m_fields->title };
115+
auto& bg{ m_fields->bg };
116116
title->setAnchorPoint(CCPoint{ 0, 0 });
117117
title->setFntFile("Determination.fnt"_spr);
118118
title->setPosition(CCPoint{ bg->getPositionX() - bg->getContentWidth() / 2 + 24, 138 });
119119
}
120120
void DeltaruneAlertLayer::changeText() {
121-
auto& textArea = m_fields->textArea;
121+
auto& textArea{ m_fields->textArea };
122122
if (!textArea) return;
123123
textArea->removeFromParent();
124124

125-
auto& sound = m_fields->textSound;
126-
auto& size = m_fields->textSize;
127-
auto& nameToSound = m_fields->nameToSound;
128-
bool& noShadow = m_fields->noShadow;
125+
auto& sound{ m_fields->textSound };
126+
auto& size{ m_fields->textSize };
127+
auto& nameToSound{ m_fields->nameToSound };
128+
bool& noShadow{ m_fields->noShadow };
129129

130130

131131
noShadow = Mod::get()->getSettingValue<bool>("noShadow") || sound == "Sans" || sound == "Papyrus";
132132

133-
CCLabelBMFont* star = CCLabelBMFont::create("*", "Determination.fnt"_spr);
134-
CCLabelBMFont* starShadow = nullptr;
133+
CCLabelBMFont* star{ CCLabelBMFont::create("*", "Determination.fnt"_spr) };
134+
CCLabelBMFont* starShadow{ nullptr };
135135
if (!noShadow) starShadow = CCLabelBMFont::create("*", "Determination.fnt"_spr);
136136

137-
auto str = m_fields->text;
138-
auto screenSize = m_fields->screenSize;
139-
auto& bg = m_fields->bg;
140-
std::string titleString = m_fields->title->getString();
137+
auto str{ m_fields->text };
138+
auto screenSize{ m_fields->screenSize };
139+
auto& bg{ m_fields->bg };
140+
std::string_view titleString{ m_fields->title->getString() };
141141

142142
int xOffset = star->getContentWidth();
143143

144144
if (m_fields->dialog) {
145-
if (nameToSound.find(titleString.c_str()) != nameToSound.end())
145+
if (nameToSound.find(titleString) != nameToSound.end())
146146
sound = nameToSound[titleString];
147147
else
148148
sound = "Default";
@@ -158,7 +158,7 @@ void DeltaruneAlertLayer::changeText() {
158158
starShadow->setPositionY(109);
159159
starShadow->setZOrder(0);
160160
starShadow->setID("starShadow"_spr);
161-
auto character = (CCSprite*) starShadow->getChildren()->objectAtIndex(0);
161+
auto character{ starShadow->getChildByType<CCSprite>(0) };
162162
character->setColor({ 15, 15, 127 });
163163
}
164164
std::string font = "Determination.fnt"_spr;
@@ -184,8 +184,8 @@ void DeltaruneAlertLayer::changeText() {
184184
newDesc->setZOrder(textArea->getZOrder());
185185
newDesc->setID("content-text-area");
186186

187-
TextArea* newDescGrad = nullptr;
188-
TextArea* newDescShad = nullptr;
187+
TextArea* newDescGrad{ nullptr };
188+
TextArea* newDescShad{ nullptr };
189189
if (!Mod::get()->getSettingValue<bool>("noGradientOverlay") && sound != "Sans" && sound != "Papyrus") {
190190
newDescGrad = TextArea::create(
191191
str,
@@ -202,7 +202,7 @@ void DeltaruneAlertLayer::changeText() {
202202
newDescGrad->setZOrder(textArea->getZOrder() + 1);
203203
newDescGrad->setID("gradient-overlay"_spr);
204204

205-
CCArrayExt<CCLabelBMFont*> linesGrad = static_cast<CCNode*>(newDescGrad->getChildren()->objectAtIndex(0))->getChildren();
205+
CCArrayExt<CCLabelBMFont*> linesGrad{ newDescGrad->getChildByType<MultilineBitmapFont>(0)->getChildren() };
206206
for (auto line : linesGrad) {
207207
CCArrayExt<CCSprite*> letters = line->getChildren();
208208
for (auto letter : letters) {
@@ -228,16 +228,16 @@ void DeltaruneAlertLayer::changeText() {
228228
newDescShad->setZOrder(textArea->getZOrder() - 1);
229229
newDescShad->setID("shadow"_spr);
230230

231-
CCArrayExt<CCLabelBMFont*> linesShad = static_cast<CCNode*>(newDescShad->getChildren()->objectAtIndex(0))->getChildren();
231+
CCArrayExt<CCLabelBMFont*> linesShad = newDescShad->getChildByType<MultilineBitmapFont>(0)->getChildren();
232232
int i = 0;
233233
for (auto line : linesShad) {
234234
CCArrayExt<CCSprite*> letters = line->getChildren();
235235
int j = 0;
236236
for (auto letter : letters) {
237-
auto origLinesParent = (CCNode*) newDesc->getChildren()->objectAtIndex(0);
238-
auto origLine = (CCLabelBMFont*) origLinesParent->getChildren()->objectAtIndex(i);
239-
auto origChar = (CCSprite*) origLine->getChildren()->objectAtIndex(j);
240-
auto color = origChar->getColor();
237+
auto origLinesParent{ newDesc->getChildByType<MultilineBitmapFont>(0) };
238+
auto origLine{ origLinesParent->getChildByType<CCLabelBMFont>(i) };
239+
auto origChar{ origLine->getChildByType<CCSprite>(j) };
240+
auto color{ origChar->getColor() };
241241

242242
if (color == ccColor3B{ 255,255,255 }) letter->setColor({ 15, 15, 127 });
243243
else if (color == ccColor3B{ 255, 0, 255 }) letter->setColor({ 76, 0, 76 });
@@ -259,7 +259,7 @@ void DeltaruneAlertLayer::changeText() {
259259
i++;
260260
}
261261
}
262-
CCArrayExt<CCLabelBMFont*> lines = static_cast<CCNode*>(newDesc->getChildren()->objectAtIndex(0))->getChildren();
262+
CCArrayExt<CCLabelBMFont*> lines{ newDesc->getChildByType<MultilineBitmapFont>(0)->getChildren() };
263263

264264
for (auto line : lines) {
265265
CCArrayExt<CCSprite*> letters = line->getChildren();
@@ -282,7 +282,7 @@ void DeltaruneAlertLayer::changeText() {
282282
textArea = newDesc;
283283
m_fields->gradientOverlay = newDescGrad;
284284
m_fields->shadow = newDescShad;
285-
float pause = Mod::get()->getSettingValue<double>("textRollingPause");
285+
double pause{ Mod::get()->getSettingValue<double>("textRollingPause") };
286286

287287
m_fields->linesProgressed += emptyLinesAmount();
288288
textArea->setPositionY(textArea->getPositionY() + m_fields->textSize * m_fields->linesProgressed);

0 commit comments

Comments
 (0)