Skip to content

Commit 27bd1c6

Browse files
committed
there's a chance alpha might not like this
1 parent 525782a commit 27bd1c6

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

src/Manager.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class Manager {
2323

2424
bool completedJDDNCheck = false;
2525

26+
bool hasNextKeyWhenLoaded = false;
27+
bool addedNextKeyWhenLabel = false;
28+
2629
float lastDeathPercent = -10.f;
2730

2831
static Manager* getSharedInstance() {

src/MenuLayer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ class $modify(MyMenuLayer, MenuLayer) {
1616
}
1717
}
1818
bool init() {
19-
bool result = MenuLayer::init();
19+
if (!MenuLayer::init()) return false;
2020
if (!manager->completedJDDNCheck && getBool("enabled") && getBool("checkJustDont")) {
2121
MyMenuLayer::forceEnableJustDont();
2222
}
2323
manager->completedJDDNCheck = true;
24-
return result;
24+
manager->hasNextKeyWhenLoaded = Loader::get()->isModLoaded("alphalaneous.next_key_when");
25+
return true;
2526
}
2627
};

src/PlayLayer.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class $modify(MyPlayLayer, PlayLayer) {
1818
static bool isNewBest(PlayLayer* pl) {
1919
return pl->getCurrentPercentInt() > pl->m_level->m_normalPercent.value();
2020
}
21+
void resetLevel() {
22+
PlayLayer::resetLevel();
23+
Manager::getSharedInstance()->addedNextKeyWhenLabel = false;
24+
}
2125
void onQuit() {
2226
PlayLayer::onQuit();
2327
Manager::getSharedInstance()->lastDeathPercent = -10.f;
@@ -37,35 +41,52 @@ class $modify(MyPlayLayer, PlayLayer) {
3741
void updateProgressbar() {
3842
PlayLayer::updateProgressbar();
3943
if (!getModBool("enabled") || m_level->isPlatformer() || !m_player1->m_isDead || m_isPlatformer) return;
40-
CCNode* allTheGoodStuff = nullptr;
44+
CCNode* newBestNodeProbably = nullptr;
45+
bool foundCurrencyRewardLayer = false;
46+
const bool isNewBest = MyPlayLayer::isNewBest(this);
4147
for (int i = static_cast<int>(getChildrenCount() - 1); i >= 0; i--) {
4248
// NEW [good]: int i = getChildrenCount() - 1; i >= 0; i--
4349
// ORIG [bad]: int i = getChildrenCount(); i-- > 0;
4450
auto theLastCCNode = typeinfo_cast<CCNode*>(this->getChildren()->objectAtIndex(i));
4551
if (typeinfo_cast<CurrencyRewardLayer*>(theLastCCNode)) {
4652
// hide CurrencyRewardLayer
47-
if (getModBool("currencyLayer")) theLastCCNode->setVisible(false);
53+
if (getModBool("currencyLayer")) {
54+
foundCurrencyRewardLayer = true;
55+
theLastCCNode->setVisible(false);
56+
}
4857
continue;
4958
}
5059
if (!theLastCCNode || theLastCCNode == this->m_uiLayer) continue; // skip UILayer
5160
if (theLastCCNode->getZOrder() != 100) continue;
5261
if (theLastCCNode->getChildrenCount() < 2) continue;
5362
if (getModBool("noVisibleNewBest")) return theLastCCNode->setVisible(false);
54-
allTheGoodStuff = theLastCCNode;
63+
newBestNodeProbably = theLastCCNode;
5564
break;
5665
}
57-
if (!allTheGoodStuff) return;
58-
for (const auto child : CCArrayExt<CCNode*>(allTheGoodStuff->getChildren())) {
66+
if (!newBestNodeProbably) return;
67+
if (manager->hasNextKeyWhenLoaded && getModBool("currencyLayer") && !manager->addedNextKeyWhenLabel && m_level->m_stars.value() > 1 && foundCurrencyRewardLayer) {
68+
CCLabelBMFont* nextKeyWhen = CCLabelBMFont::create(fmt::format("Key: {}/500", GameStatsManager::sharedState()->getTotalCollectedCurrency() % 500).c_str(), "bigFont.fnt");
69+
nextKeyWhen->setID("next-key-when-compat-label"_spr);
70+
nextKeyWhen->setTag(8042025);
71+
nextKeyWhen->setScale(.5f);
72+
nextKeyWhen->setColor({45, 255, 255});
73+
nextKeyWhen->setPosition(newBestNodeProbably->getContentSize() / 2.f);
74+
nextKeyWhen->setPositionY(nextKeyWhen->getPositionY() - 90.f);
75+
newBestNodeProbably->addChild(nextKeyWhen);
76+
manager->addedNextKeyWhenLabel = true;
77+
}
78+
for (CCNode* child : CCArrayExt<CCNode*>(newBestNodeProbably->getChildren())) {
79+
if (child->getID() == "next-key-when-compat-label"_spr) continue;
5980
const auto hopefullyALabel = typeinfo_cast<CCLabelBMFont*>(child);
60-
if (!hopefullyALabel) continue;
81+
if (!hopefullyALabel || hopefullyALabel->getTag() == 8042025) continue;
6182
std::string nodeString = hopefullyALabel->getString();
6283
std::string fontFile = hopefullyALabel->getFntFile();
6384
if (nodeString.ends_with("%") && fontFile == "bigFont.fnt") {
6485
// this is the node displaying where you died as a new best
65-
if (MyPlayLayer::isNewBest(this) && getModBool("accuratePercent")) return hopefullyALabel->setString(fmt::format("{:.{}f}%", getCurrentPercent(), getModInt("accuracy")).c_str());
86+
if (isNewBest && getModBool("accuratePercent")) return hopefullyALabel->setString(fmt::format("{:.{}f}%", getCurrentPercent(), getModInt("accuracy")).c_str());
6687
// i have to do all of this because robtop's wonderful technology shows percent from previous death if i dont include all of this
6788
std::smatch match;
68-
if (!std::regex_match(nodeString, match, manager->percentRegex)) { continue; }
89+
if (!std::regex_match(nodeString, match, manager->percentRegex)) continue;
6990
auto percent = std::regex_replace(nodeString, std::regex("%"), "");
7091
auto percentAsInt = utils::numFromString<int>(percent);
7192
if (percentAsInt.isErr()) continue;

0 commit comments

Comments
 (0)