Skip to content

Commit a457a78

Browse files
committed
impl coin collection detection pt2
1 parent ee48f84 commit a457a78

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

mod.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@
238238
"type": "bool",
239239
"default": true
240240
},
241+
"showCollectedCoins": {
242+
"name": "Show Collected Coins",
243+
"description": "Shows the coins you had collected during an attempt before dying.\n\nColor of the label adapts to the coin type.",
244+
"type": "bool",
245+
"default": false
246+
},
241247
"noVisibleNewBest": {
242248
"name": "Hide \"New Best\" Screen",
243249
"description": "<cl>Original idea by VolcaroCham.</c>\n\nHides the \"New Best\" screen when getting a new best.\n\nNot sure why anyone would willingly enable this, but now the option exists in this mod. Have fun.",

src/EffectGameObject.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class $modify(MyEffectGameObject, EffectGameObject) {
1010
std::map<GameObject*, bool>& coinsMap = Manager::getSharedInstance()->coins;
1111
if (coinsMap.contains(this)) {
1212
coinsMap.at(this) = true;
13+
// log::info("collected coin number {}", static_cast<int>(std::distance(coinsMap.begin(), coinsMap.find(this))) + 1);
1314
}
1415
}
1516
};

src/PlayLayer.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,38 @@ class $modify(MyPlayLayer, PlayLayer) {
231231
manager->addedNextKeyWhenLabel = true;
232232
}
233233

234+
if (getModBool("showCollectedCoins") && !manager->coins.empty()) {
235+
const bool hasOrbsLabelForReal = (hasOrbsLabel || isFromZilkoMod) && manager->addedNextKeyWhenLabel;
236+
const bool hasKeyLabelForReal = hasKeyLabel && manager->addedNextKeyWhenLabel;
237+
std::string formattedCoinString = "Collected coins: ";
238+
int index = 0;
239+
bool falseIfUserTrueIfRobTop = false;
240+
for (auto [coin, collected] : manager->coins) {
241+
index++;
242+
if (collected) formattedCoinString += "[C]";
243+
else formattedCoinString += "[ ]";
244+
if (index != manager->coins.size()) formattedCoinString += " ";
245+
else falseIfUserTrueIfRobTop = coin->m_objectType == GameObjectType::SecretCoin;
246+
}
247+
248+
CCLabelBMFont* coinsCollectedLabel = CCLabelBMFont::create(formattedCoinString.c_str(), "bigFont.fnt");
249+
250+
if (falseIfUserTrueIfRobTop) coinsCollectedLabel->setColor({255, 215, 0});
251+
else {
252+
if (m_level->m_levelType == GJLevelType::Editor || m_level->m_coinsVerified.value() == 0) coinsCollectedLabel->setColor({255, 215, 0});
253+
else coinsCollectedLabel->setColor({165, 110, 50});
254+
}
255+
256+
coinsCollectedLabel->setID("collected-coins-label"_spr);
257+
coinsCollectedLabel->setTag(8052025);
258+
coinsCollectedLabel->setScale(.75f);
259+
coinsCollectedLabel->setColor({235, 235, 235});
260+
coinsCollectedLabel->setPosition(newBestNodeProbably->getContentSize() / 2.f);
261+
coinsCollectedLabel->setPositionY(coinsCollectedLabel->getPositionY() - 90.f);
262+
if (hasOrbsLabelForReal) coinsCollectedLabel->setPositionY(coinsCollectedLabel->getPositionY() - 18.f);
263+
if (hasKeyLabelForReal) coinsCollectedLabel->setPositionY(coinsCollectedLabel->getPositionY() - 18.f);
264+
}
265+
234266
std::smatch match;
235267
for (CCNode* child : CCArrayExt<CCNode*>(newBestNodeProbably->getChildren())) {
236268
if (child->getID() == "next-key-when-compat-label"_spr) continue;

0 commit comments

Comments
 (0)